Rename to toBankCoin
This commit is contained in:
parent
e0db927bca
commit
748900f22d
@ -14,12 +14,12 @@ import {
|
||||
import { Encoding } from "@iov/encoding";
|
||||
|
||||
import {
|
||||
amountToBankCoin,
|
||||
buildSignedTx,
|
||||
buildUnsignedTx,
|
||||
encodeFee,
|
||||
encodeFullSignature,
|
||||
encodePubkey,
|
||||
toBankCoin,
|
||||
toErc20Amount,
|
||||
} from "./encode";
|
||||
import { BankTokens, Erc20Token } from "./types";
|
||||
@ -107,9 +107,9 @@ describe("encode", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("amountToBankCoin", () => {
|
||||
describe("toBankCoin", () => {
|
||||
it("encodes an amount", () => {
|
||||
expect(amountToBankCoin(defaultAmount, defaultTokens)).toEqual({
|
||||
expect(toBankCoin(defaultAmount, defaultTokens)).toEqual({
|
||||
denom: "uatom",
|
||||
amount: "11657995",
|
||||
});
|
||||
|
||||
@ -41,7 +41,7 @@ export function toErc20Amount(amount: Amount, erc20Token: Erc20Token): string {
|
||||
return amount.quantity;
|
||||
}
|
||||
|
||||
export function amountToBankCoin(amount: Amount, tokens: BankTokens): types.Coin {
|
||||
export function toBankCoin(amount: Amount, tokens: BankTokens): types.Coin {
|
||||
const match = tokens.find(token => token.ticker === amount.tokenTicker);
|
||||
if (!match) throw Error(`unknown ticker: ${amount.tokenTicker}`);
|
||||
if (match.fractionalDigits !== amount.fractionalDigits) {
|
||||
@ -63,7 +63,7 @@ export function encodeFee(fee: Fee, tokens: BankTokens): types.StdFee {
|
||||
throw new Error("Cannot encode fee without gas limit");
|
||||
}
|
||||
return {
|
||||
amount: [amountToBankCoin(fee.tokens, tokens)],
|
||||
amount: [toBankCoin(fee.tokens, tokens)],
|
||||
gas: fee.gasLimit,
|
||||
};
|
||||
}
|
||||
@ -99,7 +99,7 @@ export function buildUnsignedTx(
|
||||
value: {
|
||||
from_address: tx.sender,
|
||||
to_address: tx.recipient,
|
||||
amount: [amountToBankCoin(tx.amount, bankTokens)],
|
||||
amount: [toBankCoin(tx.amount, bankTokens)],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
2
packages/bcp/types/encode.d.ts
vendored
2
packages/bcp/types/encode.d.ts
vendored
@ -3,7 +3,7 @@ import { Amount, Fee, FullSignature, PubkeyBundle, SignedTransaction, UnsignedTr
|
||||
import { BankTokens, Erc20Token } from "./types";
|
||||
export declare function encodePubkey(pubkey: PubkeyBundle): types.PubKey;
|
||||
export declare function toErc20Amount(amount: Amount, erc20Token: Erc20Token): string;
|
||||
export declare function amountToBankCoin(amount: Amount, tokens: BankTokens): types.Coin;
|
||||
export declare function toBankCoin(amount: Amount, tokens: BankTokens): types.Coin;
|
||||
export declare function encodeFee(fee: Fee, tokens: BankTokens): types.StdFee;
|
||||
export declare function encodeFullSignature(fullSignature: FullSignature): types.StdSignature;
|
||||
export declare function buildUnsignedTx(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user