| 201 | |
| 202 | // Get UTXOs of all accounts |
| 203 | async fetchAllAccountUtxos(includeUnbondedTokenUtxos = false) { |
| 204 | const allScriptHashs: string[] = []; |
| 205 | const allAccounts = new Map<string, IWalletAccount>(); |
| 206 | for (const account of Object.values(this.accountCollection)) { |
| 207 | allScriptHashs.push(account.mainAddress!.scriptHash); |
| 208 | allAccounts.set(account.mainAddress!.scriptHash, account); |
| 209 | // In blockchain development, it's not uncommon for users to accidentally send small |
| 210 | // amounts of Bitcoin (satoshis) to token addresses. To recover these funds, there's an |
| 211 | // option that allows you to access the related Unspent Transaction Outputs (UTXOs). But |
| 212 | // beware! Enabling this feature could lead to unintended spending of your tokens. Always |
| 213 | // double-check before proceeding! |
| 214 | if (includeUnbondedTokenUtxos) { |
| 215 | allScriptHashs.push(account.tokenAddress!.scriptHash); |
| 216 | allAccounts.set(account.tokenAddress!.scriptHash, account); |
| 217 | } |
| 218 | } |
| 219 | const allUtxos: IUtxo[] = await this.urchain.utxos(allScriptHashs); |
| 220 | for (const utxo of allUtxos) { |
| 221 | const account = allAccounts.get(utxo.scriptHash); |
| 222 | if (account) { |
| 223 | utxo.privateKeyWif = account.privateKey; |
| 224 | if (utxo.scriptHash === account.mainAddress?.scriptHash) { |
| 225 | utxo.type = account.mainAddress?.type; |
| 226 | } |
| 227 | if (utxo.scriptHash === account.tokenAddress?.scriptHash) { |
| 228 | utxo.type = account.tokenAddress?.type; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | return allUtxos; |
| 233 | } |
| 234 | |
| 235 | sendEstimate( |
| 236 | toAddresses: ISendToAddress[], |