You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
4 years ago
|
import { request } from "./utils.ts";
|
||
|
|
||
|
export function getblockchaininfo() {
|
||
|
return request("getblockchaininfo", []);
|
||
|
}
|
||
|
|
||
|
type IGetblockcountResponse = number;
|
||
|
export async function getblockcount() {
|
||
|
const response = await request("getblockcount", []);
|
||
|
if (response.error) {
|
||
|
throw new Error(response.error.message);
|
||
|
}
|
||
|
return response.result as IGetblockcountResponse;
|
||
|
}
|
||
|
|
||
|
type IGetblockhashResponse = string;
|
||
|
export async function getblockhash(height: number) {
|
||
|
const response = await request("getblockhash", [height]);
|
||
|
if (response.error) {
|
||
|
throw new Error(response.error.message);
|
||
|
}
|
||
|
return response.result as IGetblockhashResponse;
|
||
|
}
|
||
|
|
||
|
interface IGetblockheaderResponse {
|
||
|
hash: string;
|
||
|
confirmations: number;
|
||
|
height: number;
|
||
|
version: number;
|
||
|
versionHex: string;
|
||
|
merkleroot: string;
|
||
|
time: number;
|
||
|
mediantime: number;
|
||
|
nonce: number;
|
||
|
bits: string;
|
||
|
difficulty: number;
|
||
|
chainwork: string;
|
||
|
nTx: number;
|
||
|
previousblockhash: string;
|
||
|
nextblockhash: string;
|
||
|
}
|
||
|
|
||
|
export async function getblockheader(hash: string) {
|
||
|
const response = await request("getblockheader", [hash, true]);
|
||
|
if (response.error) {
|
||
|
throw new Error(response.error.message);
|
||
|
}
|
||
|
return (response.result as unknown) as IGetblockheaderResponse;
|
||
|
}
|