-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07977b2
commit dcfbb65
Showing
9 changed files
with
288 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { SmartaccountParams } from '../../../core/smartaccount/v1/models/SmartaccountParams'; | ||
import { LCDClient } from '../LCDClient'; | ||
import { SmartaccountAPI } from './SmartaccountAPI'; | ||
|
||
const lcd = new LCDClient({ | ||
'pisco-1': { | ||
chainID: 'pisco-1', | ||
gasAdjustment: 1.5, | ||
gasPrices: { | ||
uluna: 0.02, | ||
}, | ||
lcd: 'http://localhost:1317/', | ||
prefix: 'terra', | ||
}, | ||
}); | ||
const smartaccount = new SmartaccountAPI(lcd); | ||
|
||
describe('SmartaccountAPI', () => { | ||
it('assert the module params', async () => { | ||
const res = await smartaccount.params('pisco-1'); | ||
|
||
expect(res).toStrictEqual(new SmartaccountParams()); | ||
|
||
expect(res.toData()).toEqual({}); | ||
}); | ||
|
||
// TODO: there must be a smart account created to test this | ||
// it('assert the account setting', async () => { | ||
// const res = await smartaccount.setting('a'); | ||
// // TODO: call | ||
// const setting = new Setting('a', [], [], [], true); | ||
// expect(res).toStrictEqual(setting); | ||
// expect(res.toData()).toEqual(setting); | ||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Setting } from 'core/smartaccount/v1/models/Setting'; | ||
import { AccAddress } from '../../../core'; | ||
import { LCDClient } from '../LCDClient'; | ||
import { BaseAPI } from './BaseAPI'; | ||
import { SmartaccountParams } from 'core/smartaccount'; | ||
|
||
export class SmartaccountAPI extends BaseAPI { | ||
constructor(public lcd: LCDClient) { | ||
super(lcd.apiRequesters, lcd.config); | ||
} | ||
|
||
/** | ||
* Query the feemarket module params. | ||
* | ||
* @tags Query | ||
* @name params | ||
* @request GET:/terra/smartaccount/v1/params | ||
*/ | ||
public async params(chainId: string): Promise<SmartaccountParams> { | ||
const res = await this.getReqFromChainID(chainId).get<{ | ||
params: SmartaccountParams.Data; | ||
}>(`/terra/smartaccount/v1/params`); | ||
|
||
return SmartaccountParams.fromData(res.params); | ||
} | ||
|
||
/** | ||
* Query the feemarket module setting for account. | ||
* | ||
* @tags Query | ||
* @name setting | ||
* @request GET:/terra/smartaccount/v1/setting/{account} | ||
*/ | ||
public async setting(account: AccAddress): Promise<Setting> { | ||
const res = await this.getReqFromAddress(account).get<{ | ||
setting: Setting.Data; | ||
}>(`/terra/smartaccount/v1/setting/${account}`); | ||
|
||
return Setting.fromData(res.setting); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './v1/msgs'; | ||
export * from './v1/models/AuthorizationMsg'; | ||
export * from './v1/models/Setting'; | ||
export * from './v1/models/SmartaccountParams'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { Any } from '@terra-money/terra.proto/google/protobuf/any'; | ||
import { Setting as Setting_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/setting'; | ||
import { JSONSerializable } from '../../../../util/json'; | ||
import { AuthorizationMsg } from './AuthorizationMsg'; | ||
|
||
/** | ||
* Setting holds the contract address and initial message | ||
* to be passed to the contract for custom authorization | ||
*/ | ||
export class Setting extends JSONSerializable< | ||
Setting.Amino, | ||
Setting.Data, | ||
Setting.Proto | ||
> { | ||
/** | ||
* | ||
* @param contractAddress contract address of authorization logic | ||
* @param initMsg initial message to be passed to the contract | ||
*/ | ||
constructor( | ||
public owner: string, | ||
public authorization: AuthorizationMsg[], | ||
public preTransaction: string[], | ||
public postTransaction: string[], | ||
public fallback: boolean | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromAmino(data: Setting.Amino): Setting { | ||
const { | ||
value: { | ||
owner, | ||
authorization, | ||
preTransaction, | ||
postTransaction, | ||
fallback, | ||
}, | ||
} = data; | ||
return new Setting( | ||
owner, | ||
authorization, | ||
preTransaction, | ||
postTransaction, | ||
fallback | ||
); | ||
} | ||
|
||
public toAmino(): Setting.Amino { | ||
const { owner, authorization, preTransaction, postTransaction, fallback } = | ||
this; | ||
return { | ||
value: { | ||
owner, | ||
authorization, | ||
preTransaction, | ||
postTransaction, | ||
fallback, | ||
}, | ||
}; | ||
} | ||
|
||
public static fromData(data: Setting.Data): Setting { | ||
const { | ||
owner, | ||
authorization, | ||
pre_transaction, | ||
post_transaction, | ||
fallback, | ||
} = data; | ||
return new Setting( | ||
owner, | ||
authorization, | ||
pre_transaction, | ||
post_transaction, | ||
fallback | ||
); | ||
} | ||
|
||
public toData(): Setting.Data { | ||
const { owner, authorization, preTransaction, postTransaction, fallback } = | ||
this; | ||
return { | ||
owner, | ||
authorization, | ||
pre_transaction: preTransaction, | ||
post_transaction: postTransaction, | ||
fallback, | ||
}; | ||
} | ||
|
||
public static fromProto(proto: Setting.Proto): Setting { | ||
return new Setting( | ||
proto.owner, | ||
proto.authorization.map(AuthorizationMsg.fromProto), | ||
proto.preTransaction, | ||
proto.postTransaction, | ||
proto.fallback | ||
); | ||
} | ||
|
||
public toProto(): Setting.Proto { | ||
const { owner, authorization, preTransaction, postTransaction, fallback } = | ||
this; | ||
return Setting_pb.fromPartial({ | ||
owner, | ||
authorization, | ||
preTransaction, | ||
postTransaction, | ||
fallback, | ||
}); | ||
} | ||
|
||
public packAny(): Any { | ||
return Any.fromPartial({ | ||
value: Setting_pb.encode(this.toProto()).finish(), | ||
}); | ||
} | ||
|
||
public static unpackAny(msgAny: Any): Setting { | ||
return Setting.fromProto(Setting_pb.decode(msgAny.value)); | ||
} | ||
} | ||
|
||
export namespace Setting { | ||
export interface Amino { | ||
value: { | ||
owner: string; | ||
authorization: AuthorizationMsg[]; | ||
preTransaction: string[]; | ||
postTransaction: string[]; | ||
fallback: boolean; | ||
}; | ||
} | ||
|
||
export interface Data { | ||
owner: string; | ||
authorization: AuthorizationMsg[]; | ||
pre_transaction: string[]; | ||
post_transaction: string[]; | ||
fallback: boolean; | ||
} | ||
|
||
export type Proto = Setting_pb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Params as Params_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/params'; | ||
import { JSONSerializable } from '../../../../util/json'; | ||
|
||
export class SmartaccountParams extends JSONSerializable< | ||
SmartaccountParams.Amino, | ||
SmartaccountParams.Data, | ||
SmartaccountParams.Proto | ||
> { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
public static fromAmino(_: SmartaccountParams.Amino): SmartaccountParams { | ||
_; | ||
return new SmartaccountParams(); | ||
} | ||
|
||
public toAmino(): SmartaccountParams.Amino { | ||
return { | ||
value: {}, | ||
}; | ||
} | ||
|
||
public static fromData( | ||
proto: SmartaccountParams.Data, | ||
_?: boolean | ||
): SmartaccountParams { | ||
proto; | ||
_; | ||
return new SmartaccountParams(); | ||
} | ||
|
||
public toData(_?: boolean): SmartaccountParams.Data { | ||
_; | ||
return {}; | ||
} | ||
|
||
public static fromProto(proto: SmartaccountParams.Proto): SmartaccountParams { | ||
proto; | ||
return new SmartaccountParams(); | ||
} | ||
|
||
public toProto(): SmartaccountParams.Proto { | ||
return Params_pb.fromPartial({}); | ||
} | ||
} | ||
|
||
export namespace SmartaccountParams { | ||
export interface Amino { | ||
value: {}; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface Data {} | ||
|
||
export type Proto = Params_pb; | ||
} |