Skip to content

Commit 0c3ebc6

Browse files
authored
Revert "feat(sdk-coin-apt): send many: addition of recipients (single recipient)"
1 parent 174f7eb commit 0c3ebc6

File tree

9 files changed

+57
-423
lines changed

9 files changed

+57
-423
lines changed

modules/sdk-coin-apt/src/lib/iface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface TxData {
1616
id: string;
1717
sender: string;
1818
recipient: TransactionRecipient;
19-
recipients: TransactionRecipient[];
2019
sequenceNumber: number;
2120
maxGasAmount: number;
2221
gasUnitPrice: number;

modules/sdk-coin-apt/src/lib/transaction/digitalAssetTransfer.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,19 @@ export class DigitalAssetTransfer extends Transaction {
3737
throw new InvalidTransactionError('Invalid transaction payload');
3838
}
3939
const entryFunction = payload.entryFunction;
40+
if (!this._recipient) {
41+
this._recipient = {} as TransactionRecipient;
42+
}
4043
this._assetId = entryFunction.args[0].toString();
41-
this.recipients = [
42-
{
43-
address: entryFunction.args[1].toString(),
44-
amount: DIGITAL_ASSET_TRANSFER_AMOUNT,
45-
},
46-
] as TransactionRecipient[];
44+
this._recipient.address = entryFunction.args[1].toString();
45+
this._recipient.amount = DIGITAL_ASSET_TRANSFER_AMOUNT;
4746
}
4847

