eos-common
Advanced tools
Comparing version 0.4.6 to 0.4.7
@@ -29,3 +29,3 @@ import { Symbol } from "./symbol"; | ||
symbol: Symbol; | ||
constructor(amount?: string | number | BigInt, sym?: Symbol); | ||
constructor(amount?: string | number | bigint, sym?: Symbol); | ||
/** | ||
@@ -47,2 +47,2 @@ * Check if the amount doesn't exceed the max amount | ||
} | ||
export declare function asset(amount?: number | BigInt, sym?: Symbol): Asset; | ||
export declare function asset(amount?: bigint, sym?: Symbol): Asset; |
@@ -7,4 +7,4 @@ /** | ||
private value; | ||
constructor(str?: string | number | BigInt); | ||
raw(): BigInt; | ||
constructor(str?: string | number | bigint); | ||
raw(): bigint; | ||
isTruthy(): boolean; | ||
@@ -34,2 +34,2 @@ isFalsy(): boolean; | ||
} | ||
export declare function symbol_code(str?: string | number | BigInt): SymbolCode; | ||
export declare function symbol_code(str?: string | number | bigint): SymbolCode; |
import { SymbolCode } from "./symbol_code"; | ||
export declare class Symbol { | ||
value: BigInt; | ||
value: bigint; | ||
/** | ||
@@ -17,3 +17,3 @@ * Symbol | ||
*/ | ||
constructor(sc: string | SymbolCode | number | BigInt, precision: number | BigInt); | ||
constructor(sc: string | SymbolCode | number | bigint, precision: number | bigint); | ||
/** | ||
@@ -34,3 +34,3 @@ * Is this symbol valid | ||
*/ | ||
raw(): BigInt; | ||
raw(): bigint; | ||
isTruthy(): boolean; | ||
@@ -57,2 +57,2 @@ isFalsy(): boolean; | ||
} | ||
export declare function symbol(sc: number | string | SymbolCode, precision: number | BigInt): Symbol; | ||
export declare function symbol(sc: number | string | SymbolCode, precision: number | bigint): Symbol; |
import { Symbol } from "./symbol"; | ||
import { Asset } from "./asset"; | ||
export declare function asset_to_bigint(quantity: Asset): BigInt; | ||
export declare function bigint_to_asset(amount: number | BigInt, sym: Symbol): Asset; | ||
export declare function asset_to_bigint(quantity: Asset): bigint; | ||
export declare function bigint_to_asset(amount: number | bigint, sym: Symbol): Asset; | ||
export declare function asset_to_number(quantity: Asset): number; | ||
export declare function number_to_asset(amount: number | BigInt, sym: Symbol): Asset; | ||
export declare function number_to_asset(amount: number, sym: Symbol): Asset; | ||
export declare function number_to_bigint(num: number): bigint; |
@@ -244,3 +244,3 @@ // https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/core/eosio/check.hpp | ||
return BigInt(0.0); | ||
return quantity.amount / BigInt(Math.pow(10, quantity.symbol.precision())); | ||
return BigInt(quantity.amount) / BigInt(Math.pow(10, quantity.symbol.precision())); | ||
} | ||
@@ -256,4 +256,10 @@ function bigint_to_asset(amount, sym) { | ||
function number_to_asset(amount, sym) { | ||
return new Asset(Number(amount) * Math.pow(10, sym.precision()), sym); | ||
return new Asset(amount * Math.pow(10, sym.precision()), sym); | ||
} | ||
function number_to_bigint(num) { | ||
return BigInt(num.toFixed(0)); | ||
} | ||
// (() => { | ||
// const asset = number_to_asset(3.6587120707054996, new Symbol("EOS", 4)); | ||
// })(); | ||
@@ -284,7 +290,7 @@ // https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/asset.hpp | ||
const precision = (amount_str.split(".")[1] || []).length; | ||
this.amount = BigInt(Math.round(Number(amount_str) * Math.pow(10, precision))); | ||
this.amount = number_to_bigint(Number(amount_str) * Math.pow(10, precision)); | ||
this.symbol = new Symbol(symbol_str, precision); | ||
} | ||
else if (sym) { | ||
this.amount = BigInt(amount); | ||
this.amount = (typeof amount == "number") ? number_to_bigint(amount) : BigInt(amount); | ||
this.symbol = sym; | ||
@@ -305,3 +311,3 @@ } | ||
is_amount_within_range() { | ||
return -Asset.max_amount <= this.amount && this.amount <= Asset.max_amount; | ||
return -BigInt(Asset.max_amount) <= BigInt(this.amount) && this.amount <= Asset.max_amount; | ||
} | ||
@@ -330,3 +336,3 @@ /** | ||
// (() => { | ||
// const quantity = new Asset("9643.4600 USD"); | ||
// const quantity = new Asset(9643, new Symbol("USD", 4)); | ||
// console.log(quantity); | ||
@@ -372,3 +378,3 @@ // })() | ||
export { Asset, Symbol, SymbolCode, asset, asset_to_bigint, asset_to_number, bigint_to_asset, block_timestamp_epoch, check, current_time_point, number_to_asset, seconds_per_day, stake2vote, symbol, symbol_code, vote2stake, voteWeightToday }; | ||
export { Asset, Symbol, SymbolCode, asset, asset_to_bigint, asset_to_number, bigint_to_asset, block_timestamp_epoch, check, current_time_point, number_to_asset, number_to_bigint, seconds_per_day, stake2vote, symbol, symbol_code, vote2stake, voteWeightToday }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -248,3 +248,3 @@ 'use strict'; | ||
return BigInt(0.0); | ||
return quantity.amount / BigInt(Math.pow(10, quantity.symbol.precision())); | ||
return BigInt(quantity.amount) / BigInt(Math.pow(10, quantity.symbol.precision())); | ||
} | ||
@@ -260,4 +260,10 @@ function bigint_to_asset(amount, sym) { | ||
function number_to_asset(amount, sym) { | ||
return new Asset(Number(amount) * Math.pow(10, sym.precision()), sym); | ||
return new Asset(amount * Math.pow(10, sym.precision()), sym); | ||
} | ||
function number_to_bigint(num) { | ||
return BigInt(num.toFixed(0)); | ||
} | ||
// (() => { | ||
// const asset = number_to_asset(3.6587120707054996, new Symbol("EOS", 4)); | ||
// })(); | ||
@@ -288,7 +294,7 @@ // https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/asset.hpp | ||
const precision = (amount_str.split(".")[1] || []).length; | ||
this.amount = BigInt(Math.round(Number(amount_str) * Math.pow(10, precision))); | ||
this.amount = number_to_bigint(Number(amount_str) * Math.pow(10, precision)); | ||
this.symbol = new Symbol(symbol_str, precision); | ||
} | ||
else if (sym) { | ||
this.amount = BigInt(amount); | ||
this.amount = (typeof amount == "number") ? number_to_bigint(amount) : BigInt(amount); | ||
this.symbol = sym; | ||
@@ -309,3 +315,3 @@ } | ||
is_amount_within_range() { | ||
return -Asset.max_amount <= this.amount && this.amount <= Asset.max_amount; | ||
return -BigInt(Asset.max_amount) <= BigInt(this.amount) && this.amount <= Asset.max_amount; | ||
} | ||
@@ -334,3 +340,3 @@ /** | ||
// (() => { | ||
// const quantity = new Asset("9643.4600 USD"); | ||
// const quantity = new Asset(9643, new Symbol("USD", 4)); | ||
// console.log(quantity); | ||
@@ -387,2 +393,3 @@ // })() | ||
exports.number_to_asset = number_to_asset; | ||
exports.number_to_bigint = number_to_bigint; | ||
exports.seconds_per_day = seconds_per_day; | ||
@@ -389,0 +396,0 @@ exports.stake2vote = stake2vote; |
{ | ||
"name": "eos-common", | ||
"version": "0.4.6", | ||
"version": "0.4.7", | ||
"description": "EOSIO Smart Contract common library used for Typescript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
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
38858
938