eos-common
Advanced tools
Comparing version 0.6.2 to 0.7.0
import { Sym } from "./symbol"; | ||
import bigInt, { BigInteger } from "big-integer"; | ||
/** | ||
@@ -18,11 +19,18 @@ * Asset | ||
get [Symbol.toStringTag](): string; | ||
typeof(): string; | ||
/** | ||
* The typeof operator returns a string indicating the type of the unevaluated operand. | ||
*/ | ||
get typeof(): string; | ||
/** | ||
* The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
*/ | ||
static isInstance(obj: any): boolean; | ||
/** | ||
* {constexpr int64_t} Maximum amount possible for this asset. It's capped to 2^62 - 1 | ||
*/ | ||
static max_amount: bigint; | ||
static max_amount: bigInt.BigInteger; | ||
/** | ||
* {int64_t} The amount of the asset | ||
*/ | ||
amount: bigint; | ||
amount: bigInt.BigInteger; | ||
/** | ||
@@ -38,3 +46,3 @@ * {symbol} The symbol name of the asset | ||
*/ | ||
constructor(amount?: string | number | bigint, sym?: Sym); | ||
constructor(amount?: string | number | BigInteger | bigint, sym?: Sym); | ||
/** | ||
@@ -59,3 +67,3 @@ * Check if the amount doesn't exceed the max amount | ||
*/ | ||
set_amount(amount: bigint | number): void; | ||
set_amount(amount: BigInteger | number): void; | ||
/** | ||
@@ -68,3 +76,3 @@ * Subtraction assignment operator | ||
*/ | ||
minus(a: Asset | number | bigint): Asset; | ||
minus(a: Asset | number | bigint | BigInteger): Asset; | ||
/** | ||
@@ -77,3 +85,3 @@ * Addition Assignment operator | ||
*/ | ||
plus(a: Asset | number | bigint): Asset; | ||
plus(a: Asset | number | bigint | BigInteger): Asset; | ||
/** | ||
@@ -86,3 +94,3 @@ * Addition operator | ||
*/ | ||
static plus(a: Asset, b: Asset): Asset; | ||
static plus(a: Asset, b: Asset | number | bigint | BigInteger): Asset; | ||
/** | ||
@@ -95,3 +103,3 @@ * Subtraction operator | ||
*/ | ||
static minus(a: Asset, b: Asset): Asset; | ||
static minus(a: Asset, b: Asset | number | bigint | BigInteger): Asset; | ||
/** | ||
@@ -105,3 +113,3 @@ * Multiplication assignment operator, with a number | ||
*/ | ||
times(a: number | bigint | Asset): Asset; | ||
times(a: Asset | number | bigint | BigInteger): Asset; | ||
/** | ||
@@ -115,3 +123,3 @@ * Multiplication operator, with a number proceeding | ||
*/ | ||
static times(a: Asset, b: number | bigint | Asset): Asset; | ||
static times(a: Asset, b: Asset | number | bigint | BigInteger): Asset; | ||
/** | ||
@@ -125,3 +133,3 @@ * @brief Division assignment operator, with a number | ||
*/ | ||
div(a: number | bigint | Asset): Asset; | ||
div(a: Asset | number | bigint | BigInteger): Asset; | ||
/** | ||
@@ -134,3 +142,3 @@ * Division operator, with a number proceeding | ||
*/ | ||
static div(a: Asset, b: number | bigint | Asset): Asset; | ||
static div(a: Asset, b: Asset | number | bigint | BigInteger): Asset; | ||
/** | ||
@@ -202,10 +210,8 @@ * Equality operator | ||
isGreaterThanOrEqual(a: Asset): boolean; | ||
to_string(): string; | ||
/** | ||
* %Print the asset | ||
* | ||
* @brief %Print the asset | ||
* The toString() method returns the string representation of the object. | ||
*/ | ||
print(): void; | ||
toString(): string; | ||
to_string(): string; | ||
} | ||
export declare function asset(amount?: string | number | bigint, sym?: Sym): Asset; | ||
export declare function asset(amount?: string | number | BigInteger, sym?: Sym): Asset; |
@@ -0,0 +0,0 @@ /** |
@@ -0,1 +1,2 @@ | ||
import { BigInteger } from "big-integer"; | ||
/** | ||
@@ -9,2 +10,2 @@ * Writes a number as a string | ||
*/ | ||
export declare function write_decimal(number: bigint, num_decimal_places: number, negative: boolean): string; | ||
export declare function write_decimal(number: BigInteger, num_decimal_places: number, negative: boolean): string; |
import { Name } from "./name"; | ||
import { Asset } from "./asset"; | ||
import { ExtendedSymbol } from "./extended_symbol"; | ||
import { BigInteger } from "big-integer"; | ||
/** | ||
@@ -10,4 +11,11 @@ * @class Stores the extended_asset | ||
get [Symbol.toStringTag](): string; | ||
typeof(): string; | ||
/** | ||
* The typeof operator returns a string indicating the type of the unevaluated operand. | ||
*/ | ||
get typeof(): string; | ||
/** | ||
* The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
*/ | ||
static isInstance(obj: any): boolean; | ||
/** | ||
* The asset | ||
@@ -27,41 +35,91 @@ */ | ||
/** | ||
* Construct a new symbol_code object initialising symbol and contract with the passed in symbol and name | ||
* | ||
* @param sym - The symbol | ||
* @param con - The name of the contract | ||
* Extended asset which stores the information of the owner of the asset | ||
*/ | ||
constructor(options?: { | ||
amount?: number | bigint; | ||
ext_sym?: ExtendedSymbol; | ||
quantity?: Asset | string; | ||
contract?: Name | string; | ||
}); | ||
constructor(a: Asset, c: Name); | ||
constructor(c: Name); | ||
constructor(v: number | bigint | BigInteger, s: ExtendedSymbol); | ||
constructor(s: ExtendedSymbol); | ||
/** | ||
* %Print the extended asset | ||
* The toString() method returns the string representation of the object. | ||
*/ | ||
print(): void; | ||
times(a: ExtendedAsset | number | bigint): ExtendedAsset; | ||
static times(a: ExtendedAsset, b: ExtendedAsset | number | bigint): ExtendedAsset; | ||
div(a: ExtendedAsset | number | bigint): ExtendedAsset; | ||
static div(a: ExtendedAsset, b: ExtendedAsset | number | bigint): ExtendedAsset; | ||
minus(a: ExtendedAsset | number | bigint): ExtendedAsset; | ||
toString(): string; | ||
/** | ||
* Multiplication assignment operator | ||
*/ | ||
times(a: ExtendedAsset | number | bigint | BigInteger): ExtendedAsset; | ||
static times(a: ExtendedAsset, b: ExtendedAsset | number | bigint | BigInteger): ExtendedAsset; | ||
/** | ||
* Division operator | ||
*/ | ||
div(a: ExtendedAsset | number | bigint | BigInteger): ExtendedAsset; | ||
static div(a: ExtendedAsset, b: ExtendedAsset | number | bigint | BigInteger): ExtendedAsset; | ||
/** | ||
* Subtraction operator | ||
*/ | ||
minus(a: ExtendedAsset | number | bigint | BigInteger): ExtendedAsset; | ||
static minus(a: ExtendedAsset, b: ExtendedAsset | number | bigint): ExtendedAsset; | ||
/** | ||
* Addition operator | ||
*/ | ||
plus(a: ExtendedAsset | number | bigint): ExtendedAsset; | ||
static plus(a: ExtendedAsset, b: ExtendedAsset | number | bigint): ExtendedAsset; | ||
/** | ||
* Less than operator | ||
*/ | ||
isLessThan(a: ExtendedAsset): boolean; | ||
static isLessThan(a: ExtendedAsset, b: ExtendedAsset): boolean; | ||
/** | ||
* Comparison operator | ||
*/ | ||
isEqual(a: ExtendedAsset): boolean; | ||
static isEqual(a: ExtendedAsset, b: ExtendedAsset): boolean; | ||
/** | ||
* Comparison operator | ||
*/ | ||
isNotEqual(a: ExtendedAsset): boolean; | ||
static isNotEqual(a: ExtendedAsset, b: ExtendedAsset): boolean; | ||
/** | ||
* Comparison operator | ||
*/ | ||
isLessThanOrEqual(a: ExtendedAsset): boolean; | ||
static isLessThanOrEqual(a: ExtendedAsset, b: ExtendedAsset): boolean; | ||
/** | ||
* Comparison operator | ||
*/ | ||
isGreaterThanOrEqual(a: ExtendedAsset): boolean; | ||
static isGreaterThanOrEqual(a: ExtendedAsset, b: ExtendedAsset): boolean; | ||
} | ||
export declare function extended_asset(options?: { | ||
amount?: number | bigint; | ||
ext_sym?: ExtendedSymbol; | ||
quantity?: Asset | string; | ||
contract?: Name | string; | ||
}): ExtendedAsset; | ||
export declare const extended_asset: { | ||
/** | ||
* Asset & Contract | ||
* | ||
* @example | ||
* | ||
* extended_asset( asset("1.0000 EOS"), name("eosio.token")) | ||
*/ | ||
(a?: Asset, c?: Name): ExtendedAsset; | ||
/** | ||
* Extended Symbol | ||
* | ||
* @example | ||
* | ||
* extended_asset( extended_symbol("4,EOS", "eosio.token") ) | ||
*/ | ||
(s?: ExtendedSymbol): ExtendedAsset; | ||
/** | ||
* Contract | ||
* | ||
* @example | ||
* | ||
* extended_asset( name("eosio.token") ) | ||
*/ | ||
(c?: Name): ExtendedAsset; | ||
/** | ||
* Value & Extended Symbol | ||
* | ||
* @example | ||
* | ||
* extended_asset( 10000, extended_symbol("4,EOS", "eosio.token")) | ||
*/ | ||
(v?: number | bigint | BigInteger, s?: ExtendedSymbol): ExtendedAsset; | ||
}; |
@@ -9,3 +9,10 @@ import { Name } from "./name"; | ||
get [Symbol.toStringTag](): string; | ||
typeof(): string; | ||
/** | ||
* The typeof operator returns a string indicating the type of the unevaluated operand. | ||
*/ | ||
get typeof(): string; | ||
/** | ||
* The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
*/ | ||
static isInstance(obj: any): boolean; | ||
private sym; | ||
@@ -20,7 +27,3 @@ private contract; | ||
* | ||
* // string | ||
* extended_symbol("EOS,4", "eosio.token") | ||
* | ||
* // class | ||
* new ExtendedSymbol(new Sym("EOS", 4), new Name("eosio.token")) | ||
* new ExtendedSymbol( symbol("4,EOS"), name("eosio.token") ) | ||
*/ | ||
@@ -41,7 +44,5 @@ constructor(sym?: Sym | string, contract?: Name | string); | ||
/** | ||
* %Print the extended symbol | ||
* | ||
* @brief %Print the extended symbol | ||
* The toString() method returns the string representation of the object. | ||
*/ | ||
print(show_precision?: boolean): void; | ||
toString(show_precision?: boolean): string; | ||
/** | ||
@@ -69,2 +70,9 @@ * Equivalency operator. Returns true if a == b (are the same) | ||
} | ||
/** | ||
* Extended Symbol | ||
* | ||
* @example | ||
* | ||
* extended_symbol( symbol("4,EOS"), name("eosio.token") ) | ||
*/ | ||
export declare function extended_symbol(sym?: Sym | string, contract?: Name | string): ExtendedSymbol; |
@@ -0,1 +1,2 @@ | ||
import bigInt, { BigInteger } from "big-integer"; | ||
/** | ||
@@ -7,6 +8,13 @@ * @class Stores the name | ||
get [Symbol.toStringTag](): string; | ||
typeof(): string; | ||
readonly value: bigint; | ||
constructor(str?: string | number | bigint); | ||
/** | ||
* The typeof operator returns a string indicating the type of the unevaluated operand. | ||
*/ | ||
get typeof(): string; | ||
/** | ||
* The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
*/ | ||
static isInstance(obj: any): boolean; | ||
readonly value: bigInt.BigInteger; | ||
constructor(str?: string | number | BigInteger); | ||
/** | ||
* Converts a %name Base32 symbol into its corresponding value | ||
@@ -29,3 +37,3 @@ * | ||
*/ | ||
raw(): bigint; | ||
raw(): BigInteger; | ||
/** | ||
@@ -38,6 +46,5 @@ * Explicit cast to bool of the name | ||
/** | ||
* Returns the name as a string. | ||
* | ||
* @brief Returns the name value as a string by calling write_as_string() and returning the buffer produced by write_as_string() | ||
* The toString() method returns the string representation of the object. | ||
*/ | ||
toString(): string; | ||
to_string(): string; | ||
@@ -66,2 +73,2 @@ /** | ||
} | ||
export declare function name(str?: string | number | bigint): Name; | ||
export declare function name(str?: string | number | BigInteger): Name; |
@@ -0,1 +1,2 @@ | ||
import { BigInteger } from "big-integer"; | ||
/** | ||
@@ -7,9 +8,20 @@ * @class Stores the symbol code | ||
get [Symbol.toStringTag](): string; | ||
typeof(): string; | ||
/** | ||
* The typeof operator returns a string indicating the type of the unevaluated operand. | ||
*/ | ||
get typeof(): string; | ||
/** | ||
* The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
*/ | ||
static isInstance(obj: any): boolean; | ||
private value; | ||
constructor(str?: string | number | bigint); | ||
raw(): bigint; | ||
constructor(str?: string | number | BigInteger); | ||
raw(): BigInteger; | ||
isTruthy(): boolean; | ||
isFalsy(): boolean; | ||
length(): number; | ||
/** | ||
* The toString() method returns the string representation of the object. | ||
*/ | ||
toString(): string; | ||
to_string(): string; | ||
@@ -36,2 +48,2 @@ is_valid(): boolean; | ||
} | ||
export declare function symbol_code(str?: string | number | bigint): SymbolCode; | ||
export declare function symbol_code(str?: string | number | BigInteger): SymbolCode; |
import { SymbolCode } from "./symbol_code"; | ||
import bigInt, { BigInteger } from "big-integer"; | ||
export declare class Sym { | ||
get [Symbol.toStringTag](): string; | ||
typeof(): string; | ||
value: bigint; | ||
/** | ||
* The typeof operator returns a string indicating the type of the unevaluated operand. | ||
*/ | ||
get typeof(): string; | ||
/** | ||
* The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
*/ | ||
static isInstance(obj: any): boolean; | ||
value: bigInt.BigInteger; | ||
/** | ||
* Symbol | ||
@@ -19,3 +27,3 @@ * | ||
*/ | ||
constructor(sc?: string | Sym | SymbolCode | number | bigint, precision?: number | bigint); | ||
constructor(sc?: string | Sym | SymbolCode | number | BigInteger, precision?: number); | ||
/** | ||
@@ -36,3 +44,3 @@ * Is this symbol valid | ||
*/ | ||
raw(): bigint; | ||
raw(): BigInteger; | ||
/** | ||
@@ -45,5 +53,5 @@ * Explicit cast to bool of the symbol | ||
/** | ||
* %Print the symbol | ||
* The toString() method returns the string representation of the object. | ||
*/ | ||
print(show_precision?: boolean): void; | ||
toString(show_precision?: boolean): string; | ||
/** | ||
@@ -71,2 +79,2 @@ * Equivalency operator. Returns true if a == b (are the same) | ||
} | ||
export declare function symbol(sc?: string | SymbolCode | number | bigint, precision?: number | bigint): Sym; | ||
export declare function symbol(sc?: string | SymbolCode | number | BigInteger, precision?: number): Sym; |
@@ -0,0 +0,0 @@ declare class Time { |
import { Sym } 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: Sym): Asset; | ||
import { BigInteger } from "big-integer"; | ||
export declare function asset_to_bigint(quantity: Asset): BigInteger; | ||
export declare function bigint_to_asset(amount: number | BigInteger, sym: Sym): Asset; | ||
export declare function asset_to_number(quantity: Asset): number; | ||
export declare function number_to_asset(amount: number, sym: Sym): Asset; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ export * from "./eosiolib/asset"; |
1219
dist/index.js
@@ -1,1205 +0,16 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
/** | ||
* Assert if the predicate fails and use the supplied message. | ||
* | ||
* @param {boolean} pred Pre-condition | ||
* @param {string} msg Error Message | ||
* @returns {void} | ||
* @example | ||
* | ||
* check(a == b, "a does not equal b"); | ||
*/ | ||
function check(pred, msg) { | ||
if (!pred) { | ||
throw new Error(msg); | ||
} | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
/** | ||
* @class Stores the symbol code | ||
* @brief Stores the symbol code as a uint64_t value | ||
*/ | ||
var SymbolCode = /** @class */ (function () { | ||
// constructor() | ||
function SymbolCode(str) { | ||
this.value = BigInt(0); | ||
if (typeof str == "number" || typeof str == 'bigint') { | ||
this.value = BigInt(str); | ||
} | ||
else if (str) { | ||
var value = BigInt(0); | ||
if (str.length > 7) { | ||
check(false, "string is too long to be a valid symbol_code"); | ||
} | ||
for (var _i = 0, _a = str.split("").reverse().join(""); _i < _a.length; _i++) { | ||
var itr = _a[_i]; | ||
if (itr < 'A' || itr > 'Z') { | ||
check(false, "only uppercase letters allowed in symbol_code string"); | ||
} | ||
value <<= BigInt(8); | ||
value |= BigInt(itr.charCodeAt(0)); | ||
} | ||
this.value = value; | ||
} | ||
} | ||
Object.defineProperty(SymbolCode.prototype, Symbol.toStringTag, { | ||
get: function () { | ||
return 'symbol_code'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
SymbolCode.prototype.typeof = function () { return 'symbol_code'; }; | ||
SymbolCode.prototype.raw = function () { | ||
return this.value; | ||
}; | ||
SymbolCode.prototype.isTruthy = function () { | ||
return this.value != BigInt(0); | ||
}; | ||
SymbolCode.prototype.isFalsy = function () { | ||
return this.value == BigInt(0); | ||
}; | ||
SymbolCode.prototype.length = function () { | ||
var sym = BigInt(this.value); | ||
var len = 0; | ||
while (Number(sym) & 0xFF && len <= 7) { | ||
len++; | ||
sym >>= BigInt(8); | ||
} | ||
return len; | ||
}; | ||
SymbolCode.prototype.to_string = function () { | ||
var mask = BigInt(0x00000000000000FF); | ||
if (this.value == BigInt(0)) | ||
return ''; | ||
var begin = ""; | ||
var v = BigInt(this.value); | ||
for (var i = 0; i < 7; ++i, v >>= BigInt(8)) { | ||
if (v == BigInt(0)) | ||
return begin; | ||
begin += String.fromCharCode(Number(v & mask)); | ||
} | ||
return begin; | ||
}; | ||
SymbolCode.prototype.is_valid = function () { | ||
var sym = BigInt(this.value); | ||
for (var i = BigInt(0); i < 7; i++) { | ||
var c = String.fromCharCode(Number(BigInt(sym) & BigInt(0xFF))); | ||
if (!("A" <= c && c <= "Z")) | ||
return false; | ||
sym >>= BigInt(8); | ||
if (!(BigInt(sym) & BigInt(0xFF))) { | ||
do { | ||
sym >>= BigInt(8); | ||
if ((BigInt(sym) & BigInt(0xFF))) | ||
return false; | ||
i++; | ||
} while (i < 7); | ||
} | ||
} | ||
return true; | ||
}; | ||
/** | ||
* Equivalency operator. Returns true if a == b (are the same) | ||
* | ||
* @return boolean - true if both provided symbol_codes are the same | ||
*/ | ||
SymbolCode.prototype.isEqual = function (comparison) { | ||
return comparison.value === this.value; | ||
}; | ||
/** | ||
* Inverted equivalency operator. Returns true if a != b (are different) | ||
* | ||
* @return boolean - true if both provided symbol_codes are not the same | ||
*/ | ||
SymbolCode.prototype.isNotEqual = function (comparison) { | ||
return comparison.value !== this.value; | ||
}; | ||
/** | ||
* Less than operator. Returns true if a < b. | ||
* @brief Less than operator | ||
* @return boolean - true if symbol_code `a` is less than `b` | ||
*/ | ||
SymbolCode.prototype.isLessThan = function (comparison) { | ||
return this.value < comparison.value; | ||
}; | ||
return SymbolCode; | ||
}()); | ||
function symbol_code(str) { | ||
return new SymbolCode(str); | ||
} | ||
function isNull(value) { | ||
return value == undefined || value == null; | ||
} | ||
var Sym = /** @class */ (function () { | ||
/** | ||
* Symbol | ||
* | ||
* @name Symbol | ||
* @param {string} code Symbol Code | ||
* @param {number} precision Precision | ||
* @returns {Symbol} Symbol | ||
* @example | ||
* | ||
* const sym = new Symbol("EOS", 4); | ||
* sym.code() //=> "EOS" | ||
* sym.precision //=> 4 | ||
*/ | ||
function Sym(sc, precision) { | ||
this.value = BigInt(0); | ||
if (isNull(sc) && isNull(precision)) { | ||
this.value = BigInt(0); | ||
} | ||
else if (typeof sc == "number" || typeof sc == "bigint") { | ||
this.value = BigInt(sc); | ||
} | ||
else if (typeof sc == "string") { | ||
// "precision,symbol_code" (ex: "4,EOS") | ||
if (sc.includes(",")) { | ||
var _a = sc.split(","), precision_str = _a[0], symcode_str = _a[1]; | ||
var precision_1 = Number(precision_str); | ||
check(!isNaN(precision_1), "[precision] must be number type"); | ||
check(!isNull(precision_1), "[precision] is required"); | ||
check(!isNull(symcode_str), "[symcode] is required"); | ||
var symcode = new SymbolCode(symcode_str).raw(); | ||
this.value = BigInt(symcode) << BigInt(8) | BigInt(precision_1 || Number(precision_str || "")); | ||
// "symbol_code" + @param: precision | ||
} | ||
else { | ||
check(!isNaN(Number(precision)), "[precision] must be number type"); | ||
check(!isNull(precision), "[precision] is required"); | ||
check(!isNull(sc), "[symcode] is required"); | ||
var symcode = new SymbolCode(sc).raw(); | ||
this.value = BigInt(symcode) << BigInt(8) | BigInt(precision); | ||
} | ||
} | ||
else if (typeof sc == "object") { | ||
check(!isNull(precision), "[precision] is required"); | ||
var symcode = sc; | ||
this.value = BigInt(symcode.raw()) << BigInt(8) | BigInt(precision); | ||
} | ||
else { | ||
check(false, "invalid symbol parameters"); | ||
} | ||
} | ||
Object.defineProperty(Sym.prototype, Symbol.toStringTag, { | ||
get: function () { | ||
return 'symbol'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Sym.prototype.typeof = function () { return 'symbol'; }; | ||
/** | ||
* Is this symbol valid | ||
*/ | ||
Sym.prototype.is_valid = function () { | ||
return this.code().is_valid(); | ||
}; | ||
/** | ||
* This symbol's precision | ||
*/ | ||
Sym.prototype.precision = function () { | ||
return Number(this.value & BigInt(0x00000000000000FF)); | ||
}; | ||
/** | ||
* Returns representation of symbol name | ||
*/ | ||
Sym.prototype.code = function () { | ||
return new SymbolCode(this.value >> BigInt(8)); | ||
}; | ||
/** | ||
* Returns uint64_t repreresentation of the symbol | ||
*/ | ||
Sym.prototype.raw = function () { | ||
return this.value; | ||
}; | ||
/** | ||
* Explicit cast to bool of the symbol | ||
* | ||
* @return Returns true if the symbol is set to the default value of 0 else true. | ||
*/ | ||
Sym.prototype.bool = function () { | ||
return this.value != BigInt(0); | ||
}; | ||
/** | ||
* %Print the symbol | ||
*/ | ||
Sym.prototype.print = function (show_precision) { | ||
if (show_precision === void 0) { show_precision = true; } | ||
if (show_precision) { | ||
process.stdout.write(String(this.precision()) + ","); | ||
} | ||
process.stdout.write(this.code().to_string()); | ||
}; | ||
/** | ||
* Equivalency operator. Returns true if a == b (are the same) | ||
* | ||
* @return boolean - true if both provided symbol_codes are the same | ||
*/ | ||
Sym.isEqual = function (a, b) { | ||
return a.raw() == b.raw(); | ||
}; | ||
Sym.prototype.isEqual = function (a) { | ||
return a.raw() == this.raw(); | ||
}; | ||
/** | ||
* Inverted equivalency operator. Returns true if a != b (are different) | ||
* | ||
* @return boolean - true if both provided symbol_codes are not the same | ||
*/ | ||
Sym.isNotEqual = function (a, b) { | ||
return a.raw() != b.raw(); | ||
}; | ||
Sym.prototype.isNotEqual = function (a) { | ||
return a.raw() != this.raw(); | ||
}; | ||
/** | ||
* Less than operator. Returns true if a < b. | ||
* @brief Less than operator | ||
* @return boolean - true if symbol_code `a` is less than `b` | ||
*/ | ||
Sym.isLessThan = function (a, b) { | ||
return a.raw() < b.raw(); | ||
}; | ||
Sym.prototype.isLessThan = function (a) { | ||
return this.raw() < a.raw(); | ||
}; | ||
return Sym; | ||
}()); | ||
function symbol(sc, precision) { | ||
return new Sym(sc, precision); | ||
} | ||
/** | ||
* Writes a number as a string | ||
* | ||
* @brief Writes number x 10^(-num_decimal_places) (optionally negative) as a string | ||
* @param number - The number to print before shifting the decimal point to the left by num_decimal_places. | ||
* @param num_decimal_places - The number of decimal places to shift the decimal point. | ||
* @param negative - Whether to print a minus sign in the front. | ||
*/ | ||
function write_decimal(number, num_decimal_places, negative) { | ||
var str = ""; | ||
var num_digits = 0; | ||
var isNegative = false; | ||
for (var _i = 0, _a = number.toString().split("").reverse(); _i < _a.length; _i++) { | ||
var num = _a[_i]; | ||
if (num == "-") { | ||
isNegative = true; | ||
continue; | ||
} | ||
if (num_decimal_places != 0 && num_decimal_places == num_digits) | ||
str = "." + str; | ||
str = num + str; | ||
num_digits += 1; | ||
} | ||
if (num_digits == num_decimal_places) | ||
str = "0." + str; | ||
else if (num_digits < num_decimal_places) | ||
str = "0." + "0".repeat(num_decimal_places - num_digits) + str; | ||
else if (str[0] == ".") | ||
str = "0" + str; | ||
if (negative && isNegative) | ||
str = "-" + str; | ||
return str; | ||
} | ||
function number_to_bigint(num) { | ||
return BigInt(num.toFixed(0)); | ||
} | ||
function isNull$1(value) { | ||
return value == undefined || value == null; | ||
} | ||
/** | ||
* Asset | ||
* | ||
* @name Asset | ||
* @param {number} amount The amount of the asset | ||
* @param {Symbol} sym The name of the symbol | ||
* @returns {Asset} Asset | ||
* @example | ||
* | ||
* const quantity = new Asset(10000, new Symbol("EOS", 4)); | ||
* quantity.toString() //=> "1.0000 EOS"; | ||
* quantity.symbol.code() //=> "EOS" | ||
* quantity.symbol.precision //=> 4 | ||
*/ | ||
var Asset = /** @class */ (function () { | ||
/** | ||
* Construct a new asset given the symbol name and the amount | ||
* | ||
* @param amount - The amount of the asset | ||
* @param sym - The name of the symbol | ||
*/ | ||
function Asset(amount, sym) { | ||
/** | ||
* {int64_t} The amount of the asset | ||
*/ | ||
this.amount = BigInt(0); | ||
/** | ||
* {symbol} The symbol name of the asset | ||
*/ | ||
this.symbol = symbol(); | ||
if (isNull$1(amount) && isNull$1(sym)) { | ||
return; | ||
} | ||
else if (typeof amount == "string") { | ||
var _a = amount.split(" "), amount_str = _a[0], symbol_str = _a[1]; | ||
var precision = (amount_str.split(".")[1] || []).length; | ||
this.amount = number_to_bigint(Number(amount_str) * Math.pow(10, precision)); | ||
this.symbol = new Sym(symbol_str, precision); | ||
} | ||
else if (sym) { | ||
this.amount = (typeof amount == "number") ? number_to_bigint(amount) : BigInt(amount); | ||
this.symbol = sym; | ||
} | ||
else { | ||
throw new Error("[sym] is required"); | ||
} | ||
check(this.is_amount_within_range(), "magnitude of asset amount must be less than 2^62"); | ||
check(this.symbol.is_valid(), "invalid symbol name"); | ||
} | ||
Object.defineProperty(Asset.prototype, Symbol.toStringTag, { | ||
get: function () { | ||
return 'asset'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Asset.prototype.typeof = function () { return 'asset'; }; | ||
/** | ||
* Check if the amount doesn't exceed the max amount | ||
* | ||
* @return true - if the amount doesn't exceed the max amount | ||
* @return false - otherwise | ||
*/ | ||
Asset.prototype.is_amount_within_range = function () { | ||
return -BigInt(Asset.max_amount) <= BigInt(this.amount) && this.amount <= Asset.max_amount; | ||
}; | ||
/** | ||
* Check if the asset is valid. %A valid asset has its amount <= max_amount and its symbol name valid | ||
* | ||
* @return true - if the asset is valid | ||
* @return false - otherwise | ||
*/ | ||
Asset.prototype.is_valid = function () { | ||
return this.is_amount_within_range() && this.symbol.is_valid(); | ||
}; | ||
/** | ||
* Set the amount of the asset | ||
* | ||
* @param a - New amount for the asset | ||
*/ | ||
Asset.prototype.set_amount = function (amount) { | ||
this.amount = BigInt(amount); | ||
check(this.is_amount_within_range(), "magnitude of asset amount must be less than 2^62"); | ||
}; | ||
/** | ||
* Subtraction assignment operator | ||
* | ||
* @param a - Another asset to subtract this asset with | ||
* @return asset& - Reference to this asset | ||
* @post The amount of this asset is subtracted by the amount of asset a | ||
*/ | ||
Asset.prototype.minus = function (a) { | ||
if (typeof a == "number" || typeof a == "bigint") { | ||
this.amount -= BigInt(a); | ||
} | ||
else { | ||
check(a.symbol.isEqual(this.symbol), "attempt to subtract asset with different symbol"); | ||
this.amount -= a.amount; | ||
} | ||
check(-Asset.max_amount <= this.amount, "subtraction underflow"); | ||
check(this.amount <= Asset.max_amount, "subtraction overflow"); | ||
return this; | ||
}; | ||
/** | ||
* Addition Assignment operator | ||
* | ||
* @param a - Another asset to subtract this asset with | ||
* @return asset& - Reference to this asset | ||
* @post The amount of this asset is added with the amount of asset a | ||
*/ | ||
Asset.prototype.plus = function (a) { | ||
if (typeof a == "number" || typeof a == "bigint") { | ||
this.amount += BigInt(a); | ||
} | ||
else { | ||
check(a.symbol.isEqual(this.symbol), "attempt to add asset with different symbol"); | ||
this.amount += a.amount; | ||
} | ||
check(-Asset.max_amount <= this.amount, "addition underflow"); | ||
check(this.amount <= Asset.max_amount, "addition overflow"); | ||
return this; | ||
}; | ||
/** | ||
* Addition operator | ||
* | ||
* @param a - The first asset to be added | ||
* @param b - The second asset to be added | ||
* @return asset - New asset as the result of addition | ||
*/ | ||
Asset.plus = function (a, b) { | ||
var result = new Asset(a.amount, a.symbol); | ||
result.plus(b); | ||
return result; | ||
}; | ||
/** | ||
* Subtraction operator | ||
* | ||
* @param a - The asset to be subtracted | ||
* @param b - The asset used to subtract | ||
* @return asset - New asset as the result of subtraction of a with b | ||
*/ | ||
Asset.minus = function (a, b) { | ||
var result = new Asset(a.amount, a.symbol); | ||
result.minus(b); | ||
return result; | ||
}; | ||
/** | ||
* Multiplication assignment operator, with a number | ||
* | ||
* @details Multiplication assignment operator. Multiply the amount of this asset with a number and then assign the value to itself. | ||
* @param a - The multiplier for the asset's amount | ||
* @return asset - Reference to this asset | ||
* @post The amount of this asset is multiplied by a | ||
*/ | ||
Asset.prototype.times = function (a) { | ||
var amount; | ||
if (typeof a == "number" || typeof a == "bigint") { | ||
amount = BigInt(a); | ||
} | ||
else { | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
amount = a.amount; | ||
} | ||
var tmp = this.amount * amount; | ||
check(tmp <= Asset.max_amount, "multiplication overflow"); | ||
check(tmp >= -Asset.max_amount, "multiplication underflow"); | ||
this.amount = tmp; | ||
return this; | ||
}; | ||
/** | ||
* Multiplication operator, with a number proceeding | ||
* | ||
* @brief Multiplication operator, with a number proceeding | ||
* @param a - The asset to be multiplied | ||
* @param b - The multiplier for the asset's amount | ||
* @return asset - New asset as the result of multiplication | ||
*/ | ||
Asset.times = function (a, b) { | ||
var result = new Asset(a.amount, a.symbol); | ||
result.times(b); | ||
return result; | ||
}; | ||
/** | ||
* @brief Division assignment operator, with a number | ||
* | ||
* @details Division assignment operator. Divide the amount of this asset with a number and then assign the value to itself. | ||
* @param a - The divisor for the asset's amount | ||
* @return asset - Reference to this asset | ||
* @post The amount of this asset is divided by a | ||
*/ | ||
Asset.prototype.div = function (a) { | ||
var amount; | ||
if (typeof a == "number" || typeof a == "bigint") { | ||
amount = BigInt(a); | ||
} | ||
else { | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
amount = a.amount; | ||
} | ||
check(amount != BigInt(0), "divide by zero"); | ||
check(!(this.amount == -Asset.max_amount && amount == BigInt(-1)), "signed division overflow"); | ||
this.amount /= amount; | ||
return this; | ||
}; | ||
/** | ||
* Division operator, with a number proceeding | ||
* | ||
* @param a - The asset to be divided | ||
* @param b - The divisor for the asset's amount | ||
* @return asset - New asset as the result of division | ||
*/ | ||
Asset.div = function (a, b) { | ||
var result = new Asset(a.amount, a.symbol); | ||
result.div(b); | ||
return result; | ||
}; | ||
/** | ||
* Equality operator | ||
* | ||
* @param a - The first asset to be compared | ||
* @param b - The second asset to be compared | ||
* @return true - if both asset has the same amount | ||
* @return false - otherwise | ||
* @pre Both asset must have the same symbol | ||
*/ | ||
Asset.isEqual = function (a, b) { | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount == b.amount; | ||
}; | ||
Asset.prototype.isEqual = function (a) { | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount == this.amount; | ||
}; | ||
/** | ||
* Inequality operator | ||
* | ||
* @param a - The first asset to be compared | ||
* @param b - The second asset to be compared | ||
* @return true - if both asset doesn't have the same amount | ||
* @return false - otherwise | ||
* @pre Both asset must have the same symbol | ||
*/ | ||
Asset.isNotEqual = function (a, b) { | ||
return !(a == b); | ||
}; | ||
Asset.prototype.isNotEqual = function (a) { | ||
return !(a == this); | ||
}; | ||
/** | ||
* Less than operator | ||
* | ||
* @param a - The first asset to be compared | ||
* @param b - The second asset to be compared | ||
* @return true - if the first asset's amount is less than the second asset amount | ||
* @return false - otherwise | ||
* @pre Both asset must have the same symbol | ||
*/ | ||
Asset.isLessThan = function (a, b) { | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount < b.amount; | ||
}; | ||
Asset.prototype.isLessThan = function (a) { | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount < a.amount; | ||
}; | ||
/** | ||
* Less or equal to operator | ||
* | ||
* @param a - The first asset to be compared | ||
* @param b - The second asset to be compared | ||
* @return true - if the first asset's amount is less or equal to the second asset amount | ||
* @return false - otherwise | ||
* @pre Both asset must have the same symbol | ||
*/ | ||
Asset.isLessThanOrEqual = function (a, b) { | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount <= b.amount; | ||
}; | ||
Asset.prototype.isLessThanOrEqual = function (a) { | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount <= a.amount; | ||
}; | ||
/** | ||
* Greater than operator | ||
* | ||
* @param a - The first asset to be compared | ||
* @param b - The second asset to be compared | ||
* @return true - if the first asset's amount is greater than the second asset amount | ||
* @return false - otherwise | ||
* @pre Both asset must have the same symbol | ||
*/ | ||
Asset.isGreaterThan = function (a, b) { | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount > b.amount; | ||
}; | ||
Asset.prototype.isGreaterThan = function (a) { | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount > a.amount; | ||
}; | ||
/** | ||
* Greater or equal to operator | ||
* | ||
* @param a - The first asset to be compared | ||
* @param b - The second asset to be compared | ||
* @return true - if the first asset's amount is greater or equal to the second asset amount | ||
* @return false - otherwise | ||
* @pre Both asset must have the same symbol | ||
*/ | ||
Asset.isGreaterThanOrEqual = function (a, b) { | ||
check(a.symbol.isEqual(b.symbol), "comparison of assets with different symbols is not allowed"); | ||
return a.amount >= b.amount; | ||
}; | ||
Asset.prototype.isGreaterThanOrEqual = function (a) { | ||
check(a.symbol.isEqual(this.symbol), "comparison of assets with different symbols is not allowed"); | ||
return this.amount >= a.amount; | ||
}; | ||
Asset.prototype.to_string = function () { | ||
var amount = write_decimal(this.amount, this.symbol.precision(), true); | ||
var symcode = this.symbol.code().to_string(); | ||
return amount + " " + symcode; | ||
}; | ||
/** | ||
* %Print the asset | ||
* | ||
* @brief %Print the asset | ||
*/ | ||
Asset.prototype.print = function () { | ||
process.stdout.write(this.to_string()); | ||
}; | ||
/** | ||
* {constexpr int64_t} Maximum amount possible for this asset. It's capped to 2^62 - 1 | ||
*/ | ||
Asset.max_amount = (BigInt(1) << BigInt(62)) - BigInt(1); | ||
return Asset; | ||
}()); | ||
function asset(amount, sym) { | ||
return new Asset(amount, sym); | ||
} | ||
/** | ||
* @class Stores the name | ||
* @brief Stores the name as a uint64_t value | ||
*/ | ||
var Name = /** @class */ (function () { | ||
function Name(str) { | ||
this.value = BigInt(0); | ||
var value = BigInt(0); | ||
if (typeof str == "number" || typeof str == "bigint") { | ||
this.value = BigInt(str); | ||
return; | ||
} | ||
else if (str && str.length > 13) | ||
check(false, "string is too long to be a valid name"); | ||
else if (str == undefined || str == null || str.length == 0) | ||
return; | ||
var n = Math.min(str.length, 12); | ||
for (var i = 0; i < n; ++i) { | ||
value <<= BigInt(5); | ||
value |= BigInt(Name.char_to_value(str[i])); | ||
} | ||
value <<= BigInt(4 + 5 * (12 - n)); | ||
if (str.length == 13) { | ||
var v = Name.char_to_value(str[12]); | ||
if (v > 0x0F) { | ||
check(false, "thirteenth character in name cannot be a letter that comes after j"); | ||
} | ||
value |= BigInt(v); | ||
} | ||
this.value = value; | ||
} | ||
Object.defineProperty(Name.prototype, Symbol.toStringTag, { | ||
get: function () { | ||
return 'name'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Name.prototype.typeof = function () { return 'name'; }; | ||
/** | ||
* Converts a %name Base32 symbol into its corresponding value | ||
* | ||
* @param c - Character to be converted | ||
* @return constexpr char - Converted value | ||
*/ | ||
Name.char_to_value = function (c) { | ||
if (c == '.') | ||
return 0; | ||
else if (c >= '1' && c <= '5') | ||
return c.charCodeAt(0) - '1'.charCodeAt(0) + 1; | ||
else if (c >= 'a' && c <= 'z') | ||
return c.charCodeAt(0) - 'a'.charCodeAt(0) + 6; | ||
else | ||
check(false, "character is not in allowed character set for names"); | ||
return 0; // control flow will never reach here; just added to suppress warning | ||
}; | ||
/** | ||
* Returns the length of the %name | ||
*/ | ||
Name.prototype.length = function () { | ||
var mask = BigInt(0xF800000000000000); | ||
if (this.value == BigInt(0)) | ||
return 0; | ||
var l = 0; | ||
var i = 0; | ||
for (var v = this.value; i < 13; ++i, v <<= BigInt(5)) { | ||
if ((v & mask) > 0) { | ||
l = i; | ||
} | ||
} | ||
return l + 1; | ||
}; | ||
/** | ||
* Returns the suffix of the %name | ||
*/ | ||
Name.prototype.suffix = function () { | ||
var remaining_bits_after_last_actual_dot = BigInt(0); | ||
var tmp = BigInt(0); | ||
for (var remaining_bits = BigInt(59); remaining_bits >= BigInt(4); remaining_bits -= BigInt(5)) { // Note: remaining_bits must remain signed integer | ||
// Get characters one-by-one in name in order from left to right (not including the 13th character) | ||
var c = (this.value >> remaining_bits) & BigInt(0x1F); | ||
if (!c) { // if this character is a dot | ||
tmp = remaining_bits; | ||
} | ||
else { // if this character is not a dot | ||
remaining_bits_after_last_actual_dot = tmp; | ||
} | ||
} | ||
var thirteenth_character = this.value & BigInt(0x0F); | ||
if (thirteenth_character) { // if 13th character is not a dot | ||
remaining_bits_after_last_actual_dot = tmp; | ||
} | ||
if (remaining_bits_after_last_actual_dot == BigInt(0)) // there is no actual dot in the %name other than potentially leading dots | ||
return new Name(this.value); | ||
// At this point remaining_bits_after_last_actual_dot has to be within the range of 4 to 59 (and restricted to increments of 5). | ||
// Mask for remaining bits corresponding to characters after last actual dot, except for 4 least significant bits (corresponds to 13th character). | ||
var mask = (BigInt(1) << remaining_bits_after_last_actual_dot) - BigInt(16); | ||
var shift = BigInt(64) - remaining_bits_after_last_actual_dot; | ||
return new Name(((this.value & mask) << shift) + (thirteenth_character << (shift - BigInt(1)))); | ||
}; | ||
/** | ||
* Returns uint64_t repreresentation of the name | ||
*/ | ||
Name.prototype.raw = function () { | ||
return this.value; | ||
}; | ||
/** | ||
* Explicit cast to bool of the name | ||
* | ||
* @return Returns true if the name is set to the default value of 0 else true. | ||
*/ | ||
Name.prototype.bool = function () { | ||
return this.value != BigInt(0); | ||
}; | ||
/** | ||
* Returns the name as a string. | ||
* | ||
* @brief Returns the name value as a string by calling write_as_string() and returning the buffer produced by write_as_string() | ||
*/ | ||
Name.prototype.to_string = function () { | ||
var charmap = ".12345abcdefghijklmnopqrstuvwxyz"; | ||
var mask = BigInt(0xF800000000000000); | ||
var begin = ""; | ||
var v = this.value; | ||
var actual_end = this.length(); | ||
for (var i = 0; i < 13; ++i, v <<= BigInt(5)) { | ||
if (v == BigInt(0)) | ||
return begin; | ||
if (i >= actual_end) | ||
return begin; | ||
var indx = (v & mask) >> (i == 12 ? BigInt(60) : BigInt(59)); | ||
begin += charmap[Number(indx)]; | ||
} | ||
return begin; | ||
}; | ||
/** | ||
* Equivalency operator. Returns true if a == b (are the same) | ||
* | ||
* @return boolean - true if both provided name are the same | ||
*/ | ||
Name.isEqual = function (a, b) { | ||
return a.raw() == b.raw(); | ||
}; | ||
Name.prototype.isEqual = function (a) { | ||
return a.raw() == this.raw(); | ||
}; | ||
/** | ||
* Inverted equivalency operator. Returns true if a != b (are different) | ||
* | ||
* @return boolean - true if both provided name are not the same | ||
*/ | ||
Name.isNotEqual = function (a, b) { | ||
return a.raw() != b.raw(); | ||
}; | ||
Name.prototype.isNotEqual = function (a) { | ||
return a.raw() != this.raw(); | ||
}; | ||
/** | ||
* Less than operator. Returns true if a < b. | ||
* @brief Less than operator | ||
* @return boolean - true if name `a` is less than `b` | ||
*/ | ||
Name.isLessThan = function (a, b) { | ||
return a.raw() < b.raw(); | ||
}; | ||
Name.prototype.isLessThan = function (a) { | ||
return this.raw() < a.raw(); | ||
}; | ||
return Name; | ||
}()); | ||
function name(str) { | ||
return new Name(str); | ||
} | ||
/** | ||
* @class Stores the extended_symbol | ||
* @brief Stores the extended_symbol as a uint64_t value | ||
*/ | ||
var ExtendedSymbol = /** @class */ (function () { | ||
/** | ||
* Construct a new symbol_code object initialising symbol and contract with the passed in symbol and name | ||
* | ||
* @param sym - The symbol | ||
* @param con - The name of the contract | ||
* @example | ||
* | ||
* // string | ||
* extended_symbol("EOS,4", "eosio.token") | ||
* | ||
* // class | ||
* new ExtendedSymbol(new Sym("EOS", 4), new Name("eosio.token")) | ||
*/ | ||
function ExtendedSymbol(sym, contract) { | ||
this.sym = new Sym(); | ||
this.contract = new Name(); | ||
if (sym) | ||
this.sym = typeof sym == "string" ? new Sym(sym) : sym; | ||
if (contract) | ||
this.contract = typeof contract == "string" ? new Name(contract) : contract; | ||
} | ||
Object.defineProperty(ExtendedSymbol.prototype, Symbol.toStringTag, { | ||
get: function () { | ||
return 'extended_symbol'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ExtendedSymbol.prototype.typeof = function () { return 'extended_symbol'; }; | ||
/** | ||
* Returns the symbol in the extended_contract | ||
* | ||
* @return symbol | ||
*/ | ||
ExtendedSymbol.prototype.get_symbol = function () { return this.sym; }; | ||
/** | ||
* Returns the name of the contract in the extended_symbol | ||
* | ||
* @return name | ||
*/ | ||
ExtendedSymbol.prototype.get_contract = function () { return this.contract; }; | ||
/** | ||
* %Print the extended symbol | ||
* | ||
* @brief %Print the extended symbol | ||
*/ | ||
ExtendedSymbol.prototype.print = function (show_precision) { | ||
if (show_precision === void 0) { show_precision = true; } | ||
this.sym.print(show_precision); | ||
process.stdout.write("@" + this.contract.to_string()); | ||
}; | ||
/** | ||
* Equivalency operator. Returns true if a == b (are the same) | ||
* | ||
* @return boolean - true if both provided name are the same | ||
*/ | ||
ExtendedSymbol.isEqual = function (a, b) { | ||
return a.get_contract().raw() == b.get_contract().raw() && a.get_symbol().raw() == b.get_symbol().raw(); | ||
}; | ||
ExtendedSymbol.prototype.isEqual = function (a) { | ||
return a.get_contract().raw() == this.get_contract().raw() && a.get_symbol().raw() == this.get_symbol().raw(); | ||
}; | ||
/** | ||
* Inverted equivalency operator. Returns true if a != b (are different) | ||
* | ||
* @return boolean - true if both provided name are not the same | ||
*/ | ||
ExtendedSymbol.isNotEqual = function (a, b) { | ||
return a.get_contract().raw() != b.get_contract().raw() || a.get_symbol().raw() != b.get_symbol().raw(); | ||
}; | ||
ExtendedSymbol.prototype.isNotEqual = function (a) { | ||
return a.get_contract().raw() != this.get_contract().raw() || a.get_symbol().raw() != this.get_symbol().raw(); | ||
}; | ||
/** | ||
* Less than operator. Returns true if a < b. | ||
* @brief Less than operator | ||
* @return boolean - true if name `a` is less than `b` | ||
*/ | ||
ExtendedSymbol.isLessThan = function (a, b) { | ||
return a.get_contract().raw() < b.get_contract().raw() || a.get_symbol().raw() < b.get_symbol().raw(); | ||
}; | ||
ExtendedSymbol.prototype.isLessThan = function (a) { | ||
return this.get_contract().raw() < a.get_contract().raw() || this.get_symbol().raw() < a.get_symbol().raw(); | ||
}; | ||
return ExtendedSymbol; | ||
}()); | ||
function extended_symbol(sym, contract) { | ||
return new ExtendedSymbol(sym, contract); | ||
} | ||
/** | ||
* @class Stores the extended_asset | ||
* @brief Stores the extended_asset as a uint64_t value | ||
*/ | ||
var ExtendedAsset = /** @class */ (function () { | ||
/** | ||
* Construct a new symbol_code object initialising symbol and contract with the passed in symbol and name | ||
* | ||
* @param sym - The symbol | ||
* @param con - The name of the contract | ||
*/ | ||
// /** | ||
// * Construct a new extended asset given the amount and extended symbol | ||
// */ | ||
// extended_asset( int64_t v, extended_symbol s ):quantity(v,s.get_symbol()),contract(s.get_contract()){} | ||
// /** | ||
// * Construct a new extended asset given the asset and owner name | ||
// */ | ||
// extended_asset( asset a, name c ):quantity(a),contract(c){} | ||
function ExtendedAsset(options) { | ||
if (options === void 0) { options = {}; } | ||
/** | ||
* The asset | ||
*/ | ||
this.quantity = new Asset(); | ||
/** | ||
* The owner of the asset | ||
*/ | ||
this.contract = new Name(); | ||
if ((typeof options.amount == "number" || typeof options.amount == "bigint") && options.ext_sym) { | ||
this.quantity = new Asset(options.amount, options.ext_sym.get_symbol()); | ||
this.contract = options.ext_sym.get_contract(); | ||
} | ||
if (options.contract) { | ||
this.contract = typeof options.contract == "string" ? new Name(options.contract) : options.contract; | ||
} | ||
if (options.quantity) { | ||
this.quantity = typeof options.quantity == "string" ? new Asset(options.quantity) : options.quantity; | ||
} | ||
if (options.ext_sym) { | ||
this.quantity = new Asset(0, options.ext_sym.get_symbol()); | ||
this.contract = options.ext_sym.get_contract(); | ||
} | ||
} | ||
Object.defineProperty(ExtendedAsset.prototype, Symbol.toStringTag, { | ||
get: function () { | ||
return 'extended_asset'; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ExtendedAsset.prototype.typeof = function () { return 'extended_asset'; }; | ||
/** | ||
* Get the extended symbol of the asset | ||
* | ||
* @return extended_symbol - The extended symbol of the asset | ||
*/ | ||
ExtendedAsset.prototype.get_extended_symbol = function () { return new ExtendedSymbol(this.quantity.symbol, this.contract); }; | ||
/** | ||
* %Print the extended asset | ||
*/ | ||
ExtendedAsset.prototype.print = function () { | ||
this.quantity.print(); | ||
process.stdout.write("@" + this.contract.to_string()); | ||
}; | ||
/// @cond OPERATORS | ||
// Multiplication assignment operator | ||
ExtendedAsset.prototype.times = function (a) { | ||
var amount; | ||
if (typeof a == "bigint" || typeof a == "number") { | ||
amount = BigInt(a); | ||
} | ||
else { | ||
check(a.contract.raw() == this.contract.raw(), "type mismatch"); | ||
amount = a.quantity.amount; | ||
} | ||
this.quantity.times(amount); | ||
return this; | ||
}; | ||
ExtendedAsset.times = function (a, b) { | ||
if (typeof b != "bigint" && typeof b != "number") | ||
check(a.contract.raw() == b.contract.raw(), "type mismatch"); | ||
var result = new ExtendedAsset({ quantity: a.quantity, contract: a.contract }); | ||
result.times(b); | ||
return result; | ||
}; | ||
// Division operator | ||
ExtendedAsset.prototype.div = function (a) { | ||
var amount; | ||
if (typeof a == "bigint" || typeof a == "number") { | ||
amount = BigInt(a); | ||
} | ||
else { | ||
check(a.contract.raw() == this.contract.raw(), "type mismatch"); | ||
amount = a.quantity.amount; | ||
} | ||
this.quantity.div(amount); | ||
return this; | ||
}; | ||
ExtendedAsset.div = function (a, b) { | ||
if (typeof b != "bigint" && typeof b != "number") | ||
check(a.contract.raw() == b.contract.raw(), "type mismatch"); | ||
var result = new ExtendedAsset({ quantity: a.quantity, contract: a.contract }); | ||
result.div(b); | ||
return result; | ||
}; | ||
// Subtraction operator | ||
ExtendedAsset.prototype.minus = function (a) { | ||
if (typeof a == "bigint" || typeof a == "number") { | ||
this.quantity.minus(a); | ||
} | ||
else { | ||
check(a.contract.raw() == this.contract.raw(), "type mismatch"); | ||
this.quantity.minus(a.quantity); | ||
} | ||
return this; | ||
}; | ||
ExtendedAsset.minus = function (a, b) { | ||
if (typeof b != "bigint" && typeof b != "number") | ||
check(a.contract.raw() == b.contract.raw(), "type mismatch"); | ||
var result = new ExtendedAsset({ quantity: a.quantity, contract: a.contract }); | ||
result.minus(b); | ||
return result; | ||
}; | ||
// Addition operator | ||
ExtendedAsset.prototype.plus = function (a) { | ||
if (typeof a == "bigint" || typeof a == "number") { | ||
this.quantity.plus(a); | ||
} | ||
else { | ||
check(a.contract.raw() == this.contract.raw(), "type mismatch"); | ||
this.quantity.plus(a.quantity); | ||
} | ||
return this; | ||
}; | ||
ExtendedAsset.plus = function (a, b) { | ||
if (typeof b != "bigint" && typeof b != "number") | ||
check(a.contract.raw() == b.contract.raw(), "type mismatch"); | ||
var result = new ExtendedAsset({ quantity: a.quantity, contract: a.contract }); | ||
result.plus(b); | ||
return result; | ||
}; | ||
/// Less than operator | ||
ExtendedAsset.prototype.isLessThan = function (a) { | ||
check(a.contract.raw() == this.contract.raw(), "type mismatch"); | ||
return this.quantity.isLessThan(a.quantity); | ||
}; | ||
ExtendedAsset.isLessThan = function (a, b) { | ||
check(a.contract.raw() == b.contract.raw(), "type mismatch"); | ||
return a.quantity.isLessThan(b.quantity); | ||
}; | ||
/// Comparison operator | ||
ExtendedAsset.prototype.isEqual = function (a) { | ||
return this.quantity.isEqual(a.quantity) && this.contract.isEqual(a.contract); | ||
}; | ||
ExtendedAsset.isEqual = function (a, b) { | ||
return a.quantity.isEqual(b.quantity) && a.contract.isEqual(b.contract); | ||
}; | ||
/// Comparison operator | ||
ExtendedAsset.prototype.isNotEqual = function (a) { | ||
return this.quantity.isNotEqual(a.quantity) || this.contract.isNotEqual(a.contract); | ||
}; | ||
ExtendedAsset.isNotEqual = function (a, b) { | ||
return a.quantity.isNotEqual(b.quantity) || a.contract.isNotEqual(b.contract); | ||
}; | ||
/// Comparison operator | ||
ExtendedAsset.prototype.isLessThanOrEqual = function (a) { | ||
check(a.contract.raw() == this.contract.raw(), "type mismatch"); | ||
return this.quantity.isLessThanOrEqual(a.quantity); | ||
}; | ||
ExtendedAsset.isLessThanOrEqual = function (a, b) { | ||
check(a.contract.raw() == b.contract.raw(), "type mismatch"); | ||
return a.quantity.isLessThanOrEqual(b.quantity); | ||
}; | ||
/// Comparison operator | ||
ExtendedAsset.prototype.isGreaterThanOrEqual = function (a) { | ||
check(a.contract.raw() == this.contract.raw(), "type mismatch"); | ||
return this.quantity.isGreaterThanOrEqual(a.quantity); | ||
}; | ||
ExtendedAsset.isGreaterThanOrEqual = function (a, b) { | ||
check(a.contract.raw() == b.contract.raw(), "type mismatch"); | ||
return a.quantity.isGreaterThanOrEqual(b.quantity); | ||
}; | ||
return ExtendedAsset; | ||
}()); | ||
function extended_asset(options) { | ||
if (options === void 0) { options = {}; } | ||
return new ExtendedAsset(options); | ||
} | ||
var Time = /** @class */ (function () { | ||
function Time() { | ||
} | ||
Time.prototype.sec_since_epoch = function () { | ||
return Date.now(); | ||
}; | ||
return Time; | ||
}()); | ||
function current_time_point() { | ||
return new Time(); | ||
} | ||
var block_timestamp_epoch = new Date(Date.UTC(2000, 0, 1, 0, 0, 0, 0)).getTime(); | ||
var seconds_per_day = 60 * 60 * 24; | ||
function asset_to_bigint(quantity) { | ||
if (quantity.amount == BigInt(0)) | ||
return BigInt(0.0); | ||
return BigInt(quantity.amount) / BigInt(Math.pow(10, quantity.symbol.precision())); | ||
} | ||
function bigint_to_asset(amount, sym) { | ||
return new Asset(BigInt(amount) * BigInt(Math.pow(10, sym.precision())), sym); | ||
} | ||
function asset_to_number(quantity) { | ||
if (Number(quantity.amount) == 0) | ||
return 0.0; | ||
return Number(quantity.amount) / Math.pow(10, quantity.symbol.precision()); | ||
} | ||
function number_to_asset(amount, sym) { | ||
return new Asset(amount * Math.pow(10, sym.precision()), sym); | ||
} | ||
/** | ||
* voteWeightToday computes the stake2vote weight for EOS, in order to compute the decaying value. | ||
*/ | ||
function voteWeightToday() { | ||
var seconds_per_day = 86400; | ||
var block_timestamp_epoch = new Date(Date.UTC(2000, 0, 1, 0, 0, 0, 0)).getTime(); | ||
return Math.floor((Date.now() - block_timestamp_epoch) / 1000 / (seconds_per_day * 7)) / 52; | ||
} | ||
/** | ||
* Convert EOS stake into decaying value | ||
* | ||
* @param {number} vote vote | ||
*/ | ||
function stake2vote(staked) { | ||
return staked * Math.pow(2, voteWeightToday()); | ||
} | ||
/** | ||
* Convert vote decay value into EOS stake | ||
* | ||
* @param {number} staked staked | ||
*/ | ||
function vote2stake(vote) { | ||
return vote / Math.pow(2, voteWeightToday()); | ||
} | ||
/** | ||
* Calculate producer vpay | ||
* | ||
* @return {bigint} producer pay as int64t | ||
*/ | ||
function calculate_producer_per_vote_pay(total_votes, pervote_bucket, total_producer_vote_weight) { | ||
return (pervote_bucket * total_votes) / total_producer_vote_weight; | ||
} | ||
exports.Asset = Asset; | ||
exports.ExtendedAsset = ExtendedAsset; | ||
exports.ExtendedSymbol = ExtendedSymbol; | ||
exports.Name = Name; | ||
exports.Sym = Sym; | ||
exports.SymbolCode = SymbolCode; | ||
exports.asset = asset; | ||
exports.asset_to_bigint = asset_to_bigint; | ||
exports.asset_to_number = asset_to_number; | ||
exports.bigint_to_asset = bigint_to_asset; | ||
exports.block_timestamp_epoch = block_timestamp_epoch; | ||
exports.calculate_producer_per_vote_pay = calculate_producer_per_vote_pay; | ||
exports.check = check; | ||
exports.current_time_point = current_time_point; | ||
exports.extended_asset = extended_asset; | ||
exports.extended_symbol = extended_symbol; | ||
exports.name = name; | ||
exports.number_to_asset = number_to_asset; | ||
exports.seconds_per_day = seconds_per_day; | ||
exports.stake2vote = stake2vote; | ||
exports.symbol = symbol; | ||
exports.symbol_code = symbol_code; | ||
exports.vote2stake = vote2stake; | ||
exports.voteWeightToday = voteWeightToday; | ||
exports.write_decimal = write_decimal; | ||
//# sourceMappingURL=index.js.map | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./eosiolib/asset")); | ||
__export(require("./eosiolib/extended_asset")); | ||
__export(require("./eosiolib/check")); | ||
__export(require("./eosiolib/symbol")); | ||
__export(require("./eosiolib/symbol_code")); | ||
__export(require("./eosiolib/extended_symbol")); | ||
__export(require("./eosiolib/time")); | ||
__export(require("./eosiolib/name")); | ||
__export(require("./eosiolib/utils")); | ||
__export(require("./eosiolib/voting")); | ||
__export(require("./eosiolib/eosiolib")); |
{ | ||
"name": "eos-common", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"description": "EOSIO Smart Contract common library used for Typescript", | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"browser": "dist/index.es.js", | ||
"jsnext:main": "dist/index.es.js", | ||
"types": "dist/index.d.ts", | ||
"runkitExampleFilename": "dist/examples/basic.js", | ||
"files": [ | ||
@@ -20,7 +16,7 @@ "dist" | ||
"scripts": { | ||
"build": "rollup -c rollup.config.ts", | ||
"build": "tsc", | ||
"prepublishOnly": "npm run test && npm run build", | ||
"test": "jest --coverage", | ||
"posttest": "eslint . --ext .ts", | ||
"docs": "tsc && documentation readme build/index.js -s API" | ||
"docs": "tsc --target ES2019 && documentation readme dist/eosiolib/**.js -s API" | ||
}, | ||
@@ -33,4 +29,2 @@ "repository": "git@github.com:EOS-Nation/eos-common.git", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "*", | ||
"@rollup/plugin-node-resolve": "*", | ||
"@types/jest": "*", | ||
@@ -42,13 +36,8 @@ "@typescript-eslint/eslint-plugin": "^2.20.0", | ||
"jest": "*", | ||
"rollup": "*", | ||
"rollup-plugin-cleaner": "^1.0.0", | ||
"rollup-plugin-copy": "*", | ||
"rollup-plugin-peer-deps-external": "*", | ||
"rollup-plugin-progress": "*", | ||
"rollup-plugin-terser": "*", | ||
"rollup-plugin-typescript2": "*", | ||
"ts-jest": "*", | ||
"typescript": "*" | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"big-integer": "^1.6.48" | ||
} | ||
} |
792
README.md
@@ -9,12 +9,11 @@ # `eos-common` | ||
## Goal | ||
Implements most commonly used EOSIO C++ Classes into Typescript: | ||
To implement the most commonly used EOSIO C++ Classes into Typescript: | ||
- [asset](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/asset.hpp) | ||
- [symbol](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp) | ||
- [symbol_code](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp) | ||
- [name](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/name.hpp) | ||
- [extended_asset](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/asset.hpp) | ||
- [extended_symbol](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp) | ||
- [Asset](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/asset.hpp) | ||
- [Symbol](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp) | ||
- [SymbolCode](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp) | ||
- [ExtendedAsset](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/asset.hpp) | ||
- [ExtendedSymbol](https://github.com/EOSIO/eosio.cdt/blob/master/libraries/eosiolib/symbol.hpp) | ||
## Installation | ||
@@ -37,9 +36,9 @@ | ||
```ts | ||
import { Asset, Symbol } from "eos-common" | ||
import { asset, symbol } from "eos-common" | ||
const quantity = new Asset(10000, new Symbol("EOS", 4)); | ||
const quantity = asset("1.0000 EOS"); | ||
// or | ||
const quantity = new Asset('1.0000 EOS'); | ||
const quantity = asset(10000, symbol("EOS", 4)); | ||
quantity.to_string() //=> "1.0000 EOS"; | ||
quantity.symbol.code() //=> "EOS" | ||
quantity.symbol.code().to_string() //=> "EOS" | ||
quantity.symbol.precision() //=> 4 | ||
@@ -58,17 +57,146 @@ ``` | ||
- [amount](#amount) | ||
- [symbol](#symbol) | ||
- [typeof](#typeof) | ||
- [is_amount_within_range](#is_amount_within_range) | ||
- [is_valid](#is_valid) | ||
- [set_amount](#set_amount) | ||
- [Parameters](#parameters-1) | ||
- [minus](#minus) | ||
- [Parameters](#parameters-2) | ||
- [plus](#plus) | ||
- [Parameters](#parameters-3) | ||
- [times](#times) | ||
- [Parameters](#parameters-4) | ||
- [div](#div) | ||
- [Parameters](#parameters-5) | ||
- [toString](#tostring) | ||
- [isInstance](#isinstance) | ||
- [Parameters](#parameters-6) | ||
- [plus](#plus-1) | ||
- [Parameters](#parameters-7) | ||
- [minus](#minus-1) | ||
- [Parameters](#parameters-8) | ||
- [times](#times-1) | ||
- [Parameters](#parameters-9) | ||
- [div](#div-1) | ||
- [Parameters](#parameters-10) | ||
- [isEqual](#isequal) | ||
- [Parameters](#parameters-11) | ||
- [isNotEqual](#isnotequal) | ||
- [Parameters](#parameters-12) | ||
- [isLessThan](#islessthan) | ||
- [Parameters](#parameters-13) | ||
- [isLessThanOrEqual](#islessthanorequal) | ||
- [Parameters](#parameters-14) | ||
- [isGreaterThan](#isgreaterthan) | ||
- [Parameters](#parameters-15) | ||
- [isGreaterThanOrEqual](#isgreaterthanorequal) | ||
- [Parameters](#parameters-16) | ||
- [max_amount](#max_amount) | ||
- [check](#check) | ||
- [Parameters](#parameters-1) | ||
- [Parameters](#parameters-17) | ||
- [Examples](#examples-1) | ||
- [write_decimal](#write_decimal) | ||
- [Parameters](#parameters-18) | ||
- [ExtendedAsset](#extendedasset) | ||
- [Parameters](#parameters-19) | ||
- [quantity](#quantity) | ||
- [contract](#contract) | ||
- [typeof](#typeof-1) | ||
- [get_extended_symbol](#get_extended_symbol) | ||
- [toString](#tostring-1) | ||
- [times](#times-2) | ||
- [Parameters](#parameters-20) | ||
- [div](#div-2) | ||
- [Parameters](#parameters-21) | ||
- [minus](#minus-2) | ||
- [Parameters](#parameters-22) | ||
- [plus](#plus-2) | ||
- [Parameters](#parameters-23) | ||
- [isLessThan](#islessthan-1) | ||
- [Parameters](#parameters-24) | ||
- [isEqual](#isequal-1) | ||
- [Parameters](#parameters-25) | ||
- [isNotEqual](#isnotequal-1) | ||
- [Parameters](#parameters-26) | ||
- [isLessThanOrEqual](#islessthanorequal-1) | ||
- [Parameters](#parameters-27) | ||
- [isGreaterThanOrEqual](#isgreaterthanorequal-1) | ||
- [Parameters](#parameters-28) | ||
- [isInstance](#isinstance-1) | ||
- [Parameters](#parameters-29) | ||
- [ExtendedSymbol](#extendedsymbol) | ||
- [Parameters](#parameters-30) | ||
- [typeof](#typeof-2) | ||
- [get_symbol](#get_symbol) | ||
- [get_contract](#get_contract) | ||
- [toString](#tostring-2) | ||
- [Parameters](#parameters-31) | ||
- [isInstance](#isinstance-2) | ||
- [Parameters](#parameters-32) | ||
- [isEqual](#isequal-2) | ||
- [Parameters](#parameters-33) | ||
- [isNotEqual](#isnotequal-2) | ||
- [Parameters](#parameters-34) | ||
- [isLessThan](#islessthan-2) | ||
- [Parameters](#parameters-35) | ||
- [extended_symbol](#extended_symbol) | ||
- [Parameters](#parameters-36) | ||
- [Examples](#examples-2) | ||
- [Name](#name) | ||
- [Parameters](#parameters-37) | ||
- [typeof](#typeof-3) | ||
- [length](#length) | ||
- [suffix](#suffix) | ||
- [raw](#raw) | ||
- [bool](#bool) | ||
- [toString](#tostring-3) | ||
- [isInstance](#isinstance-3) | ||
- [Parameters](#parameters-38) | ||
- [char_to_value](#char_to_value) | ||
- [Parameters](#parameters-39) | ||
- [isEqual](#isequal-3) | ||
- [Parameters](#parameters-40) | ||
- [isNotEqual](#isnotequal-3) | ||
- [Parameters](#parameters-41) | ||
- [isLessThan](#islessthan-3) | ||
- [Parameters](#parameters-42) | ||
- [SymbolCode](#symbolcode) | ||
- [Symbol](#symbol) | ||
- [Parameters](#parameters-2) | ||
- [Examples](#examples-2) | ||
- [Parameters](#parameters-43) | ||
- [typeof](#typeof-4) | ||
- [toString](#tostring-4) | ||
- [isEqual](#isequal-4) | ||
- [Parameters](#parameters-44) | ||
- [isNotEqual](#isnotequal-4) | ||
- [Parameters](#parameters-45) | ||
- [isLessThan](#islessthan-4) | ||
- [Parameters](#parameters-46) | ||
- [isInstance](#isinstance-4) | ||
- [Parameters](#parameters-47) | ||
- [Symbol](#symbol-1) | ||
- [Parameters](#parameters-48) | ||
- [Examples](#examples-3) | ||
- [typeof](#typeof-5) | ||
- [is_valid](#is_valid-1) | ||
- [precision](#precision) | ||
- [code](#code) | ||
- [raw](#raw-1) | ||
- [bool](#bool-1) | ||
- [toString](#tostring-5) | ||
- [Parameters](#parameters-49) | ||
- [isInstance](#isinstance-5) | ||
- [Parameters](#parameters-50) | ||
- [isEqual](#isequal-5) | ||
- [Parameters](#parameters-51) | ||
- [isNotEqual](#isnotequal-5) | ||
- [Parameters](#parameters-52) | ||
- [isLessThan](#islessthan-5) | ||
- [Parameters](#parameters-53) | ||
- [voteWeightToday](#voteweighttoday) | ||
- [stake2vote](#stake2vote) | ||
- [Parameters](#parameters-3) | ||
- [Parameters](#parameters-54) | ||
- [vote2stake](#vote2stake) | ||
- [Parameters](#parameters-4) | ||
- [voteWeightToday](#voteweighttoday) | ||
- [Parameters](#parameters-55) | ||
- [calculate_producer_per_vote_pay](#calculate_producer_per_vote_pay) | ||
- [Parameters](#parameters-56) | ||
@@ -88,3 +216,3 @@ ### Asset | ||
const quantity = new Asset(10000, new Symbol("EOS", 4)); | ||
quantity.to_string() //=> "1.0000 EOS"; | ||
quantity.toString() //=> "1.0000 EOS"; | ||
quantity.symbol.code() //=> "EOS" | ||
@@ -100,2 +228,10 @@ quantity.symbol.precision //=> 4 | ||
#### symbol | ||
{symbol} The symbol name of the asset | ||
#### typeof | ||
The typeof operator returns a string indicating the type of the unevaluated operand. | ||
#### is_amount_within_range | ||
@@ -117,2 +253,183 @@ | ||
#### set_amount | ||
Set the amount of the asset | ||
##### Parameters | ||
- `amount` | ||
- `a` New amount for the asset | ||
#### minus | ||
Subtraction assignment operator | ||
##### Parameters | ||
- `a` Another asset to subtract this asset with | ||
Returns **any** asset& - Reference to this asset | ||
#### plus | ||
Addition Assignment operator | ||
##### Parameters | ||
- `a` Another asset to subtract this asset with | ||
Returns **any** asset& - Reference to this asset | ||
#### times | ||
Multiplication assignment operator, with a number | ||
##### Parameters | ||
- `a` The multiplier for the asset's amount | ||
Returns **any** asset - Reference to this asset | ||
#### div | ||
##### Parameters | ||
- `a` The divisor for the asset's amount | ||
Returns **any** asset - Reference to this asset | ||
#### toString | ||
The toString() method returns the string representation of the object. | ||
#### isInstance | ||
The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
##### Parameters | ||
- `obj` | ||
#### plus | ||
Addition operator | ||
##### Parameters | ||
- `a` The first asset to be added | ||
- `b` The second asset to be added | ||
Returns **any** asset - New asset as the result of addition | ||
#### minus | ||
Subtraction operator | ||
##### Parameters | ||
- `a` The asset to be subtracted | ||
- `b` The asset used to subtract | ||
Returns **any** asset - New asset as the result of subtraction of a with b | ||
#### times | ||
Multiplication operator, with a number proceeding | ||
##### Parameters | ||
- `a` The asset to be multiplied | ||
- `b` The multiplier for the asset's amount | ||
Returns **any** asset - New asset as the result of multiplication | ||
#### div | ||
Division operator, with a number proceeding | ||
##### Parameters | ||
- `a` The asset to be divided | ||
- `b` The divisor for the asset's amount | ||
Returns **any** asset - New asset as the result of division | ||
#### isEqual | ||
Equality operator | ||
##### Parameters | ||
- `a` The first asset to be compared | ||
- `b` The second asset to be compared | ||
Returns **any** true - if both asset has the same amount | ||
Returns **any** false - otherwise | ||
#### isNotEqual | ||
Inequality operator | ||
##### Parameters | ||
- `a` The first asset to be compared | ||
- `b` The second asset to be compared | ||
Returns **any** true - if both asset doesn't have the same amount | ||
Returns **any** false - otherwise | ||
#### isLessThan | ||
Less than operator | ||
##### Parameters | ||
- `a` The first asset to be compared | ||
- `b` The second asset to be compared | ||
Returns **any** true - if the first asset's amount is less than the second asset amount | ||
Returns **any** false - otherwise | ||
#### isLessThanOrEqual | ||
Less or equal to operator | ||
##### Parameters | ||
- `a` The first asset to be compared | ||
- `b` The second asset to be compared | ||
Returns **any** true - if the first asset's amount is less or equal to the second asset amount | ||
Returns **any** false - otherwise | ||
#### isGreaterThan | ||
Greater than operator | ||
##### Parameters | ||
- `a` The first asset to be compared | ||
- `b` The second asset to be compared | ||
Returns **any** true - if the first asset's amount is greater than the second asset amount | ||
Returns **any** false - otherwise | ||
#### isGreaterThanOrEqual | ||
Greater or equal to operator | ||
##### Parameters | ||
- `a` The first asset to be compared | ||
- `b` The second asset to be compared | ||
Returns **any** true - if the first asset's amount is greater or equal to the second asset amount | ||
Returns **any** false - otherwise | ||
#### max_amount | ||
@@ -139,4 +456,344 @@ | ||
### write_decimal | ||
Writes a number as a string | ||
#### Parameters | ||
- `number` The number to print before shifting the decimal point to the left by num_decimal_places. | ||
- `num_decimal_places` The number of decimal places to shift the decimal point. | ||
- `negative` Whether to print a minus sign in the front. | ||
### ExtendedAsset | ||
#### Parameters | ||
- `obj1` | ||
- `obj2` | ||
#### quantity | ||
The asset | ||
#### contract | ||
The owner of the asset | ||
#### typeof | ||
The typeof operator returns a string indicating the type of the unevaluated operand. | ||
#### get_extended_symbol | ||
Get the extended symbol of the asset | ||
Returns **any** extended_symbol - The extended symbol of the asset | ||
#### toString | ||
The toString() method returns the string representation of the object. | ||
#### times | ||
Multiplication assignment operator | ||
##### Parameters | ||
- `a` | ||
#### div | ||
Division operator | ||
##### Parameters | ||
- `a` | ||
#### minus | ||
Subtraction operator | ||
##### Parameters | ||
- `a` | ||
#### plus | ||
Addition operator | ||
##### Parameters | ||
- `a` | ||
#### isLessThan | ||
Less than operator | ||
##### Parameters | ||
- `a` | ||
#### isEqual | ||
Comparison operator | ||
##### Parameters | ||
- `a` | ||
#### isNotEqual | ||
Comparison operator | ||
##### Parameters | ||
- `a` | ||
#### isLessThanOrEqual | ||
Comparison operator | ||
##### Parameters | ||
- `a` | ||
#### isGreaterThanOrEqual | ||
Comparison operator | ||
##### Parameters | ||
- `a` | ||
#### isInstance | ||
The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
##### Parameters | ||
- `obj` | ||
### ExtendedSymbol | ||
#### Parameters | ||
- `sym` The symbol | ||
- `contract` | ||
- `con` The name of the contract | ||
#### typeof | ||
The typeof operator returns a string indicating the type of the unevaluated operand. | ||
#### get_symbol | ||
Returns the symbol in the extended_contract | ||
Returns **any** symbol | ||
#### get_contract | ||
Returns the name of the contract in the extended_symbol | ||
Returns **any** name | ||
#### toString | ||
The toString() method returns the string representation of the object. | ||
##### Parameters | ||
- `show_precision` (optional, default `true`) | ||
#### isInstance | ||
The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
##### Parameters | ||
- `obj` | ||
#### isEqual | ||
Equivalency operator. Returns true if a == b (are the same) | ||
##### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if both provided name are the same | ||
#### isNotEqual | ||
Inverted equivalency operator. Returns true if a != b (are different) | ||
##### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if both provided name are not the same | ||
#### isLessThan | ||
Less than operator. Returns true if a < b. | ||
##### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if name `a` is less than `b` | ||
### extended_symbol | ||
Extended Symbol | ||
#### Parameters | ||
- `sym` | ||
- `contract` | ||
#### Examples | ||
```javascript | ||
extended_symbol( symbol("4,EOS"), name("eosio.token") ) | ||
``` | ||
### Name | ||
#### Parameters | ||
- `str` | ||
#### typeof | ||
The typeof operator returns a string indicating the type of the unevaluated operand. | ||
#### length | ||
Returns the length of the %name | ||
#### suffix | ||
Returns the suffix of the %name | ||
#### raw | ||
Returns uint64_t repreresentation of the name | ||
#### bool | ||
Explicit cast to bool of the name | ||
Returns **any** Returns true if the name is set to the default value of 0 else true. | ||
#### toString | ||
The toString() method returns the string representation of the object. | ||
#### isInstance | ||
The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
##### Parameters | ||
- `obj` | ||
#### char_to_value | ||
Converts a %name Base32 symbol into its corresponding value | ||
##### Parameters | ||
- `c` Character to be converted | ||
Returns **any** constexpr char - Converted value | ||
#### isEqual | ||
Equivalency operator. Returns true if a == b (are the same) | ||
##### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if both provided name are the same | ||
#### isNotEqual | ||
Inverted equivalency operator. Returns true if a != b (are different) | ||
##### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if both provided name are not the same | ||
#### isLessThan | ||
Less than operator. Returns true if a < b. | ||
##### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if name `a` is less than `b` | ||
### SymbolCode | ||
#### Parameters | ||
- `str` | ||
#### typeof | ||
The typeof operator returns a string indicating the type of the unevaluated operand. | ||
#### toString | ||
The toString() method returns the string representation of the object. | ||
#### isEqual | ||
Equivalency operator. Returns true if a == b (are the same) | ||
##### Parameters | ||
- `comparison` | ||
Returns **any** boolean - true if both provided symbol_codes are the same | ||
#### isNotEqual | ||
Inverted equivalency operator. Returns true if a != b (are different) | ||
##### Parameters | ||
- `comparison` | ||
Returns **any** boolean - true if both provided symbol_codes are not the same | ||
#### isLessThan | ||
Less than operator. Returns true if a < b. | ||
##### Parameters | ||
- `comparison` | ||
Returns **any** boolean - true if symbol_code `a` is less than `b` | ||
#### isInstance | ||
The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
##### Parameters | ||
- `obj` | ||
### Symbol | ||
@@ -155,6 +812,4 @@ | ||
const sym = new Symbol("EOS", 4); | ||
// or | ||
const sym = new Symbol("4,EOS"); | ||
sym.code() //=> "EOS" | ||
sym.precision() //=> 4 | ||
sym.precision //=> 4 | ||
``` | ||
@@ -164,2 +819,81 @@ | ||
### typeof | ||
The typeof operator returns a string indicating the type of the unevaluated operand. | ||
### is_valid | ||
Is this symbol valid | ||
### precision | ||
This symbol's precision | ||
### code | ||
Returns representation of symbol name | ||
### raw | ||
Returns uint64_t repreresentation of the symbol | ||
### bool | ||
Explicit cast to bool of the symbol | ||
Returns **any** Returns true if the symbol is set to the default value of 0 else true. | ||
### toString | ||
The toString() method returns the string representation of the object. | ||
#### Parameters | ||
- `show_precision` (optional, default `true`) | ||
### isInstance | ||
The isinstance() function returns True if the specified object is of the specified type, otherwise False. | ||
#### Parameters | ||
- `obj` | ||
### isEqual | ||
Equivalency operator. Returns true if a == b (are the same) | ||
#### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if both provided symbol_codes are the same | ||
### isNotEqual | ||
Inverted equivalency operator. Returns true if a != b (are different) | ||
#### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if both provided symbol_codes are not the same | ||
### isLessThan | ||
Less than operator. Returns true if a < b. | ||
#### Parameters | ||
- `a` | ||
- `b` | ||
Returns **any** boolean - true if symbol_code `a` is less than `b` | ||
### voteWeightToday | ||
voteWeightToday computes the stake2vote weight for EOS, in order to compute the decaying value. | ||
### stake2vote | ||
@@ -183,4 +917,12 @@ | ||
### voteWeightToday | ||
### calculate_producer_per_vote_pay | ||
voteWeightToday computes the stake2vote weight for EOS, in order to compute the decaying value. | ||
Calculate producer vpay | ||
#### Parameters | ||
- `total_votes` | ||
- `pervote_bucket` | ||
- `total_producer_vote_weight` | ||
Returns **bigint** producer pay as int64t |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
8
28
919
91152
1
2014
1
+ Addedbig-integer@^1.6.48
+ Addedbig-integer@1.6.52(transitive)