Comparing version 12.0.1 to 12.0.2
@@ -41,3 +41,3 @@ 'use strict'; | ||
assert(new RegExp('^[0-9]+(.[0-9]+)? ' + symbol + '$').test(max_supply), 'Expecting max_supply string like 10000.0000 SYM, instead got: ' + max_supply); | ||
assert(new RegExp('^[0-9]+(.[0-9]+)? ' + symbol + '$').test(max_supply), 'Expecting max_supply string like 10000.0000 SYS, instead got: ' + max_supply); | ||
@@ -44,0 +44,0 @@ var _max_supply$split = max_supply.split(' '), |
'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -242,3 +244,3 @@ | ||
@arg {number|string|object.toString} value | ||
@arg {number} precision - number of decimal places | ||
@arg {number} [precision = null] - number of decimal places (null skips padding) | ||
@return {string} decimal part is added and zero padded to match precision | ||
@@ -248,2 +250,5 @@ */ | ||
var value = UDecimalString(num); | ||
if (precision == null) { | ||
return num; | ||
} | ||
assert.equal('number', typeof precision === 'undefined' ? 'undefined' : _typeof(precision), 'precision'); | ||
@@ -283,2 +288,3 @@ | ||
assert(/^\d+$/.test(value), 'invalid whole number ' + value); | ||
assert(precision != null, 'precision required'); | ||
@@ -293,11 +299,11 @@ // Ensure minimum length | ||
value = value.slice(0, dotIdx) + '.' + value.slice(dotIdx); | ||
return UDecimalString(value); // Normalize | ||
return UDecimalPad(value, precision); // Normalize | ||
} | ||
/** | ||
@arg {string} assetSymbol - 4,SYM | ||
@arg {string} assetSymbol - 4,SYS | ||
@arg {number} [precision = null] - expected precision or mismatch AssertionError | ||
@example assert.deepEqual(parseAssetSymbol('SYM'), {precision: null, symbol: 'SYM'}) | ||
@example assert.deepEqual(parseAssetSymbol('4,SYM'), {precision: 4, symbol: 'SYM'}) | ||
@example assert.deepEqual(parseAssetSymbol('SYS'), {precision: null, symbol: 'SYS'}) | ||
@example assert.deepEqual(parseAssetSymbol('4,SYS'), {precision: 4, symbol: 'SYS'}) | ||
@throws AssertionError | ||
@@ -315,7 +321,10 @@ @throws TypeError | ||
var v = assetSymbol.split(','); | ||
assert(v.length === 2, 'Asset symbol "' + assetSymbol + '" may have a precision like this: 4,SYM'); | ||
assert(v.length === 2, 'Asset symbol "' + assetSymbol + '" may have a precision like this: 4,SYS'); | ||
var symbolPrecision = v[0] == '' ? null : parseInt(v[0]); | ||
var symbol = v[1]; | ||
var _v$1$split = v[1].split('@'), | ||
_v$1$split2 = _slicedToArray(_v$1$split, 1), | ||
symbol = _v$1$split2[0]; // remove contract (if exists) | ||
if (precision != null) { | ||
@@ -332,3 +341,3 @@ assert.equal(precision, symbolPrecision, 'Asset symbol precision mismatch'); | ||
assert(/^[A-Z]+$/.test(symbol), 'Asset symbol should contain only uppercase letters A-Z'); | ||
assert(/^[A-Z]+$/.test(symbol), 'Asset symbol should contain only uppercase letters A-Z: ' + symbol); | ||
assert(precision <= 18, 'Precision should be 18 characters or less'); | ||
@@ -335,0 +344,0 @@ assert(symbol.length <= 7, 'Asset symbol is 7 characters or less'); |
@@ -152,5 +152,2 @@ 'use strict'; | ||
assert.throws(function () { | ||
return UDecimalPad(1); | ||
}, /precision/); | ||
assert.throws(function () { | ||
return UDecimalPad('$10', 0); | ||
@@ -168,3 +165,3 @@ }, /invalid decimal/); | ||
var decFixtures = [{ value: 1, precision: 0, answer: '1' }, { value: '1', precision: 0, answer: '1' }, { value: '1.', precision: 0, answer: '1' }, { value: '1.0', precision: 0, answer: '1' }, { value: '1456.0', precision: 0, answer: '1456' }, { value: '1,456.0', precision: 0, answer: '1,456' }, | ||
var decFixtures = [{ value: 1, precision: null, answer: '1' }, { value: 1, precision: 0, answer: '1' }, { value: '1', precision: 0, answer: '1' }, { value: '1.', precision: 0, answer: '1' }, { value: '1.0', precision: 0, answer: '1' }, { value: '1456.0', precision: 0, answer: '1456' }, { value: '1,456.0', precision: 0, answer: '1,456' }, | ||
@@ -213,3 +210,3 @@ // does not validate commas | ||
var decFixtures = [{ value: 1, precision: 0, answer: '1' }, { value: '1', precision: 0, answer: '1' }, { value: '10', precision: 0, answer: '10' }, { value: 1, precision: 1, answer: '0.1' }, { value: '10', precision: 1, answer: '1' }, { value: '11', precision: 2, answer: '0.11' }, { value: '110', precision: 2, answer: '1.1' }, { value: '101', precision: 2, answer: '1.01' }, { value: '0101', precision: 2, answer: '1.01' }]; | ||
var decFixtures = [{ value: 1, precision: 0, answer: '1' }, { value: '1', precision: 0, answer: '1' }, { value: '10', precision: 0, answer: '10' }, { value: 1, precision: 1, answer: '0.1' }, { value: '10', precision: 1, answer: '1.0' }, { value: '11', precision: 2, answer: '0.11' }, { value: '110', precision: 2, answer: '1.10' }, { value: '101', precision: 2, answer: '1.01' }, { value: '0101', precision: 2, answer: '1.01' }]; | ||
var _iteratorNormalCompletion6 = true; | ||
@@ -245,4 +242,4 @@ var _didIteratorError6 = false; | ||
it('parseAssetSymbol', function () { | ||
assert.deepEqual(parseAssetSymbol('SYM'), { precision: null, symbol: 'SYM' }); | ||
assert.deepEqual(parseAssetSymbol('4,SYM'), { precision: 4, symbol: 'SYM' }); | ||
assert.deepEqual(parseAssetSymbol('SYS'), { precision: null, symbol: 'SYS' }); | ||
assert.deepEqual(parseAssetSymbol('4,SYS'), { precision: 4, symbol: 'SYS' }); | ||
@@ -253,9 +250,9 @@ assert.throws(function () { | ||
assert.throws(function () { | ||
return parseAssetSymbol('4,SYM,2', 2); | ||
return parseAssetSymbol('4,SYS,2', 2); | ||
}, /precision like this/); | ||
assert.throws(function () { | ||
return parseAssetSymbol('4,SYM', 2); | ||
return parseAssetSymbol('4,SYS', 2); | ||
}, /Asset symbol precision mismatch/); | ||
assert.throws(function () { | ||
return parseAssetSymbol('-2,SYM'); | ||
return parseAssetSymbol('-2,SYS'); | ||
}, /precision must be positive/); | ||
@@ -266,3 +263,3 @@ assert.throws(function () { | ||
assert.throws(function () { | ||
return parseAssetSymbol('19,SYM'); | ||
return parseAssetSymbol('19,SYS'); | ||
}, /18 characters or less/); | ||
@@ -269,0 +266,0 @@ assert.throws(function () { |
@@ -150,3 +150,3 @@ 'use strict'; | ||
// | ||
// const wast = fs.readFileSync(`docker/contracts/${contract}/${contract}.wast`) | ||
// const wasm = fs.readFileSync(`docker/contracts/${contract}/${contract}.wasm`) | ||
// const abi = fs.readFileSync(`docker/contracts/${contract}/${contract}.abi`) | ||
@@ -157,3 +157,3 @@ // | ||
// // TODO: undeploy contract instead | ||
// await eos.setcode(account, 0, 0, wast) | ||
// await eos.setcode(account, 0, 0, wasm) | ||
// await eos.setabi(account, JSON.parse(abi)) | ||
@@ -559,3 +559,3 @@ | ||
// ./eosioc set contract currency build/contracts/currency/currency.wast build/contracts/currency/currency.abi | ||
// ./eosioc set contract currency build/contracts/currency/currency.wasm build/contracts/currency/currency.abi | ||
it('Transaction ABI lookup', function _callee6() { | ||
@@ -562,0 +562,0 @@ var eos, tx; |
@@ -13,3 +13,2 @@ { | ||
"permission_name": "name", | ||
"field_name": "string", | ||
"type_name": "string", | ||
@@ -20,3 +19,2 @@ "token_name": "name", | ||
"action_name": "name", | ||
"context_free_type": "bytes", | ||
"time_point": "int64", | ||
@@ -73,9 +71,2 @@ "time_point_sec": "time", | ||
}, | ||
"clause_pair": { | ||
"base": "", | ||
"fields": { | ||
"id": "string", | ||
"body": "string" | ||
} | ||
}, | ||
"fields": "field_def[]", | ||
@@ -149,7 +140,7 @@ "field_def": { | ||
"fields": { | ||
"version": "string", | ||
"types": "type_def[]", | ||
"structs": "struct_def[]", | ||
"actions": "action_def[]", | ||
"tables": "table_def[]", | ||
"ricardian_clauses": "clause_pair[]" | ||
"tables": "table_def[]" | ||
} | ||
@@ -156,0 +147,0 @@ }, |
'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _require = require('eosjs-ecc'), | ||
@@ -97,11 +97,17 @@ Signature = _require.Signature, | ||
}, | ||
symbol: function symbol() { | ||
return [AssetSymbol(assetCache)]; | ||
return [_Symbol(assetCache)]; | ||
}, | ||
extended_symbol: function extended_symbol() { | ||
return [ExtendedSymbol(assetCache)]; | ||
}, | ||
asset: function asset() { | ||
return [Asset(assetCache)]; | ||
}, // must come after AssetSymbol | ||
}, // After Symbol: amount, precision, symbol, contract | ||
extended_asset: function extended_asset() { | ||
return [ExtendedAsset]; | ||
}, // after Asset | ||
return [ExtendedAsset(assetCache)]; | ||
}, // After Asset: amount, precision, symbol, contract | ||
signature: function signature() { | ||
@@ -243,7 +249,9 @@ return [variant(SignatureType)]; | ||
function precisionCache(assetCache, sym) { | ||
var account = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : currentAccount; | ||
var assetSymbol = parseAssetSymbol(sym); | ||
var precision = assetSymbol.precision; | ||
if (currentAccount) { | ||
var asset = assetCache.lookup(assetSymbol.symbol, currentAccount); | ||
if (account) { | ||
var asset = assetCache.lookup(assetSymbol.symbol, account); | ||
if (asset) { | ||
@@ -253,7 +261,7 @@ if (precision == null) { | ||
} else { | ||
assert.equal(asset.precision, precision, 'Precision mismatch for asset: ' + sym + '@' + currentAccount); | ||
assert.equal(asset.precision, precision, 'Precision mismatch for asset: ' + sym + '@' + account); | ||
} | ||
} else { | ||
// Lookup data for later (appendByteBuffer needs it) | ||
assetCache.lookupAsync(assetSymbol.symbol, currentAccount); | ||
assetCache.lookupAsync(assetSymbol.symbol, account); | ||
} | ||
@@ -264,3 +272,8 @@ } | ||
var AssetSymbol = function AssetSymbol(assetCache) { | ||
/** | ||
Internal: precision, symbol | ||
External: symbol | ||
@example 'SYS' | ||
*/ | ||
var _Symbol = function _Symbol(assetCache) { | ||
return function (validation) { | ||
@@ -317,2 +330,4 @@ return { | ||
fromObject: function fromObject(value) { | ||
assert(value != null, 'Symbol is required: ' + value); | ||
var _precisionCache2 = precisionCache(assetCache, value), | ||
@@ -340,35 +355,92 @@ symbol = _precisionCache2.symbol, | ||
/** @example '0.0001 CUR' */ | ||
var Asset = function Asset(assetCache) { | ||
/** | ||
Internal: precision, symbol, contract | ||
External: symbol, contract | ||
@example 'SYS@contract' | ||
*/ | ||
var ExtendedSymbol = function ExtendedSymbol(assetCache) { | ||
return function (validation, baseTypes, customTypes) { | ||
var amountType = baseTypes.int64(validation); | ||
var symbolType = customTypes.symbol(validation); | ||
var contractName = customTypes.name(validation); | ||
function toAssetString(value) { | ||
if (typeof value === 'string') { | ||
var _value$split = value.split(' '), | ||
return { | ||
fromByteBuffer: function fromByteBuffer(b) { | ||
var symbol = symbolType.fromByteBuffer(b); | ||
var contract = contractName.fromByteBuffer(b); | ||
return symbol + '@' + contract; | ||
}, | ||
appendByteBuffer: function appendByteBuffer(b, value) { | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'Invalid extended symbol: ' + value); | ||
var _value$split = value.split('@'), | ||
_value$split2 = _slicedToArray(_value$split, 2), | ||
amount = _value$split2[0], | ||
sym = _value$split2[1]; | ||
symbol = _value$split2[0], | ||
contract = _value$split2[1]; | ||
var _precisionCache3 = precisionCache(assetCache, sym), | ||
precision = _precisionCache3.precision, | ||
symbol = _precisionCache3.symbol; | ||
assert(contract != null, 'Missing @contract suffix in extended symbol: ' + value); | ||
if (precision == null) { | ||
return value; | ||
symbolType.appendByteBuffer(b, symbol); | ||
contractName.appendByteBuffer(b, contract); | ||
}, | ||
fromObject: function fromObject(value) { | ||
return value; | ||
}, | ||
toObject: function toObject(value) { | ||
if (validation.defaults && value == null) { | ||
return '4,SYS@contract'; | ||
} | ||
return UDecimalPad(amount, precision) + ' ' + symbol; | ||
return value; | ||
} | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
var _precisionCache4 = precisionCache(assetCache, value.symbol), | ||
_precision = _precisionCache4.precision, | ||
_symbol = _precisionCache4.symbol; | ||
}; | ||
}; | ||
}; | ||
assert(_precision != null, 'Precision unknown for asset: ' + _symbol + '@' + currentAccount); | ||
return UDecimalUnimply(value.amount, _precision) + ' ' + _symbol; | ||
} | ||
return value; | ||
} | ||
function toAssetString(value, assetCache) { | ||
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; | ||
var defaultContract = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'expecting asset string, got ' + (typeof value === 'undefined' ? 'undefined' : _typeof(value))); | ||
var _value$split3 = value.split(' '), | ||
_value$split4 = _slicedToArray(_value$split3, 2), | ||
amount = _value$split4[0], | ||
sym = _value$split4[1]; | ||
var _sym$split = sym.split('@'), | ||
_sym$split2 = _slicedToArray(_sym$split, 2), | ||
asset = _sym$split2[0], | ||
_sym$split2$ = _sym$split2[1], | ||
contract = _sym$split2$ === undefined ? defaultContract : _sym$split2$; | ||
var _precisionCache3 = precisionCache(assetCache, asset, contract), | ||
precision = _precisionCache3.precision, | ||
symbol = _precisionCache3.symbol; | ||
if (format === 'plain') { | ||
return UDecimalPad(amount, precision) + ' ' + symbol; | ||
} | ||
if (format === 'extended') { | ||
var contractSuffix = contract ? '@' + contract : ''; | ||
return UDecimalPad(amount, precision) + ' ' + symbol + contractSuffix; | ||
} | ||
if (format === 'full') { | ||
var _contractSuffix = contract ? '@' + contract : ''; | ||
var precisionPrefix = precision != null ? precision + ',' : ''; | ||
return UDecimalPad(amount, precision) + ' ' + precisionPrefix + symbol + _contractSuffix; | ||
} | ||
assert(false, 'format should be: plain, extended, or full'); | ||
} | ||
/** | ||
Internal: amount, precision, symbol, contract | ||
@example '1.0000 SYS' | ||
*/ | ||
var Asset = function Asset(assetCache) { | ||
return function (validation, baseTypes, customTypes) { | ||
var amountType = baseTypes.int64(validation); | ||
var symbolType = customTypes.symbol(validation); | ||
return { | ||
@@ -379,24 +451,30 @@ fromByteBuffer: function fromByteBuffer(b) { | ||
var _precisionCache5 = precisionCache(assetCache, sym), | ||
precision = _precisionCache5.precision; | ||
var _precisionCache4 = precisionCache(assetCache, sym), | ||
precision = _precisionCache4.precision; | ||
return UDecimalUnimply(amount, precision) + ' ' + sym; | ||
return toAssetString(UDecimalUnimply(amount, precision) + ' ' + sym, assetCache, 'full', currentAccount); | ||
}, | ||
appendByteBuffer: function appendByteBuffer(b, value) { | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'expecting string, got ' + (typeof value === 'undefined' ? 'undefined' : _typeof(value))); | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'expecting asset string, got ' + (typeof value === 'undefined' ? 'undefined' : _typeof(value))); | ||
var _value$split3 = value.split(' '), | ||
_value$split4 = _slicedToArray(_value$split3, 2), | ||
amount = _value$split4[0], | ||
sym = _value$split4[1]; | ||
var _value$split5 = value.split(' '), | ||
_value$split6 = _slicedToArray(_value$split5, 2), | ||
amount = _value$split6[0], | ||
sym = _value$split6[1]; | ||
var _precisionCache6 = precisionCache(assetCache, sym), | ||
precision = _precisionCache6.precision; | ||
var _precisionCache5 = precisionCache(assetCache, sym), | ||
precision = _precisionCache5.precision; | ||
assert(precision != null, 'Precision unknown for asset: ' + sym + '@' + currentAccount); | ||
var _sym$split3 = sym.split('@'), | ||
_sym$split4 = _slicedToArray(_sym$split3, 2), | ||
asset = _sym$split4[0], | ||
contract = _sym$split4[1]; | ||
amountType.appendByteBuffer(b, UDecimalImply(amount, precision)); | ||
symbolType.appendByteBuffer(b, sym); | ||
symbolType.appendByteBuffer(b, asset); | ||
}, | ||
fromObject: function fromObject(value) { | ||
return toAssetString(value); | ||
return toAssetString(value, assetCache, 'full', currentAccount); | ||
}, | ||
@@ -407,3 +485,3 @@ toObject: function toObject(value) { | ||
} | ||
return toAssetString(value); | ||
return toAssetString(value, assetCache, 'plain', currentAccount); | ||
} | ||
@@ -414,47 +492,42 @@ }; | ||
var ExtendedAsset = function ExtendedAsset(validation, baseTypes, customTypes) { | ||
var assetType = customTypes.asset(validation); | ||
var contractName = customTypes.name(validation); | ||
/** | ||
@example '1.0000 SYS@contract' | ||
*/ | ||
var ExtendedAsset = function ExtendedAsset(assetCache) { | ||
return function (validation, baseTypes, customTypes) { | ||
var assetType = customTypes.asset(validation); | ||
var contractName = customTypes.name(validation); | ||
function toString(value) { | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'extended_asset is expecting a string like: 9.9999 SBL@contract'); | ||
return { | ||
fromByteBuffer: function fromByteBuffer(b) { | ||
var asset = assetType.fromByteBuffer(b); | ||
var contract = contractName.fromByteBuffer(b); | ||
return asset + '@' + contract; | ||
}, | ||
appendByteBuffer: function appendByteBuffer(b, value) { | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'Invalid extended asset: ' + value); | ||
var _value$split5 = value.split('@'), | ||
_value$split6 = _slicedToArray(_value$split5, 2), | ||
asset = _value$split6[0], | ||
_value$split6$ = _value$split6[1], | ||
contract = _value$split6$ === undefined ? 'eosio.token' : _value$split6$; | ||
var _value$split7 = value.split('@'), | ||
_value$split8 = _slicedToArray(_value$split7, 2), | ||
asset = _value$split8[0], | ||
contract = _value$split8[1]; | ||
currentAccount = contract; | ||
return assetType.fromObject(asset) + '@' + contract; | ||
} | ||
assert.equal(typeof contract === 'undefined' ? 'undefined' : _typeof(contract), 'string', 'Invalid extended asset: ' + value); | ||
return { | ||
fromByteBuffer: function fromByteBuffer(b) { | ||
var asset = assetType.fromByteBuffer(b); | ||
var contract = contractName.fromByteBuffer(b); | ||
currentAccount = contract; | ||
return asset + '@' + contract; | ||
}, | ||
appendByteBuffer: function appendByteBuffer(b, value) { | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'value'); | ||
assetType.appendByteBuffer(b, asset); | ||
contractName.appendByteBuffer(b, contract); | ||
}, | ||
fromObject: function fromObject(value) { | ||
// like: 1.0000 SYS@contract or 1 SYS@contract | ||
assert(/^\d+(\.\d+)* [A-Z]+@[a-z0-5]+(\.[a-z0-5]+)*$/.test(value), 'Invalid extended asset: ' + value); | ||
var _value$split7 = value.split('@'), | ||
_value$split8 = _slicedToArray(_value$split7, 2), | ||
asset = _value$split8[0], | ||
contract = _value$split8[1]; | ||
currentAccount = contract; | ||
assetType.appendByteBuffer(b, asset); | ||
contractName.appendByteBuffer(b, contract); | ||
}, | ||
fromObject: function fromObject(value) { | ||
return toString(value); | ||
}, | ||
toObject: function toObject(value) { | ||
if (validation.defaults && value == null) { | ||
return '0.0001 SYS@eosio'; | ||
return toAssetString(value, assetCache, 'full'); | ||
}, | ||
toObject: function toObject(value) { | ||
if (validation.defaults && value == null) { | ||
return '1.0000 SYS@eosio.token'; | ||
} | ||
return toAssetString(value, assetCache, 'extended'); | ||
} | ||
return toString(value); | ||
} | ||
}; | ||
}; | ||
@@ -569,12 +642,18 @@ }; | ||
currentAccount = object.account; | ||
var ser = (object.name || '') == '' ? fields.data : structLookup(object.name, object.account); | ||
if (ser) { | ||
b.readVarint32(); // length prefix (usefull if object.name is unknown) | ||
object.data = ser.fromByteBuffer(b, config); | ||
} else { | ||
// console.log(`Unknown Action.name ${object.name}`) | ||
var lenPrefix = b.readVarint32(); | ||
var bCopy = b.copy(b.offset, b.offset + lenPrefix); | ||
b.skip(lenPrefix); | ||
object.data = Buffer.from(bCopy.toBinary(), 'binary'); | ||
try { | ||
var ser = (object.name || '') == '' ? fields.data : structLookup(object.name, object.account); | ||
if (ser) { | ||
b.readVarint32(); // length prefix (usefull if object.name is unknown) | ||
object.data = ser.fromByteBuffer(b, config); | ||
} else { | ||
// console.log(`Unknown Action.name ${object.name}`) | ||
var lenPrefix = b.readVarint32(); | ||
var bCopy = b.copy(b.offset, b.offset + lenPrefix); | ||
b.skip(lenPrefix); | ||
object.data = Buffer.from(bCopy.toBinary(), 'binary'); | ||
} | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
currentAccount = null; | ||
} | ||
@@ -589,16 +668,22 @@ }, | ||
currentAccount = object.account; | ||
var ser = (object.name || '') == '' ? fields.data : structLookup(object.name, object.account); | ||
if (ser) { | ||
var b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN); | ||
ser.appendByteBuffer(b2, object.data); | ||
b.writeVarint32(b2.offset); | ||
b.append(b2.copy(0, b2.offset), 'binary'); | ||
} else { | ||
// console.log(`Unknown Action.name ${object.name}`) | ||
var data = typeof object.data === 'string' ? new Buffer(object.data, 'hex') : object.data; | ||
if (!Buffer.isBuffer(data)) { | ||
throw new TypeError('Unknown struct \'' + object.name + '\' for contract \'' + object.account + '\', locate this struct or provide serialized action.data'); | ||
try { | ||
var ser = (object.name || '') == '' ? fields.data : structLookup(object.name, object.account); | ||
if (ser) { | ||
var b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN); | ||
ser.appendByteBuffer(b2, object.data); | ||
b.writeVarint32(b2.offset); | ||
b.append(b2.copy(0, b2.offset), 'binary'); | ||
} else { | ||
// console.log(`Unknown Action.name ${object.name}`) | ||
var data = typeof object.data === 'string' ? new Buffer(object.data, 'hex') : object.data; | ||
if (!Buffer.isBuffer(data)) { | ||
throw new TypeError('Unknown struct \'' + object.name + '\' for contract \'' + object.account + '\', locate this struct or provide serialized action.data'); | ||
} | ||
b.writeVarint32(data.length); | ||
b.append(data.toString('binary'), 'binary'); | ||
} | ||
b.writeVarint32(data.length); | ||
b.append(data.toString('binary'), 'binary'); | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
currentAccount = null; | ||
} | ||
@@ -615,17 +700,22 @@ }, | ||
currentAccount = object.account; | ||
var ser = (name || '') == '' ? fields.data : structLookup(name, object.account); | ||
if (ser) { | ||
if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
result.data = ser.fromObject(data); // resolve shorthand | ||
return; | ||
} else if (typeof data === 'string') { | ||
var buf = new Buffer(data, 'hex'); | ||
result.data = Fcbuffer.fromBuffer(ser, buf); | ||
try { | ||
var ser = (name || '') == '' ? fields.data : structLookup(name, object.account); | ||
if (ser) { | ||
if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
result.data = ser.fromObject(data); // resolve shorthand | ||
return; | ||
} else if (typeof data === 'string') { | ||
var buf = new Buffer(data, 'hex'); | ||
result.data = Fcbuffer.fromBuffer(ser, buf); | ||
} else { | ||
throw new TypeError('Expecting hex string or object in action.data'); | ||
} | ||
} else { | ||
throw new TypeError('Expecting hex string or object in action.data'); | ||
// console.log(`Unknown Action.name ${object.name}`) | ||
result.data = data; | ||
} | ||
} else { | ||
// console.log(`Unknown Action.name ${object.name}`) | ||
result.data = data; | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
currentAccount = null; | ||
} | ||
@@ -646,30 +736,35 @@ }, | ||
currentAccount = object.account; | ||
try { | ||
var ser = (name || '') == '' ? fields.data : structLookup(name, object.account); | ||
if (!ser) { | ||
// Types without an ABI will accept hex | ||
// const b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN) | ||
// const buf = !Buffer.isBuffer(data) ? new Buffer(data, 'hex') : data | ||
// b2.writeVarint32(buf.length) | ||
// b2.append(buf) | ||
// result.data = b2.copy(0, b2.offset).toString('hex') | ||
result.data = Buffer.isBuffer(data) ? data.toString('hex') : data; | ||
return; | ||
} | ||
var ser = (name || '') == '' ? fields.data : structLookup(name, object.account); | ||
if (!ser) { | ||
// Types without an ABI will accept hex | ||
// const b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN) | ||
// const buf = !Buffer.isBuffer(data) ? new Buffer(data, 'hex') : data | ||
// b2.writeVarint32(buf.length) | ||
// b2.append(buf) | ||
// result.data = b2.copy(0, b2.offset).toString('hex') | ||
result.data = Buffer.isBuffer(data) ? data.toString('hex') : data; | ||
return; | ||
} | ||
if (forceActionDataHex) { | ||
var b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN); | ||
if (data) { | ||
ser.appendByteBuffer(b2, data); | ||
} | ||
result.data = b2.copy(0, b2.offset).toString('hex'); | ||
if (forceActionDataHex) { | ||
var b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN); | ||
if (data) { | ||
ser.appendByteBuffer(b2, data); | ||
// console.log('result.data', result.data) | ||
return; | ||
} | ||
result.data = b2.copy(0, b2.offset).toString('hex'); | ||
// console.log('result.data', result.data) | ||
return; | ||
// Serializable JSON | ||
result.data = ser.toObject(data, config); | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
currentAccount = null; | ||
} | ||
// Serializable JSON | ||
result.data = ser.toObject(data, config); | ||
} | ||
}; | ||
}; |
@@ -6,22 +6,9 @@ 'use strict'; | ||
var Fcbuffer = require('fcbuffer'); | ||
var ByteBuffer = require('bytebuffer'); | ||
var Eos = require('.'); | ||
var AssetCache = require('./asset-cache'); | ||
describe('shorthand', function () { | ||
it('asset', function () { | ||
var eos = Eos.Localnet(); | ||
var types = eos.fc.types; | ||
var AssetType = types.asset(); | ||
assertSerializer(AssetType, '1.0000 SYS'); | ||
var obj = AssetType.fromObject('1 SYS'); | ||
assert.equal(obj, '1.0000 SYS'); | ||
var obj2 = AssetType.fromObject({ amount: 10000, symbol: 'SYS' }); | ||
assert.equal(obj, '1.0000 SYS'); | ||
}); | ||
it('authority', function () { | ||
@@ -66,21 +53,31 @@ var eos = Eos.Localnet(); | ||
it('extended_asset', function () { | ||
it('symbol', function () { | ||
var eos = Eos.Localnet(); | ||
var types = eos.fc.types; | ||
var _Symbol = types.symbol(); | ||
assertSerializer(_Symbol, '4,SYS', '4,SYS', 'SYS'); | ||
}); | ||
it('extended_symbol', function () { | ||
var eos = Eos.Localnet({ defaults: true }); | ||
var eaType = eos.fc.types.extended_asset(); | ||
var eaString = eaType.toObject(); | ||
assertSerializer(eaType, eaString); | ||
assert.equal(eaType.toObject('1 SYS'), '1.0000 SYS@eosio.token'); | ||
var esType = eos.fc.types.extended_symbol(); | ||
var esString = esType.toObject(); | ||
assertSerializer(esType, esString); | ||
}); | ||
it('symbol', function () { | ||
it('asset', function () { | ||
var eos = Eos.Localnet(); | ||
var types = eos.fc.types; | ||
var ExtendedAssetType = types.extended_asset(); | ||
var AssetType = types.asset(); | ||
assertSerializer(AssetType, '1.1 4,SYS@eosio.token', '1.1000 SYS@eosio.token', '1.1000 SYS'); | ||
}); | ||
assertSerializer(ExtendedAssetType, '1.0000 SYS@eosio.token'); | ||
// const obj = AssetSymbolType.fromObject('1.000 SYS@eosio.token') | ||
// const buf = Fcbuffer.toBuffer(AssetSymbolType, obj) | ||
// assert.equal(buf.toString('hex'), '04454f5300000000') | ||
it('extended_asset', function () { | ||
var eos = Eos.Localnet({ defaults: true }); | ||
var eaType = eos.fc.types.extended_asset(); | ||
var eaString = eaType.toObject(); | ||
assertSerializer(eaType, eaString); | ||
}); | ||
@@ -116,3 +113,3 @@ | ||
describe('Message.data', function () { | ||
describe('Action.data', function () { | ||
it('json', function () { | ||
@@ -138,4 +135,4 @@ var eos = Eos.Localnet({ forceActionDataHex: false }); | ||
it('hex', function () { | ||
var eos = Eos.Localnet({ forceActionDataHex: false, debug: false }); | ||
it('force hex', function () { | ||
var eos = Eos.Localnet({ forceActionDataHex: true }); | ||
var _eos$fc3 = eos.fc, | ||
@@ -145,37 +142,9 @@ structs = _eos$fc3.structs, | ||
var tr = { from: 'inita', to: 'initb', quantity: '1.0000 SYS', memo: '' }; | ||
var hex = Fcbuffer.toBuffer(structs.transfer, tr).toString('hex'); | ||
// const lenPrefixHex = Number(hex.length / 2).toString(16) + hex.toString('hex') | ||
var value = { | ||
account: 'eosio.token', | ||
name: 'transfer', | ||
data: hex, | ||
authorization: [] | ||
}; | ||
var type = structs.action; | ||
var obj = type.fromObject(value); // tests fromObject | ||
var buf = Fcbuffer.toBuffer(type, obj); // tests appendByteBuffer | ||
var obj2 = Fcbuffer.fromBuffer(type, buf); // tests fromByteBuffer | ||
var obj3 = type.toObject(obj); // tests toObject | ||
assert.deepEqual(Object.assign({}, value, { data: tr }), obj3, 'serialize object'); | ||
assert.deepEqual(obj3, obj2, 'serialize buffer'); | ||
}); | ||
it('force hex', function () { | ||
var eos = Eos.Localnet({ forceActionDataHex: true }); | ||
var _eos$fc4 = eos.fc, | ||
structs = _eos$fc4.structs, | ||
types = _eos$fc4.types; | ||
var value = { | ||
account: 'eosio.token', | ||
name: 'transfer', | ||
data: { | ||
from: 'inita', | ||
to: 'initb', | ||
quantity: '1 SYS', | ||
quantity: '1.0000 SYS', | ||
memo: '' | ||
@@ -185,14 +154,3 @@ }, | ||
}; | ||
var type = structs.action; | ||
var obj = type.fromObject(value); // tests fromObject | ||
var buf = Fcbuffer.toBuffer(type, obj); // tests appendByteBuffer | ||
var obj2 = Fcbuffer.fromBuffer(type, buf); // tests fromByteBuffer | ||
var obj3 = type.toObject(obj); // tests toObject | ||
var data = Fcbuffer.toBuffer(structs.transfer, value.data); | ||
var dataHex = //Number(data.length).toString(16) + | ||
data.toString('hex'); | ||
assert.deepEqual(Object.assign({}, value, { data: dataHex }), obj3, 'serialize object'); | ||
assert.deepEqual(obj3, obj2, 'serialize buffer'); | ||
assertSerializer(structs.action, value, value); | ||
}); | ||
@@ -202,5 +160,5 @@ | ||
var eos = Eos.Localnet({ forceActionDataHex: false }); | ||
var _eos$fc5 = eos.fc, | ||
structs = _eos$fc5.structs, | ||
types = _eos$fc5.types; | ||
var _eos$fc4 = eos.fc, | ||
structs = _eos$fc4.structs, | ||
types = _eos$fc4.types; | ||
@@ -218,9 +176,24 @@ var value = { | ||
function assertSerializer(type, value) { | ||
var fromObjectResult = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var toObjectResult = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : fromObjectResult; | ||
var obj = type.fromObject(value); // tests fromObject | ||
var buf = Fcbuffer.toBuffer(type, obj); // tests appendByteBuffer | ||
var buf = Fcbuffer.toBuffer(type, value); // tests appendByteBuffer | ||
var obj2 = Fcbuffer.fromBuffer(type, buf); // tests fromByteBuffer | ||
var obj3 = type.toObject(obj); // tests toObject | ||
assert.deepEqual(value, obj3, 'serialize object'); | ||
assert.deepEqual(obj3, obj2, 'serialize buffer'); | ||
if (!fromObjectResult && !toObjectResult) { | ||
assert.deepEqual(value, obj3, 'serialize object'); | ||
assert.deepEqual(obj3, obj2, 'serialize buffer'); | ||
return; | ||
} | ||
if (fromObjectResult) { | ||
assert(fromObjectResult, obj, 'fromObjectResult'); | ||
assert(fromObjectResult, obj2, 'fromObjectResult'); | ||
} | ||
if (toObjectResult) { | ||
assert(toObjectResult, obj3, 'toObjectResult'); | ||
} | ||
} |
@@ -607,6 +607,3 @@ 'use strict'; | ||
// console.log('rawTx', JSON.stringify(rawTx,null,4)) | ||
// resolve shorthand | ||
// const txObject = Transaction.toObject(Transaction.fromObject(rawTx)) | ||
txObject = Transaction.fromObject(rawTx); | ||
@@ -620,14 +617,4 @@ | ||
case 9: | ||
// if(txObject.context_free_cpu_bandwidth == null) { | ||
// // number of CPU usage units to bill transaction for | ||
// // eosiod getCpuEstimate does not exist, it will probably have another name | ||
// txObject.context_free_cpu_bandwidth = await eos.getCpuEstimate(txObject) | ||
// } | ||
// console.log('txObject', JSON.stringify(txObject,null,4)) | ||
// Broadcast what is signed (instead of rawTx) | ||
buf = Fcbuffer.toBuffer(Transaction, txObject); | ||
tr = Fcbuffer.fromBuffer(Transaction, buf); | ||
tr = Transaction.toObject(txObject); | ||
transactionId = createHash('sha256').update(buf).digest().toString('hex'); | ||
@@ -648,8 +635,7 @@ sigs = []; | ||
Promise.all(sigs).then(function (sigs) { | ||
sigs = [].concat.apply([], sigs); //flatten arrays in array | ||
// tr.signatures = sigs // replaced by packedTr | ||
sigs = [].concat.apply([], sigs); // flatten arrays in array | ||
for (var i = 0; i < sigs.length; i++) { | ||
var sig = sigs[i]; | ||
// convert from hex to base58 format | ||
// normalize (hex to base58 format for example) | ||
if (typeof sig === 'string' && sig.length === 130) { | ||
@@ -794,3 +780,5 @@ sigs[i] = ecc.Signature.from(sig).toString(); | ||
} else { | ||
parrentRes(result); | ||
Promise.resolve(parrentRes(result)).catch(function (error) { | ||
parentErr(error); | ||
}); | ||
} | ||
@@ -797,0 +785,0 @@ }; |
{ | ||
"name": "eosjs", | ||
"version": "12.0.1", | ||
"version": "12.0.2", | ||
"description": "General purpose library for the EOS blockchain.", | ||
@@ -50,3 +50,3 @@ "main": "lib/index.js", | ||
"eosjs-api": "^6.0.1", | ||
"eosjs-ecc": "^4.0.0", | ||
"eosjs-ecc": "^4.0.1", | ||
"fcbuffer": "^2.2.0" | ||
@@ -53,0 +53,0 @@ }, |
@@ -139,3 +139,3 @@ [](https://travis-ci.org/EOSIO/eosjs) | ||
* owner: `'EOS6MRy..'` is shorthand for `{threshold: 1, keys: [key: 'EOS6MRy..', weight: 1]}` | ||
* active: `inita` or `inita@active` is shorthand for | ||
* active: `inita` or `inita@active` is shorthand for | ||
* `{{threshold: 1, accounts: [..actor: inita, permission: active, weight: 1]}}` | ||
@@ -148,7 +148,6 @@ * `inita@other` would replace the permission `active` with `other` | ||
initaPrivate = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' | ||
initaPublic = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV' | ||
keyProvider = initaPrivate | ||
wif = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' | ||
pubkey = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV' | ||
eos = Eos.Localnet({keyProvider}) | ||
eos = Eos.Localnet({keyProvider: wif}) | ||
@@ -158,3 +157,3 @@ eos.transaction(tr => { | ||
creator: 'inita', | ||
'mycontract11', | ||
name: 'mycontract11', | ||
owner: pubkey, | ||
@@ -208,13 +207,5 @@ active: pubkey | ||
Eos = require('eosjs') // Eos = require('./src') | ||
let {ecc} = Eos.modules | ||
initaPrivate = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' | ||
keyProvider = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' | ||
// New deterministic key for the currency account. Only use a simple | ||
// seedPrivate in production if you want to give away money. | ||
currencyPrivate = ecc.seedPrivate('currency') | ||
currencyPublic = ecc.privateToPublic(currencyPrivate) | ||
keyProvider = [initaPrivate, currencyPrivate] | ||
// Requires a large library, separate from the eosjs bundle | ||
@@ -226,23 +217,13 @@ // $ npm install binaryen@37.0.0 | ||
eos.newaccount({ | ||
creator: 'inita', | ||
name: 'currency', | ||
owner: currencyPublic, | ||
active: currencyPublic | ||
}) | ||
wast = fs.readFileSync(`docker/contracts/eosio.token/eosio.token.wast`) | ||
wasm = fs.readFileSync(`docker/contracts/eosio.token/eosio.token.wasm`) | ||
abi = fs.readFileSync(`docker/contracts/eosio.token/eosio.token.abi`) | ||
// Publish contract to the blockchain | ||
eos.setcode('currency', 0, 0, wast) | ||
eos.setabi('currency', JSON.parse(abi)) | ||
eos.setcode('inita', 0, 0, wasm) | ||
eos.setabi('inita', JSON.parse(abi)) | ||
currency = null | ||
// eos.contract(account<string>, [options], [callback]) | ||
eos.contract('currency').then(c => currency = c) | ||
eos.contract('inita').then(c => inita = c) | ||
// Issue is one of the actions in currency.abi | ||
currency.issue('inita', '1000.0000 CUR', {authorization: 'currency'}) | ||
inita.create('inita', '1000.0000 CUR', {authorization: 'inita'}) | ||
``` | ||
@@ -249,0 +230,0 @@ |
153456
3843
401
Updatedeosjs-ecc@^4.0.1