incubed
Version:
Typescript-version of the incubed client
175 lines (174 loc) • 6.49 kB
TypeScript
/***********************************************************
* This file is part of the Slock.it IoT Layer. *
* The Slock.it IoT Layer contains: *
* - USN (Universal Sharing Network) *
* - INCUBED (Trustless INcentivized remote Node Network) *
************************************************************
* Copyright (C) 2016 - 2018 Slock.it GmbH *
* All Rights Reserved. *
************************************************************
* You may use, distribute and modify this code under the *
* terms of the license contract you have concluded with *
* Slock.it GmbH. *
* For information about liability, maintenance etc. also *
* refer to the contract concluded with Slock.it GmbH. *
************************************************************
* For more information, please refer to https://slock.it *
* For questions, please contact info@slock.it *
***********************************************************/
import * as ethUtil from 'ethereumjs-util';
import * as Tx from 'ethereumjs-tx';
/** RLP-functions */
export declare const rlp: typeof ethUtil.rlp;
/** Buffer[] of the header */
export declare type BlockHeader = Buffer[];
/** Buffer[] of the transaction */
export declare type Transaction = Buffer[];
/** Buffer[] of the Account */
export declare type Account = Buffer[];
/** Buffer[] of the Receipt */
export declare type Receipt = [Buffer, Buffer, Buffer, [Buffer, Buffer[], Buffer][]];
/** Block as returned by eth_getBlockByNumber */
export interface BlockData {
hash: string;
parentHash: string;
sha3Uncles: string;
miner: string;
coinbase?: string;
stateRoot: string;
transactionsRoot: string;
receiptsRoot: string;
receiptRoot?: string;
logsBloom: string;
difficulty: string | number;
number: string | number;
gasLimit: string | number;
gasUsed: string | number;
timestamp: string | number;
extraData: string;
sealFields?: string[];
mixHash?: string;
nonce?: string | number;
transactions?: any[];
uncles?: string[];
}
/** Transaction as returned by eth_getTransactionByHash */
export interface TransactionData {
hash: string;
blockHash?: string;
blockNumber?: number | string;
chainId?: number | string;
condition?: string;
creates?: string;
from?: string;
gas?: number | string;
gasLimit?: number | string;
gasPrice?: number | string;
input: string;
data?: string;
nonce: number | string;
publicKey?: string;
raw?: string;
standardV?: string;
to: string;
transactionIndex: number;
r?: string;
s?: string;
v?: string;
value: number | string;
}
/** Account-Object */
export interface AccountData {
nonce: string;
balance: string;
storageHash: string;
codeHash: string;
code?: string;
}
/** LogData as part of the TransactionReceipt */
export interface LogData {
removed: boolean;
logIndex: string;
transactionLogIndex: string;
transactionIndex: string;
transactionHash: string;
blockHash: string;
blockNumber: string;
address: string;
data: string;
topics: string[];
}
/** TransactionReceipt as returned by eth_getTransactionReceipt */
export interface ReceiptData {
transactionHash?: string;
transactionIndex?: number;
blockNumber?: string | number;
blockHash?: string;
status?: string | boolean;
root?: string;
cumulativeGasUsed?: string | number;
gasUsed?: string | number;
logsBloom?: string;
logs: LogData[];
}
/** serialize the data */
export declare const serialize: (val: Buffer[] | Block | [Buffer, Buffer, Buffer, [Buffer, Buffer[], Buffer][]]) => Buffer;
/** returns the hash of the object */
export declare const hash: (val: Buffer | Buffer[] | Block | [Buffer, Buffer, Buffer, [Buffer, Buffer[], Buffer][]]) => Buffer;
/** converts it to a Buffer with 256 bytes length */
export declare const bytes256: (val: any) => any;
/** converts it to a Buffer with 32 bytes length */
export declare const bytes32: (val: any) => any;
/** converts it to a Buffer with 8 bytes length */
export declare const bytes8: (val: any) => any;
/** converts it to a Buffer */
export declare const bytes: (val: any) => any;
/** converts it to a Buffer with 20 bytes length */
export declare const address: (val: any) => any;
/** converts it to a Buffer with a variable length. 0 = length 0*/
export declare const uint: (val: any) => any;
export declare const uint64: (val: any) => any;
/** create a Buffer[] from RPC-Response */
export declare const toBlockHeader: (block: BlockData) => Buffer[];
/** create a Buffer[] from RPC-Response */
export declare const toTransaction: (tx: TransactionData) => Buffer[];
export declare const toAccount: (account: AccountData) => Buffer[];
/** create a Buffer[] from RPC-Response */
export declare const toReceipt: (r: ReceiptData) => [Buffer, Buffer, Buffer, [Buffer, Buffer[], Buffer][]];
/**
* encodes and decodes the blockheader
*/
export declare class Block {
/** the raw Buffer fields of the BlockHeader */
raw: BlockHeader;
/** the transaction-Object (if given) */
transactions: Tx[];
readonly parentHash: Buffer;
readonly uncleHash: Buffer;
readonly coinbase: Buffer;
readonly stateRoot: Buffer;
readonly transactionsTrie: Buffer;
readonly receiptTrie: Buffer;
readonly bloom: Buffer;
readonly difficulty: Buffer;
readonly number: Buffer;
readonly gasLimit: Buffer;
readonly gasUsed: Buffer;
readonly timestamp: Buffer;
readonly extra: Buffer;
readonly sealedFields: Buffer[];
/** creates a Block-Onject from either the block-data as returned from rpc, a buffer or a hex-string of the encoded blockheader */
constructor(data: Buffer | string | BlockData);
/** the blockhash as buffer */
hash(): Buffer;
/** the blockhash as buffer without the seal fields*/
bareHash(): Buffer;
/** the serialized header as buffer */
serializeHeader(): Buffer;
}
/** creates a Transaction-object from the rpc-transaction-data */
export declare function createTx(transaction: any): any;
/** converts blockdata to a hexstring*/
export declare function blockToHex(block: any): string;
/** converts a hexstring to a block-object */
export declare function blockFromHex(hex: string): Block;