mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Extract decodeBaseAccount
This commit is contained in:
parent
9dd314e0bb
commit
8a00b4d6df
@ -26,6 +26,18 @@ function uint64FromProto(input: number | Long): Uint64 {
|
||||
return Uint64.fromString(input.toString());
|
||||
}
|
||||
|
||||
function decodeBaseAccount(data: Uint8Array, prefix: string): Account {
|
||||
const { address, pubKey, accountNumber, sequence } = cosmos.auth.BaseAccount.decode(data);
|
||||
// Pubkey is still Amino-encoded in BaseAccount (https://github.com/cosmos/cosmos-sdk/issues/6886)
|
||||
const pubkey = pubKey.length ? decodeAminoPubkey(pubKey) : null;
|
||||
return {
|
||||
address: Bech32.encode(prefix, address),
|
||||
pubkey: pubkey,
|
||||
accountNumber: uint64FromProto(accountNumber).toNumber(),
|
||||
sequence: uint64FromProto(sequence).toNumber(),
|
||||
};
|
||||
}
|
||||
|
||||
function coinFromProto(input: cosmos.ICoin): Coin {
|
||||
assertDefined(input.amount);
|
||||
assertDefined(input.denom);
|
||||
@ -60,15 +72,7 @@ export class StargateClient {
|
||||
const { typeUrl, value } = decodeAny(responseData);
|
||||
switch (typeUrl) {
|
||||
case "/cosmos.auth.BaseAccount": {
|
||||
const { address, pubKey, accountNumber, sequence } = cosmos.auth.BaseAccount.decode(value);
|
||||
// Pubkey is still Amino-encoded in BaseAccount (https://github.com/cosmos/cosmos-sdk/issues/6886)
|
||||
const pubkey = pubKey.length ? decodeAminoPubkey(pubKey) : null;
|
||||
return {
|
||||
address: Bech32.encode(prefix, address),
|
||||
pubkey: pubkey,
|
||||
accountNumber: uint64FromProto(accountNumber).toNumber(),
|
||||
sequence: uint64FromProto(sequence).toNumber(),
|
||||
};
|
||||
return decodeBaseAccount(value, prefix);
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unsupported type: '${typeUrl}'`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user