Skip to content

Commit

Permalink
changed initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 8, 2024
1 parent db0a17b commit c9a2c92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
24 changes: 15 additions & 9 deletions src/core/smartaccount/v1/models/AuthorizationMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,35 @@ export class AuthorizationMsg extends JSONSerializable<
const {
value: { contractAddress, initMsg },
} = data;
return new AuthorizationMsg(contractAddress, initMsg);
return new AuthorizationMsg(
contractAddress,
Initialization.fromAmino(initMsg)
);
}

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

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

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

Expand Down Expand Up @@ -81,13 +87,13 @@ export namespace AuthorizationMsg {
export interface Amino {
value: {
contractAddress: string;
initMsg: Initialization;
initMsg: Initialization.Amino;
};
}

export interface Data {
contractAddress: string;
initMsg: Initialization;
contract_address: string;
init_msg: Initialization.Data;
}

export type Proto = AuthorizationMsg_pb;
Expand Down
18 changes: 12 additions & 6 deletions src/core/smartaccount/v1/models/Initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,37 @@ export class Initialization extends JSONSerializable<
const {
value: { senders, account, msg },
} = data;
return new Initialization(senders, account, msg);
const buf = Buffer.from(msg, 'ascii');
const msgBs = new Uint8Array(buf);
return new Initialization(senders, account, msgBs);
}

public toAmino(): Initialization.Amino {
const { senders, account, msg } = this;
const base64Str = Buffer.from(msg).toString('ascii');
return {
value: {
senders,
account,
msg,
msg: base64Str,
},
};
}

public static fromData(data: Initialization.Data): Initialization {
const { senders, account, msg } = data;
return new Initialization(senders, account, msg);
const buf = Buffer.from(msg, 'ascii');
const msgBs = new Uint8Array(buf);
return new Initialization(senders, account, msgBs);
}

public toData(): Initialization.Data {
const { senders, account, msg } = this;
const base64Str = Buffer.from(msg).toString('ascii');
return {
senders,
account,
msg,
msg: base64Str,
};
}

Expand Down Expand Up @@ -85,14 +91,14 @@ export namespace Initialization {
value: {
senders: string[];
account: string;
msg: Uint8Array;
msg: string;
};
}

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

export type Proto = Initialization_pb;
Expand Down

0 comments on commit c9a2c92

Please sign in to comment.