Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eos-common

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eos-common - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

50

dist/eosiolib/asset.js

@@ -9,30 +9,4 @@ "use strict";

const eosiolib_1 = require("./eosiolib");
const utils_1 = require("./utils");
const big_integer_1 = __importDefault(require("big-integer"));
function number_to_bigint(num) {
return big_integer_1.default(num.toFixed(0));
}
function isNull(value) {
return value == undefined || value == null;
}
function getSymbol(a) {
const obj = a;
if (obj.typeof == "asset")
return obj.symbol;
return null;
}
function getAmount(obj) {
if (obj.typeof == "asset")
return obj.amount;
if (obj.typeof == "extended_asset")
return obj.quantity.amount;
if (big_integer_1.default.isInstance(obj))
return obj;
if (typeof obj == "number")
return big_integer_1.default(obj);
if (typeof obj == "bigint")
return big_integer_1.default(obj);
if (typeof obj == "string")
return big_integer_1.default(obj);
throw new Error("invalid amount");
}
/**

@@ -68,3 +42,3 @@ * Asset

this.symbol = symbol_1.symbol();
if (isNull(amount) && isNull(sym)) {
if (utils_1.isNull(amount) && utils_1.isNull(sym)) {
return;

@@ -75,7 +49,7 @@ }

const precision = (amount_str.split(".")[1] || []).length;
this.amount = number_to_bigint(Number(amount_str) * Math.pow(10, precision));
this.amount = utils_1.number_to_bigint(Number(amount_str) * Math.pow(10, precision));
this.symbol = new symbol_1.Sym(symbol_str, precision);
}
else if (sym) {
this.amount = getAmount(amount);
this.amount = utils_1.getAmount(amount);
this.symbol = sym;

@@ -135,4 +109,4 @@ }

minus(a) {
const amount = getAmount(a);
const sym = getSymbol(a);
const amount = utils_1.getAmount(a);
const sym = utils_1.getSymbol(a);
if (sym)

@@ -153,4 +127,4 @@ check_1.check(sym.isEqual(this.symbol), "attempt to subtract asset with different symbol");

plus(a) {
const amount = getAmount(a);
const sym = getSymbol(a);
const amount = utils_1.getAmount(a);
const sym = utils_1.getSymbol(a);
if (sym)

@@ -196,4 +170,4 @@ check_1.check(sym.isEqual(this.symbol), "attempt to add asset with different symbol");

times(a) {
const amount = getAmount(a);
const sym = getSymbol(a);
const amount = utils_1.getAmount(a);
const sym = utils_1.getSymbol(a);
if (sym)

@@ -229,4 +203,4 @@ check_1.check(sym.isEqual(this.symbol), "comparison of assets with different symbols is not allowed");

div(a) {
const amount = getAmount(a);
const sym = getSymbol(a);
const amount = utils_1.getAmount(a);
const sym = utils_1.getSymbol(a);
if (sym)

@@ -233,0 +207,0 @@ check_1.check(sym.isEqual(this.symbol), "comparison of assets with different symbols is not allowed");

@@ -11,31 +11,3 @@ "use strict";

const big_integer_1 = __importDefault(require("big-integer"));
function getType(obj) {
if (typeof obj == "object" && obj.typeof)
return obj.typeof;
return typeof obj;
}
function getAmount(obj) {
if (obj.typeof == "asset")
return obj.amount;
if (obj.typeof == "extended_asset")
return obj.quantity.amount;
if (big_integer_1.default.isInstance(obj))
return obj;
if (typeof obj == "number")
return big_integer_1.default(obj);
if (typeof obj == "bigint")
return big_integer_1.default(obj);
if (typeof obj == "string")
return big_integer_1.default(obj);
throw new Error("invalid amount");
}
function getContract(obj) {
if (obj.typeof == "extended_asset")
return obj.contract;
if (obj.typeof == "extended_symbol")
return obj.get_contract();
if (obj.typeof == "name")
return obj;
return null;
}
const utils_1 = require("./utils");
/**

@@ -56,11 +28,11 @@ * @class Stores the extended_asset

// Asset & Contract
if (getType(obj1) == "asset")
if (utils_1.getType(obj1) == "asset")
this.quantity = obj1;
if (getType(obj2) == "name")
if (utils_1.getType(obj2) == "name")
this.contract = obj2;
// Contract
if (getType(obj1) == "name")
if (utils_1.getType(obj1) == "name")
this.contract = obj1;
// Value & Extended Symbol
if (getType(obj2) == "extended_symbol") {
if (utils_1.getType(obj2) == "extended_symbol") {
this.quantity = new asset_1.Asset(big_integer_1.default(obj1 || 0), obj2.get_symbol());

@@ -70,3 +42,3 @@ this.contract = obj2.get_contract();

// Extended Symbol
if (getType(obj1) == "extended_symbol") {
if (utils_1.getType(obj1) == "extended_symbol") {
this.quantity = new asset_1.Asset(0, obj1.get_symbol());

@@ -111,4 +83,4 @@ this.contract = obj1.get_contract();

times(a) {
const amount = getAmount(a);
const contract = getContract(a);
const amount = utils_1.getAmount(a);
const contract = utils_1.getContract(a);
if (contract)

@@ -120,3 +92,3 @@ check_1.check(contract.raw().equals(this.contract.raw()), "type mismatch");

static times(a, b) {
const contract = getContract(a);
const contract = utils_1.getContract(a);
if (contract)

@@ -132,4 +104,4 @@ check_1.check(a.contract.raw().equals(contract.raw()), "type mismatch");

div(a) {
const amount = getAmount(a);
const contract = getContract(a);
const amount = utils_1.getAmount(a);
const contract = utils_1.getContract(a);
if (contract)

@@ -141,3 +113,3 @@ check_1.check(contract.raw().equals(this.contract.raw()), "type mismatch");

static div(a, b) {
const contract = getContract(a);
const contract = utils_1.getContract(a);
if (contract)

@@ -153,4 +125,4 @@ check_1.check(a.contract.raw().equals(contract.raw()), "type mismatch");

minus(a) {
const amount = getAmount(a);
const contract = getContract(a);
const amount = utils_1.getAmount(a);
const contract = utils_1.getContract(a);
if (contract)

@@ -162,3 +134,3 @@ check_1.check(contract.raw().equals(this.contract.raw()), "type mismatch");

static minus(a, b) {
const contract = getContract(a);
const contract = utils_1.getContract(a);
if (contract)

@@ -174,4 +146,4 @@ check_1.check(a.contract.raw().equals(contract.raw()), "type mismatch");

plus(a) {
const amount = getAmount(a);
const contract = getContract(a);
const amount = utils_1.getAmount(a);
const contract = utils_1.getContract(a);
if (contract)

@@ -183,3 +155,3 @@ check_1.check(contract.raw().equals(this.contract.raw()), "type mismatch");

static plus(a, b) {
const contract = getContract(a);
const contract = utils_1.getContract(a);
if (contract)

@@ -186,0 +158,0 @@ check_1.check(a.contract.raw().equals(contract.raw()), "type mismatch");

@@ -9,5 +9,3 @@ "use strict";

const big_integer_1 = __importDefault(require("big-integer"));
function isNull(value) {
return value == undefined || value == null;
}
const utils_1 = require("./utils");
class Sym {

@@ -29,3 +27,3 @@ /**

this.value = big_integer_1.default(0);
if (isNull(sc) && isNull(precision)) {
if (utils_1.isNull(sc) && utils_1.isNull(precision)) {
this.value = big_integer_1.default(0);

@@ -42,4 +40,4 @@ }

check_1.check(!isNaN(precision), "[precision] must be number type");
check_1.check(!isNull(precision), "[precision] is required");
check_1.check(!isNull(symcode_str), "[symcode] is required");
check_1.check(!utils_1.isNull(precision), "[precision] is required");
check_1.check(!utils_1.isNull(symcode_str), "[symcode] is required");
const symcode = new symbol_code_1.SymbolCode(symcode_str).raw();

@@ -51,4 +49,4 @@ this.value = big_integer_1.default(symcode).shiftLeft(8).or(Number(precision_str || ""));

check_1.check(!isNaN(Number(precision)), "[precision] must be number type");
check_1.check(!isNull(precision), "[precision] is required");
check_1.check(!isNull(sc), "[symcode] is required");
check_1.check(!utils_1.isNull(precision), "[precision] is required");
check_1.check(!utils_1.isNull(sc), "[symcode] is required");
const symcode = new symbol_code_1.SymbolCode(sc).raw();

@@ -62,3 +60,3 @@ this.value = big_integer_1.default(symcode).shiftLeft(8).or(precision || 0);

if (symcode.typeof == "symbol_code") {
check_1.check(!isNull(precision), "[precision] is required");
check_1.check(!utils_1.isNull(precision), "[precision] is required");
this.value = big_integer_1.default(symcode.raw()).shiftLeft(8).or(precision || 0);

@@ -65,0 +63,0 @@ // bigInt object

import { Sym } from "./symbol";
import { Asset } from "./asset";
import { ExtendedAsset } from "./extended_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;
import { Name } from "./name";
import { ExtendedSymbol } from "./extended_symbol";
export declare function getType(obj: any): string;
export declare function number_to_bigint(num: number): BigInteger;
export declare function isNull(value: any): boolean;
export declare function getAmount(obj: any): BigInteger;
export declare function getSymbol(obj: any): Sym | null;
export declare function getContract(obj: any): Name | null;
export declare function asset_to_number(quantity: Asset | ExtendedAsset): number;
export declare function number_to_asset(num: number | bigint | BigInteger, sym: Sym | ExtendedSymbol): Asset;

@@ -8,21 +8,69 @@ "use strict";

const big_integer_1 = __importDefault(require("big-integer"));
function asset_to_bigint(quantity) {
if (quantity.amount == big_integer_1.default(0))
return big_integer_1.default(0.0);
return big_integer_1.default(quantity.amount).divide(Math.pow(10, quantity.symbol.precision()));
function getType(obj) {
if (typeof obj == "object" && obj.typeof)
return obj.typeof;
return typeof obj;
}
exports.asset_to_bigint = asset_to_bigint;
function bigint_to_asset(amount, sym) {
return new asset_1.Asset(amount, sym).times(Math.pow(10, sym.precision()));
exports.getType = getType;
function number_to_bigint(num) {
return big_integer_1.default(num.toFixed(0));
}
exports.bigint_to_asset = bigint_to_asset;
exports.number_to_bigint = number_to_bigint;
function isNull(value) {
return value == undefined || value == null;
}
exports.isNull = isNull;
function getAmount(obj) {
if (obj.typeof == "asset")
return obj.amount;
if (obj.typeof == "extended_asset")
return obj.quantity.amount;
if (big_integer_1.default.isInstance(obj))
return obj;
if (typeof obj == "number")
return big_integer_1.default(obj);
if (typeof obj == "bigint")
return big_integer_1.default(obj);
if (typeof obj == "string")
return big_integer_1.default(obj);
throw new Error("invalid getAmount param");
}
exports.getAmount = getAmount;
function getSymbol(obj) {
if (obj.typeof == "symbol")
return obj;
if (obj.typeof == "asset")
return obj.symbol;
if (obj.typeof == "extended_asset")
return obj.quantity.symbol;
return null;
}
exports.getSymbol = getSymbol;
function getContract(obj) {
if (obj.typeof == "extended_asset")
return obj.contract;
if (obj.typeof == "extended_symbol")
return obj.get_contract();
return null;
}
exports.getContract = getContract;
function asset_to_number(quantity) {
if (Number(quantity.amount) == 0)
return 0.0;
return Number(quantity.amount) / Math.pow(10, quantity.symbol.precision());
const amount = getAmount(quantity);
if (amount == big_integer_1.default(0))
return Number(amount);
const sym = getSymbol(quantity);
if (sym)
return Number(amount) / Math.pow(10, sym.precision());
throw new Error("invalid quantity");
}
exports.asset_to_number = asset_to_number;
function number_to_asset(amount, sym) {
return new asset_1.Asset(amount * Math.pow(10, sym.precision()), sym);
function number_to_asset(num, sym) {
const symbol = getSymbol(sym);
if (!symbol)
throw new Error("invalid sym");
const exp = Math.pow(10, symbol.precision());
if (typeof num == "number")
return new asset_1.Asset(num * exp, symbol);
return new asset_1.Asset(getAmount(num).multiply(exp), symbol);
}
exports.number_to_asset = number_to_asset;

@@ -9,4 +9,4 @@ export * from "./eosiolib/asset";

export * from "./eosiolib/name";
export * from "./eosiolib/utils";
export * from "./eosiolib/voting";
export * from "./eosiolib/eosiolib";
export * from "./eosiolib/utils";

@@ -14,4 +14,4 @@ "use strict";

__export(require("./eosiolib/name"));
__export(require("./eosiolib/utils"));
__export(require("./eosiolib/voting"));
__export(require("./eosiolib/eosiolib"));
__export(require("./eosiolib/utils"));
{
"name": "eos-common",
"version": "0.7.0",
"version": "0.7.1",
"description": "EOSIO Smart Contract common library used for Typescript",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc