Skip to content

Commit e58c0e8

Browse files
committed
fix(sdk-coin-cosmos): utils and cosmosSharedCoin fixes
TICKET: COIN-4881 - Addition of validDenoms in CosmosNetwork interface - Fixing denom validation in utils - Addition of staticsCoin in CosmosSharedCoin
1 parent 5644b36 commit e58c0e8

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

modules/sdk-coin-cosmos/src/cosmosSharedCoin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import { KeyPair, Utils, TransactionBuilderFactory } from './lib';
99
* instead of requiring individual coin modules
1010
*/
1111
export class CosmosSharedCoin extends CosmosCoin {
12-
private readonly _network: CosmosNetwork;
12+
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
13+
protected readonly _network: CosmosNetwork;
1314

1415
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
1516
super(bitgo, staticsCoin);
1617

1718
if (!staticsCoin) {
1819
throw new Error('missing required constructor parameter staticsCoin');
1920
}
20-
21+
this._staticsCoin = staticsCoin;
2122
// Get the network configuration from statics
2223
const network = staticsCoin.network as CosmosNetwork;
2324
if (!network || !network.addressPrefix || !network.validatorPrefix) {

modules/sdk-coin-cosmos/src/lib/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ export class Utils extends CosmosUtils {
4444
if (!amount?.denom) {
4545
throw new InvalidTransactionError('Invalid amount: missing denom');
4646
}
47-
if (amount.denom !== this._network.denom) {
48-
throw new InvalidTransactionError(
49-
`Invalid amount: denom '${amount.denom}' does not match network denom '${this._network.denom}'`
50-
);
47+
if (!this._network.validDenoms.includes(amount.denom)) {
48+
throw new InvalidTransactionError(`Invalid amount: denom '${amount.denom}' is not a valid denomination`);
5149
}
5250
if (!amount?.amount) {
5351
throw new InvalidTransactionError('Invalid amount: missing amount');

modules/statics/src/networks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export interface CosmosNetwork extends AccountNetwork {
8585
readonly denom: string;
8686
readonly gasAmount: string;
8787
readonly gasLimit: number;
88+
readonly validDenoms: string[];
8889
}
8990

9091
/**

0 commit comments

Comments
 (0)