-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[block] Slight UX improvements on blocks (#1001)
* [block] Slight UX improvements on blocks - navigation between blocks - counts of transactions * [blocks] Move Block APIs to SDK v2
- Loading branch information
1 parent
3a58058
commit fc3c8ea
Showing
11 changed files
with
181 additions
and
99 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
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,42 @@ | ||
import {withResponseError} from "./client"; | ||
import {Aptos, Block} from "@aptos-labs/ts-sdk"; | ||
|
||
export function getBlockByHeight( | ||
requestParameters: {height: number; withTransactions: boolean}, | ||
aptos: Aptos, | ||
): Promise<Block> { | ||
const {height, withTransactions} = requestParameters; | ||
return withResponseError( | ||
aptos.getBlockByHeight({blockHeight: height, options: {withTransactions}}), | ||
); | ||
} | ||
|
||
export function getBlockByVersion( | ||
requestParameters: {version: number; withTransactions: boolean}, | ||
aptos: Aptos, | ||
): Promise<Block> { | ||
const {version, withTransactions} = requestParameters; | ||
return withResponseError( | ||
aptos.getBlockByVersion({ | ||
ledgerVersion: version, | ||
options: {withTransactions}, | ||
}), | ||
); | ||
} | ||
|
||
export async function getRecentBlocks( | ||
currentBlockHeight: bigint | number, | ||
count: bigint | number, | ||
aptos: Aptos, | ||
): Promise<Block[]> { | ||
const blockPromises = []; | ||
// Don't await here, or they'll be in serial | ||
for (let i = BigInt(0); i < BigInt(count); i++) { | ||
const block = aptos.getBlockByHeight({ | ||
blockHeight: BigInt(currentBlockHeight) - i, | ||
options: {withTransactions: false}, // Always false, or this will take forever | ||
}); | ||
blockPromises.push(block); | ||
} | ||
return Promise.all(blockPromises); | ||
} |
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
Oops, something went wrong.