proto-signing: Update msgs and registry for new codec

This commit is contained in:
willclarktech 2020-10-14 17:13:59 +02:00
parent 887850c4ad
commit aa320394f5
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
4 changed files with 17 additions and 17 deletions

View File

@ -6,7 +6,7 @@ import { Registry } from "./registry";
export const defaultRegistry = new Registry();
@registered(defaultRegistry, "/cosmos.Coin")
@registered(defaultRegistry, "/cosmos.base.v1beta1.Coin")
export class Coin extends Message {
@cosmosField.string(1)
public readonly denom?: string;
@ -15,13 +15,13 @@ export class Coin extends Message {
public readonly amount?: string;
}
@registered(defaultRegistry, "/cosmos.bank.MsgSend")
@registered(defaultRegistry, "/cosmos.bank.v1beta1.MsgSend")
export class MsgSend extends Message {
@cosmosField.bytes(1)
public readonly from_address?: Uint8Array;
@cosmosField.string(1)
public readonly from_address?: string;
@cosmosField.bytes(2)
public readonly to_address?: Uint8Array;
@cosmosField.string(2)
public readonly to_address?: string;
@cosmosField.repeatedMessage(3, Coin)
public readonly amount?: readonly Coin[];

View File

@ -29,9 +29,9 @@ export interface TxBodyValue {
}
const defaultTypeUrls = {
cosmosCoin: "/cosmos.Coin",
cosmosMsgSend: "/cosmos.bank.MsgSend",
cosmosTxBody: "/cosmos.tx.TxBody",
cosmosCoin: "/cosmos.base.v1beta1.Coin",
cosmosMsgSend: "/cosmos.bank.v1beta1.MsgSend",
cosmosTxBody: "/cosmos.tx.v1beta1.TxBody",
googleAny: "/google.protobuf.Any",
};
@ -41,8 +41,8 @@ export class Registry {
public constructor(customTypes: Iterable<[string, GeneratedType]> = []) {
const { cosmosCoin, cosmosMsgSend } = defaultTypeUrls;
this.types = new Map<string, GeneratedType>([
[cosmosCoin, cosmos.Coin],
[cosmosMsgSend, cosmos.bank.MsgSend],
[cosmosCoin, cosmos.base.v1beta1.Coin],
[cosmosMsgSend, cosmos.bank.v1beta1.MsgSend],
...customTypes,
]);
}
@ -73,7 +73,7 @@ export class Registry {
}
public encodeTxBody(txBodyFields: TxBodyValue): Uint8Array {
const { TxBody } = cosmos.tx;
const { TxBody } = cosmos.tx.v1beta1;
const { Any } = google.protobuf;
const wrappedMessages = txBodyFields.messages.map((message) => {
@ -104,8 +104,8 @@ export class Registry {
return decoded;
}
public decodeTxBody(txBody: Uint8Array): cosmos.tx.TxBody {
const { TxBody } = cosmos.tx;
public decodeTxBody(txBody: Uint8Array): cosmos.tx.v1beta1.TxBody {
const { TxBody } = cosmos.tx.v1beta1;
const decodedTxBody = TxBody.decode(txBody);
return {

View File

@ -6,7 +6,7 @@ export declare class Coin extends Message {
readonly amount?: string;
}
export declare class MsgSend extends Message {
readonly from_address?: Uint8Array;
readonly to_address?: Uint8Array;
readonly from_address?: string;
readonly to_address?: string;
readonly amount?: readonly Coin[];
}

View File

@ -37,5 +37,5 @@ export declare class Registry {
encode({ typeUrl, value }: EncodeObject): Uint8Array;
encodeTxBody(txBodyFields: TxBodyValue): Uint8Array;
decode({ typeUrl, value }: DecodeObject): any;
decodeTxBody(txBody: Uint8Array): cosmos.tx.TxBody;
decodeTxBody(txBody: Uint8Array): cosmos.tx.v1beta1.TxBody;
}