Merge pull request #737 from cosmos/731-rm-coinFromProto

Remove coinFromProto etc
This commit is contained in:
Will Clark 2021-03-30 11:17:49 +01:00 committed by GitHub
commit 7e94bb54fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 183 deletions

View File

@ -84,6 +84,11 @@ and this project adheres to
do not need a Tendermint RPC client and Stargate applications should use
`Tendermint34Client`.
### Removed
- @cosmjs/stargate: `coinFromProto` helper has been removed as it is no longer
needed after the `ts-proto` migration.
## [0.24.0] - 2021-03-11
- @cosmjs/cosmwasm: This package is now deprecated. The same functionality is

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding";
import { AminoConverter, Coin, coinFromProto } from "@cosmjs/stargate";
import { assertDefinedAndNotNull } from "@cosmjs/utils";
import { AminoConverter, Coin } from "@cosmjs/stargate";
import Long from "long";
import {
@ -127,18 +126,12 @@ export interface AminoMsgClearAdmin {
export const cosmWasmTypes: Record<string, AminoConverter> = {
"/cosmwasm.wasm.v1beta1.MsgStoreCode": {
aminoType: "wasm/MsgStoreCode",
toAmino: ({ sender, wasmByteCode, source, builder }: MsgStoreCode): AminoMsgStoreCode["value"] => {
assertDefinedAndNotNull(sender, "missing sender");
assertDefinedAndNotNull(wasmByteCode, "missing wasmByteCode");
assertDefinedAndNotNull(source, "missing source");
assertDefinedAndNotNull(builder, "missing builder");
return {
sender: sender,
wasm_byte_code: toBase64(wasmByteCode),
source: source,
builder: builder,
};
},
toAmino: ({ sender, wasmByteCode, source, builder }: MsgStoreCode): AminoMsgStoreCode["value"] => ({
sender: sender,
wasm_byte_code: toBase64(wasmByteCode),
source: source,
builder: builder,
}),
fromAmino: ({ sender, wasm_byte_code, source, builder }: AminoMsgStoreCode["value"]): MsgStoreCode => ({
sender: sender,
wasmByteCode: fromBase64(wasm_byte_code),
@ -156,21 +149,14 @@ export const cosmWasmTypes: Record<string, AminoConverter> = {
initMsg,
funds,
admin,
}: MsgInstantiateContract): AminoMsgInstantiateContract["value"] => {
assertDefinedAndNotNull(sender, "missing sender");
assertDefinedAndNotNull(codeId, "missing codeId");
assertDefinedAndNotNull(label, "missing label");
assertDefinedAndNotNull(initMsg, "missing initMsg");
assertDefinedAndNotNull(funds, "missing funds");
return {
sender: sender,
code_id: codeId.toString(),
label: label,
init_msg: JSON.parse(fromUtf8(initMsg)),
funds: funds.map(coinFromProto),
admin: admin ?? undefined,
};
},
}: MsgInstantiateContract): AminoMsgInstantiateContract["value"] => ({
sender: sender,
code_id: codeId.toString(),
label: label,
init_msg: JSON.parse(fromUtf8(initMsg)),
funds: funds,
admin: admin ?? undefined,
}),
fromAmino: ({
sender,
code_id,
@ -189,16 +175,11 @@ export const cosmWasmTypes: Record<string, AminoConverter> = {
},
"/cosmwasm.wasm.v1beta1.MsgUpdateAdmin": {
aminoType: "wasm/MsgUpdateAdmin",
toAmino: ({ sender, newAdmin, contract }: MsgUpdateAdmin): AminoMsgUpdateAdmin["value"] => {
assertDefinedAndNotNull(sender, "missing sender");
assertDefinedAndNotNull(newAdmin, "missing newAdmin");
assertDefinedAndNotNull(contract, "missing contract");
return {
sender: sender,
new_admin: newAdmin,
contract: contract,
};
},
toAmino: ({ sender, newAdmin, contract }: MsgUpdateAdmin): AminoMsgUpdateAdmin["value"] => ({
sender: sender,
new_admin: newAdmin,
contract: contract,
}),
fromAmino: ({ sender, new_admin, contract }: AminoMsgUpdateAdmin["value"]): MsgUpdateAdmin => ({
sender: sender,
newAdmin: new_admin,
@ -207,14 +188,10 @@ export const cosmWasmTypes: Record<string, AminoConverter> = {
},
"/cosmwasm.wasm.v1beta1.MsgClearAdmin": {
aminoType: "wasm/MsgClearAdmin",
toAmino: ({ sender, contract }: MsgClearAdmin): AminoMsgClearAdmin["value"] => {
assertDefinedAndNotNull(sender, "missing sender");
assertDefinedAndNotNull(contract, "missing contract");
return {
sender: sender,
contract: contract,
};
},
toAmino: ({ sender, contract }: MsgClearAdmin): AminoMsgClearAdmin["value"] => ({
sender: sender,
contract: contract,
}),
fromAmino: ({ sender, contract }: AminoMsgClearAdmin["value"]): MsgClearAdmin => ({
sender: sender,
contract: contract,
@ -222,18 +199,12 @@ export const cosmWasmTypes: Record<string, AminoConverter> = {
},
"/cosmwasm.wasm.v1beta1.MsgExecuteContract": {
aminoType: "wasm/MsgExecuteContract",
toAmino: ({ sender, contract, msg, funds }: MsgExecuteContract): AminoMsgExecuteContract["value"] => {
assertDefinedAndNotNull(sender, "missing sender");
assertDefinedAndNotNull(contract, "missing contract");
assertDefinedAndNotNull(msg, "missing msg");
assertDefinedAndNotNull(funds, "missing funds");
return {
sender: sender,
contract: contract,
msg: JSON.parse(fromUtf8(msg)),
funds: funds.map(coinFromProto),
};
},
toAmino: ({ sender, contract, msg, funds }: MsgExecuteContract): AminoMsgExecuteContract["value"] => ({
sender: sender,
contract: contract,
msg: JSON.parse(fromUtf8(msg)),
funds: funds,
}),
fromAmino: ({ sender, contract, msg, funds }: AminoMsgExecuteContract["value"]): MsgExecuteContract => ({
sender: sender,
contract: contract,
@ -248,18 +219,12 @@ export const cosmWasmTypes: Record<string, AminoConverter> = {
contract,
codeId,
migrateMsg,
}: MsgMigrateContract): AminoMsgMigrateContract["value"] => {
assertDefinedAndNotNull(sender, "missing sender");
assertDefinedAndNotNull(contract, "missing contract");
assertDefinedAndNotNull(codeId, "missing codeId");
assertDefinedAndNotNull(migrateMsg, "missing migrateMsg");
return {
sender: sender,
contract: contract,
code_id: codeId.toString(),
msg: JSON.parse(fromUtf8(migrateMsg)),
};
},
}: MsgMigrateContract): AminoMsgMigrateContract["value"] => ({
sender: sender,
contract: contract,
code_id: codeId.toString(),
msg: JSON.parse(fromUtf8(migrateMsg)),
}),
fromAmino: ({
sender,
contract,

View File

@ -16,7 +16,6 @@ import {
Block,
BroadcastTxResponse,
Coin,
coinFromProto,
IndexedTx,
isSearchByHeightQuery,
isSearchBySentFromOrToQuery,
@ -144,8 +143,7 @@ export class CosmWasmClient {
}
public async getBalance(address: string, searchDenom: string): Promise<Coin | null> {
const balance = await this.forceGetQueryClient().bank.balance(address, searchDenom);
return balance ? coinFromProto(balance) : null;
return this.forceGetQueryClient().bank.balance(address, searchDenom);
}
public async getTx(id: string): Promise<IndexedTx | null> {

View File

@ -31,7 +31,6 @@ import {
MsgEditValidator,
MsgUndelegate,
} from "./codec/cosmos/staking/v1beta1/tx";
import { coinFromProto } from "./stargateclient";
export interface AminoConverter {
readonly aminoType: string;
@ -43,16 +42,11 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
return {
"/cosmos.bank.v1beta1.MsgSend": {
aminoType: "cosmos-sdk/MsgSend",
toAmino: ({ fromAddress, toAddress, amount }: MsgSend): AminoMsgSend["value"] => {
assertDefinedAndNotNull(fromAddress, "missing fromAddress");
assertDefinedAndNotNull(toAddress, "missing toAddress");
assertDefinedAndNotNull(amount, "missing amount");
return {
from_address: fromAddress,
to_address: toAddress,
amount: amount.map(coinFromProto),
};
},
toAmino: ({ fromAddress, toAddress, amount }: MsgSend): AminoMsgSend["value"] => ({
from_address: fromAddress,
to_address: toAddress,
amount: [...amount],
}),
fromAmino: ({ from_address, to_address, amount }: AminoMsgSend["value"]): MsgSend => ({
fromAddress: from_address,
toAddress: to_address,
@ -61,28 +55,16 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
},
"/cosmos.bank.v1beta1.MsgMultiSend": {
aminoType: "cosmos-sdk/MsgMultiSend",
toAmino: ({ inputs, outputs }: MsgMultiSend): AminoMsgMultiSend["value"] => {
assertDefinedAndNotNull(inputs, "missing inputs");
assertDefinedAndNotNull(outputs, "missing outputs");
return {
inputs: inputs.map((input) => {
assertDefinedAndNotNull(input.address, "missing input.address");
assertDefinedAndNotNull(input.coins, "missing input.amount");
return {
address: input.address,
coins: input.coins.map(coinFromProto),
};
}),
outputs: outputs.map((output) => {
assertDefinedAndNotNull(output.address, "missing output.address");
assertDefinedAndNotNull(output.coins, "missing output.coins");
return {
address: output.address,
coins: output.coins.map(coinFromProto),
};
}),
};
},
toAmino: ({ inputs, outputs }: MsgMultiSend): AminoMsgMultiSend["value"] => ({
inputs: inputs.map((input) => ({
address: input.address,
coins: [...input.coins],
})),
outputs: outputs.map((output) => ({
address: output.address,
coins: [...output.coins],
})),
}),
fromAmino: ({ inputs, outputs }: AminoMsgMultiSend["value"]): MsgMultiSend => ({
inputs: inputs.map((input) => ({
address: input.address,
@ -96,14 +78,10 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
},
"/cosmos.distribution.v1beta1.MsgFundCommunityPool": {
aminoType: "cosmos-sdk/MsgFundCommunityPool",
toAmino: ({ amount, depositor }: MsgFundCommunityPool): AminoMsgFundCommunityPool["value"] => {
assertDefinedAndNotNull(amount);
assertDefinedAndNotNull(depositor);
return {
amount: amount.map(coinFromProto),
depositor: depositor,
};
},
toAmino: ({ amount, depositor }: MsgFundCommunityPool): AminoMsgFundCommunityPool["value"] => ({
amount: [...amount],
depositor: depositor,
}),
fromAmino: ({ amount, depositor }: AminoMsgFundCommunityPool["value"]): MsgFundCommunityPool => ({
amount: [...amount],
depositor: depositor,
@ -114,14 +92,10 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
toAmino: ({
delegatorAddress,
withdrawAddress,
}: MsgSetWithdrawAddress): AminoMsgSetWithdrawAddress["value"] => {
assertDefinedAndNotNull(delegatorAddress);
assertDefinedAndNotNull(withdrawAddress);
return {
delegator_address: delegatorAddress,
withdraw_address: withdrawAddress,
};
},
}: MsgSetWithdrawAddress): AminoMsgSetWithdrawAddress["value"] => ({
delegator_address: delegatorAddress,
withdraw_address: withdrawAddress,
}),
fromAmino: ({
delegator_address,
withdraw_address,
@ -135,14 +109,10 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
toAmino: ({
delegatorAddress,
validatorAddress,
}: MsgWithdrawDelegatorReward): AminoMsgWithdrawDelegatorReward["value"] => {
assertDefinedAndNotNull(delegatorAddress);
assertDefinedAndNotNull(validatorAddress);
return {
delegator_address: delegatorAddress,
validator_address: validatorAddress,
};
},
}: MsgWithdrawDelegatorReward): AminoMsgWithdrawDelegatorReward["value"] => ({
delegator_address: delegatorAddress,
validator_address: validatorAddress,
}),
fromAmino: ({
delegator_address,
validator_address,
@ -155,12 +125,9 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
aminoType: "cosmos-sdk/MsgWithdrawValidatorCommission",
toAmino: ({
validatorAddress,
}: MsgWithdrawValidatorCommission): AminoMsgWithdrawValidatorCommission["value"] => {
assertDefinedAndNotNull(validatorAddress);
return {
validator_address: validatorAddress,
};
},
}: MsgWithdrawValidatorCommission): AminoMsgWithdrawValidatorCommission["value"] => ({
validator_address: validatorAddress,
}),
fromAmino: ({
validator_address,
}: AminoMsgWithdrawValidatorCommission["value"]): MsgWithdrawValidatorCommission => ({
@ -175,15 +142,12 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
validatorDstAddress,
amount,
}: MsgBeginRedelegate): AminoMsgBeginRedelegate["value"] => {
assertDefinedAndNotNull(delegatorAddress, "missing delegatorAddress");
assertDefinedAndNotNull(validatorSrcAddress, "missing validatorSrcAddress");
assertDefinedAndNotNull(validatorDstAddress, "missing validatorDstAddress");
assertDefinedAndNotNull(amount, "missing amount");
return {
delegator_address: delegatorAddress,
validator_src_address: validatorSrcAddress,
validator_dst_address: validatorDstAddress,
amount: coinFromProto(amount),
amount: amount,
};
},
fromAmino: ({
@ -210,20 +174,8 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
value,
}: MsgCreateValidator): AminoMsgCreateValidator["value"] => {
assertDefinedAndNotNull(description, "missing description");
assertDefinedAndNotNull(description.moniker, "missing description.moniker");
assertDefinedAndNotNull(description.identity, "missing description.identity");
assertDefinedAndNotNull(description.website, "missing description.website");
assertDefinedAndNotNull(description.securityContact, "missing description.securityContact");
assertDefinedAndNotNull(description.details, "missing description.details");
assertDefinedAndNotNull(commission, "missing commission");
assertDefinedAndNotNull(commission.rate, "missing commission.rate");
assertDefinedAndNotNull(commission.maxRate, "missing commission.maxRate");
assertDefinedAndNotNull(commission.maxChangeRate, "missing commission.maxChangeRate");
assertDefinedAndNotNull(minSelfDelegation, "missing minSelfDelegation");
assertDefinedAndNotNull(delegatorAddress, "missing delegatorAddress");
assertDefinedAndNotNull(validatorAddress, "missing validatorAddress");
assertDefinedAndNotNull(pubkey, "missing pubkey");
assertDefinedAndNotNull(pubkey.value, "missing pubkey.value");
assertDefinedAndNotNull(value, "missing value");
return {
description: {
@ -248,7 +200,7 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
},
prefix,
),
value: coinFromProto(value),
value: value,
};
},
fromAmino: ({
@ -291,13 +243,11 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
"/cosmos.staking.v1beta1.MsgDelegate": {
aminoType: "cosmos-sdk/MsgDelegate",
toAmino: ({ delegatorAddress, validatorAddress, amount }: MsgDelegate): AminoMsgDelegate["value"] => {
assertDefinedAndNotNull(delegatorAddress, "missing delegatorAddress");
assertDefinedAndNotNull(validatorAddress, "missing validatorAddress");
assertDefinedAndNotNull(amount, "missing amount");
return {
delegator_address: delegatorAddress,
validator_address: validatorAddress,
amount: coinFromProto(amount),
amount: amount,
};
},
fromAmino: ({
@ -319,14 +269,6 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
validatorAddress,
}: MsgEditValidator): AminoMsgEditValidator["value"] => {
assertDefinedAndNotNull(description, "missing description");
assertDefinedAndNotNull(description.moniker, "missing description.moniker");
assertDefinedAndNotNull(description.identity, "missing description.identity");
assertDefinedAndNotNull(description.website, "missing description.website");
assertDefinedAndNotNull(description.securityContact, "missing description.securityContact");
assertDefinedAndNotNull(description.details, "missing description.details");
assertDefinedAndNotNull(commissionRate, "missing commissionRate");
assertDefinedAndNotNull(minSelfDelegation, "missing minSelfDelegation");
assertDefinedAndNotNull(validatorAddress, "missing validatorAddress");
return {
description: {
moniker: description.moniker,
@ -365,13 +307,11 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
validatorAddress,
amount,
}: MsgUndelegate): AminoMsgUndelegate["value"] => {
assertDefinedAndNotNull(delegatorAddress, "missing delegatorAddress");
assertDefinedAndNotNull(validatorAddress, "missing validatorAddress");
assertDefinedAndNotNull(amount, "missing amount");
return {
delegator_address: delegatorAddress,
validator_address: validatorAddress,
amount: coinFromProto(amount),
amount: amount,
};
},
fromAmino: ({

View File

@ -75,7 +75,6 @@ export {
BroadcastTxFailure,
BroadcastTxResponse,
BroadcastTxSuccess,
coinFromProto,
IndexedTx,
isBroadcastTxFailure,
isBroadcastTxSuccess,

View File

@ -6,7 +6,6 @@ import {
Tendermint34Client,
toRfc3339WithNanoseconds,
} from "@cosmjs/tendermint-rpc";
import { assertDefinedAndNotNull } from "@cosmjs/utils";
import { Account, accountFromAny } from "./accounts";
import { MsgData, TxMsgData } from "./codec/cosmos/base/abci/v1beta1/abci";
@ -99,15 +98,6 @@ export function assertIsBroadcastTxSuccess(
}
}
export function coinFromProto(input: Coin): Coin {
assertDefinedAndNotNull(input.amount);
assertDefinedAndNotNull(input.denom);
return {
amount: input.amount,
denom: input.denom,
};
}
/** Use for testing only */
export interface PrivateStargateClient {
readonly tmClient: Tendermint34Client | undefined;
@ -213,8 +203,7 @@ export class StargateClient {
}
public async getBalance(address: string, searchDenom: string): Promise<Coin | null> {
const balance = await this.forceGetQueryClient().bank.balance(address, searchDenom);
return balance ? coinFromProto(balance) : null;
return this.forceGetQueryClient().bank.balance(address, searchDenom);
}
/**
@ -224,8 +213,7 @@ export class StargateClient {
* proofs from such a method.
*/
public async getAllBalancesUnverified(address: string): Promise<readonly Coin[]> {
const balances = await this.forceGetQueryClient().bank.unverified.allBalances(address);
return balances.map(coinFromProto);
return this.forceGetQueryClient().bank.unverified.allBalances(address);
}
public async getTx(id: string): Promise<IndexedTx | null> {