New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@greymass/eosio

Package Overview
Dependencies
Maintainers
3
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@greymass/eosio - npm Package Compare versions

Comparing version 0.5.5 to 0.6.0

14

CHANGELOG.md

@@ -5,2 +5,16 @@ # Change Log

## 0.6.0
Breaking changes:
- Improved handling of binary extensions
- Properly support optional values in binary extensions
- Fields declared as binary extension (`$`) now always exist unless optional (`?`)
- ABISerializableConstructor gains an optional abiDefault function that can be implemented to return a initialized instance of the type
- ABIField.default (aka `@Struct.field('sometype', {default: <value>})`) was removed
Notes:
The ABIField.default was removed because it had inconsistent behavior depending if the type was decoded from binary or initalized using `.from`. If you need this behavior, implement it in your custom types `from` method, e.g. `return super.from({my_value: 'im default', ...value});`.
## 0.5.0

@@ -7,0 +21,0 @@

2

package.json
{
"name": "@greymass/eosio",
"description": "Library for working with EOSIO blockchains",
"version": "0.5.5",
"version": "0.6.0",
"homepage": "https://github.com/greymass/eosio-core",

@@ -6,0 +6,0 @@ "license": "BSD-3-Clause-No-Military-License",

@@ -1,8 +0,8 @@

# @greymass/eosio - Javascript SDK for EOSIO
# eosio-core (@greymass/eosio)
This library is a complete SDK for working with EOSIO blockchains.
JavaScript library for working with EOSIO blockchains
Avaiable on npm: https://www.npmjs.com/package/@greymass/eosio
### Install
## Install

@@ -13,9 +13,9 @@ ```

### AutoDocs
## API Documentation
https://greymass.github.io/eosio-core/
### Documentation
## Documentation
Documentation beyond the automatically generated link above is currently incomplete. Until full documentation is complete, the tests themselves provide good reference material on how to do nearly everything.
Documentation beyond the automatically generated API documentation above is currently incomplete. Until full documentation is complete, the tests themselves provide good reference material on how to do nearly everything.

@@ -26,5 +26,5 @@ https://github.com/greymass/eosio-core/tree/master/test

- Using APIs: https://github.com/greymass/eosio-core/blob/master/test/api.ts
- Serialization: https://github.com/greymass/eosio-core/blob/master/test/serializer.ts
- Crypto Operations: https://github.com/greymass/eosio-core/blob/master/test/crypto.ts
- Primative EOSIO Types: https://github.com/greymass/eosio-core/blob/master/test/chain.ts
- Using APIs: https://github.com/greymass/eosio-core/blob/master/test/api.ts
- Serialization: https://github.com/greymass/eosio-core/blob/master/test/serializer.ts
- Crypto Operations: https://github.com/greymass/eosio-core/blob/master/test/crypto.ts
- Primative EOSIO Types: https://github.com/greymass/eosio-core/blob/master/test/chain.ts

@@ -35,5 +35,5 @@ import {

export class AccountPermission extends Struct {
@Struct.field('name') perm_name!: Name
@Struct.field('name') parent!: Name
@Struct.field(Authority) required_auth!: Authority
@Struct.field('name') declare perm_name: Name
@Struct.field('name') declare parent: Name
@Struct.field(Authority) declare required_auth: Authority
}

@@ -43,5 +43,5 @@

export class AccountResourceLimit extends Struct {
@Struct.field('int64') used!: Int64
@Struct.field('int64') available!: Int64
@Struct.field('int64') max!: Int64
@Struct.field('int64') declare used: Int64
@Struct.field('int64') declare available: Int64
@Struct.field('int64') declare max: Int64
}

@@ -51,6 +51,6 @@

export class AccountTotalResources extends Struct {
@Struct.field('name') owner!: Name
@Struct.field('asset') net_weight!: Asset
@Struct.field('asset') cpu_weight!: Asset
@Struct.field('uint64') ram_bytes!: UInt64
@Struct.field('name') declare owner: Name
@Struct.field('asset') declare net_weight: Asset
@Struct.field('asset') declare cpu_weight: Asset
@Struct.field('uint64') declare ram_bytes: UInt64
}

@@ -60,6 +60,6 @@

export class AccountSelfDelegatedBandwidth extends Struct {
@Struct.field('name') from!: Name
@Struct.field('name') to!: Name
@Struct.field('asset') net_weight!: Asset
@Struct.field('asset') cpu_weight!: Asset
@Struct.field('name') declare from: Name
@Struct.field('name') declare to: Name
@Struct.field('asset') declare net_weight: Asset
@Struct.field('asset') declare cpu_weight: Asset
}

@@ -69,6 +69,6 @@

export class AccountRefundRequest extends Struct {
@Struct.field('name') owner!: Name
@Struct.field('time_point') request_time!: TimePoint
@Struct.field('asset') net_amount!: Asset
@Struct.field('asset') cpu_amount!: Asset
@Struct.field('name') declare owner: Name
@Struct.field('time_point') declare request_time: TimePoint
@Struct.field('asset') declare net_amount: Asset
@Struct.field('asset') declare cpu_amount: Asset
}

@@ -78,9 +78,9 @@

export class AccountVoterInfo extends Struct {
@Struct.field('name') owner!: Name
@Struct.field('name') proxy!: Name
@Struct.field('name', {array: true}) producers!: Name[]
@Struct.field('name') declare owner: Name
@Struct.field('name') declare proxy: Name
@Struct.field('name', {array: true}) declare producers: Name[]
@Struct.field('int64', {optional: true}) staked?: Int64
// @Struct.field('float64') last_vote_weight!: Float64
// @Struct.field('float64') proxied_vote_weight!: Float64
@Struct.field('bool') is_proxy!: boolean
// @Struct.field('float64') declare last_vote_weight: Float64
// @Struct.field('float64') declare proxied_vote_weight: Float64
@Struct.field('bool') declare is_proxy: boolean
@Struct.field('uint32', {optional: true}) flags1?: UInt32

@@ -103,9 +103,9 @@ @Struct.field('uint32') reserved2!: UInt32

export class AccountRexInfo extends Struct {
@Struct.field('uint32') version!: UInt32
@Struct.field('name') owner!: Name
@Struct.field('asset') vote_stake!: Asset
@Struct.field('asset') rex_balance!: Asset
@Struct.field('int64') matured_rex!: Int64
@Struct.field('uint32') declare version: UInt32
@Struct.field('name') declare owner: Name
@Struct.field('asset') declare vote_stake: Asset
@Struct.field('asset') declare rex_balance: Asset
@Struct.field('int64') declare matured_rex: Int64
@Struct.field(AccountRexInfoMaturities, {array: true})
rex_maturities!: AccountRexInfoMaturities[]
declare rex_maturities: AccountRexInfoMaturities[]
}

@@ -121,23 +121,23 @@

/** The account name of the retrieved account */
@Struct.field('name') account_name!: Name
@Struct.field('name') declare account_name: Name
/** Highest block number on the chain */
@Struct.field('uint32') head_block_num!: UInt32
@Struct.field('uint32') declare head_block_num: UInt32
/** Highest block unix timestamp. */
@Struct.field('time_point') head_block_time!: TimePoint
@Struct.field('time_point') declare head_block_time: TimePoint
/** Indicator of if this is a privileged system account */
@Struct.field('bool') privileged!: boolean
@Struct.field('bool') declare privileged: boolean
/** Last update to accounts contract as unix timestamp. */
@Struct.field('time_point') last_code_update!: TimePoint
@Struct.field('time_point') declare last_code_update: TimePoint
/** Account created as unix timestamp. */
@Struct.field('time_point') created!: TimePoint
@Struct.field('time_point') declare created: TimePoint
/** Account core token balance */
@Struct.field('asset?') core_liquid_balance?: Asset
@Struct.field('int64') ram_quota!: Int64
@Struct.field('int64') net_weight!: Int64
@Struct.field('int64') cpu_weight!: Int64
@Struct.field(AccountResourceLimit) net_limit!: AccountResourceLimit
@Struct.field(AccountResourceLimit) cpu_limit!: AccountResourceLimit
@Struct.field('uint64') ram_usage!: UInt64
@Struct.field(AccountPermission, {array: true}) permissions!: AccountPermission[]
@Struct.field(AccountTotalResources) total_resources!: AccountTotalResources
@Struct.field('int64') declare ram_quota: Int64
@Struct.field('int64') declare net_weight: Int64
@Struct.field('int64') declare cpu_weight: Int64
@Struct.field(AccountResourceLimit) declare net_limit: AccountResourceLimit
@Struct.field(AccountResourceLimit) declare cpu_limit: AccountResourceLimit
@Struct.field('uint64') declare ram_usage: UInt64
@Struct.field(AccountPermission, {array: true}) declare permissions: AccountPermission[]
@Struct.field(AccountTotalResources) declare total_resources: AccountTotalResources
@Struct.field(AccountSelfDelegatedBandwidth, {optional: true})

@@ -161,4 +161,4 @@ self_delegated_bandwidth?: AccountSelfDelegatedBandwidth

export class NewProducersEntry extends Struct {
@Struct.field('name') producer_name!: Name
@Struct.field('public_key') block_signing_key!: PublicKey
@Struct.field('name') declare producer_name: Name
@Struct.field('public_key') declare block_signing_key: PublicKey
}

@@ -168,4 +168,4 @@

export class NewProducers extends Struct {
@Struct.field('uint32') version!: UInt32
@Struct.field(NewProducersEntry, {array: true}) producers!: NewProducersEntry
@Struct.field('uint32') declare version: UInt32
@Struct.field(NewProducersEntry, {array: true}) declare producers: NewProducersEntry
}

@@ -175,4 +175,4 @@

export class BlockExtension extends Struct {
@Struct.field('uint16') type!: UInt16
@Struct.field('bytes') data!: Bytes
@Struct.field('uint16') declare type: UInt16
@Struct.field('bytes') declare data: Bytes
}

@@ -182,4 +182,4 @@

export class HeaderExtension extends Struct {
@Struct.field('uint16') type!: UInt16
@Struct.field('bytes') data!: Bytes
@Struct.field('uint16') declare type: UInt16
@Struct.field('bytes') declare data: Bytes
}

@@ -229,3 +229,3 @@

export class GetBlockResponseTransactionReceipt extends TransactionReceipt {
@Struct.field(TrxVariant) trx!: TrxVariant
@Struct.field(TrxVariant) declare trx: TrxVariant

@@ -239,19 +239,19 @@ get id(): Checksum256 {

export class GetBlockResponse extends Struct {
@Struct.field('time_point') timestamp!: TimePoint
@Struct.field('name') producer!: Name
@Struct.field('uint16') confirmed!: UInt16
@Struct.field('checksum256') previous!: Checksum256
@Struct.field('checksum256') transaction_mroot!: Checksum256
@Struct.field('checksum256') action_mroot!: Checksum256
@Struct.field('uint32') schedule_version!: UInt32
@Struct.field('time_point') declare timestamp: TimePoint
@Struct.field('name') declare producer: Name
@Struct.field('uint16') declare confirmed: UInt16
@Struct.field('checksum256') declare previous: Checksum256
@Struct.field('checksum256') declare transaction_mroot: Checksum256
@Struct.field('checksum256') declare action_mroot: Checksum256
@Struct.field('uint32') declare schedule_version: UInt32
@Struct.field(NewProducers, {optional: true}) new_producers?: NewProducers
@Struct.field('header_extension', {optional: true}) header_extensions?: HeaderExtension[]
@Struct.field('any', {optional: true}) new_protocol_features?: any
@Struct.field('signature') producer_signature!: Signature
@Struct.field('signature') declare producer_signature: Signature
@Struct.field(GetBlockResponseTransactionReceipt, {array: true})
transactions!: GetBlockResponseTransactionReceipt[]
@Struct.field('block_extension', {optional: true}) block_extensions!: BlockExtension[]
@Struct.field('checksum256') id!: Checksum256
@Struct.field('uint32') block_num!: UInt32
@Struct.field('uint32') ref_block_prefix!: UInt32
declare transactions: GetBlockResponseTransactionReceipt[]
@Struct.field('block_extension', {optional: true}) declare block_extensions: BlockExtension[]
@Struct.field('checksum256') declare id: Checksum256
@Struct.field('uint32') declare block_num: UInt32
@Struct.field('uint32') declare ref_block_prefix: UInt32
}

@@ -261,4 +261,4 @@

export class ActiveScheduleProducerAuthority extends Struct {
@Struct.field('name') producer_name!: Name
@Struct.field('any') authority!: any
@Struct.field('name') declare producer_name: Name
@Struct.field('any') declare authority: any
}

@@ -268,4 +268,5 @@

export class ActiveScheduleProducer extends Struct {
@Struct.field('name') producer_name!: Name
@Struct.field(ActiveScheduleProducerAuthority) authority!: ActiveScheduleProducerAuthority
@Struct.field('name') declare producer_name: Name
@Struct.field(ActiveScheduleProducerAuthority)
declare authority: ActiveScheduleProducerAuthority
}

@@ -275,4 +276,4 @@

export class ActiveSchedule extends Struct {
@Struct.field('uint32') version!: UInt32
@Struct.field(ActiveScheduleProducer, {array: true}) producers!: ActiveScheduleProducer[]
@Struct.field('uint32') declare version: UInt32
@Struct.field(ActiveScheduleProducer, {array: true}) declare producers: ActiveScheduleProducer[]
}

@@ -282,12 +283,12 @@

export class BlockStateHeader extends Struct {
@Struct.field('time_point') timestamp!: TimePoint
@Struct.field('name') producer!: Name
@Struct.field('uint16') confirmed!: UInt16
@Struct.field('checksum256') previous!: Checksum256
@Struct.field('checksum256') transaction_mroot!: Checksum256
@Struct.field('checksum256') action_mroot!: Checksum256
@Struct.field('uint32') schedule_version!: UInt32
@Struct.field('time_point') declare timestamp: TimePoint
@Struct.field('name') declare producer: Name
@Struct.field('uint16') declare confirmed: UInt16
@Struct.field('checksum256') declare previous: Checksum256
@Struct.field('checksum256') declare transaction_mroot: Checksum256
@Struct.field('checksum256') declare action_mroot: Checksum256
@Struct.field('uint32') declare schedule_version: UInt32
@Struct.field(HeaderExtension, {array: true, optional: true})
header_extensions?: HeaderExtension[]
@Struct.field('signature') producer_signature!: Signature
@Struct.field('signature') declare producer_signature: Signature
}

@@ -297,17 +298,17 @@

export class GetBlockHeaderStateResponse extends Struct {
@Struct.field('uint32') block_num!: UInt32
@Struct.field('uint32') dpos_proposed_irreversible_blocknum!: UInt32
@Struct.field('uint32') dpos_irreversible_blocknum!: UInt32
@Struct.field('checksum256') id!: Checksum256
@Struct.field(BlockStateHeader) header!: BlockStateHeader
@Struct.field('uint32') declare block_num: UInt32
@Struct.field('uint32') declare dpos_proposed_irreversible_blocknum: UInt32
@Struct.field('uint32') declare dpos_irreversible_blocknum: UInt32
@Struct.field('checksum256') declare id: Checksum256
@Struct.field(BlockStateHeader) declare header: BlockStateHeader
/** Unstructured any fields specific to header state calls */
@Struct.field('any') active_schedule!: any
@Struct.field('any') blockroot_merkle!: any
@Struct.field('any') producer_to_last_produced!: any
@Struct.field('any') producer_to_last_implied_irb!: any
@Struct.field('any') valid_block_signing_authority!: any
@Struct.field('any') confirm_count!: any
@Struct.field('any') pending_schedule!: any
@Struct.field('any') activated_protocol_features!: any
@Struct.field('any') additional_signatures!: any
@Struct.field('any') declare active_schedule: any
@Struct.field('any') declare blockroot_merkle: any
@Struct.field('any') declare producer_to_last_produced: any
@Struct.field('any') declare producer_to_last_implied_irb: any
@Struct.field('any') declare valid_block_signing_authority: any
@Struct.field('any') declare confirm_count: any
@Struct.field('any') declare pending_schedule: any
@Struct.field('any') declare activated_protocol_features: any
@Struct.field('any') declare additional_signatures: any
}

@@ -318,25 +319,25 @@

/** Hash representing the last commit in the tagged release. */
@Struct.field('string') server_version!: string
@Struct.field('string') declare server_version: string
/** Hash representing the ID of the chain. */
@Struct.field('checksum256') chain_id!: Checksum256
@Struct.field('checksum256') declare chain_id: Checksum256
/** Highest block number on the chain */
@Struct.field('uint32') head_block_num!: UInt32
@Struct.field('uint32') declare head_block_num: UInt32
/** Highest block number on the chain that has been irreversibly applied to state. */
@Struct.field('uint32') last_irreversible_block_num!: UInt32
@Struct.field('uint32') declare last_irreversible_block_num: UInt32
/** Highest block ID on the chain that has been irreversibly applied to state. */
@Struct.field('checksum256') last_irreversible_block_id!: Checksum256
@Struct.field('checksum256') declare last_irreversible_block_id: Checksum256
/** Highest block ID on the chain. */
@Struct.field('checksum256') head_block_id!: Checksum256
@Struct.field('checksum256') declare head_block_id: Checksum256
/** Highest block unix timestamp. */
@Struct.field('time_point') head_block_time!: TimePoint
@Struct.field('time_point') declare head_block_time: TimePoint
/** Producer that signed the highest block (head block). */
@Struct.field('name') head_block_producer!: Name
@Struct.field('name') declare head_block_producer: Name
/** CPU limit calculated after each block is produced, approximately 1000 times `blockCpuLimit`. */
@Struct.field('uint64') virtual_block_cpu_limit!: UInt64
@Struct.field('uint64') declare virtual_block_cpu_limit: UInt64
/** NET limit calculated after each block is produced, approximately 1000 times `blockNetLimit`. */
@Struct.field('uint64') virtual_block_net_limit!: UInt64
@Struct.field('uint64') declare virtual_block_net_limit: UInt64
/** Actual maximum CPU limit. */
@Struct.field('uint64') block_cpu_limit!: UInt64
@Struct.field('uint64') declare block_cpu_limit: UInt64
/** Actual maximum NET limit. */
@Struct.field('uint64') block_net_limit!: UInt64
@Struct.field('uint64') declare block_net_limit: UInt64
/** String representation of server version. */

@@ -459,7 +460,7 @@ @Struct.field('string?') server_version_string?: string

export class GetTableByScopeResponseRow extends Struct {
@Struct.field('name') code!: Name
@Struct.field('name') scope!: Name
@Struct.field('name') table!: Name
@Struct.field('name') payer!: Name
@Struct.field('uint32') count!: UInt32
@Struct.field('name') declare code: Name
@Struct.field('name') declare scope: Name
@Struct.field('name') declare table: Name
@Struct.field('name') declare payer: Name
@Struct.field('uint32') declare count: UInt32
}

@@ -469,4 +470,5 @@

export class GetTableByScopeResponse extends Struct {
@Struct.field(GetTableByScopeResponseRow, {array: true}) rows!: GetTableByScopeResponseRow[]
@Struct.field('string') more!: string
@Struct.field(GetTableByScopeResponseRow, {array: true})
declare rows: GetTableByScopeResponseRow[]
@Struct.field('string') declare more: string
}

@@ -476,6 +478,6 @@

export class OrderedActionsResult extends Struct {
@Struct.field(UInt64) global_action_seq!: UInt64
@Struct.field(Int64) account_action_seq!: Int64
@Struct.field(UInt32) block_num!: UInt32
@Struct.field(BlockTimestamp) block_time!: BlockTimestamp
@Struct.field(UInt64) declare global_action_seq: UInt64
@Struct.field(Int64) declare account_action_seq: Int64
@Struct.field(UInt32) declare block_num: UInt32
@Struct.field(BlockTimestamp) declare block_time: BlockTimestamp
@Struct.field('any') action_trace?: any

@@ -487,5 +489,5 @@ @Struct.field('boolean?') irrevirsible?: boolean

export class GetActionsResponse extends Struct {
@Struct.field(OrderedActionsResult, {array: true}) actions!: OrderedActionsResult[]
@Struct.field(Int32) last_irreversible_block!: Int32
@Struct.field(Int32) head_block_num!: Int32
@Struct.field(OrderedActionsResult, {array: true}) declare actions: OrderedActionsResult[]
@Struct.field(Int32) declare last_irreversible_block: Int32
@Struct.field(Int32) declare head_block_num: Int32
@Struct.field('boolean?') time_limit_exceeded_error?: boolean

@@ -499,12 +501,12 @@ }

export class Trx extends Struct {
@Struct.field('any') actions!: AnyAction[]
@Struct.field('any') context_free_actions!: AnyAction[]
@Struct.field('any') context_free_data!: any[]
@Struct.field('number') delay_sec!: number
@Struct.field('string') expiration!: string
@Struct.field('number') max_cpu_usage_ms!: number
@Struct.field('number') max_net_usage_words!: number
@Struct.field('number') ref_block_num!: number
@Struct.field('number') ref_block_prefix!: number
@Struct.field('string', {array: true}) signatures!: string[]
@Struct.field('any') declare actions: AnyAction[]
@Struct.field('any') declare context_free_actions: AnyAction[]
@Struct.field('any') declare context_free_data: any[]
@Struct.field('number') declare delay_sec: number
@Struct.field('string') declare expiration: string
@Struct.field('number') declare max_cpu_usage_ms: number
@Struct.field('number') declare max_net_usage_words: number
@Struct.field('number') declare ref_block_num: number
@Struct.field('number') declare ref_block_prefix: number
@Struct.field('string', {array: true}) declare signatures: string[]
}

@@ -514,4 +516,4 @@

export class TransactionInfo extends Struct {
@Struct.field(TransactionReceipt) receipt!: TransactionReceipt
@Struct.field('trx') trx!: Trx
@Struct.field(TransactionReceipt) declare receipt: TransactionReceipt
@Struct.field('trx') declare trx: Trx
}

@@ -521,8 +523,8 @@

export class GetTransactionResponse extends Struct {
@Struct.field(Checksum256) id!: Checksum256
@Struct.field(UInt32) block_num!: UInt32
@Struct.field(BlockTimestamp) block_time!: BlockTimestamp
@Struct.field(UInt32) last_irreversible_block!: UInt32
@Struct.field(Checksum256) declare id: Checksum256
@Struct.field(UInt32) declare block_num: UInt32
@Struct.field(BlockTimestamp) declare block_time: BlockTimestamp
@Struct.field(UInt32) declare last_irreversible_block: UInt32
@Struct.field('any?') traces?: TransactionTrace[]
@Struct.field('any') trx!: TransactionInfo
@Struct.field('any') declare trx: TransactionInfo
}

@@ -532,3 +534,3 @@

export class GetKeyAccountsResponse extends Struct {
@Struct.field('name', {array: true}) account_names!: Name[]
@Struct.field('name', {array: true}) declare account_names: Name[]
}

@@ -538,3 +540,3 @@

export class GetControlledAccountsResponse extends Struct {
@Struct.field('name', {array: true}) controlled_accounts!: Name[]
@Struct.field('name', {array: true}) declare controlled_accounts: Name[]
}

@@ -61,2 +61,6 @@ import {ABISerializableObject} from '../serializer/serializable'

static abiDefault() {
return new this(Int64.from(0), Asset.Symbol.abiDefault())
}
constructor(units: Int64, symbol: Asset.Symbol) {

@@ -143,2 +147,6 @@ this.units = units

static abiDefault() {
return this.from('4,SYS') // CORE_SYMBOL = 4,CORE_SYMBOL_NAME
}
value: UInt64

@@ -219,2 +227,6 @@

static abiDefault() {
return this.from('SYS') // CORE_SYMBOL_NAME
}
value: UInt64

@@ -221,0 +233,0 @@

@@ -53,2 +53,6 @@ import {ABISerializableObject} from '../serializer/serializable'

static abiDefault() {
return new Bytes()
}
static equal(a: BytesType, b: BytesType): boolean {

@@ -55,0 +59,0 @@ return this.from(a).equals(this.from(b))

@@ -34,2 +34,8 @@ import {ripemd160, sha256, sha512} from 'hash.js'

static abiDefault<T extends typeof Checksum>(this: T): InstanceType<T>
static abiDefault(): unknown
static abiDefault() {
return new this(new Uint8Array(this.byteSize))
}
readonly array: Uint8Array

@@ -36,0 +42,0 @@

@@ -34,2 +34,6 @@ import {ABISerializableObject} from '../serializer/serializable'

static abiDefault() {
return this.from(0)
}
static random<T extends typeof Float>(this: T): InstanceType<T>

@@ -36,0 +40,0 @@ static random(): unknown

@@ -180,2 +180,6 @@ import BN from 'bn.js'

static abiDefault() {
return this.from(0)
}
static random<T extends typeof Int>(this: T): InstanceType<T>

@@ -182,0 +186,0 @@ static random(): unknown

@@ -46,2 +46,6 @@ import {ABISerializableObject} from '../serializer/serializable'

static abiDefault() {
return new this(UInt64.from(0))
}
constructor(value: UInt64) {

@@ -48,0 +52,0 @@ this.value = value

@@ -30,8 +30,3 @@ import {

}
const object: any = {}
for (const field of this.structFields) {
const v = value[field.name] === undefined ? field.default : value[field.name]
object[field.name] = v
}
return abiDecode({object, type: this})
return abiDecode({object: value, type: this})
}

@@ -38,0 +33,0 @@

@@ -58,2 +58,7 @@ import {ABIDecoder} from '../serializer/decoder'

static abiDefault<T extends TimePointConstructor>(this: T): InstanceType<T>
static abiDefault(): unknown {
return this.from(0)
}
toABI(encoder: ABIEncoder) {

@@ -60,0 +65,0 @@ const self = this as any

@@ -31,4 +31,4 @@ import {abiEncode} from '../serializer/encoder'

export class TransactionExtension extends Struct {
@Struct.field('uint16') type!: UInt16
@Struct.field('bytes') data!: Bytes
@Struct.field('uint16') declare type: UInt16
@Struct.field('bytes') declare data: Bytes
}

@@ -56,16 +56,21 @@

/** The time at which a transaction expires. */
@Struct.field('time_point_sec') expiration!: TimePointSec
@Struct.field('time_point_sec') declare expiration: TimePointSec
/** *Specifies a block num in the last 2^16 blocks. */
@Struct.field('uint16') ref_block_num!: UInt16
@Struct.field('uint16') declare ref_block_num: UInt16
/** Specifies the lower 32 bits of the block id. */
@Struct.field('uint32') ref_block_prefix!: UInt32
@Struct.field('uint32') declare ref_block_prefix: UInt32
/** Upper limit on total network bandwidth (in 8 byte words) billed for this transaction. */
@Struct.field('varuint32', {default: 0}) max_net_usage_words!: VarUInt
@Struct.field('varuint32') declare max_net_usage_words: VarUInt
/** Upper limit on the total CPU time billed for this transaction. */
@Struct.field('uint8', {default: 0}) max_cpu_usage_ms!: UInt8
@Struct.field('uint8') declare max_cpu_usage_ms: UInt8
/** Number of seconds to delay this transaction for during which it may be canceled. */
@Struct.field('varuint32', {default: 0}) delay_sec!: VarUInt
@Struct.field('varuint32') declare delay_sec: VarUInt
static from(object: TransactionHeaderType) {
return super.from(object) as TransactionHeader
return super.from({
max_net_usage_words: 0,
max_cpu_usage_ms: 0,
delay_sec: 0,
...object,
}) as TransactionHeader
}

@@ -97,8 +102,8 @@ }

/** The context free actions in the transaction. */
@Struct.field(Action, {array: true, default: []}) context_free_actions!: Action[]
@Struct.field(Action, {array: true}) declare context_free_actions: Action[]
/** The actions in the transaction. */
@Struct.field(Action, {array: true, default: []}) actions!: Action[]
@Struct.field(Action, {array: true}) declare actions: Action[]
/** Transaction extensions. */
@Struct.field(TransactionExtension, {array: true, default: []})
transaction_extensions!: TransactionExtension[]
@Struct.field(TransactionExtension, {array: true})
declare transaction_extensions: TransactionExtension[]

@@ -124,2 +129,3 @@ static from(

const transaction = {
transaction_extensions: [],
...object,

@@ -167,18 +173,40 @@ context_free_actions,

/** List of signatures. */
@Struct.field('signature[]', {default: []}) signatures!: Signature[]
@Struct.field('signature[]') declare signatures: Signature[]
/** Context-free action data, for each context-free action, there is an entry here. */
@Struct.field('bytes[]', {default: []}) context_free_data!: Bytes[]
@Struct.field('bytes[]') declare context_free_data: Bytes[]
static from(object: SignedTransactionType) {
return super.from(object) as SignedTransaction
return super.from({
signatures: [],
context_free_data: [],
...object,
}) as SignedTransaction
}
}
export type PackedTransactionType =
| PackedTransaction
| {
signatures?: SignatureType[]
compression?: UInt8Type
packed_context_free_data?: BytesType
packed_trx: BytesType
}
@Struct.type('packed_transaction')
export class PackedTransaction extends Struct {
@Struct.field('signature[]') signatures!: Signature[]
@Struct.field('uint8', {default: 0}) compression!: UInt8
@Struct.field('bytes') packed_context_free_data!: Bytes
@Struct.field('bytes') packed_trx!: Bytes
@Struct.field('signature[]') declare signatures: Signature[]
@Struct.field('uint8') declare compression: UInt8
@Struct.field('bytes') declare packed_context_free_data: Bytes
@Struct.field('bytes') declare packed_trx: Bytes
static from(object: PackedTransactionType) {
return super.from({
signatures: [],
packed_context_free_data: '',
compression: 0,
...object,
}) as PackedTransaction
}
static fromSigned(signed: SignedTransaction) {

@@ -215,5 +243,5 @@ const tx = Transaction.from(signed)

export class TransactionReceipt extends Struct {
@Struct.field('string') status!: string
@Struct.field('uint32') cpu_usage_us!: UInt32
@Struct.field('uint32') net_usage_words!: UInt32
@Struct.field('string') declare status: string
@Struct.field('uint32') declare cpu_usage_us: UInt32
@Struct.field('uint32') declare net_usage_words: UInt32
}

@@ -38,2 +38,3 @@ import {ABIDecoder} from './decoder'

abiName: 'string',
abiDefault: () => '',
fromABI: (decoder: ABIDecoder) => {

@@ -50,2 +51,3 @@ return decoder.readString()

abiName: 'bool',
abiDefault: () => false,
fromABI: (decoder: ABIDecoder) => {

@@ -52,0 +54,0 @@ return decoder.readByte() === 1

@@ -147,3 +147,3 @@ /**

if (!decoder.canRead()) {
return undefined
return defaultValue(type, ctx)
}

@@ -223,7 +223,9 @@ }

if (value === null || value === undefined) {
if (type.isOptional || type.isExtension) {
if (type.isOptional) {
return null
} else {
throw new Error(`Unexpectedly encountered ${value} for non-optional`)
}
if (type.isExtension) {
return defaultValue(type, ctx)
}
throw new Error(`Unexpectedly encountered ${value} for non-optional`)
} else if (type.isArray) {

@@ -310,2 +312,52 @@ if (!Array.isArray(value)) {

/** Return default value (aka initialized value, matching C++ where possible) for given type */
function defaultValue(
type: ABI.ResolvedType,
ctx: DecodingContext,
seen: Set<string> = new Set()
): any {
if (type.isArray) {
return []
}
if (type.isOptional) {
return null
}
const abiType = ctx.types[type.name]
if (abiType && abiType.abiDefault) {
return abiType.abiDefault()
}
if (seen.has(type.name)) {
throw new Error('Circular type reference')
}
seen.add(type.name)
if (type.allFields) {
const rv: any = {}
for (const field of type.allFields) {
ctx.codingPath.push({field: field.name, type: field.type})
rv[field.name] = defaultValue(field.type, ctx, seen)
ctx.codingPath.pop()
}
if (abiType) {
rv[Resolved] = true
return abiType.from(rv)
}
return rv
}
if (type.variant && type.variant.length > 0) {
const rv = [type.variant[0].typeName, defaultValue(type.variant[0], ctx)]
if (abiType) {
rv[Resolved] = true
return abiType.from(rv)
}
return rv
}
if (type.ref) {
ctx.codingPath.push({field: '', type: type.ref})
const rv = defaultValue(type.ref, ctx, seen)
ctx.codingPath.pop()
return rv
}
throw new Error('Unable to determine default value')
}
export class ABIDecoder {

@@ -312,0 +364,0 @@ static __className = 'ABIDecoder'

@@ -35,3 +35,2 @@ import {ABI} from '../chain'

name: string
default?: any
}

@@ -50,2 +49,4 @@

abiAlias?: ABITypeDescriptor
/** Return value to use when creating a new instance of this type, used when decoding binary extensions. */
abiDefault?: () => ABISerializable
/**

@@ -91,8 +92,8 @@ * Create new instance from JavaScript object.

}
if (t.optional === true) {
typeName += '?'
}
if (t.extension === true) {
typeName += '$'
}
if (t.optional === true) {
typeName += '?'
}
return typeName

@@ -146,8 +147,8 @@ }

}
if (type.optional === true) {
typeName += '?'
}
if (type.extension === true) {
typeName += '$'
}
if (type.optional === true) {
typeName += '?'
}
return typeName

@@ -154,0 +155,0 @@ }

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc