Change account_number/sequence type to number | string
This commit is contained in:
parent
29e98ec156
commit
4dca3619de
@ -17,6 +17,9 @@
|
||||
`Secp256k1Pen` class in favour of `Secp256k1Wallet` which takes an
|
||||
`OfflineSigner` instead of a `SigningCallback`.
|
||||
- @cosmjs/sdk38: Rename `CosmosSdkAccount` to `BaseAccount` and export the type.
|
||||
- @cosmjs/sdk38: `BaseAccount` now uses `number | string` as the type for
|
||||
`account_number` and `sequence`. The new helpers `uint64ToNumber` and
|
||||
`uint64ToString` allow you to normalize the mixed input.
|
||||
- @cosmjs/math: Add missing integer check to `Uint64.fromNumber`. Before
|
||||
`Uint64.fromNumber(1.1)` produced some result.
|
||||
- @cosmjs/sdk38: Add `SigningCosmosClient.signAndPost` as a mid-level
|
||||
|
||||
@ -13,6 +13,7 @@ import {
|
||||
PubKey,
|
||||
setupAuthExtension,
|
||||
StdTx,
|
||||
uint64ToNumber,
|
||||
} from "@cosmjs/sdk38";
|
||||
|
||||
import { setupWasmExtension, WasmExtension } from "./lcdapi/wasm";
|
||||
@ -234,8 +235,8 @@ export class CosmWasmClient {
|
||||
address: value.address,
|
||||
balance: value.coins,
|
||||
pubkey: value.public_key ? decodeBech32Pubkey(value.public_key) : undefined,
|
||||
accountNumber: value.account_number,
|
||||
sequence: value.sequence,
|
||||
accountNumber: uint64ToNumber(value.account_number),
|
||||
sequence: uint64ToNumber(value.sequence),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import { fromBase64, fromHex, toHex } from "@cosmjs/encoding";
|
||||
import { Uint53 } from "@cosmjs/math";
|
||||
|
||||
import { Coin } from "./coins";
|
||||
import { AuthExtension, BroadcastMode, LcdClient, setupAuthExtension } from "./lcdapi";
|
||||
import { AuthExtension, BroadcastMode, LcdClient, setupAuthExtension, uint64ToNumber } from "./lcdapi";
|
||||
import { Log, parseLogs } from "./logs";
|
||||
import { decodeBech32Pubkey } from "./pubkey";
|
||||
import { CosmosSdkTx, PubKey, StdTx } from "./types";
|
||||
@ -235,8 +235,8 @@ export class CosmosClient {
|
||||
address: value.address,
|
||||
balance: value.coins,
|
||||
pubkey: value.public_key ? decodeBech32Pubkey(value.public_key) : undefined,
|
||||
accountNumber: value.account_number,
|
||||
sequence: value.sequence,
|
||||
accountNumber: uint64ToNumber(value.account_number),
|
||||
sequence: uint64ToNumber(value.sequence),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { toUtf8 } from "@cosmjs/encoding";
|
||||
|
||||
import { uint64ToString } from "./lcdapi";
|
||||
import { Msg } from "./msgs";
|
||||
import { StdFee } from "./types";
|
||||
|
||||
@ -41,16 +42,16 @@ export function makeSignBytes(
|
||||
fee: StdFee,
|
||||
chainId: string,
|
||||
memo: string,
|
||||
accountNumber: number,
|
||||
sequence: number,
|
||||
accountNumber: number | string,
|
||||
sequence: number | string,
|
||||
): Uint8Array {
|
||||
const signDoc: StdSignDoc = {
|
||||
account_number: accountNumber.toString(),
|
||||
account_number: uint64ToString(accountNumber),
|
||||
chain_id: chainId,
|
||||
fee: fee,
|
||||
memo: memo,
|
||||
msgs: msgs,
|
||||
sequence: sequence.toString(),
|
||||
sequence: uint64ToString(sequence),
|
||||
};
|
||||
const sortedSignDoc = sortJson(signDoc);
|
||||
return toUtf8(JSON.stringify(sortedSignDoc));
|
||||
|
||||
@ -16,8 +16,26 @@ export interface BaseAccount {
|
||||
readonly coins: readonly Coin[];
|
||||
/** Bech32 encoded pubkey */
|
||||
readonly public_key: string;
|
||||
readonly account_number: number;
|
||||
readonly sequence: number;
|
||||
/**
|
||||
* The account number assigned by the blockchain.
|
||||
*
|
||||
* This was string encoded in Cosmos SDK 0.37, changed to number in Cosmos SDK 0.38 ([1])
|
||||
* and changed back to string in Cosmos SDK 0.39 ([2]).
|
||||
*
|
||||
* [1]: https://github.com/cosmos/cosmos-sdk/pull/5280
|
||||
* [2]: https://github.com/cosmos/cosmos-sdk/pull/6749
|
||||
*/
|
||||
readonly account_number: number | string;
|
||||
/**
|
||||
* The sequence number for replay protection.
|
||||
*
|
||||
* This was string encoded in Cosmos SDK 0.37, changed to number in Cosmos SDK 0.38 ([1])
|
||||
* and changed back to string in Cosmos SDK 0.39 ([2]).
|
||||
*
|
||||
* [1]: https://github.com/cosmos/cosmos-sdk/pull/5280
|
||||
* [2]: https://github.com/cosmos/cosmos-sdk/pull/6749
|
||||
*/
|
||||
readonly sequence: number | string;
|
||||
}
|
||||
|
||||
export interface AuthAccountsResponse {
|
||||
|
||||
4
packages/sdk38/types/encoding.d.ts
vendored
4
packages/sdk38/types/encoding.d.ts
vendored
@ -5,6 +5,6 @@ export declare function makeSignBytes(
|
||||
fee: StdFee,
|
||||
chainId: string,
|
||||
memo: string,
|
||||
accountNumber: number,
|
||||
sequence: number,
|
||||
accountNumber: number | string,
|
||||
sequence: number | string,
|
||||
): Uint8Array;
|
||||
|
||||
22
packages/sdk38/types/lcdapi/auth.d.ts
vendored
22
packages/sdk38/types/lcdapi/auth.d.ts
vendored
@ -14,8 +14,26 @@ export interface BaseAccount {
|
||||
readonly coins: readonly Coin[];
|
||||
/** Bech32 encoded pubkey */
|
||||
readonly public_key: string;
|
||||
readonly account_number: number;
|
||||
readonly sequence: number;
|
||||
/**
|
||||
* The account number assigned by the blockchain.
|
||||
*
|
||||
* This was string encoded in Cosmos SDK 0.37, changed to number in Cosmos SDK 0.38 ([1])
|
||||
* and changed back to string in Cosmos SDK 0.39 ([2]).
|
||||
*
|
||||
* [1]: https://github.com/cosmos/cosmos-sdk/pull/5280
|
||||
* [2]: https://github.com/cosmos/cosmos-sdk/pull/6749
|
||||
*/
|
||||
readonly account_number: number | string;
|
||||
/**
|
||||
* The sequence number for replay protection.
|
||||
*
|
||||
* This was string encoded in Cosmos SDK 0.37, changed to number in Cosmos SDK 0.38 ([1])
|
||||
* and changed back to string in Cosmos SDK 0.39 ([2]).
|
||||
*
|
||||
* [1]: https://github.com/cosmos/cosmos-sdk/pull/5280
|
||||
* [2]: https://github.com/cosmos/cosmos-sdk/pull/6749
|
||||
*/
|
||||
readonly sequence: number | string;
|
||||
}
|
||||
export interface AuthAccountsResponse {
|
||||
readonly height: string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user