Skip to content

Commit

Permalink
changed authorizationMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 7, 2024
1 parent 85aac42 commit db0a17b
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 10 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
},
"dependencies": {
"@terra-money/legacy.proto": "npm:@terra-money/terra.proto@^0.1.7",
"@terra-money/terra.proto": "5.1.0-beta.1",
"@terra-money/terra.proto": "5.1.0-beta.2",
"assert": "^2.0.0",
"axios": "^0.27.2",
"bech32": "^2.0.0",
Expand All @@ -104,4 +104,4 @@
"utf-8-validate": "^5.0.5",
"ws": "^7.5.9"
}
}
}
1 change: 1 addition & 0 deletions src/core/smartaccount/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './v1/msgs';
export * from './v1/models/Initialization';
export * from './v1/models/AuthorizationMsg';
export * from './v1/models/Setting';
export * from './v1/models/SmartaccountParams';
12 changes: 8 additions & 4 deletions src/core/smartaccount/v1/models/AuthorizationMsg.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
import { Initialization } from './Initialization';

/**
* AuthorizationMsg holds the contract address and initial message
Expand All @@ -16,7 +17,7 @@ export class AuthorizationMsg extends JSONSerializable<
* @param contractAddress contract address of authorization logic
* @param initMsg initial message to be passed to the contract
*/
constructor(public contractAddress: string, public initMsg: string) {
constructor(public contractAddress: string, public initMsg: Initialization) {
super();
}

Expand Down Expand Up @@ -51,7 +52,10 @@ export class AuthorizationMsg extends JSONSerializable<
}

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

public toProto(): AuthorizationMsg.Proto {
Expand All @@ -77,13 +81,13 @@ export namespace AuthorizationMsg {
export interface Amino {
value: {
contractAddress: string;
initMsg: string;
initMsg: Initialization;
};
}

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

export type Proto = AuthorizationMsg_pb;
Expand Down
99 changes: 99 additions & 0 deletions src/core/smartaccount/v1/models/Initialization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { Initialization as Initialization_pb } from '@terra-money/terra.proto/terra/smartaccount/v1/wasm';
import { JSONSerializable } from '../../../../util/json';

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

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

public toAmino(): Initialization.Amino {
const { senders, account, msg } = this;
return {
value: {
senders,
account,
msg,
},
};
}

public static fromData(data: Initialization.Data): Initialization {
const { senders, account, msg } = data;
return new Initialization(senders, account, msg);
}

public toData(): Initialization.Data {
const { senders, account, msg } = this;
return {
senders,
account,
msg,
};
}

public static fromProto(proto: Initialization.Proto): Initialization {
return new Initialization(proto.senders, proto.account, proto.msg);
}

public toProto(): Initialization.Proto {
const { senders, account, msg } = this;
return Initialization_pb.fromPartial({
senders,
account,
msg,
});
}

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

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

export namespace Initialization {
export interface Amino {
value: {
senders: string[];
account: string;
msg: Uint8Array;
};
}

export interface Data {
senders: string[];
account: string;
msg: Uint8Array;
}

export type Proto = Initialization_pb;
}

0 comments on commit db0a17b

Please sign in to comment.