@greymass/eosio
Advanced tools
Comparing version 0.6.2 to 0.6.3
{ | ||
"name": "@greymass/eosio", | ||
"description": "Library for working with EOSIO blockchains", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"homepage": "https://github.com/greymass/eosio-core", | ||
@@ -6,0 +6,0 @@ "license": "BSD-3-Clause-No-Military-License", |
@@ -17,2 +17,26 @@ # eosio-core (@greymass/eosio) | ||
## Running Tests | ||
### Run the unit test suite: | ||
``` | ||
make test | ||
``` | ||
### Run the unit test suite with coverage: | ||
``` | ||
make coverage | ||
``` | ||
The report for the current version can also be found at: https://greymass.github.io/eosio-core/coverage/ | ||
### Run the test suite in a browser: | ||
``` | ||
make browser-test | ||
``` | ||
The browser test suite for the current version of the library is available at: https://greymass.github.io/eosio-core/tests.html | ||
## Documentation | ||
@@ -19,0 +43,0 @@ |
@@ -33,3 +33,7 @@ import {APIClient} from '../client' | ||
GetTableRowsResponse, | ||
GetTransactionStatusResponse, | ||
PushTransactionResponse, | ||
SendTransaction2Options, | ||
SendTransaction2Response, | ||
SendTransactionResponse, | ||
TableIndexType, | ||
@@ -98,2 +102,14 @@ TableIndexTypes, | ||
async compute_transaction(tx: SignedTransactionType | PackedTransaction) { | ||
if (!isInstanceOf(tx, PackedTransaction)) { | ||
tx = PackedTransaction.fromSigned(SignedTransaction.from(tx)) | ||
} | ||
return this.client.call<SendTransactionResponse>({ | ||
path: '/v1/chain/compute_transaction', | ||
params: { | ||
transaction: tx, | ||
}, | ||
}) | ||
} | ||
async push_transaction(tx: SignedTransactionType | PackedTransaction) { | ||
@@ -109,2 +125,31 @@ if (!isInstanceOf(tx, PackedTransaction)) { | ||
async send_transaction(tx: SignedTransactionType | PackedTransaction) { | ||
if (!isInstanceOf(tx, PackedTransaction)) { | ||
tx = PackedTransaction.fromSigned(SignedTransaction.from(tx)) | ||
} | ||
return this.client.call<SendTransactionResponse>({ | ||
path: '/v1/chain/send_transaction', | ||
params: tx, | ||
}) | ||
} | ||
async send_transaction2( | ||
tx: SignedTransactionType | PackedTransaction, | ||
options?: SendTransaction2Options | ||
) { | ||
if (!isInstanceOf(tx, PackedTransaction)) { | ||
tx = PackedTransaction.fromSigned(SignedTransaction.from(tx)) | ||
} | ||
return this.client.call<SendTransaction2Response>({ | ||
path: '/v1/chain/send_transaction2', | ||
params: { | ||
return_failure_trace: true, | ||
retry_trx: false, | ||
retry_trx_num_blocks: 0, | ||
transaction: tx, | ||
...options, | ||
}, | ||
}) | ||
} | ||
async get_table_rows<Index extends TableIndexType = Name>( | ||
@@ -252,2 +297,12 @@ params: GetTableRowsParams<Index> | ||
} | ||
async get_transaction_status(id: Checksum256Type) { | ||
return this.client.call({ | ||
path: '/v1/chain/get_transaction_status', | ||
params: { | ||
id: Checksum256.from(id), | ||
}, | ||
responseType: GetTransactionStatusResponse, | ||
}) | ||
} | ||
} |
@@ -360,2 +360,38 @@ import { | ||
export interface SendTransactionResponse { | ||
transaction_id: string | ||
processed: { | ||
id: string | ||
block_num: number | ||
block_time: string | ||
receipt: {status: string; cpu_usage_us: number; net_usage_words: number} | ||
elapsed: number | ||
net_usage: number | ||
scheduled: boolean | ||
action_traces: any[] | ||
account_ram_delta: any | ||
} | ||
} | ||
export interface SendTransaction2Options { | ||
return_failure_trace?: boolean | ||
retry_trx?: boolean | ||
retry_trx_num_blocks?: number | ||
} | ||
export interface SendTransaction2Response { | ||
transaction_id: string | ||
processed: { | ||
id: string | ||
block_num: number | ||
block_time: string | ||
receipt: {status: string; cpu_usage_us: number; net_usage_words: number} | ||
elapsed: number | ||
net_usage: number | ||
scheduled: boolean | ||
action_traces: any[] | ||
account_ram_delta: any | ||
} | ||
} | ||
export interface TableIndexTypes { | ||
@@ -515,1 +551,14 @@ float128: Float128 | ||
} | ||
@Struct.type('get_transaction_status_response') | ||
export class GetTransactionStatusResponse extends Struct { | ||
@Struct.field('string') declare state: string | ||
@Struct.field('uint32') declare head_number: UInt32 | ||
@Struct.field('checksum256') declare head_id: Checksum256 | ||
@Struct.field('time_point') declare head_timestamp: TimePoint | ||
@Struct.field('uint32') declare irreversible_number: UInt32 | ||
@Struct.field('checksum256') declare irreversible_id: Checksum256 | ||
@Struct.field('time_point') declare irreversible_timestamp: TimePoint | ||
@Struct.field('checksum256') declare earliest_tracked_block_id: Checksum256 | ||
@Struct.field('uint32') declare earliest_tracked_block_number: UInt32 | ||
} |
@@ -85,2 +85,8 @@ import {ABISerializableObject} from '../serializer/serializable' | ||
/** Number of bytes in this instance. */ | ||
get length(): number { | ||
return this.array.byteLength | ||
} | ||
/** Hex string representation of this instance. */ | ||
get hexString(): string { | ||
@@ -90,2 +96,3 @@ return arrayToHex(this.array) | ||
/** UTF-8 string representation of this instance. */ | ||
get utf8String(): string { | ||
@@ -113,2 +120,29 @@ return new TextDecoder().decode(this.array) | ||
/** Mutating. Pad this instance to length. */ | ||
zeropad(n: number, truncate = false) { | ||
const newSize = truncate ? n : Math.max(n, this.array.byteLength) | ||
const buffer = new ArrayBuffer(newSize) | ||
const array = new Uint8Array(buffer) | ||
array.fill(0) | ||
if (truncate && this.array.byteLength > newSize) { | ||
array.set(this.array.slice(0, newSize), 0) | ||
} else { | ||
array.set(this.array, newSize - this.array.byteLength) | ||
} | ||
this.array = array | ||
} | ||
/** Non-mutating, returns a copy of this instance with zeros padded. */ | ||
zeropadded(n: number, truncate = false) { | ||
const rv = new Bytes(this.array) | ||
rv.zeropad(n, truncate) | ||
return rv | ||
} | ||
/** Mutating. Drop bytes from the start of this instance. */ | ||
dropFirst(n = 1) { | ||
this.array = this.array.subarray(n) | ||
} | ||
/** Non-mutating, returns a copy of this instance with dropped bytes from the start. */ | ||
droppingFirst(n = 1) { | ||
@@ -115,0 +149,0 @@ return new Bytes(this.array.subarray(n)) |
@@ -51,6 +51,7 @@ import {Base58} from '../base58' | ||
const type = string.startsWith('PVT_R1') ? KeyType.R1 : KeyType.K1 | ||
let data = new Bytes(error.info.data) | ||
if (data.array.length == 33) { | ||
data = data.droppingFirst() | ||
const data = new Bytes(error.info.data) | ||
if (data.length === 33) { | ||
data.dropFirst() | ||
} | ||
data.zeropad(32, true) | ||
return new this(type, data) | ||
@@ -72,2 +73,5 @@ } | ||
constructor(type: KeyType, data: Bytes) { | ||
if ((type === KeyType.K1 || type === KeyType.R1) && data.length !== 32) { | ||
throw new Error('Invalid private key length') | ||
} | ||
this.type = type | ||
@@ -74,0 +78,0 @@ this.data = data |
@@ -10,3 +10,3 @@ import {getCurve} from './curves' | ||
const privkey = curve.genKeyPair().getPrivate() | ||
return privkey.toArrayLike(Uint8Array as any, 'be') as Uint8Array | ||
return privkey.toArrayLike(Uint8Array as any, 'be', 32) as Uint8Array | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
954204
17499
53