Skip to content

Commit

Permalink
feat(crypto fund): add --tx-id parameter with submitFundTransaction c…
Browse files Browse the repository at this point in the history
…ompatibility and docs PE-6732
  • Loading branch information
fedellen committed Sep 12, 2024
1 parent 02b6c84 commit 23b6035
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -727,18 +727,23 @@ turbo top-up --address 'crypto-wallet-public-native-address' --token ethereum --

##### `crypto-fund`

Fund a wallet with Turbo Credits by submitting a payment transaction for the crypto amount to the Turbo wallet and then submitting that transaction id to Turbo Payment Service for top up processing.
Fund a wallet with Turbo Credits by submitting a payment transaction for the crypto amount to the Turbo wallet and then submitting that transaction id to Turbo Payment Service for top up processing. Alternatively, submit a transaction ID of an existing funding transaction to Turbo Payment Service for top up processing.

Command Options:

- `-v, --value <value>` - Value of crypto token for fund. e.g: 0.0001 for 0.0001 KYVE
- `-i, --tx-id <txId>` - Transaction ID of an existing funding transaction

e.g:

```shell
turbo crypto-fund --value 0.0001 --token kyve --private-key 'b27...45c'
```

```shell
turbo crypto-fund --tx-id 'my-valid-arweave-fund-transaction-id' --token arweave
```

##### `upload-folder`

Upload a folder of files and create and upload a manifest file for the folder upload to the Turbo Upload Service.
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ applyOptions(

applyOptions(
program.command('crypto-fund').description('Top up a wallet with crypto'),
[...walletOptions, optionMap.value],
[...walletOptions, optionMap.value, optionMap.txId],
).action(async (_commandOptions, command: Command) => {
await runCommand(command, cryptoFund);
});
Expand Down
17 changes: 16 additions & 1 deletion src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,23 @@ export async function getBalance(options: AddressOptions) {
/** Fund the connected signer with crypto */
export async function cryptoFund(options: CryptoFundOptions) {
const value = options.value;
const txId = options.txId;

if (txId !== undefined) {
const turbo = TurboFactory.unauthenticated(configFromOptions(options));
const result = await turbo.submitFundTransaction({ txId: txId });

console.log(
'Submitted existing crypto fund transaction to payment service: \n',
JSON.stringify(result, null, 2),
);
return;
}

if (value === undefined) {
throw new Error('Must provide a --value to top up');
throw new Error(
'Must provide a --value or --transaction-id for crypto-fund command',
);
}

const turbo = await turboFromOptions(options);
Expand Down
4 changes: 4 additions & 0 deletions src/cli/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const optionMap = {
description: 'Fiat currency type to use for the action',
default: 'usd',
},
txId: {
alias: '-i, --tx-id <txId>',
description: 'Transaction ID or hash to use for action',
},
address: {
alias: '-a, --address <nativeAddress>',
description: 'Native address to use for action',
Expand Down
1 change: 1 addition & 0 deletions src/cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ export type UploadFileOptions = WalletOptions & {

export type CryptoFundOptions = WalletOptions & {
value: string | undefined;
txId: string | undefined;
};

0 comments on commit 23b6035

Please sign in to comment.