4948
protected async buildRawTransaction(): Promise<void> {
5049
const network: Network = this._coinConfig.network.type === NetworkType.MAINNET ? Network.MAINNET : Network.TESTNET;
5150
const aptos = new Aptos(new AptosConfig({ network }));
5251
const senderAddress = AccountAddress.fromString(this._sender);
53-
const recipientAddress = AccountAddress.fromString(this.recipients[0].address);
52+
const recipientAddress = AccountAddress.fromString(this._recipient.address);
5453
const digitalAssetAddress = AccountAddress.fromString(this._assetId);
5554

5655
const transferDigitalAssetAbi: EntryFunctionABI = {

modules/sdk-coin-apt/src/lib/transaction/fungibleAssetTransfer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ export class FungibleAssetTransfer extends Transaction {
3232
throw new InvalidTransactionError('Invalid transaction payload');
3333
}
3434
const entryFunction = payload.entryFunction;
35+
if (!this._recipient) {
36+
this._recipient = {} as TransactionRecipient;
37+
}
3538
this._assetId = entryFunction.args[0].toString();
36-
this.recipients = [
37-
{
38-
address: entryFunction.args[1].toString(),
39-
amount: utils.getAmountFromPayloadArgs(entryFunction.args[2].bcsToBytes()),
40-
},
41-
] as TransactionRecipient[];
39+
this._recipient.address = entryFunction.args[1].toString();
40+
this._recipient.amount = utils.getAmountFromPayloadArgs(entryFunction.args[2].bcsToBytes());
4241
}
4342

4443
protected async buildRawTransaction(): Promise<void> {
4544
const network: Network = this._coinConfig.network.type === NetworkType.MAINNET ? Network.MAINNET : Network.TESTNET;
4645
const aptos = new Aptos(new AptosConfig({ network }));
4746
const senderAddress = AccountAddress.fromString(this._sender);
48-
const recipientAddress = AccountAddress.fromString(this.recipients[0].address);
47+
const recipientAddress = AccountAddress.fromString(this._recipient.address);
4948
const fungibleTokenAddress = this._assetId;
49+
5050
const faTransferAbi: EntryFunctionABI = {
5151
typeParameters: [{ constraints: [] }],
5252
parameters: [parseTypeTag('0x1::object::Object'), new TypeTagAddress(), new TypeTagU64()],
@@ -57,7 +57,7 @@ export class FungibleAssetTransfer extends Transaction {
5757
data: {
5858
function: FUNGIBLE_ASSET_TRANSFER_FUNCTION,
5959
typeArguments: [FUNGIBLE_ASSET_TYPE_ARGUMENT],
60-
functionArguments: [fungibleTokenAddress, recipientAddress, this.recipients[0].amount],
60+
functionArguments: [fungibleTokenAddress, recipientAddress, this.recipient.amount],
6161
abi: faTransferAbi,
6262
},
6363
options: {

modules/sdk-coin-apt/src/lib/transaction/transaction.ts

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ import { DEFAULT_GAS_UNIT_PRICE, UNAVAILABLE_TEXT } from '../constants';
3232
import utils from '../utils';
3333
import BigNumber from 'bignumber.js';
3434
import { AptTransactionExplanation, TxData } from '../iface';
35-
import assert from 'assert';
3635

3736
export abstract class Transaction extends BaseTransaction {
3837
protected _rawTransaction: RawTransaction;
3938
protected _senderSignature: Signature;
4039
protected _feePayerSignature: Signature;
4140
protected _sender: string;
42-
protected _recipients: TransactionRecipient[];
41+
protected _recipient: TransactionRecipient;
4342
protected _sequenceNumber: number;
4443
protected _maxGasAmount: number;
4544
protected _gasUnitPrice: number;
@@ -60,7 +59,6 @@ export abstract class Transaction extends BaseTransaction {
6059
this._expirationTime = utils.getTxnExpirationTimestamp();
6160
this._sequenceNumber = 0;
6261
this._sender = AccountAddress.ZERO.toString();
63-
this._recipients = [];
6462
this._assetId = AccountAddress.ZERO.toString();
6563
this._isSimulateTxn = false;
6664
this._senderSignature = {
@@ -92,27 +90,12 @@ export abstract class Transaction extends BaseTransaction {
9290
this._sender = value;
9391
}
9492

95-
/**
96-
* @deprecated - use `recipients()`.
97-
*/
9893
get recipient(): TransactionRecipient {
99-
assert(this._recipients.length > 0, 'No recipients available');
100-
return this._recipients[0];
94+
return this._recipient;
10195
}
10296

103-
/**
104-
* @deprecated - use `recipients()`.
105-
*/
10697
set recipient(value: TransactionRecipient) {
107-
this.recipients = [value];
108-
}
109-
110-
get recipients(): TransactionRecipient[] {
111-
return this._recipients;
112-
}
113-
114-
set recipients(value: TransactionRecipient[]) {
115-
this._recipients = value;
98+
this._recipient = value;
11699
}
117100

118101
get sequenceNumber(): number {
@@ -275,24 +258,20 @@ export abstract class Transaction extends BaseTransaction {
275258
}
276259

277260
loadInputsAndOutputs(): void {
278-
const totalAmount = this._recipients.reduce(
279-
(accumulator, current) => accumulator.plus(current.amount),
280-
new BigNumber('0')
281-
);
282261
this._inputs = [
283262
{
284263
address: this.sender,
285-
value: totalAmount.toString(),
264+
value: this.recipient.amount as string,
286265
coin: this._coinConfig.name,
287266
},
288267
];
289-
this._outputs = this._recipients.map((recipient) => {
290-
return {
291-
address: recipient.address,
292-
value: recipient.amount as string,
268+
this._outputs = [
269+
{
270+
address: this.recipient.address,
271+
value: this.recipient.amount as string,
293272
coin: this._coinConfig.name,
294-
};
295-
});
273+
},
274+
];
296275
}
297276

298277
fromRawTransaction(rawTransaction: string): void {
@@ -324,7 +303,6 @@ export abstract class Transaction extends BaseTransaction {
324303
id: this.id,
325304
sender: this.sender,
326305
recipient: this.recipient,
327-
recipients: this.recipients,
328306
sequenceNumber: this.sequenceNumber,
329307
maxGasAmount: this.maxGasAmount,
330308
gasUnitPrice: this.gasUnitPrice,
@@ -357,10 +335,8 @@ export abstract class Transaction extends BaseTransaction {
357335
'type',
358336
];
359337

360-
const outputs: TransactionRecipient[] = this._recipients;
361-
const outputAmount = outputs
362-
.reduce((accumulator, current) => accumulator.plus(current.amount), new BigNumber('0'))
363-
.toString();
338+
const outputs: TransactionRecipient[] = [this.recipient];
339+
const outputAmount = outputs[0].amount;
364340
return {
365341
displayOrder,
366342
id: this.id,

modules/sdk-coin-apt/src/lib/transaction/transferTransaction.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,25 @@ export class TransferTransaction extends Transaction {
3030
throw new InvalidTransactionError('Invalid transaction payload');
3131
}
3232
const entryFunction = payload.entryFunction;
33+
if (!this._recipient) {
34+
this._recipient = {} as TransactionRecipient;
35+
}
3336
this._assetId = entryFunction.type_args[0].toString();
34-
this.recipients = [
35-
{
36-
address: entryFunction.args[0].toString(),
37-
amount: utils.getAmountFromPayloadArgs(entryFunction.args[1].bcsToBytes()),
38-
},
39-
] as TransactionRecipient[];
37+
this._recipient.address = entryFunction.args[0].toString();
38+
this._recipient.amount = utils.getAmountFromPayloadArgs(entryFunction.args[1].bcsToBytes());
4039
}
4140

4241
protected async buildRawTransaction(): Promise<void> {
4342
const network: Network = this._coinConfig.network.type === NetworkType.MAINNET ? Network.MAINNET : Network.TESTNET;
4443
const aptos = new Aptos(new AptosConfig({ network }));
4544
const senderAddress = AccountAddress.fromString(this._sender);
46-
const recipientAddress = AccountAddress.fromString(this.recipients[0].address);
45+
const recipientAddress = AccountAddress.fromString(this._recipient.address);
4746
const simpleTxn = await aptos.transaction.build.simple({
4847
sender: senderAddress,
4948
data: {
5049
function: COIN_TRANSFER_FUNCTION,
5150
typeArguments: [this.assetId],
52-
functionArguments: [recipientAddress, this.recipients[0].amount],
51+
functionArguments: [recipientAddress, this.recipient.amount],
5352
},
5453
options: {
5554
maxGasAmount: this.maxGasAmount,

modules/sdk-coin-apt/src/lib/transactionBuilder/transactionBuilder.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,10 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
6363
return this;
6464
}
6565

66-
/**
67-
* @deprecated - use `recipients()`.
68-
*/
6966
recipient(recipient: Recipient): this {
7067
this.validateAddress({ address: recipient.address });
7168
this.validateValue(new BigNumber(recipient.amount));
72-
this.transaction.recipients = [recipient];
73-
return this;
74-
}
75-
76-
recipients(recipients: Recipient[]): this {
77-
for (const recipient of recipients) {
78-
this.validateAddress({ address: recipient.address });
79-
this.validateValue(new BigNumber(recipient.amount));
80-
}
81-
this.transaction.recipients = recipients;
69+
this.transaction.recipient = recipient;
8270
return this;
8371
}
8472

@@ -155,10 +143,8 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
155143
throw new Error('transaction not defined');
156144
}
157145
this.validateAddress({ address: transaction.sender });
158-
for (const recipient of transaction.recipients) {
159-
this.validateAddress({ address: recipient.address });
160-
this.validateValue(new BigNumber(recipient.amount));
161-
}
146+
this.validateAddress({ address: transaction.recipient.address });
147+
this.validateValue(new BigNumber(transaction.recipient.amount));
162148
}
163149

164150
isValidRawTransaction(rawTransaction: string): boolean {

0 commit comments

Comments
 (0)