bcp builds properly
This commit is contained in:
parent
8b262e6b12
commit
62b5c88c58
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
import { Address, Algorithm, TokenTicker } from "@iov/bcp";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
import amino from "@tendermint/amino-js";
|
||||
import { types } from "@cosmwasm/sdk";
|
||||
|
||||
import {
|
||||
decodeAmount,
|
||||
@ -113,7 +113,7 @@ describe("decode", () => {
|
||||
|
||||
describe("decodeAmount", () => {
|
||||
it("works", () => {
|
||||
const amount: amino.Coin = {
|
||||
const amount: types.Coin = {
|
||||
denom: "uatom",
|
||||
amount: "11657995",
|
||||
};
|
||||
@ -123,7 +123,7 @@ describe("decode", () => {
|
||||
|
||||
describe("parseMsg", () => {
|
||||
it("works", () => {
|
||||
const msg: amino.Msg = {
|
||||
const msg: types.Msg = {
|
||||
type: "cosmos-sdk/MsgSend",
|
||||
value: {
|
||||
from_address: "cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r",
|
||||
|
||||
@ -18,13 +18,12 @@ import {
|
||||
UnsignedTransaction,
|
||||
} from "@iov/bcp";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
import amino from "@tendermint/amino-js";
|
||||
|
||||
import { TokenInfos } from "./types";
|
||||
|
||||
const { fromBase64 } = Encoding;
|
||||
|
||||
export function decodePubkey(pubkey: amino.PubKey): PubkeyBundle {
|
||||
export function decodePubkey(pubkey: types.PubKey): PubkeyBundle {
|
||||
switch (pubkey.type) {
|
||||
// https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/secp256k1/secp256k1.go#L23
|
||||
case "tendermint/PubKeySecp256k1":
|
||||
@ -47,7 +46,7 @@ export function decodeSignature(signature: string): SignatureBytes {
|
||||
return fromBase64(signature) as SignatureBytes;
|
||||
}
|
||||
|
||||
export function decodeFullSignature(signature: amino.StdSignature, nonce: number): FullSignature {
|
||||
export function decodeFullSignature(signature: types.StdSignature, nonce: number): FullSignature {
|
||||
return {
|
||||
nonce: nonce as Nonce,
|
||||
pubkey: decodePubkey(signature.pub_key),
|
||||
@ -55,7 +54,7 @@ export function decodeFullSignature(signature: amino.StdSignature, nonce: number
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeAmount(tokens: TokenInfos, coin: amino.Coin): Amount {
|
||||
export function decodeAmount(tokens: TokenInfos, coin: types.Coin): Amount {
|
||||
const [value, ticker] = coinToDecimal(tokens, coin);
|
||||
return {
|
||||
quantity: value.atomics,
|
||||
@ -64,14 +63,14 @@ export function decodeAmount(tokens: TokenInfos, coin: amino.Coin): Amount {
|
||||
};
|
||||
}
|
||||
|
||||
export function parseMsg(msg: amino.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction {
|
||||
export function parseMsg(msg: types.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction {
|
||||
if (msg.type !== "cosmos-sdk/MsgSend") {
|
||||
throw new Error("Unknown message type in transaction");
|
||||
}
|
||||
if (!(msg.value as amino.MsgSend).from_address) {
|
||||
if (!(msg.value as types.MsgSend).from_address) {
|
||||
throw new Error("Only MsgSend is supported");
|
||||
}
|
||||
const msgValue = msg.value as amino.MsgSend;
|
||||
const msgValue = msg.value as types.MsgSend;
|
||||
if (msgValue.amount.length !== 1) {
|
||||
throw new Error("Only MsgSend with one amount is supported");
|
||||
}
|
||||
@ -84,7 +83,7 @@ export function parseMsg(msg: amino.Msg, chainId: ChainId, tokens: TokenInfos):
|
||||
};
|
||||
}
|
||||
|
||||
export function parseFee(fee: amino.StdFee, tokens: TokenInfos): Fee {
|
||||
export function parseFee(fee: types.StdFee, tokens: TokenInfos): Fee {
|
||||
if (fee.amount.length !== 1) {
|
||||
throw new Error("Only fee with one amount is supported");
|
||||
}
|
||||
@ -94,7 +93,7 @@ export function parseFee(fee: amino.StdFee, tokens: TokenInfos): Fee {
|
||||
};
|
||||
}
|
||||
|
||||
export function parseTx(tx: amino.Tx, chainId: ChainId, nonce: Nonce, tokens: TokenInfos): SignedTransaction {
|
||||
export function parseTx(tx: types.Tx, chainId: ChainId, nonce: Nonce, tokens: TokenInfos): SignedTransaction {
|
||||
const txValue = tx.value;
|
||||
if (!types.isAminoStdTx(txValue)) {
|
||||
throw new Error("Only Amino StdTx is supported");
|
||||
|
||||
@ -12,13 +12,12 @@ import {
|
||||
} from "@iov/bcp";
|
||||
import { Secp256k1 } from "@iov/crypto";
|
||||
import { Decimal, Encoding } from "@iov/encoding";
|
||||
import amino from "@tendermint/amino-js";
|
||||
|
||||
import { TokenInfos } from "./types";
|
||||
|
||||
const { toBase64 } = Encoding;
|
||||
|
||||
export function encodePubkey(pubkey: PubkeyBundle): amino.PubKey {
|
||||
export function encodePubkey(pubkey: PubkeyBundle): types.PubKey {
|
||||
switch (pubkey.algo) {
|
||||
case Algorithm.Secp256k1:
|
||||
return {
|
||||
@ -35,7 +34,7 @@ export function encodePubkey(pubkey: PubkeyBundle): amino.PubKey {
|
||||
}
|
||||
}
|
||||
|
||||
export function encodeAmount(amount: Amount, tokens: TokenInfos): amino.Coin {
|
||||
export function encodeAmount(amount: Amount, tokens: TokenInfos): types.Coin {
|
||||
return decimalToCoin(
|
||||
tokens,
|
||||
Decimal.fromAtomics(amount.quantity, amount.fractionalDigits),
|
||||
@ -43,7 +42,7 @@ export function encodeAmount(amount: Amount, tokens: TokenInfos): amino.Coin {
|
||||
);
|
||||
}
|
||||
|
||||
export function encodeFee(fee: Fee, tokens: TokenInfos): amino.StdFee {
|
||||
export function encodeFee(fee: Fee, tokens: TokenInfos): types.StdFee {
|
||||
if (fee.tokens === undefined) {
|
||||
throw new Error("Cannot encode fee without tokens");
|
||||
}
|
||||
@ -56,7 +55,7 @@ export function encodeFee(fee: Fee, tokens: TokenInfos): amino.StdFee {
|
||||
};
|
||||
}
|
||||
|
||||
export function encodeFullSignature(fullSignature: FullSignature): amino.StdSignature {
|
||||
export function encodeFullSignature(fullSignature: FullSignature): types.StdSignature {
|
||||
return {
|
||||
pub_key: {
|
||||
type: "tendermint/PubKeySecp256k1",
|
||||
|
||||
15
packages/bcp/types/decode.d.ts
vendored
15
packages/bcp/types/decode.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
import { TxsResponse } from "@cosmwasm/sdk";
|
||||
import { TxsResponse, types } from "@cosmwasm/sdk";
|
||||
import {
|
||||
Amount,
|
||||
ChainId,
|
||||
@ -12,16 +12,15 @@ import {
|
||||
SignedTransaction,
|
||||
UnsignedTransaction,
|
||||
} from "@iov/bcp";
|
||||
import amino from "@tendermint/amino-js";
|
||||
import { TokenInfos } from "./types";
|
||||
export declare function decodePubkey(pubkey: amino.PubKey): PubkeyBundle;
|
||||
export declare function decodePubkey(pubkey: types.PubKey): PubkeyBundle;
|
||||
export declare function decodeSignature(signature: string): SignatureBytes;
|
||||
export declare function decodeFullSignature(signature: amino.StdSignature, nonce: number): FullSignature;
|
||||
export declare function decodeAmount(tokens: TokenInfos, coin: amino.Coin): Amount;
|
||||
export declare function parseMsg(msg: amino.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction;
|
||||
export declare function parseFee(fee: amino.StdFee, tokens: TokenInfos): Fee;
|
||||
export declare function decodeFullSignature(signature: types.StdSignature, nonce: number): FullSignature;
|
||||
export declare function decodeAmount(tokens: TokenInfos, coin: types.Coin): Amount;
|
||||
export declare function parseMsg(msg: types.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction;
|
||||
export declare function parseFee(fee: types.StdFee, tokens: TokenInfos): Fee;
|
||||
export declare function parseTx(
|
||||
tx: amino.Tx,
|
||||
tx: types.Tx,
|
||||
chainId: ChainId,
|
||||
nonce: Nonce,
|
||||
tokens: TokenInfos,
|
||||
|
||||
9
packages/bcp/types/encode.d.ts
vendored
9
packages/bcp/types/encode.d.ts
vendored
@ -1,10 +1,9 @@
|
||||
import { types } from "@cosmwasm/sdk";
|
||||
import { Amount, Fee, FullSignature, PubkeyBundle, SignedTransaction, UnsignedTransaction } from "@iov/bcp";
|
||||
import amino from "@tendermint/amino-js";
|
||||
import { TokenInfos } from "./types";
|
||||
export declare function encodePubkey(pubkey: PubkeyBundle): amino.PubKey;
|
||||
export declare function encodeAmount(amount: Amount, tokens: TokenInfos): amino.Coin;
|
||||
export declare function encodeFee(fee: Fee, tokens: TokenInfos): amino.StdFee;
|
||||
export declare function encodeFullSignature(fullSignature: FullSignature): amino.StdSignature;
|
||||
export declare function encodePubkey(pubkey: PubkeyBundle): types.PubKey;
|
||||
export declare function encodeAmount(amount: Amount, tokens: TokenInfos): types.Coin;
|
||||
export declare function encodeFee(fee: Fee, tokens: TokenInfos): types.StdFee;
|
||||
export declare function encodeFullSignature(fullSignature: FullSignature): types.StdSignature;
|
||||
export declare function buildUnsignedTx(tx: UnsignedTransaction, tokens: TokenInfos): types.AminoTx;
|
||||
export declare function buildSignedTx(tx: SignedTransaction, tokens: TokenInfos): types.AminoTx;
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import amino from "@tendermint/amino-js";
|
||||
|
||||
// We will move all needed *interfaces* from amino-js here
|
||||
// This means bcp can just import them from here (if needed at all)
|
||||
export interface Tx {
|
||||
@ -28,7 +26,6 @@ export interface MsgSend {
|
||||
readonly amount: ReadonlyArray<Coin>;
|
||||
}
|
||||
|
||||
|
||||
export interface StdFee {
|
||||
readonly amount: ReadonlyArray<Coin>;
|
||||
readonly gas: string;
|
||||
@ -53,8 +50,8 @@ export interface PubKey {
|
||||
|
||||
export type AminoTx = Tx & { readonly value: StdTx };
|
||||
|
||||
export function isAminoStdTx(txValue: unknown): txValue is amino.StdTx {
|
||||
const { memo, msg, fee, signatures } = txValue as amino.StdTx;
|
||||
export function isAminoStdTx(txValue: unknown): txValue is StdTx {
|
||||
const { memo, msg, fee, signatures } = txValue as StdTx;
|
||||
return (
|
||||
typeof memo === "string" && Array.isArray(msg) && typeof fee === "object" && Array.isArray(signatures)
|
||||
);
|
||||
|
||||
3
packages/sdk/types/types.d.ts
vendored
3
packages/sdk/types/types.d.ts
vendored
@ -1,4 +1,3 @@
|
||||
import amino from "@tendermint/amino-js";
|
||||
export interface Tx {
|
||||
type: string;
|
||||
value: any;
|
||||
@ -41,7 +40,7 @@ export interface PubKey {
|
||||
export declare type AminoTx = Tx & {
|
||||
readonly value: StdTx;
|
||||
};
|
||||
export declare function isAminoStdTx(txValue: unknown): txValue is amino.StdTx;
|
||||
export declare function isAminoStdTx(txValue: unknown): txValue is StdTx;
|
||||
export interface TokenInfo {
|
||||
readonly denom: string;
|
||||
readonly ticker: string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user