forked from ava-labs/avalanche-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ava-labs#115 from ava-labs/large_address_support
Support more than 1024 addresses for atomic imports
- Loading branch information
Showing
8 changed files
with
159 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { UTXOSet as PlatformUTXOSet } from 'avalanche/dist/apis/platformvm/utxos' | ||
import { avm, cChain, pChain } from '@/AVA' | ||
import { UTXOSet as AVMUTXOSet } from 'avalanche/dist/apis/avm/utxos' | ||
|
||
// Handles more than 1024 addresses | ||
async function getAtomicUTXOsForAddresses(addrs: string[], chainAlias: string): Promise<any> { | ||
let selection = addrs.slice(0, 1024) | ||
let remaining = addrs.slice(1024) | ||
|
||
let utxoSet = await getAtomicUTXOs(selection, chainAlias) | ||
|
||
if (remaining.length > 0) { | ||
// @ts-ignore | ||
let nextSet = await getAtomicUTXOsForAddresses(remaining, chainAlias) | ||
utxoSet = utxoSet.merge(nextSet) | ||
} | ||
|
||
return utxoSet | ||
} | ||
|
||
// todo: Use end index to get ALL utxos | ||
async function getAtomicUTXOs(addrs: string[], chainAlias: string, endIndex: any = undefined) { | ||
if (addrs.length > 1024) { | ||
throw 'Number of addresses can not be greater than 1024.' | ||
} | ||
|
||
if (chainAlias === 'P') { | ||
let result: PlatformUTXOSet = (await pChain.getUTXOs(addrs, avm.getBlockchainID())).utxos | ||
return result | ||
} else { | ||
let resultP: AVMUTXOSet = (await avm.getUTXOs(addrs, pChain.getBlockchainID())).utxos | ||
let resultC: AVMUTXOSet = (await avm.getUTXOs(addrs, cChain.getBlockchainID())).utxos | ||
let result = resultP.merge(resultC) | ||
return result | ||
} | ||
} | ||
|
||
export { getAtomicUTXOsForAddresses } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters