@greymass/eosio
Advanced tools
Comparing version 0.1.10 to 0.2.0
/** | ||
* EOSIO Core v0.1.10 | ||
* EOSIO Core v0.2.0 | ||
* https://github.com/greymass/eosio-core | ||
@@ -68,4 +68,7 @@ * | ||
static from<T extends typeof Float>(this: T, value: FloatType): InstanceType<T>; | ||
static from(value: FloatType): unknown; | ||
static fromABI<T extends typeof Float>(this: T, decoder: ABIDecoder): InstanceType<T>; | ||
static random(): Float; | ||
static fromABI(decoder: ABIDecoder): unknown; | ||
static random<T extends typeof Float>(this: T): InstanceType<T>; | ||
static random(): unknown; | ||
value: number; | ||
@@ -83,3 +86,2 @@ constructor(value: number); | ||
toString(): string; | ||
static from<T extends typeof Float>(this: T, value: Float32Type): InstanceType<T>; | ||
} | ||
@@ -90,3 +92,2 @@ declare type Float64Type = Float64 | FloatType; | ||
static byteWidth: number; | ||
static from<T extends typeof Float>(this: T, value: Float64Type): InstanceType<T>; | ||
} | ||
@@ -97,4 +98,4 @@ declare type Float128Type = Float128 | BytesType; | ||
static byteWidth: number; | ||
static from<T extends typeof Float128>(this: T, value: Float128Type): InstanceType<T>; | ||
static fromABI<T extends typeof Float128>(this: T, decoder: ABIDecoder): InstanceType<T>; | ||
static from(value: Float128Type): Float128; | ||
static fromABI(decoder: ABIDecoder): Float128; | ||
static random(): Float128; | ||
@@ -189,10 +190,13 @@ data: Bytes; | ||
declare type ChecksumType = Checksum | BytesType; | ||
declare class Checksum implements ABISerializableObject { | ||
static abiName: string; | ||
static byteSize: number; | ||
static from(value: any): Checksum; | ||
static fromABI(decoder: ABIDecoder): Checksum; | ||
array: Uint8Array; | ||
static from<T extends typeof Checksum>(this: T, value: ChecksumType): InstanceType<T>; | ||
static from(value: ChecksumType): unknown; | ||
static fromABI<T extends typeof Checksum>(this: T, decoder: ABIDecoder): InstanceType<T>; | ||
static fromABI(decoder: ABIDecoder): unknown; | ||
readonly array: Uint8Array; | ||
constructor(array: Uint8Array); | ||
equals(other: Checksum160Type | Checksum256Type | Checksum512Type): boolean; | ||
equals(other: Checksum160Type | Checksum256Type | Checksum512Type): any; | ||
get hexString(): string; | ||
@@ -207,3 +211,3 @@ toABI(encoder: ABIEncoder): void; | ||
static byteSize: number; | ||
static from<T extends typeof Checksum256>(this: T, value: Checksum256Type): InstanceType<T>; | ||
static from(value: Checksum256Type): Checksum256; | ||
static hash(data: BytesType): Checksum256; | ||
@@ -215,3 +219,3 @@ } | ||
static byteSize: number; | ||
static from<T extends typeof Checksum512>(this: T, value: Checksum512Type): InstanceType<T>; | ||
static from(value: Checksum512Type): Checksum512; | ||
static hash(data: BytesType): Checksum512; | ||
@@ -223,3 +227,3 @@ } | ||
static byteSize: number; | ||
static from<T extends typeof Checksum160>(this: T, value: Checksum160Type): InstanceType<T>; | ||
static from(value: Checksum160Type): Checksum160; | ||
static hash(data: BytesType): Checksum160; | ||
@@ -315,4 +319,7 @@ } | ||
static from<T extends TimePointConstructor>(this: T, value: TimePointType): InstanceType<T>; | ||
static from(value: TimePointType): unknown; | ||
static fromString<T extends TimePointConstructor>(this: T, string: string): InstanceType<T>; | ||
static fromString(string: string): unknown; | ||
static fromDate<T extends TimePointConstructor>(this: T, date: Date): InstanceType<T>; | ||
static fromDate(date: Date): unknown; | ||
toABI(encoder: ABIEncoder): void; | ||
@@ -642,4 +649,7 @@ equals(other: TimePointType): boolean; | ||
static from<T extends typeof Int>(this: T, value: IntType): InstanceType<T>; | ||
static from(value: any): unknown; | ||
static fromABI<T extends typeof Int>(this: T, decoder: ABIDecoder): InstanceType<T>; | ||
static random(): Int; | ||
static fromABI(decoder: ABIDecoder): unknown; | ||
static random<T extends typeof Int>(this: T): InstanceType<T>; | ||
static random(): unknown; | ||
value: number; | ||
@@ -658,4 +668,7 @@ constructor(value: number); | ||
static from<T extends typeof BNInt>(this: T, value: IntType | Uint8Array): InstanceType<T>; | ||
static from(value: any): unknown; | ||
static fromABI<T extends typeof BNInt>(this: T, decoder: ABIDecoder): InstanceType<T>; | ||
static fromABI(decoder: ABIDecoder): unknown; | ||
static random<T extends typeof BNInt>(this: T): InstanceType<T>; | ||
static random(): unknown; | ||
value: BN; | ||
@@ -678,3 +691,2 @@ constructor(value: BN); | ||
static isSigned: boolean; | ||
static from<T extends typeof Int8>(this: T, value: Int8Type): InstanceType<T>; | ||
} | ||
@@ -686,3 +698,2 @@ declare type Int16Type = Int16 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof Int16>(this: T, value: Int16Type): InstanceType<T>; | ||
} | ||
@@ -694,3 +705,2 @@ declare type Int32Type = Int32 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof Int32>(this: T, value: Int32Type): InstanceType<T>; | ||
} | ||
@@ -702,3 +712,2 @@ declare type Int64Type = Int64 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof Int64>(this: T, value: Int64Type | Uint8Array): InstanceType<T>; | ||
} | ||
@@ -710,3 +719,2 @@ declare type Int128Type = Int128 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof Int128>(this: T, value: Int128Type | Uint8Array): InstanceType<T>; | ||
} | ||
@@ -718,3 +726,2 @@ declare type UInt8Type = UInt8 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof UInt8>(this: T, value: UInt8Type): InstanceType<T>; | ||
} | ||
@@ -726,3 +733,2 @@ declare type UInt16Type = UInt16 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof UInt16>(this: T, value: UInt16Type): InstanceType<T>; | ||
} | ||
@@ -734,3 +740,2 @@ declare type UInt32Type = UInt32 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof UInt32>(this: T, value: UInt32Type): InstanceType<T>; | ||
} | ||
@@ -742,3 +747,2 @@ declare type UInt64Type = UInt64 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof UInt64>(this: T, value: UInt64Type | Uint8Array): InstanceType<T>; | ||
} | ||
@@ -750,3 +754,2 @@ declare type UInt128Type = UInt128 | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof UInt128>(this: T, value: UInt128Type | Uint8Array): InstanceType<T>; | ||
} | ||
@@ -758,4 +761,3 @@ declare type VarIntType = VarInt | IntType; | ||
static isSigned: boolean; | ||
static from<T extends typeof VarInt>(this: T, value: VarIntType): InstanceType<T>; | ||
static fromABI<T extends typeof VarInt>(this: T, decoder: ABIDecoder): InstanceType<T>; | ||
static fromABI(decoder: ABIDecoder): VarInt; | ||
toABI(encoder: ABIEncoder): void; | ||
@@ -768,4 +770,3 @@ } | ||
static isSigned: boolean; | ||
static from<T extends typeof VarUInt>(this: T, value: VarUIntType): InstanceType<T>; | ||
static fromABI<T extends typeof VarUInt>(this: T, decoder: ABIDecoder): InstanceType<T>; | ||
static fromABI(decoder: ABIDecoder): VarUInt; | ||
toABI(encoder: ABIEncoder): void; | ||
@@ -950,3 +951,4 @@ } | ||
static abiBase: ABISerializableConstructor; | ||
static from<T extends StructConstructor>(this: T, value: any): InstanceType<T>; | ||
static from<T extends StructConstructor>(this: T, value: Record<string, any> | InstanceType<T>): InstanceType<T>; | ||
static from(value: any): unknown; | ||
static get structFields(): ABIField[]; | ||
@@ -979,5 +981,5 @@ /** @internal */ | ||
/** Create new permission level from representing types. Can be expressed as a string in the format `<actor>@<permission>`. */ | ||
static from<T extends StructConstructor>(this: T, value: PermissionLevelType | string): InstanceType<T>; | ||
static from(value: PermissionLevelType | string): any; | ||
/** Return true if this permission level equals other. */ | ||
equals(other: PermissionLevelType | string): boolean; | ||
equals(other: PermissionLevelType | string): any; | ||
} | ||
@@ -1053,3 +1055,3 @@ | ||
delay_sec: VarUInt; | ||
static from<T extends StructConstructor>(this: T, object: TransactionHeaderType): InstanceType<T>; | ||
static from(object: TransactionHeaderType): TransactionHeader; | ||
} | ||
@@ -1107,3 +1109,3 @@ interface TransactionFields extends TransactionHeaderFields { | ||
context_free_data: Bytes[]; | ||
static from<T extends StructConstructor>(this: T, object: SignedTransactionType): InstanceType<T>; | ||
static from(object: SignedTransactionType): SignedTransaction; | ||
} | ||
@@ -1225,2 +1227,3 @@ declare class PackedTransaction extends Struct { | ||
rex_info?: AccountRexInfo; | ||
getPermission(permission: NameType): AccountPermission; | ||
} | ||
@@ -1620,2 +1623,3 @@ declare class NewProducersEntry extends Struct { | ||
static from<T extends VariantConstructor>(this: T, object: AnyVariant): InstanceType<T>; | ||
static from(object: AnyVariant): unknown; | ||
value: ABISerializable; | ||
@@ -1622,0 +1626,0 @@ variantIdx: number; |
{ | ||
"name": "@greymass/eosio", | ||
"description": "Library for working with EOSIO blockchains", | ||
"version": "0.1.10", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/greymass/eosio-core", | ||
@@ -6,0 +6,0 @@ "license": "BSD-3-Clause", |
@@ -138,2 +138,11 @@ import {ABI} from '../../chain/abi' | ||
@Struct.field(AccountRexInfo, {optional: true}) rex_info?: AccountRexInfo | ||
getPermission(permission: NameType): AccountPermission { | ||
const name = Name.from(permission) | ||
const match = this.permissions.find((p) => p.perm_name.equals(name)) | ||
if (!match) { | ||
throw new Error(`Unknown permission ${name} on account ${this.account_name}.`) | ||
} | ||
return match | ||
} | ||
} | ||
@@ -140,0 +149,0 @@ |
@@ -10,2 +10,4 @@ import {ripemd160, sha256, sha512} from 'hash.js' | ||
type ChecksumType = Checksum | BytesType | ||
class Checksum implements ABISerializableObject { | ||
@@ -15,3 +17,5 @@ static abiName: string | ||
static from(value: any) { | ||
static from<T extends typeof Checksum>(this: T, value: ChecksumType): InstanceType<T> | ||
static from(value: ChecksumType): unknown | ||
static from(value: ChecksumType) { | ||
if (isInstanceOf(value, Checksum)) { | ||
@@ -23,2 +27,4 @@ return new this(value.array) | ||
static fromABI<T extends typeof Checksum>(this: T, decoder: ABIDecoder): InstanceType<T> | ||
static fromABI(decoder: ABIDecoder): unknown | ||
static fromABI(decoder: ABIDecoder) { | ||
@@ -28,3 +34,3 @@ return new this(decoder.readArray(this.byteSize)) | ||
array: Uint8Array | ||
readonly array: Uint8Array | ||
@@ -68,4 +74,4 @@ constructor(array: Uint8Array) { | ||
static from<T extends typeof Checksum256>(this: T, value: Checksum256Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
static from(value: Checksum256Type) { | ||
return super.from(value) as Checksum256 | ||
} | ||
@@ -84,4 +90,4 @@ | ||
static from<T extends typeof Checksum512>(this: T, value: Checksum512Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
static from(value: Checksum512Type) { | ||
return super.from(value) as Checksum512 | ||
} | ||
@@ -100,4 +106,4 @@ | ||
static from<T extends typeof Checksum160>(this: T, value: Checksum160Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
static from(value: Checksum160Type) { | ||
return super.from(value) as Checksum160 | ||
} | ||
@@ -104,0 +110,0 @@ |
@@ -13,5 +13,7 @@ import {ABISerializableObject} from '../serializer/serializable' | ||
static from<T extends typeof Float>(this: T, value: FloatType): InstanceType<T> { | ||
static from<T extends typeof Float>(this: T, value: FloatType): InstanceType<T> | ||
static from(value: FloatType): unknown | ||
static from(value: FloatType) { | ||
if (isInstanceOf(value, this as any)) { | ||
return value as InstanceType<T> | ||
return value | ||
} | ||
@@ -23,9 +25,13 @@ if (typeof value === 'string') { | ||
} | ||
return new this(value) as InstanceType<T> | ||
return new this(value) | ||
} | ||
static fromABI<T extends typeof Float>(this: T, decoder: ABIDecoder): InstanceType<T> { | ||
return new this(decoder.readFloat(this.byteWidth)) as InstanceType<T> | ||
static fromABI<T extends typeof Float>(this: T, decoder: ABIDecoder): InstanceType<T> | ||
static fromABI(decoder: ABIDecoder): unknown | ||
static fromABI(decoder: ABIDecoder) { | ||
return new this(decoder.readFloat(this.byteWidth)) | ||
} | ||
static random<T extends typeof Float>(this: T): InstanceType<T> | ||
static random(): unknown | ||
static random() { | ||
@@ -73,6 +79,2 @@ const bytes = secureRandom(this.byteWidth) | ||
} | ||
static from<T extends typeof Float>(this: T, value: Float32Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -84,6 +86,2 @@ | ||
static byteWidth = 8 | ||
static from<T extends typeof Float>(this: T, value: Float64Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -96,5 +94,5 @@ | ||
static from<T extends typeof Float128>(this: T, value: Float128Type): InstanceType<T> { | ||
if (isInstanceOf(value, this as typeof Float128)) { | ||
return value as InstanceType<T> | ||
static from(value: Float128Type) { | ||
if (isInstanceOf(value, this)) { | ||
return value | ||
} | ||
@@ -104,7 +102,7 @@ if (typeof value === 'string' && value.startsWith('0x')) { | ||
} | ||
return new this(Bytes.from(value)) as InstanceType<T> | ||
return new this(Bytes.from(value)) | ||
} | ||
static fromABI<T extends typeof Float128>(this: T, decoder: ABIDecoder): InstanceType<T> { | ||
return new this(new Bytes(decoder.readArray(this.byteWidth))) as InstanceType<T> | ||
static fromABI(decoder: ABIDecoder) { | ||
return new this(new Bytes(decoder.readArray(this.byteWidth))) | ||
} | ||
@@ -111,0 +109,0 @@ |
@@ -23,5 +23,7 @@ import BN from 'bn.js' | ||
static from<T extends typeof Int>(this: T, value: IntType): InstanceType<T> { | ||
static from<T extends typeof Int>(this: T, value: IntType): InstanceType<T> | ||
static from(value: any): unknown | ||
static from(value: any): any { | ||
if (isInstanceOf(value, this as typeof Int)) { | ||
return value as InstanceType<T> | ||
return value | ||
} | ||
@@ -40,9 +42,13 @@ if (typeof value === 'string') { | ||
} | ||
return new this(value) as InstanceType<T> | ||
return new this(value) | ||
} | ||
static fromABI<T extends typeof Int>(this: T, decoder: ABIDecoder): InstanceType<T> { | ||
return new this(decoder.readNum(this.byteWidth, this.isSigned)) as InstanceType<T> | ||
static fromABI<T extends typeof Int>(this: T, decoder: ABIDecoder): InstanceType<T> | ||
static fromABI(decoder: ABIDecoder): unknown | ||
static fromABI(decoder: ABIDecoder) { | ||
return new this(decoder.readNum(this.byteWidth, this.isSigned)) | ||
} | ||
static random<T extends typeof Int>(this: T): InstanceType<T> | ||
static random(): unknown | ||
static random() { | ||
@@ -91,11 +97,13 @@ const bytes = secureRandom(this.byteWidth) | ||
static from<T extends typeof BNInt>(this: T, value: IntType | Uint8Array): InstanceType<T> { | ||
static from<T extends typeof BNInt>(this: T, value: IntType | Uint8Array): InstanceType<T> | ||
static from(value: any): unknown | ||
static from(value: any): any { | ||
if (isInstanceOf(value, this as typeof BNInt)) { | ||
return value as InstanceType<T> | ||
return value | ||
} | ||
if (isInstanceOf(value, BNInt)) { | ||
return new this(value.value) as InstanceType<T> | ||
return new this(value.value) | ||
} | ||
if (isInstanceOf(value, Uint8Array)) { | ||
return new this(new BN(value, undefined, 'le')) as InstanceType<T> | ||
return new this(new BN(value, undefined, 'le')) | ||
} | ||
@@ -105,13 +113,17 @@ if (isInstanceOf(value, Int)) { | ||
} | ||
return new this(new BN(value)) as InstanceType<T> | ||
return new this(new BN(value)) | ||
} | ||
static fromABI<T extends typeof BNInt>(this: T, decoder: ABIDecoder): InstanceType<T> { | ||
return new this(decoder.readBn(this.byteWidth, this.isSigned)) as InstanceType<T> | ||
static fromABI<T extends typeof BNInt>(this: T, decoder: ABIDecoder): InstanceType<T> | ||
static fromABI(decoder: ABIDecoder): unknown | ||
static fromABI(decoder: ABIDecoder) { | ||
return new this(decoder.readBn(this.byteWidth, this.isSigned)) | ||
} | ||
static random<T extends typeof BNInt>(this: T): InstanceType<T> { | ||
static random<T extends typeof BNInt>(this: T): InstanceType<T> | ||
static random(): unknown | ||
static random() { | ||
const bytes = secureRandom(this.byteWidth) | ||
const decoder = new ABIDecoder(bytes) | ||
return this.fromABI(decoder) as InstanceType<T> | ||
return this.fromABI(decoder) | ||
} | ||
@@ -173,6 +185,2 @@ | ||
static isSigned = true | ||
static from<T extends typeof Int8>(this: T, value: Int8Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -185,6 +193,2 @@ | ||
static isSigned = true | ||
static from<T extends typeof Int16>(this: T, value: Int16Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -197,6 +201,2 @@ | ||
static isSigned = true | ||
static from<T extends typeof Int32>(this: T, value: Int32Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -209,6 +209,2 @@ | ||
static isSigned = true | ||
static from<T extends typeof Int64>(this: T, value: Int64Type | Uint8Array): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -221,6 +217,2 @@ | ||
static isSigned = true | ||
static from<T extends typeof Int128>(this: T, value: Int128Type | Uint8Array): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -233,6 +225,2 @@ | ||
static isSigned = false | ||
static from<T extends typeof UInt8>(this: T, value: UInt8Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -245,6 +233,2 @@ | ||
static isSigned = false | ||
static from<T extends typeof UInt16>(this: T, value: UInt16Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -257,6 +241,2 @@ | ||
static isSigned = false | ||
static from<T extends typeof UInt32>(this: T, value: UInt32Type): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -269,6 +249,2 @@ | ||
static isSigned = false | ||
static from<T extends typeof UInt64>(this: T, value: UInt64Type | Uint8Array): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -281,9 +257,2 @@ | ||
static isSigned = false | ||
static from<T extends typeof UInt128>( | ||
this: T, | ||
value: UInt128Type | Uint8Array | ||
): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
} | ||
} | ||
@@ -297,10 +266,6 @@ | ||
static from<T extends typeof VarInt>(this: T, value: VarIntType): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
static fromABI(decoder: ABIDecoder) { | ||
return new this(decoder.readVarint32()) | ||
} | ||
static fromABI<T extends typeof VarInt>(this: T, decoder: ABIDecoder): InstanceType<T> { | ||
return new this(decoder.readVarint32()) as InstanceType<T> | ||
} | ||
toABI(encoder: ABIEncoder) { | ||
@@ -316,10 +281,6 @@ encoder.writeVarint32(this.value) | ||
static from<T extends typeof VarUInt>(this: T, value: VarUIntType): InstanceType<T> { | ||
return super.from(value) as InstanceType<T> | ||
static fromABI(decoder: ABIDecoder) { | ||
return new this(decoder.readVaruint32()) | ||
} | ||
static fromABI<T extends typeof VarUInt>(this: T, decoder: ABIDecoder): InstanceType<T> { | ||
return new this(decoder.readVaruint32()) as InstanceType<T> | ||
} | ||
toABI(encoder: ABIEncoder) { | ||
@@ -326,0 +287,0 @@ encoder.writeVaruint32(this.value) |
import {Name, NameType} from './name' | ||
import {Struct, StructConstructor} from './struct' | ||
import {Struct} from './struct' | ||
@@ -13,6 +13,3 @@ export type PermissionLevelType = PermissionLevel | {actor: NameType; permission: NameType} | ||
/** Create new permission level from representing types. Can be expressed as a string in the format `<actor>@<permission>`. */ | ||
static from<T extends StructConstructor>( | ||
this: T, | ||
value: PermissionLevelType | string | ||
): InstanceType<T> { | ||
static from(value: PermissionLevelType | string) { | ||
if (typeof value === 'string') { | ||
@@ -27,3 +24,3 @@ const parts = value.split('@') | ||
} | ||
return super.from(value) as InstanceType<T> | ||
return super.from(value) as PermissionLevel | ||
} | ||
@@ -30,0 +27,0 @@ |
@@ -20,3 +20,8 @@ import { | ||
static from<T extends StructConstructor>(this: T, value: any): InstanceType<T> { | ||
static from<T extends StructConstructor>( | ||
this: T, | ||
value: Record<string, any> | InstanceType<T> | ||
): InstanceType<T> | ||
static from(value: any): unknown | ||
static from(value: any) { | ||
if (value[Resolved] === true) { | ||
@@ -77,3 +82,3 @@ // objects already resolved | ||
} | ||
return abiEncode({object: this}).equals(abiEncode({object: self.from(other)})) | ||
return abiEncode({object: this}).equals(abiEncode({object: self.from(other) as any})) | ||
} | ||
@@ -80,0 +85,0 @@ |
@@ -22,21 +22,25 @@ import BN from 'bn.js' | ||
class TimePointBase implements ABISerializableObject { | ||
static from<T extends TimePointConstructor>(this: T, value: TimePointType): InstanceType<T> { | ||
if (isInstanceOf(value, this as TimePointConstructor)) { | ||
return value as InstanceType<T> | ||
static from<T extends TimePointConstructor>(this: T, value: TimePointType): InstanceType<T> | ||
static from(value: TimePointType): unknown | ||
static from(this: TimePointConstructor, value: TimePointType) { | ||
if (isInstanceOf(value, this)) { | ||
return value | ||
} | ||
if (isInstanceOf(value, TimePointBase)) { | ||
// converting between types | ||
return this.fromMilliseconds(value.toMilliseconds()) as InstanceType<T> | ||
return this.fromMilliseconds(value.toMilliseconds()) | ||
} | ||
if (isInstanceOf(value, Date)) { | ||
return this.fromDate(value) as InstanceType<T> | ||
return this.fromDate(value) | ||
} | ||
if (typeof value === 'string') { | ||
return this.fromString(value) as InstanceType<T> | ||
return this.fromString(value) | ||
} | ||
return this.fromInteger(value) as InstanceType<T> | ||
return this.fromInteger(value) | ||
} | ||
static fromString<T extends TimePointConstructor>(this: T, string: string): InstanceType<T> { | ||
static fromString<T extends TimePointConstructor>(this: T, string: string): InstanceType<T> | ||
static fromString(string: string): unknown | ||
static fromString(this: TimePointConstructor, string: string) { | ||
const value = Date.parse(string + 'Z') | ||
@@ -46,7 +50,9 @@ if (!Number.isFinite(value)) { | ||
} | ||
return this.fromMilliseconds(value) as InstanceType<T> | ||
return this.fromMilliseconds(value) | ||
} | ||
static fromDate<T extends TimePointConstructor>(this: T, date: Date): InstanceType<T> { | ||
return this.fromMilliseconds(date.getTime()) as InstanceType<T> | ||
static fromDate<T extends TimePointConstructor>(this: T, date: Date): InstanceType<T> | ||
static fromDate(date: Date): unknown | ||
static fromDate(this: TimePointConstructor, date: Date) { | ||
return this.fromMilliseconds(date.getTime()) | ||
} | ||
@@ -53,0 +59,0 @@ |
@@ -14,3 +14,3 @@ import {Action, ActionType, AnyAction} from './action' | ||
} from './integer' | ||
import {Struct, StructConstructor} from './struct' | ||
import {Struct} from './struct' | ||
import {TimePointSec, TimePointType} from './time' | ||
@@ -62,7 +62,4 @@ | ||
static from<T extends StructConstructor>( | ||
this: T, | ||
object: TransactionHeaderType | ||
): InstanceType<T> { | ||
return super.from(object) as InstanceType<T> | ||
static from(object: TransactionHeaderType) { | ||
return super.from(object) as TransactionHeader | ||
} | ||
@@ -161,7 +158,4 @@ } | ||
static from<T extends StructConstructor>( | ||
this: T, | ||
object: SignedTransactionType | ||
): InstanceType<T> { | ||
return super.from(object) as InstanceType<T> | ||
static from(object: SignedTransactionType) { | ||
return super.from(object) as SignedTransaction | ||
} | ||
@@ -186,3 +180,3 @@ } | ||
packed_trx: abiEncode({object: tx}), | ||
}) | ||
}) as PackedTransaction | ||
} | ||
@@ -194,3 +188,3 @@ | ||
} | ||
return abiDecode({data: this.packed_trx, type: Transaction}) as Transaction | ||
return abiDecode({data: this.packed_trx, type: Transaction}) | ||
} | ||
@@ -197,0 +191,0 @@ |
@@ -24,8 +24,10 @@ import { | ||
static from<T extends VariantConstructor>(this: T, object: AnyVariant): InstanceType<T> { | ||
static from<T extends VariantConstructor>(this: T, object: AnyVariant): InstanceType<T> | ||
static from(object: AnyVariant): unknown | ||
static from(object: AnyVariant) { | ||
if (object[Resolved]) { | ||
return new this(object) as InstanceType<T> | ||
return new this(object as [string, ABISerializable]) | ||
} | ||
if (isInstanceOf(object, this)) { | ||
return object as InstanceType<T> | ||
return object | ||
} | ||
@@ -32,0 +34,0 @@ return abiDecode({object, type: this}) |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1
721161
45
14274