Skip to content

Commit 07977b2

Browse files
committed
created smartaccount msgs
1 parent 95bfaba commit 07977b2

File tree

7 files changed

+562
-0
lines changed

7 files changed

+562
-0
lines changed

src/core/smartaccount/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './v1/msgs';
2+
export * from './v1/models/AuthorizationMsg';
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
2+
import { AuthorizationMsg as AuthorizationMsg_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/setting';
3+
import { JSONSerializable } from '../../../../util/json';
4+
5+
/**
6+
* AuthorizationMsg holds the contract address and initial message
7+
* to be passed to the contract for custom authorization
8+
*/
9+
export class AuthorizationMsg extends JSONSerializable<
10+
AuthorizationMsg.Amino,
11+
AuthorizationMsg.Data,
12+
AuthorizationMsg.Proto
13+
> {
14+
/**
15+
*
16+
* @param contractAddress contract address of authorization logic
17+
* @param initMsg initial message to be passed to the contract
18+
*/
19+
constructor(public contractAddress: string, public initMsg: string) {
20+
super();
21+
}
22+
23+
public static fromAmino(data: AuthorizationMsg.Amino): AuthorizationMsg {
24+
const {
25+
value: { contractAddress, initMsg },
26+
} = data;
27+
return new AuthorizationMsg(contractAddress, initMsg);
28+
}
29+
30+
public toAmino(): AuthorizationMsg.Amino {
31+
const { contractAddress, initMsg } = this;
32+
return {
33+
value: {
34+
contractAddress,
35+
initMsg,
36+
},
37+
};
38+
}
39+
40+
public static fromData(data: AuthorizationMsg.Data): AuthorizationMsg {
41+
const { contractAddress, initMsg } = data;
42+
return new AuthorizationMsg(contractAddress, initMsg);
43+
}
44+
45+
public toData(): AuthorizationMsg.Data {
46+
const { contractAddress, initMsg } = this;
47+
return {
48+
contractAddress,
49+
initMsg,
50+
};
51+
}
52+
53+
public static fromProto(proto: AuthorizationMsg.Proto): AuthorizationMsg {
54+
return new AuthorizationMsg(proto.contractAddress, proto.initMsg);
55+
}
56+
57+
public toProto(): AuthorizationMsg.Proto {
58+
const { contractAddress, initMsg } = this;
59+
return AuthorizationMsg_pb.fromPartial({
60+
contractAddress,
61+
initMsg,
62+
});
63+
}
64+
65+
public packAny(): Any {
66+
return Any.fromPartial({
67+
value: AuthorizationMsg_pb.encode(this.toProto()).finish(),
68+
});
69+
}
70+
71+
public static unpackAny(msgAny: Any): AuthorizationMsg {
72+
return AuthorizationMsg.fromProto(AuthorizationMsg_pb.decode(msgAny.value));
73+
}
74+
}
75+
76+
export namespace AuthorizationMsg {
77+
export interface Amino {
78+
value: {
79+
contractAddress: string;
80+
initMsg: string;
81+
};
82+
}
83+
84+
export interface Data {
85+
contractAddress: string;
86+
initMsg: string;
87+
}
88+
89+
export type Proto = AuthorizationMsg_pb;
90+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
2+
import { MsgCreateSmartAccount as MsgCreateSmartAccount_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/tx';
3+
import { JSONSerializable } from '../../../../util/json';
4+
import { AccAddress } from '../../../bech32';
5+
6+
/**
7+
* MsgCreateSmartAccount creates a new smart account
8+
*/
9+
export class MsgCreateSmartAccount extends JSONSerializable<
10+
MsgCreateSmartAccount.Amino,
11+
MsgCreateSmartAccount.Data,
12+
MsgCreateSmartAccount.Proto
13+
> {
14+
/**
15+
*
16+
* @param account sender's account address
17+
*/
18+
constructor(public account: AccAddress) {
19+
super();
20+
}
21+
22+
public static fromAmino(
23+
data: MsgCreateSmartAccount.Amino
24+
): MsgCreateSmartAccount {
25+
const {
26+
value: { account },
27+
} = data;
28+
return new MsgCreateSmartAccount(account);
29+
}
30+
31+
public toAmino(): MsgCreateSmartAccount.Amino {
32+
const { account } = this;
33+
return {
34+
type: 'terra/MsgCreateSmartAccount',
35+
value: {
36+
account,
37+
},
38+
};
39+
}
40+
41+
public static fromData(
42+
data: MsgCreateSmartAccount.Data
43+
): MsgCreateSmartAccount {
44+
const { account } = data;
45+
return new MsgCreateSmartAccount(account);
46+
}
47+
48+
public toData(): MsgCreateSmartAccount.Data {
49+
const { account } = this;
50+
return {
51+
'@type': '/terra.smartaccount.v1.MsgCreateSmartAccount',
52+
account,
53+
};
54+
}
55+
56+
public static fromProto(
57+
proto: MsgCreateSmartAccount.Proto
58+
): MsgCreateSmartAccount {
59+
return new MsgCreateSmartAccount(proto.account);
60+
}
61+
62+
public toProto(): MsgCreateSmartAccount.Proto {
63+
const { account } = this;
64+
return MsgCreateSmartAccount_pb.fromPartial({
65+
account,
66+
});
67+
}
68+
69+
public packAny(): Any {
70+
return Any.fromPartial({
71+
typeUrl: '/terra.smartaccount.v1.MsgCreateSmartAccount',
72+
value: MsgCreateSmartAccount_pb.encode(this.toProto()).finish(),
73+
});
74+
}
75+
76+
public static unpackAny(msgAny: Any): MsgCreateSmartAccount {
77+
return MsgCreateSmartAccount.fromProto(
78+
MsgCreateSmartAccount_pb.decode(msgAny.value)
79+
);
80+
}
81+
}
82+
83+
export namespace MsgCreateSmartAccount {
84+
export interface Amino {
85+
type: 'terra/MsgCreateSmartAccount';
86+
value: {
87+
account: AccAddress;
88+
};
89+
}
90+
91+
export interface Data {
92+
'@type': '/terra.smartaccount.v1.MsgCreateSmartAccount';
93+
account: AccAddress;
94+
}
95+
96+
export type Proto = MsgCreateSmartAccount_pb;
97+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
2+
import { MsgDisableSmartAccount as MsgDisableSmartAccount_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/tx';
3+
import { JSONSerializable } from '../../../../util/json';
4+
import { AccAddress } from '../../../bech32';
5+
6+
/**
7+
* MsgDisableSmartAccount disables a smart account
8+
*/
9+
export class MsgDisableSmartAccount extends JSONSerializable<
10+
MsgDisableSmartAccount.Amino,
11+
MsgDisableSmartAccount.Data,
12+
MsgDisableSmartAccount.Proto
13+
> {
14+
/**
15+
*
16+
* @param account sender's account address
17+
*/
18+
constructor(public account: AccAddress) {
19+
super();
20+
}
21+
22+
public static fromAmino(
23+
data: MsgDisableSmartAccount.Amino
24+
): MsgDisableSmartAccount {
25+
const {
26+
value: { account },
27+
} = data;
28+
return new MsgDisableSmartAccount(account);
29+
}
30+
31+
public toAmino(): MsgDisableSmartAccount.Amino {
32+
const { account } = this;
33+
return {
34+
type: 'terra/MsgDisableSmartAccount',
35+
value: {
36+
account,
37+
},
38+
};
39+
}
40+
41+
public static fromData(
42+
data: MsgDisableSmartAccount.Data
43+
): MsgDisableSmartAccount {
44+
const { account } = data;
45+
return new MsgDisableSmartAccount(account);
46+
}
47+
48+
public toData(): MsgDisableSmartAccount.Data {
49+
const { account } = this;
50+
return {
51+
'@type': '/terra.smartaccount.v1.MsgDisableSmartAccount',
52+
account,
53+
};
54+
}
55+
56+
public static fromProto(
57+
proto: MsgDisableSmartAccount.Proto
58+
): MsgDisableSmartAccount {
59+
return new MsgDisableSmartAccount(proto.account);
60+
}
61+
62+
public toProto(): MsgDisableSmartAccount.Proto {
63+
const { account } = this;
64+
return MsgDisableSmartAccount_pb.fromPartial({
65+
account,
66+
});
67+
}
68+
69+
public packAny(): Any {
70+
return Any.fromPartial({
71+
typeUrl: '/terra.smartaccount.v1.MsgDisableSmartAccount',
72+
value: MsgDisableSmartAccount_pb.encode(this.toProto()).finish(),
73+
});
74+
}
75+
76+
public static unpackAny(msgAny: Any): MsgDisableSmartAccount {
77+
return MsgDisableSmartAccount.fromProto(
78+
MsgDisableSmartAccount_pb.decode(msgAny.value)
79+
);
80+
}
81+
}
82+
83+
export namespace MsgDisableSmartAccount {
84+
export interface Amino {
85+
type: 'terra/MsgDisableSmartAccount';
86+
value: {
87+
account: AccAddress;
88+
};
89+
}
90+
91+
export interface Data {
92+
'@type': '/terra.smartaccount.v1.MsgDisableSmartAccount';
93+
account: AccAddress;
94+
}
95+
96+
export type Proto = MsgDisableSmartAccount_pb;
97+
}

0 commit comments

Comments
 (0)