eos-common
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -34,23 +34,30 @@ import { SymbolCode } from "./symbol_code"; | ||
raw(): bigint; | ||
isTruthy(): boolean; | ||
isFalsy(): boolean; | ||
/** | ||
* Explicit cast to bool of the symbol | ||
* | ||
* @return Returns true if the symbol is set to the default value of 0 else true. | ||
*/ | ||
bool(): boolean; | ||
/** | ||
* Equivalency operator. Returns true if a == b (are the same) | ||
* | ||
* @return boolean - true if both provided symbols are the same | ||
* @return boolean - true if both provided symbol_codes are the same | ||
*/ | ||
isEqual(comparison: Symbol): boolean; | ||
static isEqual(a: Symbol, b: Symbol): boolean; | ||
isEqual(a: Symbol): boolean; | ||
/** | ||
* Inverted equivalency operator. Returns true if a != b (are different) | ||
* | ||
* @return boolean - true if both provided symbols are not the same | ||
* @return boolean - true if both provided symbol_codes are not the same | ||
*/ | ||
isNotEqual(comparison: Symbol): boolean; | ||
static isNotEqual(a: Symbol, b: Symbol): boolean; | ||
isNotEqual(a: Symbol): boolean; | ||
/** | ||
* Less than operator. Returns true if a < b. | ||
* @brief Less than operator | ||
* @return boolean - true if symbol `a` is less than `b` | ||
* @return boolean - true if symbol_code `a` is less than `b` | ||
*/ | ||
isLessThan(comparison: Symbol): boolean; | ||
static isLessThan(a: Symbol, b: Symbol): boolean; | ||
isLessThan(a: Symbol): boolean; | ||
} | ||
export declare function symbol(sc?: string | SymbolCode | number | bigint, precision?: number | bigint): Symbol; |
@@ -127,8 +127,2 @@ // https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/core/eosio/check.hpp | ||
} | ||
// (() => { | ||
// console.log(symbol_code("EOSDT").to_string()); | ||
// console.log(symbol_code("EBTC").to_string()); | ||
// console.log(symbol_code("USDE").to_string()); | ||
// console.log(symbol_code("USDT").to_string()); | ||
// })(); | ||
@@ -157,9 +151,2 @@ function asset_to_bigint(quantity) { | ||
} | ||
// console.log(isNull(undefined)) | ||
// console.log(isNull(null)) | ||
// console.log(isNull("foo")) | ||
// console.log(isNull(0)) | ||
// (() => { | ||
// const asset = number_to_asset(3.6587120707054996, new Symbol("EOS", 4)); | ||
// })(); | ||
@@ -213,3 +200,3 @@ // https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp | ||
precision() { | ||
return Number(BigInt(this.value) & BigInt(0x00000000000000FF)); | ||
return Number(this.value & BigInt(0x00000000000000FF)); | ||
} | ||
@@ -220,3 +207,3 @@ /** | ||
code() { | ||
return new SymbolCode(BigInt(this.value) >> BigInt(8)); | ||
return new SymbolCode(this.value >> BigInt(8)); | ||
} | ||
@@ -229,32 +216,43 @@ /** | ||
} | ||
isTruthy() { | ||
/** | ||
* Explicit cast to bool of the symbol | ||
* | ||
* @return Returns true if the symbol is set to the default value of 0 else true. | ||
*/ | ||
bool() { | ||
return this.value != BigInt(0); | ||
} | ||
isFalsy() { | ||
return this.value == BigInt(0); | ||
} | ||
/** | ||
* Equivalency operator. Returns true if a == b (are the same) | ||
* | ||
* @return boolean - true if both provided symbols are the same | ||
* @return boolean - true if both provided symbol_codes are the same | ||
*/ | ||
isEqual(comparison) { | ||
return comparison.value === this.value; | ||
static isEqual(a, b) { | ||
return a.raw() == b.raw(); | ||
} | ||
isEqual(a) { | ||
return a.raw() == this.raw(); | ||
} | ||
/** | ||
* Inverted equivalency operator. Returns true if a != b (are different) | ||
* | ||
* @return boolean - true if both provided symbols are not the same | ||
* @return boolean - true if both provided symbol_codes are not the same | ||
*/ | ||
isNotEqual(comparison) { | ||
return comparison.value !== this.value; | ||
static isNotEqual(a, b) { | ||
return a.raw() != b.raw(); | ||
} | ||
isNotEqual(a) { | ||
return a.raw() != this.raw(); | ||
} | ||
/** | ||
* Less than operator. Returns true if a < b. | ||
* @brief Less than operator | ||
* @return boolean - true if symbol `a` is less than `b` | ||
* @return boolean - true if symbol_code `a` is less than `b` | ||
*/ | ||
isLessThan(comparison) { | ||
return this.value < comparison.value; | ||
static isLessThan(a, b) { | ||
return a.raw() < b.raw(); | ||
} | ||
isLessThan(a) { | ||
return this.raw() < a.raw(); | ||
} | ||
} | ||
@@ -264,19 +262,2 @@ function symbol(sc, precision) { | ||
} | ||
// (() => { | ||
// console.log("EOSDT", "=>", symbol("EOSDT", 8).code().to_string()); | ||
// console.log("EBTC", "=>", symbol("EBTC", 8).code().to_string()); | ||
// console.log("USDE", "=>", symbol("USDE", 4).code().to_string()); | ||
// console.log("USDT", "=>", symbol("USDT", 4).code().to_string()); | ||
// })(); | ||
// (() => { | ||
// console.log(typeof new SymbolCode) | ||
// console.log(typeof new SymbolCode("EOS")) | ||
// console.log(symbol("A", 4).raw()); | ||
// console.log(symbol("AB", 4).raw()); | ||
// console.log(symbol("ABC", 4).raw()); | ||
// console.log(symbol("ABCD", 4).raw()); | ||
// console.log(symbol("ABCDE", 4).raw()); | ||
// console.log(symbol("ABCDEF", 4).raw()); | ||
// console.log(symbol("ABCDEFG", 4).raw()); | ||
// })(); | ||
@@ -405,3 +386,3 @@ /** | ||
else { | ||
check(a.symbol == this.symbol, "attempt to subtract asset with different symbol"); | ||
check(a.symbol.isEqual(this.symbol), "attempt to subtract asset with different symbol"); | ||
this.amount -= a.amount; | ||
@@ -425,3 +406,3 @@ } | ||
else { | ||
check(a.symbol == this.symbol, "attempt to add asset with different symbol"); | ||
check(a.symbol.isEqual(this.symbol), "attempt to add asset with different symbol"); | ||
this.amount += a.amount; | ||
@@ -471,3 +452,3 @@ } | ||
else { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
amount = a.amount; | ||
@@ -508,3 +489,3 @@ } | ||
else { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
amount = a.amount; | ||
@@ -539,7 +520,7 @@ } | ||
static isEqual(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount == b.amount; | ||
} | ||
isEqual(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount == this.amount; | ||
@@ -572,7 +553,7 @@ } | ||
static isLessThan(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount < b.amount; | ||
} | ||
isLessThan(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount < a.amount; | ||
@@ -590,7 +571,7 @@ } | ||
static isLessThanOrEqual(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount <= b.amount; | ||
} | ||
isLessThanOrEqual(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount <= a.amount; | ||
@@ -608,7 +589,7 @@ } | ||
static isGreaterThan(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount > b.amount; | ||
} | ||
isGreaterThan(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount > a.amount; | ||
@@ -626,7 +607,7 @@ } | ||
static isGreaterThanOrEqual(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount >= b.amount; | ||
} | ||
isGreaterThanOrEqual(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount >= a.amount; | ||
@@ -647,16 +628,2 @@ } | ||
} | ||
// const asset_mask: bigint = (BigInt(1) << BigInt(62)) - BigInt(1); | ||
// const asset_min: bigint = -asset_mask; // -4611686018427387903 | ||
// const asset_max: bigint = asset_mask; // 4611686018427387903 | ||
// const sym_no_prec = symbol("SYMBOLL", 0n); // Symbol with no precision | ||
// const sym_prec = symbol("SYMBOLL", 63n); // Symbol with precision | ||
// console.log( "asset_min", asset_min ); | ||
// console.log( asset( asset_min, sym_no_prec ).to_string() ) | ||
// .toBe( "-4611686018427387903 SYMBOLL" ) | ||
// asset( asset_min - 1n, symbol() ) | ||
// console.log( asset( asset_min, sym_no_prec ).minus( 1 ).amount ); | ||
// (() => { | ||
// const quantity = new Asset(9643, new Symbol("USD", 4)); | ||
// console.log(quantity); | ||
// })() | ||
@@ -663,0 +630,0 @@ class Time { |
@@ -131,8 +131,2 @@ 'use strict'; | ||
} | ||
// (() => { | ||
// console.log(symbol_code("EOSDT").to_string()); | ||
// console.log(symbol_code("EBTC").to_string()); | ||
// console.log(symbol_code("USDE").to_string()); | ||
// console.log(symbol_code("USDT").to_string()); | ||
// })(); | ||
@@ -161,9 +155,2 @@ function asset_to_bigint(quantity) { | ||
} | ||
// console.log(isNull(undefined)) | ||
// console.log(isNull(null)) | ||
// console.log(isNull("foo")) | ||
// console.log(isNull(0)) | ||
// (() => { | ||
// const asset = number_to_asset(3.6587120707054996, new Symbol("EOS", 4)); | ||
// })(); | ||
@@ -217,3 +204,3 @@ // https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp | ||
precision() { | ||
return Number(BigInt(this.value) & BigInt(0x00000000000000FF)); | ||
return Number(this.value & BigInt(0x00000000000000FF)); | ||
} | ||
@@ -224,3 +211,3 @@ /** | ||
code() { | ||
return new SymbolCode(BigInt(this.value) >> BigInt(8)); | ||
return new SymbolCode(this.value >> BigInt(8)); | ||
} | ||
@@ -233,32 +220,43 @@ /** | ||
} | ||
isTruthy() { | ||
/** | ||
* Explicit cast to bool of the symbol | ||
* | ||
* @return Returns true if the symbol is set to the default value of 0 else true. | ||
*/ | ||
bool() { | ||
return this.value != BigInt(0); | ||
} | ||
isFalsy() { | ||
return this.value == BigInt(0); | ||
} | ||
/** | ||
* Equivalency operator. Returns true if a == b (are the same) | ||
* | ||
* @return boolean - true if both provided symbols are the same | ||
* @return boolean - true if both provided symbol_codes are the same | ||
*/ | ||
isEqual(comparison) { | ||
return comparison.value === this.value; | ||
static isEqual(a, b) { | ||
return a.raw() == b.raw(); | ||
} | ||
isEqual(a) { | ||
return a.raw() == this.raw(); | ||
} | ||
/** | ||
* Inverted equivalency operator. Returns true if a != b (are different) | ||
* | ||
* @return boolean - true if both provided symbols are not the same | ||
* @return boolean - true if both provided symbol_codes are not the same | ||
*/ | ||
isNotEqual(comparison) { | ||
return comparison.value !== this.value; | ||
static isNotEqual(a, b) { | ||
return a.raw() != b.raw(); | ||
} | ||
isNotEqual(a) { | ||
return a.raw() != this.raw(); | ||
} | ||
/** | ||
* Less than operator. Returns true if a < b. | ||
* @brief Less than operator | ||
* @return boolean - true if symbol `a` is less than `b` | ||
* @return boolean - true if symbol_code `a` is less than `b` | ||
*/ | ||
isLessThan(comparison) { | ||
return this.value < comparison.value; | ||
static isLessThan(a, b) { | ||
return a.raw() < b.raw(); | ||
} | ||
isLessThan(a) { | ||
return this.raw() < a.raw(); | ||
} | ||
} | ||
@@ -268,19 +266,2 @@ function symbol(sc, precision) { | ||
} | ||
// (() => { | ||
// console.log("EOSDT", "=>", symbol("EOSDT", 8).code().to_string()); | ||
// console.log("EBTC", "=>", symbol("EBTC", 8).code().to_string()); | ||
// console.log("USDE", "=>", symbol("USDE", 4).code().to_string()); | ||
// console.log("USDT", "=>", symbol("USDT", 4).code().to_string()); | ||
// })(); | ||
// (() => { | ||
// console.log(typeof new SymbolCode) | ||
// console.log(typeof new SymbolCode("EOS")) | ||
// console.log(symbol("A", 4).raw()); | ||
// console.log(symbol("AB", 4).raw()); | ||
// console.log(symbol("ABC", 4).raw()); | ||
// console.log(symbol("ABCD", 4).raw()); | ||
// console.log(symbol("ABCDE", 4).raw()); | ||
// console.log(symbol("ABCDEF", 4).raw()); | ||
// console.log(symbol("ABCDEFG", 4).raw()); | ||
// })(); | ||
@@ -409,3 +390,3 @@ /** | ||
else { | ||
check(a.symbol == this.symbol, "attempt to subtract asset with different symbol"); | ||
check(a.symbol.isEqual(this.symbol), "attempt to subtract asset with different symbol"); | ||
this.amount -= a.amount; | ||
@@ -429,3 +410,3 @@ } | ||
else { | ||
check(a.symbol == this.symbol, "attempt to add asset with different symbol"); | ||
check(a.symbol.isEqual(this.symbol), "attempt to add asset with different symbol"); | ||
this.amount += a.amount; | ||
@@ -475,3 +456,3 @@ } | ||
else { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
amount = a.amount; | ||
@@ -512,3 +493,3 @@ } | ||
else { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
amount = a.amount; | ||
@@ -543,7 +524,7 @@ } | ||
static isEqual(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount == b.amount; | ||
} | ||
isEqual(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount == this.amount; | ||
@@ -576,7 +557,7 @@ } | ||
static isLessThan(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount < b.amount; | ||
} | ||
isLessThan(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount < a.amount; | ||
@@ -594,7 +575,7 @@ } | ||
static isLessThanOrEqual(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount <= b.amount; | ||
} | ||
isLessThanOrEqual(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount <= a.amount; | ||
@@ -612,7 +593,7 @@ } | ||
static isGreaterThan(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount > b.amount; | ||
} | ||
isGreaterThan(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount > a.amount; | ||
@@ -630,7 +611,7 @@ } | ||
static isGreaterThanOrEqual(a, b) { | ||
check(a.symbol == b.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount >= b.amount; | ||
} | ||
isGreaterThanOrEqual(a) { | ||
check(a.symbol == this.symbol, "comparison of assets with different symbols is not allowed"); | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount >= a.amount; | ||
@@ -651,16 +632,2 @@ } | ||
} | ||
// const asset_mask: bigint = (BigInt(1) << BigInt(62)) - BigInt(1); | ||
// const asset_min: bigint = -asset_mask; // -4611686018427387903 | ||
// const asset_max: bigint = asset_mask; // 4611686018427387903 | ||
// const sym_no_prec = symbol("SYMBOLL", 0n); // Symbol with no precision | ||
// const sym_prec = symbol("SYMBOLL", 63n); // Symbol with precision | ||
// console.log( "asset_min", asset_min ); | ||
// console.log( asset( asset_min, sym_no_prec ).to_string() ) | ||
// .toBe( "-4611686018427387903 SYMBOLL" ) | ||
// asset( asset_min - 1n, symbol() ) | ||
// console.log( asset( asset_min, sym_no_prec ).minus( 1 ).amount ); | ||
// (() => { | ||
// const quantity = new Asset(9643, new Symbol("USD", 4)); | ||
// console.log(quantity); | ||
// })() | ||
@@ -667,0 +634,0 @@ class Time { |
{ | ||
"name": "eos-common", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"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
65852
1658