Changeset View
Changeset View
Standalone View
Standalone View
apps/marlin-wallet/web/src/wallet.ts
| // Copyright (c) 2025 The Bitcoin developers | // Copyright (c) 2025 The Bitcoin developers | ||||
| // Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
| import { Wallet } from 'ecash-wallet'; | import { Wallet } from 'ecash-wallet'; | ||||
| import { Address, Script, OP_RETURN } from 'ecash-lib'; | import { Address, Script, DEFAULT_DUST_SATS, OP_RETURN } from 'ecash-lib'; | ||||
| import { config } from './config'; | import { config } from './config'; | ||||
| import type { AssetDefinition } from './supported-assets'; | |||||
| // Wallet date that we can't retrieve from ecash-wallet. | // Wallet date that we can't retrieve from ecash-wallet. | ||||
| // For now it's just the mnemonic. | // For now it's just the mnemonic. | ||||
| export interface WalletData { | export interface WalletData { | ||||
| mnemonic: string; | mnemonic: string; | ||||
| } | } | ||||
| // Return the eCash address string for this wallet | // Return the eCash address string for this wallet | ||||
| Show All 34 Lines | ) { | ||||
| outputs.push({ | outputs.push({ | ||||
| address: recipientAddress, | address: recipientAddress, | ||||
| sats: BigInt(sats), | sats: BigInt(sats), | ||||
| }); | }); | ||||
| // Create the action with outputs | // Create the action with outputs | ||||
| return wallet.action({ outputs }); | return wallet.action({ outputs }); | ||||
| } | } | ||||
| /** | |||||
| * Build a wallet action that sends tokens (ALP, SLP, etc.). | |||||
| */ | |||||
| export function buildTokenSendAction( | |||||
| wallet: Wallet, | |||||
| recipientAddress: string, | |||||
| atoms: bigint, | |||||
| token: AssetDefinition, | |||||
| ) { | |||||
| const { tokenId, tokenType } = token; | |||||
| if (!tokenId || !tokenType) { | |||||
| throw new Error('Token send requires tokenId and tokenType'); | |||||
| } | |||||
| const recipientScript = Address.parse(recipientAddress).toScript(); | |||||
| return wallet.action({ | |||||
| outputs: [ | |||||
| { sats: 0n }, | |||||
| { | |||||
| sats: DEFAULT_DUST_SATS, | |||||
| script: recipientScript, | |||||
| tokenId, | |||||
| atoms, | |||||
| }, | |||||
| ], | |||||
| tokenActions: [ | |||||
| { | |||||
| type: 'SEND', | |||||
| tokenId, | |||||
| tokenType, | |||||
| }, | |||||
| ], | |||||
| }); | |||||
| } | |||||