Skip to content

Commit

Permalink
created smartaccount msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 4, 2024
1 parent 95bfaba commit 07977b2
Show file tree
Hide file tree
Showing 7 changed files with 562 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/smartaccount/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './v1/msgs';
export * from './v1/models/AuthorizationMsg';
90 changes: 90 additions & 0 deletions src/core/smartaccount/v1/models/AuthorizationMsg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { AuthorizationMsg as AuthorizationMsg_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/setting';
import { JSONSerializable } from '../../../../util/json';

/**
* AuthorizationMsg holds the contract address and initial message
* to be passed to the contract for custom authorization
*/
export class AuthorizationMsg extends JSONSerializable<
AuthorizationMsg.Amino,
AuthorizationMsg.Data,
AuthorizationMsg.Proto
> {
/**
*
* @param contractAddress contract address of authorization logic
* @param initMsg initial message to be passed to the contract
*/
constructor(public contractAddress: string, public initMsg: string) {
super();
}

public static fromAmino(data: AuthorizationMsg.Amino): AuthorizationMsg {
const {
value: { contractAddress, initMsg },
} = data;
return new AuthorizationMsg(contractAddress, initMsg);
}

public toAmino(): AuthorizationMsg.Amino {
const { contractAddress, initMsg } = this;
return {
value: {
contractAddress,
initMsg,
},
};
}

public static fromData(data: AuthorizationMsg.Data): AuthorizationMsg {
const { contractAddress, initMsg } = data;
return new AuthorizationMsg(contractAddress, initMsg);
}

public toData(): AuthorizationMsg.Data {
const { contractAddress, initMsg } = this;
return {
contractAddress,
initMsg,
};
}

public static fromProto(proto: AuthorizationMsg.Proto): AuthorizationMsg {
return new AuthorizationMsg(proto.contractAddress, proto.initMsg);
}

public toProto(): AuthorizationMsg.Proto {
const { contractAddress, initMsg } = this;
return AuthorizationMsg_pb.fromPartial({
contractAddress,
initMsg,
});
}

public packAny(): Any {
return Any.fromPartial({
value: AuthorizationMsg_pb.encode(this.toProto()).finish(),
});
}

public static unpackAny(msgAny: Any): AuthorizationMsg {
return AuthorizationMsg.fromProto(AuthorizationMsg_pb.decode(msgAny.value));
}
}

export namespace AuthorizationMsg {
export interface Amino {
value: {
contractAddress: string;
initMsg: string;
};
}

export interface Data {
contractAddress: string;
initMsg: string;
}

export type Proto = AuthorizationMsg_pb;
}
97 changes: 97 additions & 0 deletions src/core/smartaccount/v1/msgs/MsgCreateSmartAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgCreateSmartAccount as MsgCreateSmartAccount_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/tx';
import { JSONSerializable } from '../../../../util/json';
import { AccAddress } from '../../../bech32';

/**
* MsgCreateSmartAccount creates a new smart account
*/
export class MsgCreateSmartAccount extends JSONSerializable<
MsgCreateSmartAccount.Amino,
MsgCreateSmartAccount.Data,
MsgCreateSmartAccount.Proto
> {
/**
*
* @param account sender's account address
*/
constructor(public account: AccAddress) {
super();
}

public static fromAmino(
data: MsgCreateSmartAccount.Amino
): MsgCreateSmartAccount {
const {
value: { account },
} = data;
return new MsgCreateSmartAccount(account);
}

public toAmino(): MsgCreateSmartAccount.Amino {
const { account } = this;
return {
type: 'terra/MsgCreateSmartAccount',
value: {
account,
},
};
}

public static fromData(
data: MsgCreateSmartAccount.Data
): MsgCreateSmartAccount {
const { account } = data;
return new MsgCreateSmartAccount(account);
}

public toData(): MsgCreateSmartAccount.Data {
const { account } = this;
return {
'@type': '/terra.smartaccount.v1.MsgCreateSmartAccount',
account,
};
}

public static fromProto(
proto: MsgCreateSmartAccount.Proto
): MsgCreateSmartAccount {
return new MsgCreateSmartAccount(proto.account);
}

public toProto(): MsgCreateSmartAccount.Proto {
const { account } = this;
return MsgCreateSmartAccount_pb.fromPartial({
account,
});
}

public packAny(): Any {
return Any.fromPartial({
typeUrl: '/terra.smartaccount.v1.MsgCreateSmartAccount',
value: MsgCreateSmartAccount_pb.encode(this.toProto()).finish(),
});
}

public static unpackAny(msgAny: Any): MsgCreateSmartAccount {
return MsgCreateSmartAccount.fromProto(
MsgCreateSmartAccount_pb.decode(msgAny.value)
);
}
}

export namespace MsgCreateSmartAccount {
export interface Amino {
type: 'terra/MsgCreateSmartAccount';
value: {
account: AccAddress;
};
}

export interface Data {
'@type': '/terra.smartaccount.v1.MsgCreateSmartAccount';
account: AccAddress;
}

export type Proto = MsgCreateSmartAccount_pb;
}
97 changes: 97 additions & 0 deletions src/core/smartaccount/v1/msgs/MsgDisableSmartAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgDisableSmartAccount as MsgDisableSmartAccount_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/tx';
import { JSONSerializable } from '../../../../util/json';
import { AccAddress } from '../../../bech32';

/**
* MsgDisableSmartAccount disables a smart account
*/
export class MsgDisableSmartAccount extends JSONSerializable<
MsgDisableSmartAccount.Amino,
MsgDisableSmartAccount.Data,
MsgDisableSmartAccount.Proto
> {
/**
*
* @param account sender's account address
*/
constructor(public account: AccAddress) {
super();
}

public static fromAmino(
data: MsgDisableSmartAccount.Amino
): MsgDisableSmartAccount {
const {
value: { account },
} = data;
return new MsgDisableSmartAccount(account);
}

public toAmino(): MsgDisableSmartAccount.Amino {
const { account } = this;
return {
type: 'terra/MsgDisableSmartAccount',
value: {
account,
},
};
}

public static fromData(
data: MsgDisableSmartAccount.Data
): MsgDisableSmartAccount {
const { account } = data;
return new MsgDisableSmartAccount(account);
}

public toData(): MsgDisableSmartAccount.Data {
const { account } = this;
return {
'@type': '/terra.smartaccount.v1.MsgDisableSmartAccount',
account,
};
}

public static fromProto(
proto: MsgDisableSmartAccount.Proto
): MsgDisableSmartAccount {
return new MsgDisableSmartAccount(proto.account);
}

public toProto(): MsgDisableSmartAccount.Proto {
const { account } = this;
return MsgDisableSmartAccount_pb.fromPartial({
account,
});
}

public packAny(): Any {
return Any.fromPartial({
typeUrl: '/terra.smartaccount.v1.MsgDisableSmartAccount',
value: MsgDisableSmartAccount_pb.encode(this.toProto()).finish(),
});
}

public static unpackAny(msgAny: Any): MsgDisableSmartAccount {
return MsgDisableSmartAccount.fromProto(
MsgDisableSmartAccount_pb.decode(msgAny.value)
);
}
}

export namespace MsgDisableSmartAccount {
export interface Amino {
type: 'terra/MsgDisableSmartAccount';
value: {
account: AccAddress;
};
}

export interface Data {
'@type': '/terra.smartaccount.v1.MsgDisableSmartAccount';
account: AccAddress;
}

export type Proto = MsgDisableSmartAccount_pb;
}
Loading

0 comments on commit 07977b2

Please sign in to comment.