@greymass/eosio
Advanced tools
Comparing version 0.1.5 to 0.1.6
/** | ||
* EOSIO Core v0.1.5 | ||
* EOSIO Core v0.1.6 | ||
* https://github.com/greymass/eosio-core | ||
@@ -111,2 +111,6 @@ * | ||
static from(value: AssetType): Asset; | ||
static from(value: number, symbol: Asset.SymbolType): Asset; | ||
static fromString(value: string): Asset; | ||
static fromFloat(value: number, symbol: Asset.SymbolType): Asset; | ||
static fromUnits(value: Int64Type, symbol: Asset.SymbolType): Asset; | ||
static fromABI(decoder: ABIDecoder): Asset; | ||
@@ -113,0 +117,0 @@ constructor(units: Int64, symbol: Asset.Symbol); |
{ | ||
"name": "@greymass/eosio", | ||
"description": "Library for working with EOSIO blockchains", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"homepage": "https://github.com/greymass/eosio-core", | ||
@@ -6,0 +6,0 @@ "license": "BSD-3-Clause", |
import BN from 'bn.js' | ||
import {ABISerializableObject} from '../serializer/serializable' | ||
import {Int64, UInt64} from './integer' | ||
import {Int64, Int64Type, UInt64} from './integer' | ||
import {ABIEncoder} from '../serializer/encoder' | ||
@@ -18,6 +18,22 @@ import {ABIDecoder} from '../serializer/decoder' | ||
static from(value: AssetType) { | ||
static from(value: AssetType): Asset | ||
static from(value: number, symbol: Asset.SymbolType): Asset | ||
static from(value: AssetType | number, symbol?: Asset.SymbolType) { | ||
if (isInstanceOf(value, Asset)) { | ||
return value | ||
} | ||
switch (typeof value) { | ||
case 'number': | ||
if (!symbol) { | ||
throw new Error('Symbol is required when creating Asset from number') | ||
} | ||
return this.fromFloat(value, symbol) | ||
case 'string': | ||
return this.fromString(value) | ||
default: | ||
throw new Error('Invalid asset') | ||
} | ||
} | ||
static fromString(value: string) { | ||
const parts = (typeof value === 'string' ? value : '').split(' ') | ||
@@ -33,2 +49,11 @@ if (parts.length !== 2) { | ||
static fromFloat(value: number, symbol: Asset.SymbolType) { | ||
const s = Asset.Symbol.from(symbol) | ||
return new Asset(s.convertFloat(value), s) | ||
} | ||
static fromUnits(value: Int64Type, symbol: Asset.SymbolType) { | ||
return new Asset(Int64.from(value), Asset.Symbol.from(symbol)) | ||
} | ||
static fromABI(decoder: ABIDecoder): Asset { | ||
@@ -35,0 +60,0 @@ const units = Int64.fromABI(decoder) |
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
726483
14355