Skip to content
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
36 changes: 20 additions & 16 deletions modules/sdk-coin-ada/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
if (e instanceof BuildTransactionError) {
throw e;
}
throw new BuildTransactionError(`Error processing output: ${e.message}`);
throw new BuildTransactionError(`Error processing output: ${e.message ?? e}`);
}
});
return change;
Expand Down Expand Up @@ -311,21 +311,25 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
* @param address - Recipient address
*/
private buildTokens(asset: Asset, minAmountNeededForOneAssetOutput, outputs, address) {
let txOutputBuilder = CardanoWasm.TransactionOutputBuilder.new();
const toAddress = util.getWalletAddress(address);
txOutputBuilder = txOutputBuilder.with_address(toAddress);
let txOutputAmountBuilder = txOutputBuilder.next();
const assetName = CardanoWasm.AssetName.new(Buffer.from(asset.asset_name, 'hex'));
const policyId = CardanoWasm.ScriptHash.from_bytes(Buffer.from(asset.policy_id, 'hex'));
const multiAsset = CardanoWasm.MultiAsset.new();
const assets = CardanoWasm.Assets.new();
assets.insert(assetName, CardanoWasm.BigNum.from_str(asset.quantity));
multiAsset.insert(policyId, assets);

txOutputAmountBuilder = txOutputAmountBuilder.with_coin_and_asset(minAmountNeededForOneAssetOutput, multiAsset);

const txOutput = txOutputAmountBuilder.build();
outputs.add(txOutput);
try {
let txOutputBuilder = CardanoWasm.TransactionOutputBuilder.new();
const toAddress = util.getWalletAddress(address);
txOutputBuilder = txOutputBuilder.with_address(toAddress);
let txOutputAmountBuilder = txOutputBuilder.next();
const assetName = CardanoWasm.AssetName.new(Buffer.from(asset.asset_name, 'hex'));
const policyId = CardanoWasm.ScriptHash.from_bytes(Buffer.from(asset.policy_id, 'hex'));
const multiAsset = CardanoWasm.MultiAsset.new();
const assets = CardanoWasm.Assets.new();
assets.insert(assetName, CardanoWasm.BigNum.from_str(asset.quantity));
multiAsset.insert(policyId, assets);

txOutputAmountBuilder = txOutputAmountBuilder.with_coin_and_asset(minAmountNeededForOneAssetOutput, multiAsset);

const txOutput = txOutputAmountBuilder.build();
outputs.add(txOutput);
} catch (e) {
throw new BuildTransactionError(`Error building tokens: ${e.message || e} for asset ${JSON.stringify(asset)}`);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/statics/src/coins/adaTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const adaTokens = [
'tada:water',
'Test ADA Token',
0,
'2533cca6eb42076e144e9f2772c390dece9fce173bc38c72294b3924',
'2533cca6eb42076e144e9f2772c390dece9fce173bc38c72294b39245741544552',
'WATER',
'asset1n69xf60d0760xvn8v2ffd5frvsm0cl2r8hfjf6',
UnderlyingAsset['tada:water'],
Expand Down