Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk-coin-atom): add sendMany support #3965

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/abstract-cosmos/src/cosmosCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
VerifyTransactionOptions,
} from '@bitgo/sdk-core';
import { EcdsaPaillierProof, EcdsaRangeProof, EcdsaTypes } from '@bitgo/sdk-lib-mpc';
import { CoinFamily, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
import { BaseCoin as StaticsBaseCoin, CoinFamily } from '@bitgo/statics';
import { bip32 } from '@bitgo/utxo-lib';
import { Coin } from '@cosmjs/stargate';
import { BigNumber } from 'bignumber.js';
Expand Down
175 changes: 91 additions & 84 deletions modules/abstract-cosmos/src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { fromHex, toBase64 } from '@cosmjs/encoding';
import { makeSignBytes } from '@cosmjs/proto-signing';
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';

import { UNAVAILABLE_TEXT } from './constants';

import {
CosmosLikeTransaction,
DelegateOrUndelegeteMessage,
Expand Down Expand Up @@ -174,64 +172,65 @@ export class CosmosTransaction extends BaseTransaction {
*/
explainTransactionInternal(json: TxData, explanationResult: TransactionExplanation): TransactionExplanation {
let outputs: TransactionRecipient[];
let message;
let outputAmount;
switch (json.type) {
case TransactionType.Send:
explanationResult.type = TransactionType.Send;
message = json.sendMessages[0].value as SendMessage;
outputAmount = message.amount[0].amount;
outputs = [
{
address: message.toAddress,
amount: outputAmount,
},
];
outputAmount = BigInt(0);
outputs = json.sendMessages.map((message) => {
const sendMessage = message.value as SendMessage;
outputAmount = outputAmount + BigInt(sendMessage.amount[0].amount);
return {
address: sendMessage.toAddress,
amount: sendMessage.amount[0].amount,
};
});
break;
case TransactionType.StakingActivate:
explanationResult.type = TransactionType.StakingActivate;
message = json.sendMessages[0].value as DelegateOrUndelegeteMessage;
outputAmount = message.amount.amount;
outputs = [
{
address: message.validatorAddress,
amount: outputAmount,
},
];
outputAmount = BigInt(0);
outputs = json.sendMessages.map((message) => {
const delegateMessage = message.value as DelegateOrUndelegeteMessage;
outputAmount = outputAmount + BigInt(delegateMessage.amount.amount);
return {
address: delegateMessage.validatorAddress,
amount: delegateMessage.amount.amount,
};
});
break;
case TransactionType.StakingDeactivate:
explanationResult.type = TransactionType.StakingDeactivate;
message = json.sendMessages[0].value as DelegateOrUndelegeteMessage;
outputAmount = message.amount.amount;
outputs = [
{
address: message.validatorAddress,
amount: outputAmount,
},
];
outputAmount = BigInt(0);
outputs = json.sendMessages.map((message) => {
const delegateMessage = message.value as DelegateOrUndelegeteMessage;
outputAmount = outputAmount + BigInt(delegateMessage.amount.amount);
return {
address: delegateMessage.validatorAddress,
amount: delegateMessage.amount.amount,
};
});
break;
case TransactionType.StakingWithdraw:
explanationResult.type = TransactionType.StakingWithdraw;
message = json.sendMessages[0].value as WithdrawDelegatorRewardsMessage;
outputs = [
{
address: message.validatorAddress,
outputs = json.sendMessages.map((message) => {
const withdrawMessage = message.value as WithdrawDelegatorRewardsMessage;
return {
address: withdrawMessage.validatorAddress,
amount: UNAVAILABLE_TEXT,
},
];
outputAmount = UNAVAILABLE_TEXT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this intentionally removed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, to make is similar to atom. I also checked that it is not being used anywhere

};
});
dpkjnr marked this conversation as resolved.
Show resolved Hide resolved
break;
case TransactionType.ContractCall:
explanationResult.type = TransactionType.ContractCall;
message = json.sendMessages[0].value as ExecuteContractMessage;
outputAmount = message.funds?.[0]?.amount ?? '0';
outputs = [
{
address: message.contract,
amount: outputAmount,
},
];
outputAmount = outputAmount;
outputAmount = BigInt(0);
outputs = json.sendMessages.map((message) => {
const executeContractMessage = message.value as ExecuteContractMessage;
outputAmount = outputAmount + BigInt(executeContractMessage.funds?.[0]?.amount ?? '0');
return {
address: executeContractMessage.contract,
amount: executeContractMessage.funds?.[0]?.amount ?? '0',
};
});
break;
default:
throw new InvalidTransactionError('Transaction type not supported');
Expand All @@ -243,7 +242,7 @@ export class CosmosTransaction extends BaseTransaction {
}
return {
...explanationResult,
outputAmount,
outputAmount: outputAmount?.toString(),
outputs,
};
}
Expand All @@ -262,56 +261,64 @@ export class CosmosTransaction extends BaseTransaction {
const inputs: Entry[] = [];
switch (this.type) {
case TransactionType.Send:
const message = this.cosmosLikeTransaction.sendMessages[0].value as SendMessage;
inputs.push({
address: message.fromAddress,
value: message.amount[0].amount,
coin: this._coinConfig.name,
});
outputs.push({
address: message.toAddress,
value: message.amount[0].amount,
coin: this._coinConfig.name,
this.cosmosLikeTransaction.sendMessages.forEach((message) => {
const sendMessage = message.value as SendMessage;
inputs.push({
address: sendMessage.fromAddress,
value: sendMessage.amount[0].amount,
coin: this._coinConfig.name,
});
outputs.push({
address: sendMessage.toAddress,
value: sendMessage.amount[0].amount,
coin: this._coinConfig.name,
});
});
break;
case TransactionType.StakingActivate:
case TransactionType.StakingDeactivate:
const delegateMessage = this.cosmosLikeTransaction.sendMessages[0].value as DelegateOrUndelegeteMessage;
inputs.push({
address: delegateMessage.delegatorAddress,
value: delegateMessage.amount.amount,
coin: this._coinConfig.name,
});
outputs.push({
address: delegateMessage.validatorAddress,
value: delegateMessage.amount.amount,
coin: this._coinConfig.name,
this.cosmosLikeTransaction.sendMessages.forEach((message) => {
const delegateMessage = message.value as DelegateOrUndelegeteMessage;
inputs.push({
address: delegateMessage.delegatorAddress,
value: delegateMessage.amount.amount,
coin: this._coinConfig.name,
});
outputs.push({
address: delegateMessage.validatorAddress,
value: delegateMessage.amount.amount,
coin: this._coinConfig.name,
});
});
break;
case TransactionType.StakingWithdraw:
const withdrawMessage = this.cosmosLikeTransaction.sendMessages[0].value as WithdrawDelegatorRewardsMessage;
inputs.push({
address: withdrawMessage.delegatorAddress,
value: UNAVAILABLE_TEXT,
coin: this._coinConfig.name,
});
outputs.push({
address: withdrawMessage.validatorAddress,
value: UNAVAILABLE_TEXT,
coin: this._coinConfig.name,
this.cosmosLikeTransaction.sendMessages.forEach((message) => {
const withdrawMessage = message.value as WithdrawDelegatorRewardsMessage;
inputs.push({
address: withdrawMessage.delegatorAddress,
value: UNAVAILABLE_TEXT,
coin: this._coinConfig.name,
});
outputs.push({
address: withdrawMessage.validatorAddress,
value: UNAVAILABLE_TEXT,
coin: this._coinConfig.name,
});
});
break;
case TransactionType.ContractCall:
const executeContractMessage = this.cosmosLikeTransaction.sendMessages[0].value as ExecuteContractMessage;
inputs.push({
address: executeContractMessage.sender,
value: executeContractMessage.funds?.[0]?.amount ?? '0',
coin: this._coinConfig.name,
});
outputs.push({
address: executeContractMessage.contract,
value: executeContractMessage.funds?.[0]?.amount ?? '0',
coin: this._coinConfig.name,
this.cosmosLikeTransaction.sendMessages.forEach((message) => {
const executeContractMessage = message.value as ExecuteContractMessage;
inputs.push({
address: executeContractMessage.sender,
value: executeContractMessage.funds?.[0]?.amount ?? '0',
coin: this._coinConfig.name,
});
outputs.push({
address: executeContractMessage.contract,
value: executeContractMessage.funds?.[0]?.amount ?? '0',
coin: this._coinConfig.name,
});
});
break;
default:
Expand Down
Loading
Loading