Skip to content

Commit

Permalink
Add nodejs send wrapper methods (#1103)
Browse files Browse the repository at this point in the history
* Add send wrapper methods

* Update bindings/nodejs/lib/wallet/account.ts

Co-authored-by: Thibault Martinez <[email protected]>

* Address review comments

* Update bindings/nodejs/CHANGELOG.md

* Update bindings/nodejs/lib/wallet/account.ts

Co-authored-by: Thibault Martinez <[email protected]>

* Update bindings/nodejs/lib/wallet/account.ts

Co-authored-by: Thibault Martinez <[email protected]>

* Fix example

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
Thoralf-M and thibault-martinez authored Aug 30, 2023
1 parent 1be824f commit 72f19a3
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 61 deletions.
32 changes: 16 additions & 16 deletions bindings/nodejs-old/lib/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class Account {
* recommended to use melting, if the foundry output is available.
* @param tokenId The native token id.
* @param burnAmount The to be burned amount.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The transaction.
*/
Expand All @@ -164,7 +164,7 @@ export class Account {
/**
* Burn an nft output
* @param nftId The NftId.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The transaction.
*/
Expand Down Expand Up @@ -229,7 +229,7 @@ export class Account {
/**
* `createAliasOutput` creates an alias output
* @param params The alias output options.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns A transaction object.
*/
Expand All @@ -255,7 +255,7 @@ export class Account {
* `melted_tokens` field.
* @param tokenId The native token id.
* @param meltAmount To be melted amount.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The transaction.
*/
Expand Down Expand Up @@ -296,7 +296,7 @@ export class Account {
/**
* Destroy an alias output.
* @param aliasId The AliasId.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The transaction.
*/
Expand All @@ -321,7 +321,7 @@ export class Account {
* Function to destroy a foundry output with a circulating supply of 0.
* Native tokens in the foundry (minted by other foundries) will be transactioned to the controlling alias.
* @param foundryId The FoundryId.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The transaction.
*/
Expand Down Expand Up @@ -761,7 +761,7 @@ export class Account {
* Mint additional native tokens.
* @param tokenId The native token id.
* @param mintAmount To be minted amount.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The minting transaction.
*/
Expand All @@ -788,7 +788,7 @@ export class Account {
/**
* Create a native token.
* @param params The options for creating the token.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The creating transaction and the token ID.
*/
Expand All @@ -813,7 +813,7 @@ export class Account {
/**
* Mint nfts.
* @param params The options for minting nfts.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The minting transaction.
*/
Expand Down Expand Up @@ -844,7 +844,7 @@ export class Account {
* storage deposit will be sent to the recipient. When the assets contain
* an nft id, the data from the existing `NftOutput` will be used, just with
* the address unlock conditions replaced.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The prepared output.
*/
Expand All @@ -868,7 +868,7 @@ export class Account {
/**
* Prepare a send transaction, useful for offline signing.
* @param params Address with amounts to send.
* @param options The options to define a `RemainderValueStrategy`
* @param options Additional transaction options
* or custom inputs.
* @returns The prepared transaction data.
*/
Expand All @@ -892,7 +892,7 @@ export class Account {
/**
* Prepare a transaction, useful for offline signing.
* @param outputs Outputs to use in the transaction.
* @param options The options to define a `RemainderValueStrategy`
* @param options Additional transaction options
* or custom inputs.
* @returns The prepared transaction data.
*/
Expand Down Expand Up @@ -971,7 +971,7 @@ export class Account {
/**
* Send a transaction with amounts from input addresses.
* @param params Addresses with amounts.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The sent transaction.
*/
Expand All @@ -996,7 +996,7 @@ export class Account {
/**
* Send native tokens.
* @param params Addresses amounts and native tokens.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The sent transaction.
*/
Expand All @@ -1021,7 +1021,7 @@ export class Account {
/**
* Send nft.
* @param params Addresses and nft ids.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The sent transaction.
*/
Expand All @@ -1046,7 +1046,7 @@ export class Account {
/**
* Send outputs in a transaction.
* @param outputs The outputs to send.
* @param transactionOptions The options to define a `RemainderValueStrategy`
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The sent transaction.
*/
Expand Down
6 changes: 6 additions & 0 deletions bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 1.1.0 - 2023-MM-DD

### Added

- `Account::{burn(), consolidateOutputs(), createAliasOutput(), meltNativeToken(), mintNativeToken(), createNativeToken(), mintNfts(), sendTransaction(), sendNativeTokens(), sendNft()}` methods;

## 1.0.7 - 2023-08-29

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ async function run() {

// Consolidate unspent outputs and print the consolidation transaction ID
// Set `force` to true to force the consolidation even though the `output_threshold` isn't reached
const preparedTransaction = await account.prepareConsolidateOutputs({
const transaction = await account.consolidateOutputs({
force: true,
});
const transaction = await preparedTransaction.send();
console.log('Transaction sent: %s', transaction.transactionId);

// Wait for the consolidation transaction to get confirmed
Expand Down
4 changes: 1 addition & 3 deletions bindings/nodejs/examples/how_tos/alias/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ async function run() {
console.log('Sending the create-alias transaction...');

// Create an alias
const transaction = await account
.prepareCreateAliasOutput()
.then((prepared) => prepared.send());
const transaction = await account.createAliasOutput();

console.log(`Transaction sent: ${transaction.transactionId}`);

Expand Down
7 changes: 4 additions & 3 deletions bindings/nodejs/examples/how_tos/native_tokens/melt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ async function run() {
console.log(`Balance before melting: ${token.available}`);

// Melt some of the circulating supply
const transaction = await account
.prepareMeltNativeToken(token.tokenId, MELT_AMOUNT)
.then((prepared) => prepared.send());
const transaction = await account.meltNativeToken(
token.tokenId,
MELT_AMOUNT,
);

console.log(`Transaction sent: ${transaction.transactionId}`);

Expand Down
4 changes: 1 addition & 3 deletions bindings/nodejs/examples/how_tos/native_tokens/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ async function run() {
}
console.log(`Balance before sending: ${token.available}`);

const transaction = await account
.prepareSendNativeTokens(outputs)
.then((prepared) => prepared.send());
const transaction = await account.sendNativeTokens(outputs);

console.log(`Transaction sent: ${transaction.transactionId}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ async function run() {
'This NFT will be the issuer from the awesome NFT collection',
),
};
const prepared = await account.prepareMintNfts([params]);

const transaction = await prepared.send();
const transaction = await account.mintNfts([params]);

// Wait for transaction to get included
const blockId = await account.retryTransactionUntilIncluded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ async function run() {
i + chunk.length
}/${NFT_COLLECTION_SIZE})`,
);
const prepared = await account.prepareMintNfts(chunk);
const transaction = await prepared.send();
const transaction = await account.mintNfts(chunk);

// Wait for transaction to get included
const blockId = await account.retryTransactionUntilIncluded(
Expand Down
4 changes: 1 addition & 3 deletions bindings/nodejs/examples/how_tos/nfts/mint_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ async function run() {
issuer: senderAddress,
immutableMetadata: NFT1_IMMUTABLE_METADATA,
};
const prepared = await account.prepareMintNfts([params]);

let transaction = await prepared.send();
let transaction = await account.mintNfts([params]);
console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
Expand Down
4 changes: 1 addition & 3 deletions bindings/nodejs/examples/how_tos/nfts/send_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ async function run() {
];

// Send the full NFT output to the specified address
const transaction = await account
.prepareSendNft(outputs)
.then((prepared) => prepared.send());
const transaction = await account.sendNft(outputs);

console.log(`Transaction sent: ${transaction.transactionId}`);

Expand Down
Loading

0 comments on commit 72f19a3

Please sign in to comment.