@greymass/eosio
Advanced tools
Comparing version 0.1.4 to 0.1.5
/** | ||
* EOSIO Core v0.1.4 | ||
* EOSIO Core v0.1.5 | ||
* https://github.com/greymass/eosio-core | ||
@@ -520,2 +520,3 @@ * | ||
private pageSize; | ||
static __className: string; | ||
private pos; | ||
@@ -598,2 +599,3 @@ private data; | ||
private array; | ||
static __className: string; | ||
private pos; | ||
@@ -772,2 +774,3 @@ private data; | ||
declare class ABI { | ||
static __className: string; | ||
static version: string; | ||
@@ -1494,2 +1497,3 @@ version: string; | ||
readonly error: APIErrorData; | ||
static __className: string; | ||
static formatError(error: APIErrorData): string; | ||
@@ -1505,2 +1509,3 @@ constructor(path: string, error: APIErrorData); | ||
declare class APIClient { | ||
static __className: string; | ||
readonly provider: APIProvider; | ||
@@ -1620,2 +1625,7 @@ constructor(options: APIClientOptions); | ||
export { ABI, ABIDecoder, ABIDef, ABIEncoder, ABISerializable, ABISerializableConstructor, ABISerializableObject, ABISerializableType, types$1 as API, APIClient, APIClientOptions, APIError, APIErrorData, APIErrorDetail, APIProvider, Action, ActionFields, ActionType, AnyAction, AnyInt, AnyTransaction, AnyVariant, Asset, AssetType, Base58, BlockTimestamp, Bytes, BytesEncoding, BytesType, Checksum160, Checksum160Type, Checksum256, Checksum256Type, Checksum512, Checksum512Type, CurveType, ExtendedAsset, ExtendedAssetType, FetchProvider, FetchProviderOptions, Int128, Int128Type, Int16, Int16Type, Int32, Int32Type, Int64, Int64Type, Int8, Int8Type, Name, NameType, PackedTransaction, PermissionLevel, PermissionLevelType, PrivateKey, PrivateKeyType, PublicKey, PublicKeyType, Serializer, Signature, SignatureType, SignedTransaction, SignedTransactionFields, SignedTransactionType, Struct, StructConstructor, TimePoint, TimePointSec, TimePointType, Transaction, TransactionExtension, TransactionFields, TransactionHeader, TransactionHeaderFields, TransactionHeaderType, TransactionReceipt, TransactionType, TypeAlias, UInt128, UInt128Type, UInt16, UInt16Type, UInt32, UInt32Type, UInt64, UInt64Type, UInt8, UInt8Type, VarInt, VarIntType, VarUInt, VarUIntType, Variant, VariantConstructor }; | ||
/** Check if object in instance of class. */ | ||
declare function isInstanceOf<T extends { | ||
new (...args: any[]): InstanceType<T>; | ||
}>(object: any, someClass: T): object is InstanceType<T>; | ||
export { ABI, ABIDecoder, ABIDef, ABIEncoder, ABISerializable, ABISerializableConstructor, ABISerializableObject, ABISerializableType, types$1 as API, APIClient, APIClientOptions, APIError, APIErrorData, APIErrorDetail, APIProvider, Action, ActionFields, ActionType, AnyAction, AnyInt, AnyTransaction, AnyVariant, Asset, AssetType, Base58, BlockTimestamp, Bytes, BytesEncoding, BytesType, Checksum160, Checksum160Type, Checksum256, Checksum256Type, Checksum512, Checksum512Type, CurveType, ExtendedAsset, ExtendedAssetType, FetchProvider, FetchProviderOptions, Int128, Int128Type, Int16, Int16Type, Int32, Int32Type, Int64, Int64Type, Int8, Int8Type, Name, NameType, PackedTransaction, PermissionLevel, PermissionLevelType, PrivateKey, PrivateKeyType, PublicKey, PublicKeyType, Serializer, Signature, SignatureType, SignedTransaction, SignedTransactionFields, SignedTransactionType, Struct, StructConstructor, TimePoint, TimePointSec, TimePointType, Transaction, TransactionExtension, TransactionFields, TransactionHeader, TransactionHeaderFields, TransactionHeaderType, TransactionReceipt, TransactionType, TypeAlias, UInt128, UInt128Type, UInt16, UInt16Type, UInt32, UInt32Type, UInt64, UInt64Type, UInt8, UInt8Type, VarInt, VarIntType, VarUInt, VarUIntType, Variant, VariantConstructor, isInstanceOf }; |
{ | ||
"name": "@greymass/eosio", | ||
"description": "Library for working with EOSIO blockchains", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"homepage": "https://github.com/greymass/eosio-core", | ||
@@ -6,0 +6,0 @@ "license": "BSD-3-Clause", |
@@ -29,2 +29,4 @@ import {APIProvider, FetchProvider, FetchProviderOptions} from './provider' | ||
export class APIError extends Error { | ||
static __className = 'APIError' | ||
static formatError(error: APIErrorData) { | ||
@@ -61,2 +63,4 @@ if (error.what === 'unspecified' && error.details && error.details.length > 0) { | ||
export class APIClient { | ||
static __className = 'APIClient' | ||
readonly provider: APIProvider | ||
@@ -63,0 +67,0 @@ |
@@ -24,2 +24,3 @@ import {APIClient} from '../client' | ||
import {Bytes} from '../../chain/bytes' | ||
import {isInstanceOf} from '../../utils' | ||
@@ -83,3 +84,3 @@ export class ChainAPI { | ||
async push_transaction(tx: SignedTransactionType | PackedTransaction) { | ||
if (!(tx instanceof PackedTransaction)) { | ||
if (!isInstanceOf(tx, PackedTransaction)) { | ||
tx = PackedTransaction.fromSigned(SignedTransaction.from(tx)) | ||
@@ -117,9 +118,9 @@ } | ||
// determine key type from bounds type | ||
if (someBound instanceof Int64) { | ||
if (isInstanceOf(someBound, Int64)) { | ||
key_type = 'i64' | ||
} else if (someBound instanceof Int128) { | ||
} else if (isInstanceOf(someBound, Int128)) { | ||
key_type = 'i128' | ||
} else if (someBound instanceof Checksum256) { | ||
} else if (isInstanceOf(someBound, Checksum256)) { | ||
key_type = 'sha256' | ||
} else if (someBound instanceof Checksum160) { | ||
} else if (isInstanceOf(someBound, Checksum160)) { | ||
key_type = 'ripemd160' | ||
@@ -126,0 +127,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import {isInstanceOf} from '../utils' | ||
import {Name, NameType} from './name' | ||
@@ -6,2 +7,3 @@ | ||
export class ABI { | ||
static __className = 'ABI' | ||
static version = 'eosio::abi/1.1' | ||
@@ -34,3 +36,3 @@ | ||
static from(value: ABIDef) { | ||
if (value instanceof ABI) { | ||
if (isInstanceOf(value, ABI)) { | ||
return value | ||
@@ -37,0 +39,0 @@ } |
@@ -8,2 +8,3 @@ import BN from 'bn.js' | ||
import {Name, NameType} from './name' | ||
import {isInstanceOf} from '../utils' | ||
@@ -19,3 +20,3 @@ export type AssetType = Asset | string | ||
static from(value: AssetType) { | ||
if (value instanceof Asset) { | ||
if (isInstanceOf(value, Asset)) { | ||
return value | ||
@@ -97,6 +98,6 @@ } | ||
static from(value: SymbolType) { | ||
if (value instanceof Symbol) { | ||
if (isInstanceOf(value, Symbol)) { | ||
return value | ||
} | ||
if (value instanceof UInt64) { | ||
if (isInstanceOf(value, UInt64)) { | ||
return new Symbol(value) | ||
@@ -187,3 +188,3 @@ } | ||
static from(value: SymbolCodeType) { | ||
if (value instanceof SymbolCode) { | ||
if (isInstanceOf(value, SymbolCode)) { | ||
return value | ||
@@ -230,3 +231,3 @@ } | ||
static from(value: ExtendedAssetType) { | ||
if (value instanceof ExtendedAsset) { | ||
if (isInstanceOf(value, ExtendedAsset)) { | ||
return value | ||
@@ -233,0 +234,0 @@ } |
import {ABISerializableObject} from '../serializer/serializable' | ||
import {ABIEncoder} from '../serializer/encoder' | ||
import {ABIDecoder} from '../serializer/decoder' | ||
import {arrayEquals, arrayToHex, hexToArray, secureRandom} from '../utils' | ||
import {arrayEquals, arrayToHex, hexToArray, isInstanceOf, secureRandom} from '../utils' | ||
import {Checksum160, Checksum256, Checksum512} from './checksum' | ||
@@ -15,3 +15,3 @@ | ||
static from(value: BytesType, encoding?: BytesEncoding): Bytes { | ||
if (value instanceof Bytes) { | ||
if (isInstanceOf(value, Bytes)) { | ||
return value | ||
@@ -22,3 +22,3 @@ } | ||
} | ||
if (value instanceof Uint8Array) { | ||
if (isInstanceOf(value, Uint8Array)) { | ||
return new Bytes(value) | ||
@@ -56,3 +56,3 @@ } | ||
static isBytes(value: any): value is BytesType { | ||
if (value instanceof Bytes || value instanceof Uint8Array) { | ||
if (isInstanceOf(value, Bytes) || isInstanceOf(value, Uint8Array)) { | ||
return true | ||
@@ -59,0 +59,0 @@ } |
@@ -8,3 +8,3 @@ import {ripemd160, sha256, sha512} from 'hash.js' | ||
import {Bytes, BytesType} from './bytes' | ||
import {arrayEquals, arrayToHex} from '../utils' | ||
import {arrayEquals, arrayToHex, isInstanceOf} from '../utils' | ||
@@ -16,3 +16,3 @@ class Checksum implements ABISerializableObject { | ||
static from(value: any) { | ||
if (value instanceof Checksum) { | ||
if (isInstanceOf(value, Checksum)) { | ||
return new this(value.array) | ||
@@ -19,0 +19,0 @@ } |
import {ABISerializableObject} from '../serializer/serializable' | ||
import {ABIDecoder} from '../serializer/decoder' | ||
import {ABIEncoder} from '../serializer/encoder' | ||
import {secureRandom} from '../utils' | ||
import {isInstanceOf, secureRandom} from '../utils' | ||
import {Bytes, BytesType} from './bytes' | ||
@@ -14,3 +14,3 @@ | ||
static from<T extends typeof Float>(this: T, value: FloatType): InstanceType<T> { | ||
if (value instanceof this) { | ||
if (isInstanceOf(value, this as any)) { | ||
return value as InstanceType<T> | ||
@@ -20,3 +20,3 @@ } | ||
value = Number.parseFloat(value) | ||
} else if ((value as any) instanceof Float) { | ||
} else if (isInstanceOf(value, Float)) { | ||
value = (value as any).value as number | ||
@@ -95,3 +95,3 @@ } | ||
static from<T extends typeof Float128>(this: T, value: Float128Type): InstanceType<T> { | ||
if (value instanceof this) { | ||
if (isInstanceOf(value, this as typeof Float128)) { | ||
return value as InstanceType<T> | ||
@@ -98,0 +98,0 @@ } |
@@ -6,3 +6,3 @@ import BN from 'bn.js' | ||
import {ABIEncoder} from '../serializer/encoder' | ||
import {secureRandom} from '../utils' | ||
import {isInstanceOf, secureRandom} from '../utils' | ||
@@ -25,3 +25,3 @@ type IntType = Int | BNInt | number | string | BN | ||
static from<T extends typeof Int>(this: T, value: IntType): InstanceType<T> { | ||
if (value instanceof this) { | ||
if (isInstanceOf(value, this as typeof Int)) { | ||
return value as InstanceType<T> | ||
@@ -31,5 +31,5 @@ } | ||
value = Number.parseInt(value, 10) | ||
} else if (value instanceof BNInt) { | ||
} else if (isInstanceOf(value, BNInt)) { | ||
value = value.value.toNumber() | ||
} else if (value instanceof Int) { | ||
} else if (isInstanceOf(value, Int)) { | ||
value = value.value | ||
@@ -93,12 +93,12 @@ } else if (BN.isBN(value)) { | ||
static from<T extends typeof BNInt>(this: T, value: IntType | Uint8Array): InstanceType<T> { | ||
if (value instanceof this) { | ||
if (isInstanceOf(value, this as typeof BNInt)) { | ||
return value as InstanceType<T> | ||
} | ||
if (value instanceof BNInt) { | ||
if (isInstanceOf(value, BNInt)) { | ||
return new this(value.value) as InstanceType<T> | ||
} | ||
if (value instanceof Uint8Array) { | ||
if (isInstanceOf(value, Uint8Array)) { | ||
return new this(new BN(value, undefined, 'le')) as InstanceType<T> | ||
} | ||
if (value instanceof Int) { | ||
if (isInstanceOf(value, Int)) { | ||
value = value.value | ||
@@ -105,0 +105,0 @@ } |
@@ -5,2 +5,3 @@ import {UInt64} from './integer' | ||
import {ABIDecoder} from '../serializer/decoder' | ||
import {isInstanceOf} from '../utils' | ||
@@ -22,7 +23,7 @@ /** Type representing a name. */ | ||
static from(value: NameType): Name { | ||
if (value instanceof Name) { | ||
if (isInstanceOf(value, Name)) { | ||
return value | ||
} else if (typeof value === 'string') { | ||
return new Name(stringToName(value)) | ||
} else if (value instanceof UInt64) { | ||
} else if (isInstanceOf(value, UInt64)) { | ||
return new Name(value) | ||
@@ -29,0 +30,0 @@ } else { |
@@ -13,2 +13,3 @@ import {Base58} from '../base58' | ||
import {CurveType} from './curve-type' | ||
import {isInstanceOf} from '../utils' | ||
@@ -23,3 +24,3 @@ export type PrivateKeyType = PrivateKey | string | ||
static from(value: PrivateKeyType) { | ||
if (value instanceof PrivateKey) { | ||
if (isInstanceOf(value, PrivateKey)) { | ||
return value | ||
@@ -26,0 +27,0 @@ } |
@@ -9,2 +9,3 @@ import {ABIDecoder} from '../serializer/decoder' | ||
import {CurveType} from './curve-type' | ||
import {isInstanceOf} from '../utils' | ||
@@ -23,3 +24,3 @@ export type PublicKeyType = PublicKey | string | {type: string; compressed: Uint8Array} | ||
static from(value: PublicKeyType) { | ||
if (value instanceof PublicKey) { | ||
if (isInstanceOf(value, PublicKey)) { | ||
return value | ||
@@ -26,0 +27,0 @@ } |
@@ -13,2 +13,3 @@ import {ABIDecoder} from '../serializer/decoder' | ||
import {CurveType} from './curve-type' | ||
import {isInstanceOf} from '../utils' | ||
@@ -30,3 +31,3 @@ export type SignatureType = | ||
static from(value: SignatureType) { | ||
if (value instanceof Signature) { | ||
if (isInstanceOf(value, Signature)) { | ||
return value | ||
@@ -33,0 +34,0 @@ } |
@@ -8,2 +8,3 @@ import { | ||
import {abiEncode} from '../serializer/encoder' | ||
import {isInstanceOf} from '../utils' | ||
@@ -25,3 +26,3 @@ export interface StructConstructor extends ABISerializableConstructor { | ||
} | ||
if (value instanceof this) { | ||
if (isInstanceOf(value, this)) { | ||
return value | ||
@@ -28,0 +29,0 @@ } |
@@ -6,2 +6,3 @@ import BN from 'bn.js' | ||
import {ABISerializableObject} from '../serializer/serializable' | ||
import {isInstanceOf} from '../utils' | ||
@@ -23,10 +24,10 @@ import {AnyInt, Int64, Int64Type, UInt32, UInt32Type} from './integer' | ||
static from<T extends TimePointConstructor>(this: T, value: TimePointType): InstanceType<T> { | ||
if (value instanceof this) { | ||
if (isInstanceOf(value, this as TimePointConstructor)) { | ||
return value as InstanceType<T> | ||
} | ||
if (value instanceof TimePointBase) { | ||
if (isInstanceOf(value, TimePointBase)) { | ||
// converting between types | ||
return this.fromMilliseconds(value.toMilliseconds()) as InstanceType<T> | ||
} | ||
if (value instanceof Date) { | ||
if (isInstanceOf(value, Date)) { | ||
return this.fromDate(value) as InstanceType<T> | ||
@@ -33,0 +34,0 @@ } |
@@ -12,2 +12,3 @@ import { | ||
import {abiEncode} from '../serializer/encoder' | ||
import {isInstanceOf} from '../utils' | ||
@@ -28,3 +29,3 @@ export interface VariantConstructor extends ABISerializableConstructor { | ||
} | ||
if (object instanceof this) { | ||
if (isInstanceOf(object, this)) { | ||
return object as InstanceType<T> | ||
@@ -31,0 +32,0 @@ } |
@@ -28,1 +28,2 @@ // api | ||
export * from './base58' | ||
export {isInstanceOf} from './utils' |
@@ -20,2 +20,3 @@ /** | ||
import {Variant} from '../chain/variant' | ||
import {isInstanceOf} from '../utils' | ||
@@ -45,2 +46,3 @@ interface DecodeArgsBase { | ||
class DecodingError extends Error { | ||
static __className = 'DecodingError' | ||
ctx: DecodingContext | ||
@@ -113,3 +115,3 @@ underlyingError: Error | ||
let decoder: ABIDecoder | ||
if (args.data instanceof ABIDecoder) { | ||
if (isInstanceOf(args.data, ABIDecoder)) { | ||
decoder = args.data | ||
@@ -250,3 +252,3 @@ } else { | ||
} | ||
if (typeof abiType === 'function' && value instanceof abiType) { | ||
if (typeof abiType === 'function' && isInstanceOf(value, abiType)) { | ||
return value | ||
@@ -271,3 +273,3 @@ } | ||
value = value[1] | ||
} else if (value instanceof Variant) { | ||
} else if (isInstanceOf(value, Variant)) { | ||
vName = value.variantName | ||
@@ -306,2 +308,4 @@ value = value.value | ||
export class ABIDecoder { | ||
static __className = 'ABIDecoder' | ||
private pos = 0 | ||
@@ -308,0 +312,0 @@ private data: DataView |
@@ -21,4 +21,6 @@ /** | ||
import {Variant} from '../chain/variant' | ||
import {isInstanceOf} from '../utils' | ||
class EncodingError extends Error { | ||
static __className = 'EncodingError' | ||
ctx: EncodingContext | ||
@@ -210,3 +212,3 @@ underlyingError: Error | ||
value = value[1] | ||
} else if (value instanceof Variant) { | ||
} else if (isInstanceOf(value, Variant)) { | ||
vName = value.variantName | ||
@@ -250,2 +252,4 @@ value = value.value | ||
export class ABIEncoder { | ||
static __className = 'ABIEncoder' | ||
private pos = 0 | ||
@@ -252,0 +256,0 @@ private data: DataView |
@@ -80,1 +80,30 @@ import {ABISerializableObject} from './serializer/serializable' | ||
} | ||
/** Used in isInstanceOf checks so we don't spam with warnings. */ | ||
let didWarn = false | ||
/** Check if object in instance of class. */ | ||
export function isInstanceOf<T extends {new (...args: any[]): InstanceType<T>}>( | ||
object: any, | ||
someClass: T | ||
): object is InstanceType<T> { | ||
if (object instanceof someClass) { | ||
return true | ||
} | ||
// not an actual instance but since bundlers can fail to dedupe stuff or | ||
// multiple versions can be included we check for compatibility if possible | ||
const className = someClass['__className'] || someClass['abiName'] | ||
if (!className || !object.constructor) { | ||
return false | ||
} | ||
const isAlienInstance = | ||
(object.constructor['__className'] || object.constructor['abiName']) === className | ||
if (isAlienInstance && !didWarn) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`Detected alien instance of ${className}, this usually means more than one version of @greymass/eosio has been included in your bundle.` | ||
) | ||
didWarn = true | ||
} | ||
return isAlienInstance | ||
} |
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
722530
14289