-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up transaction timer to handle edgecase where there is an err…
…or calculating spendPostTime
- Loading branch information
Showing
6 changed files
with
114 additions
and
21 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,52 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
import { Asset } from '@ironfish/rust-nodejs' | ||
import { Assert, RpcClient } from '@ironfish/sdk' | ||
|
||
async function getNoteTreeSize(client: RpcClient) { | ||
const getCurrentBlock = await client.chain.getChainInfo() | ||
|
||
const currentBlockSequence = parseInt(getCurrentBlock.content.currentBlockIdentifier.index) | ||
|
||
const getBlockResponse = await client.chain.getBlock({ | ||
sequence: currentBlockSequence, | ||
}) | ||
|
||
Assert.isNotNull(getBlockResponse.content.block.noteSize) | ||
|
||
const config = await client.config.getConfig() | ||
|
||
// Adding a buffer to avoid a mismatch between confirmations used to load notes and confirmations used when creating witnesses to spend them | ||
return getBlockResponse.content.block.noteSize - (config.content.confirmations || 2) | ||
} | ||
|
||
export async function fetchNotes(client: RpcClient, account: string, notesToCombine: number) { | ||
const noteSize = await getNoteTreeSize(client) | ||
|
||
const getNotesResponse = await client.wallet.getNotes({ | ||
account, | ||
pageSize: notesToCombine, | ||
filter: { | ||
assetId: Asset.nativeId().toString('hex'), | ||
spent: false, | ||
}, | ||
}) | ||
|
||
// filtering notes by noteSize and sorting them by value in ascending order | ||
const notes = getNotesResponse.content.notes | ||
.filter((note) => { | ||
if (!note.index) { | ||
return false | ||
} | ||
return note.index < noteSize | ||
}) | ||
.sort((a, b) => { | ||
if (a.value < b.value) { | ||
return -1 | ||
} | ||
return 1 | ||
}) | ||
|
||
return notes | ||
} |
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