Comparing version 14.1.1 to 14.2.0
@@ -25,2 +25,4 @@ 'use strict'; | ||
} | ||
assert(network, 'Network is required, provide config.httpEndpoint'); | ||
return network.getCode(account).then(function (_ref) { | ||
@@ -27,0 +29,0 @@ var abi = _ref.abi; |
'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 _regenerator = require('babel-runtime/regenerator'); | ||
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 _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var assert = require('assert'); | ||
@@ -25,17 +35,18 @@ var Structs = require('./structs'); | ||
if (contract === 'eosio') { | ||
contract = 'eosio.token'; | ||
} | ||
// if(contract === 'eosio') { | ||
// contract = 'eosio.token' | ||
// } | ||
var extendedAsset = symbol + '@' + contract; | ||
var extendedSymbol = symbol + '@' + contract; | ||
if (cache[extendedAsset] != null) { | ||
return Promise.resolve(cache[extendedAsset]); | ||
if (cache[extendedSymbol] != null) { | ||
return Promise.resolve(cache[extendedSymbol]); | ||
} | ||
assert(network, 'Network is required, provide config.httpEndpoint'); | ||
var statsPromise = network.getCurrencyStats(contract, symbol).then(function (result) { | ||
var stats = result[symbol]; | ||
if (!stats) { | ||
cache[extendedAsset] = null; // retry (null means no asset was observed) | ||
// console.log(`Missing currency stats for asset: ${extendedAsset}`) | ||
cache[extendedSymbol] = null; // retry (null means no asset was observed) | ||
// console.log(`Missing currency stats for asset: ${extendedSymbol}`) | ||
return; | ||
@@ -47,3 +58,3 @@ } | ||
assert.equal(typeof max_supply === 'undefined' ? 'undefined' : _typeof(max_supply), 'string', 'Expecting max_supply string in currency stats: ' + result); | ||
assert.equal(typeof max_supply === 'undefined' ? 'undefined' : (0, _typeof3.default)(max_supply), 'string', 'Expecting max_supply string in currency stats: ' + result); | ||
@@ -53,7 +64,7 @@ assert(new RegExp('^[0-9]+(.[0-9]+)? ' + symbol + '$').test(max_supply), 'Expecting max_supply string like 10000.0000 SYS, instead got: ' + max_supply); | ||
var _max_supply$split = max_supply.split(' '), | ||
_max_supply$split2 = _slicedToArray(_max_supply$split, 1), | ||
_max_supply$split2 = (0, _slicedToArray3.default)(_max_supply$split, 1), | ||
supply = _max_supply$split2[0]; | ||
var _supply$split = supply.split('.'), | ||
_supply$split2 = _slicedToArray(_supply$split, 2), | ||
_supply$split2 = (0, _slicedToArray3.default)(_supply$split, 2), | ||
_supply$split2$ = _supply$split2[1], | ||
@@ -66,3 +77,3 @@ decimalstr = _supply$split2$ === undefined ? '' : _supply$split2$; | ||
return cache[extendedAsset] = { precision: precision }; | ||
return cache[extendedSymbol] = { precision: precision }; | ||
}); | ||
@@ -72,3 +83,3 @@ | ||
return cache[extendedAsset] = statsPromise; | ||
return cache[extendedSymbol] = statsPromise; | ||
} | ||
@@ -84,9 +95,9 @@ | ||
if (contract === 'eosio') { | ||
contract = 'eosio.token'; | ||
} | ||
// if(contract === 'eosio') { | ||
// contract = 'eosio.token' | ||
// } | ||
var extendedAsset = symbol + '@' + contract; | ||
var extendedSymbol = symbol + '@' + contract; | ||
var c = cache[extendedAsset]; | ||
var c = cache[extendedSymbol]; | ||
@@ -109,3 +120,3 @@ if (c instanceof Promise) { | ||
AssetCache.resolve = function _callee() { | ||
return regeneratorRuntime.async(function _callee$(_context) { | ||
return _regenerator2.default.async(function _callee$(_context) { | ||
while (1) { | ||
@@ -115,3 +126,3 @@ switch (_context.prev = _context.next) { | ||
_context.next = 2; | ||
return regeneratorRuntime.awrap(Promise.all(promises)); | ||
return _regenerator2.default.awrap(Promise.all(promises)); | ||
@@ -118,0 +129,0 @@ case 2: |
'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 _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
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 _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var assert = require('assert'); | ||
@@ -311,3 +317,3 @@ | ||
assert.equal(typeof symbol === 'undefined' ? 'undefined' : _typeof(symbol), 'string', 'symbol is a required string'); | ||
assert.equal(typeof symbol === 'undefined' ? 'undefined' : (0, _typeof3.default)(symbol), 'string', 'symbol is a required string'); | ||
@@ -333,3 +339,3 @@ var join = function join(e1, e2) { | ||
var _str$split = str.split(' '), | ||
_str$split2 = _slicedToArray(_str$split, 1), | ||
_str$split2 = (0, _slicedToArray3.default)(_str$split, 1), | ||
amountRaw = _str$split2[0]; | ||
@@ -347,3 +353,3 @@ | ||
var _str$split3 = str.split('@'), | ||
_str$split4 = _slicedToArray(_str$split3, 2), | ||
_str$split4 = (0, _slicedToArray3.default)(_str$split3, 2), | ||
contractRaw = _str$split4[1]; | ||
@@ -350,0 +356,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 _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint-env mocha */ | ||
@@ -248,3 +252,3 @@ var assert = require('assert'); | ||
for (var _iterator7 = parseExtendedAssets[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { | ||
var _step7$value = _slicedToArray(_step7.value, 5), | ||
var _step7$value = (0, _slicedToArray3.default)(_step7.value, 5), | ||
str = _step7$value[0], | ||
@@ -251,0 +255,0 @@ amount = _step7$value[1], |
238
lib/index.js
'use strict'; | ||
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 _regenerator = require('babel-runtime/regenerator'); | ||
try { | ||
require("babel-polyfill"); | ||
} catch (e) { | ||
if (e.message.indexOf('only one instance of babel-polyfill is allowed') === -1) { | ||
console.error(e); | ||
} | ||
} | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var ecc = require('eosjs-ecc'); | ||
@@ -26,14 +26,20 @@ var Fcbuffer = require('fcbuffer'); | ||
var configDefaults = { | ||
broadcast: true, | ||
debug: false, | ||
sign: true | ||
}; | ||
var Eos = function Eos() { | ||
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return createEos(Object.assign({}, { | ||
apiLog: consoleObjCallbackLog(config.verbose), | ||
transactionLog: consoleObjCallbackLog(config.verbose) | ||
}, configDefaults, config)); | ||
config = Object.assign({}, { | ||
httpEndpoint: 'http://127.0.0.1:8888', | ||
debug: false, | ||
verbose: false, | ||
broadcast: true, | ||
sign: true | ||
}, config); | ||
var defaultLogger = { | ||
log: config.verbose ? console.log : null, | ||
error: console.error | ||
}; | ||
config.logger = Object.assign({}, defaultLogger, config.logger); | ||
return createEos(config); | ||
}; | ||
@@ -70,3 +76,3 @@ | ||
function createEos(config) { | ||
var network = EosApi(config); | ||
var network = config.httpEndpoint != null ? EosApi(config) : null; | ||
config.network = network; | ||
@@ -81,3 +87,5 @@ | ||
checkChainId(network, config.chainId); | ||
if (network) { | ||
checkChainId(network, config.chainId, config.logger); | ||
} | ||
@@ -91,3 +99,3 @@ if (config.mockTransactions != null) { | ||
} | ||
assert.equal(_typeof(config.mockTransactions), 'function', 'config.mockTransactions'); | ||
assert.equal((0, _typeof3.default)(config.mockTransactions), 'function', 'config.mockTransactions'); | ||
} | ||
@@ -117,20 +125,2 @@ | ||
function consoleObjCallbackLog() { | ||
var verbose = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
return function (error, result, name) { | ||
if (error) { | ||
if (name) { | ||
console.error(name, 'error'); | ||
} | ||
console.error(error); | ||
} else if (verbose) { | ||
if (name) { | ||
console.log(name, 'reply:'); | ||
} | ||
console.log(JSON.stringify(result, null, 4)); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -146,3 +136,2 @@ Merge in write functions (operations). Tested against existing methods for | ||
function mergeWriteFunctions(config, EosApi, structs) { | ||
assert(config.network, 'network instance required'); | ||
var network = config.network; | ||
@@ -182,5 +171,5 @@ | ||
var keyProvider, keys, pvt, keyMap, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, key, isPrivate, isPublic, pubkeys; | ||
var keyProvider, keys, pvt, sigs, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, key, keyMap, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _key, isPrivate, isPublic, pubkeys; | ||
return regeneratorRuntime.async(function _callee$(_context) { | ||
return _regenerator2.default.async(function _callee$(_context) { | ||
while (1) { | ||
@@ -207,3 +196,3 @@ switch (_context.prev = _context.next) { | ||
_context.next = 7; | ||
return regeneratorRuntime.awrap(Promise.resolve(keys)); | ||
return _regenerator2.default.awrap(Promise.resolve(keys)); | ||
@@ -246,35 +235,30 @@ case 7: | ||
case 15: | ||
keyMap = new Map(); | ||
if (!(config.httpEndpoint == null)) { | ||
_context.next = 37; | ||
break; | ||
} | ||
// keys are either public or private keys | ||
sigs = []; | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context.prev = 19; | ||
_context.prev = 20; | ||
for (_iterator = keys[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
key = _step.value; | ||
isPrivate = key.private != null; | ||
isPublic = key.public != null; | ||
if (isPrivate) { | ||
keyMap.set(ecc.privateToPublic(key.private), key.private); | ||
} else { | ||
keyMap.set(key.public, null); | ||
} | ||
sigs.push(sign(buf, key.private)); | ||
} | ||
_context.next = 27; | ||
_context.next = 28; | ||
break; | ||
case 23: | ||
_context.prev = 23; | ||
_context.t0 = _context['catch'](19); | ||
case 24: | ||
_context.prev = 24; | ||
_context.t0 = _context['catch'](20); | ||
_didIteratorError = true; | ||
_iteratorError = _context.t0; | ||
case 27: | ||
_context.prev = 27; | ||
case 28: | ||
_context.prev = 28; | ||
_context.prev = 29; | ||
@@ -285,7 +269,7 @@ if (!_iteratorNormalCompletion && _iterator.return) { | ||
case 30: | ||
_context.prev = 30; | ||
case 31: | ||
_context.prev = 31; | ||
if (!_didIteratorError) { | ||
_context.next = 33; | ||
_context.next = 34; | ||
break; | ||
@@ -296,9 +280,67 @@ } | ||
case 33: | ||
return _context.finish(30); | ||
case 34: | ||
return _context.finish(27); | ||
return _context.finish(31); | ||
case 35: | ||
return _context.finish(28); | ||
case 36: | ||
return _context.abrupt('return', sigs); | ||
case 37: | ||
keyMap = new Map(); | ||
// keys are either public or private keys | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context.prev = 41; | ||
for (_iterator2 = keys[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
_key = _step2.value; | ||
isPrivate = _key.private != null; | ||
isPublic = _key.public != null; | ||
if (isPrivate) { | ||
keyMap.set(ecc.privateToPublic(_key.private), _key.private); | ||
} else { | ||
keyMap.set(_key.public, null); | ||
} | ||
} | ||
_context.next = 49; | ||
break; | ||
case 45: | ||
_context.prev = 45; | ||
_context.t1 = _context['catch'](41); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context.t1; | ||
case 49: | ||
_context.prev = 49; | ||
_context.prev = 50; | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
case 52: | ||
_context.prev = 52; | ||
if (!_didIteratorError2) { | ||
_context.next = 55; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 55: | ||
return _context.finish(52); | ||
case 56: | ||
return _context.finish(49); | ||
case 57: | ||
pubkeys = Array.from(keyMap.keys()); | ||
@@ -315,9 +357,9 @@ return _context.abrupt('return', eos.getRequiredKeys(transaction, pubkeys).then(function (_ref2) { | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator2 = required_keys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var requiredKey = _step2.value; | ||
for (var _iterator3 = required_keys[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var requiredKey = _step3.value; | ||
@@ -335,12 +377,12 @@ // normalize (EOSKey.. => PUB_K1_Key..) | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
@@ -360,9 +402,9 @@ } | ||
var sigs = []; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
try { | ||
for (var _iterator3 = pvts[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var _pvt = _step3.value; | ||
for (var _iterator4 = pvts[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var _pvt = _step4.value; | ||
@@ -372,12 +414,12 @@ sigs.push(sign(buf, _pvt)); | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
} | ||
@@ -390,3 +432,3 @@ } | ||
case 37: | ||
case 59: | ||
case 'end': | ||
@@ -396,14 +438,18 @@ return _context.stop(); | ||
} | ||
}, null, this, [[19, 23, 27, 35], [28,, 30, 34]]); | ||
}, null, this, [[20, 24, 28, 36], [29,, 31, 35], [41, 45, 49, 57], [50,, 52, 56]]); | ||
}; | ||
}; | ||
function checkChainId(network, chainId) { | ||
function checkChainId(network, chainId, logger) { | ||
network.getInfo({}).then(function (info) { | ||
if (info.chain_id !== chainId) { | ||
console.warn('WARN: chainId mismatch, signatures will not match transaction authority. ' + ('expected ' + chainId + ' !== actual ' + info.chain_id)); | ||
if (logger.error) { | ||
logger.error('chainId mismatch, signatures will not match transaction authority. ' + ('expected ' + chainId + ' !== actual ' + info.chain_id)); | ||
} | ||
} | ||
}).catch(function (error) { | ||
console.error(error); | ||
if (logger.error) { | ||
logger.error(error); | ||
} | ||
}); | ||
} |
'use strict'; | ||
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 _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint-env mocha */ | ||
@@ -25,3 +33,3 @@ var assert = require('assert'); | ||
var headers = { | ||
expiration: new Date().toISOString().split('.')[0], | ||
expiration: new Date().toISOString().split('.')[0], // Don't use `new Date` in production | ||
ref_block_num: 1, | ||
@@ -36,28 +44,91 @@ ref_block_prefix: 452435776, | ||
it('transaction', function _callee() { | ||
var privateKey, eos, memo, trx; | ||
return regeneratorRuntime.async(function _callee$(_context) { | ||
var transactionHeaders = function transactionHeaders(expireInSeconds, callback) { | ||
callback(null /*error*/, headers); | ||
}; | ||
it('multi-signature', function _callee() { | ||
var eos, trx; | ||
return _regenerator2.default.async(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return regeneratorRuntime.awrap(ecc.unsafeRandomKey()); | ||
eos = Eos({ | ||
keyProvider: [ecc.seedPrivate('key1'), ecc.seedPrivate('key2')], | ||
httpEndpoint: null, | ||
transactionHeaders: transactionHeaders | ||
}); | ||
_context.next = 3; | ||
return _regenerator2.default.awrap(eos.nonce(1, { authorization: 'inita' })); | ||
case 2: | ||
privateKey = _context.sent; | ||
case 3: | ||
trx = _context.sent; | ||
assert.equal(trx.transaction.signatures.length, 2, 'signature count'); | ||
case 5: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, null, this); | ||
}); | ||
it('transaction', function _callee2() { | ||
var eos, trx; | ||
return _regenerator2.default.async(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
eos = Eos({ | ||
keyProvider: privateKey, | ||
// httpEndpoint: 'https://doesnotexist.example.org', | ||
transactionHeaders: function transactionHeaders(expireInSeconds, callback) { | ||
callback(null /*error*/, headers); | ||
}, | ||
broadcast: false, | ||
sign: true | ||
keyProvider: wif, | ||
httpEndpoint: null | ||
}); | ||
_context2.next = 3; | ||
return _regenerator2.default.awrap(eos.transaction({ | ||
expiration: new Date().toISOString().split('.')[0], // Don't use `new Date` in production | ||
ref_block_num: 1, | ||
ref_block_prefix: 452435776, | ||
actions: [{ | ||
account: 'eosio.null', | ||
name: 'nonce', | ||
authorization: [{ | ||
actor: 'inita', | ||
permission: 'active' | ||
}], | ||
data: '0131' //hex | ||
}] | ||
})); | ||
case 3: | ||
trx = _context2.sent; | ||
assert.equal(trx.transaction.signatures.length, 1, 'signature count'); | ||
case 5: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, null, this); | ||
}); | ||
it('transactionHeaders callback', function _callee3() { | ||
var eos, memo, trx; | ||
return _regenerator2.default.async(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
eos = Eos({ | ||
keyProvider: wif, | ||
httpEndpoint: null, | ||
transactionHeaders: transactionHeaders | ||
}); | ||
memo = ''; | ||
_context.next = 7; | ||
return regeneratorRuntime.awrap(eos.transfer('bankers', 'people', '1000000 SYS', memo)); | ||
_context3.next = 4; | ||
return _regenerator2.default.awrap(eos.transfer('bankers', 'people', '1000000 SYS', memo)); | ||
case 7: | ||
trx = _context.sent; | ||
case 4: | ||
trx = _context3.sent; | ||
@@ -76,7 +147,7 @@ | ||
assert.equal(trx.transaction.signatures.length, 1, 'expecting 1 signature'); | ||
assert.equal(trx.transaction.signatures.length, 1, 'signature count'); | ||
case 10: | ||
case 7: | ||
case 'end': | ||
return _context.stop(); | ||
return _context3.stop(); | ||
} | ||
@@ -104,12 +175,12 @@ } | ||
describe('Contracts', function () { | ||
it('Messages do not sort', function _callee2() { | ||
it('Messages do not sort', function _callee4() { | ||
var local, opts, tx; | ||
return regeneratorRuntime.async(function _callee2$(_context2) { | ||
return _regenerator2.default.async(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
local = Eos(); | ||
opts = { sign: false, broadcast: false }; | ||
_context2.next = 4; | ||
return regeneratorRuntime.awrap(local.transaction(['currency', 'eosio.token'], function (_ref) { | ||
_context4.next = 4; | ||
return _regenerator2.default.awrap(local.transaction(['currency', 'eosio.token'], function (_ref) { | ||
var currency = _ref.currency, | ||
@@ -126,3 +197,3 @@ eosio_token = _ref.eosio_token; | ||
case 4: | ||
tx = _context2.sent; | ||
tx = _context4.sent; | ||
@@ -134,3 +205,3 @@ assert.equal(tx.transaction.transaction.actions[0].account, 'eosio.token'); | ||
case 'end': | ||
return _context2.stop(); | ||
return _context4.stop(); | ||
} | ||
@@ -146,7 +217,7 @@ } | ||
it('deploy ' + contract + '@' + account, function _callee3() { | ||
it('deploy ' + contract + '@' + account, function _callee5() { | ||
var config, eos, wasm, abi, code, diskAbi; | ||
return regeneratorRuntime.async(function _callee3$(_context3) { | ||
return _regenerator2.default.async(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
@@ -159,15 +230,15 @@ this.timeout(4000); | ||
abi = fs.readFileSync('docker/contracts/' + contract + '/' + contract + '.abi'); | ||
_context3.next = 7; | ||
return regeneratorRuntime.awrap(eos.setcode(account, 0, 0, wasm)); | ||
_context5.next = 7; | ||
return _regenerator2.default.awrap(eos.setcode(account, 0, 0, wasm)); | ||
case 7: | ||
_context3.next = 9; | ||
return regeneratorRuntime.awrap(eos.setabi(account, JSON.parse(abi))); | ||
_context5.next = 9; | ||
return _regenerator2.default.awrap(eos.setabi(account, JSON.parse(abi))); | ||
case 9: | ||
_context3.next = 11; | ||
return regeneratorRuntime.awrap(eos.getCode(account)); | ||
_context5.next = 11; | ||
return _regenerator2.default.awrap(eos.getCode(account)); | ||
case 11: | ||
code = _context3.sent; | ||
code = _context5.sent; | ||
diskAbi = JSON.parse(abi); | ||
@@ -184,3 +255,3 @@ | ||
case 'end': | ||
return _context3.stop(); | ||
return _context5.stop(); | ||
} | ||
@@ -204,14 +275,14 @@ } | ||
function load(name) { | ||
it(name, function _callee4() { | ||
it(name, function _callee6() { | ||
var eos, contract; | ||
return regeneratorRuntime.async(function _callee4$(_context4) { | ||
return _regenerator2.default.async(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
eos = Eos(); | ||
_context4.next = 3; | ||
return regeneratorRuntime.awrap(eos.contract(name)); | ||
_context6.next = 3; | ||
return _regenerator2.default.awrap(eos.contract(name)); | ||
case 3: | ||
contract = _context4.sent; | ||
contract = _context6.sent; | ||
@@ -222,3 +293,3 @@ assert(contract, 'contract'); | ||
case 'end': | ||
return _context4.stop(); | ||
return _context6.stop(); | ||
} | ||
@@ -260,3 +331,3 @@ } | ||
assert.equal(tr.transaction.signatures.length, 1); | ||
assert.equal(_typeof(tr.transaction.signatures[0]), 'string'); | ||
assert.equal((0, _typeof3.default)(tr.transaction.signatures[0]), 'string'); | ||
}); | ||
@@ -276,3 +347,3 @@ }); | ||
assert.equal(tr.transaction.signatures.length, 1); | ||
assert.equal(_typeof(tr.transaction.signatures[0]), 'string'); | ||
assert.equal((0, _typeof3.default)(tr.transaction.signatures[0]), 'string'); | ||
}); | ||
@@ -307,3 +378,3 @@ }); | ||
assert.equal(tr.transaction.signatures.length, 1); | ||
assert.equal(_typeof(tr.transaction.signatures[0]), 'string'); | ||
assert.equal((0, _typeof3.default)(tr.transaction.signatures[0]), 'string'); | ||
}); | ||
@@ -346,7 +417,7 @@ }); | ||
it('create asset', function _callee5() { | ||
it('create asset', function _callee7() { | ||
var eos, pubkey, auth; | ||
return regeneratorRuntime.async(function _callee5$(_context5) { | ||
return _regenerator2.default.async(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
@@ -356,12 +427,12 @@ eos = Eos({ signProvider: signProvider }); | ||
auth = { authorization: 'eosio.token' }; | ||
_context5.next = 5; | ||
return regeneratorRuntime.awrap(eos.create('eosio.token', '10000 ' + randomAsset(), auth)); | ||
_context7.next = 5; | ||
return _regenerator2.default.awrap(eos.create('eosio.token', '10000 ' + randomAsset(), auth)); | ||
case 5: | ||
_context5.next = 7; | ||
return regeneratorRuntime.awrap(eos.create('eosio.token', '10000.00 ' + randomAsset(), auth)); | ||
_context7.next = 7; | ||
return _regenerator2.default.awrap(eos.create('eosio.token', '10000.00 ' + randomAsset(), auth)); | ||
case 7: | ||
case 'end': | ||
return _context5.stop(); | ||
return _context7.stop(); | ||
} | ||
@@ -384,2 +455,3 @@ } | ||
}); | ||
tr.buyrambytes({ | ||
@@ -390,7 +462,8 @@ payer: 'eosio', | ||
}); | ||
tr.delegatebw({ | ||
from: 'eosio', | ||
receiver: name, | ||
stake_net_quantity: '1.0000 SYS', | ||
stake_cpu_quantity: '1.0000 SYS', | ||
stake_net_quantity: '10.0000 SYS', | ||
stake_cpu_quantity: '10.0000 SYS', | ||
transfer: 0 | ||
@@ -484,7 +557,7 @@ }); | ||
it('action to contract atomic', function _callee6() { | ||
it('action to contract atomic', function _callee8() { | ||
var amt, eos, trTest, assertTr; | ||
return regeneratorRuntime.async(function _callee6$(_context6) { | ||
return _regenerator2.default.async(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
@@ -507,6 +580,6 @@ amt = 1; // for unique transactions | ||
_context6.t0 = regeneratorRuntime; | ||
_context6.t1 = assertTr; | ||
_context6.next = 8; | ||
return regeneratorRuntime.awrap(eos.transaction(['eosio.token'], function (_ref6) { | ||
_context8.t0 = _regenerator2.default; | ||
_context8.t1 = assertTr; | ||
_context8.next = 8; | ||
return _regenerator2.default.awrap(eos.transaction(['eosio.token'], function (_ref6) { | ||
var eosio_token = _ref6.eosio_token; | ||
@@ -517,12 +590,12 @@ return trTest(eosio_token); | ||
case 8: | ||
_context6.t2 = _context6.sent; | ||
_context6.t3 = (0, _context6.t1)(_context6.t2); | ||
_context6.next = 12; | ||
return _context6.t0.awrap.call(_context6.t0, _context6.t3); | ||
_context8.t2 = _context8.sent; | ||
_context8.t3 = (0, _context8.t1)(_context8.t2); | ||
_context8.next = 12; | ||
return _context8.t0.awrap.call(_context8.t0, _context8.t3); | ||
case 12: | ||
_context6.t4 = regeneratorRuntime; | ||
_context6.t5 = assertTr; | ||
_context6.next = 16; | ||
return regeneratorRuntime.awrap(eos.transaction('eosio.token', function (eosio_token) { | ||
_context8.t4 = _regenerator2.default; | ||
_context8.t5 = assertTr; | ||
_context8.next = 16; | ||
return _regenerator2.default.awrap(eos.transaction('eosio.token', function (eosio_token) { | ||
return trTest(eosio_token); | ||
@@ -532,10 +605,10 @@ })); | ||
case 16: | ||
_context6.t6 = _context6.sent; | ||
_context6.t7 = (0, _context6.t5)(_context6.t6); | ||
_context6.next = 20; | ||
return _context6.t4.awrap.call(_context6.t4, _context6.t7); | ||
_context8.t6 = _context8.sent; | ||
_context8.t7 = (0, _context8.t5)(_context8.t6); | ||
_context8.next = 20; | ||
return _context8.t4.awrap.call(_context8.t4, _context8.t7); | ||
case 20: | ||
case 'end': | ||
return _context6.stop(); | ||
return _context8.stop(); | ||
} | ||
@@ -621,14 +694,34 @@ } | ||
}); | ||
it('custom contract transfer', function _callee9() { | ||
var eos; | ||
return _regenerator2.default.async(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
eos = Eos({ signProvider: signProvider }); | ||
_context9.next = 3; | ||
return _regenerator2.default.awrap(eos.contract('currency').then(function (currency) { | ||
return currency.transfer('currency', 'inita', '1.0000 CUR', ''); | ||
})); | ||
case 3: | ||
case 'end': | ||
return _context9.stop(); | ||
} | ||
} | ||
}, null, this); | ||
}); | ||
}); | ||
// ./eosioc set contract currency build/contracts/currency/currency.wasm build/contracts/currency/currency.abi | ||
it('Transaction ABI lookup', function _callee7() { | ||
it('Transaction ABI lookup', function _callee10() { | ||
var eos, tx; | ||
return regeneratorRuntime.async(function _callee7$(_context7) { | ||
return _regenerator2.default.async(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
eos = Eos(); | ||
_context7.next = 3; | ||
return regeneratorRuntime.awrap(eos.transaction({ | ||
_context10.next = 3; | ||
return _regenerator2.default.awrap(eos.transaction({ | ||
actions: [{ | ||
@@ -651,3 +744,3 @@ account: 'currency', | ||
case 3: | ||
tx = _context7.sent; | ||
tx = _context10.sent; | ||
@@ -658,3 +751,3 @@ assert.equal(tx.transaction.transaction.actions[0].account, 'currency'); | ||
case 'end': | ||
return _context7.stop(); | ||
return _context10.stop(); | ||
} | ||
@@ -661,0 +754,0 @@ } |
@@ -204,3 +204,12 @@ { | ||
} | ||
}, | ||
"nonce": { | ||
"action": { | ||
"name": "nonce", | ||
"account": "eosio.null" | ||
}, | ||
"fields": { | ||
"value": "string" | ||
} | ||
} | ||
} |
@@ -179,2 +179,11 @@ { | ||
}, | ||
"namebid_info": { | ||
"base": "", | ||
"fields": { | ||
"newname": "account_name", | ||
"high_bidder": "account_name", | ||
"high_bid": "int64", | ||
"last_bid_time": "uint64" | ||
} | ||
}, | ||
"newaccount": { | ||
@@ -181,0 +190,0 @@ "base": "", |
'use strict'; | ||
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 _typeof2 = require('babel-runtime/helpers/typeof'); | ||
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 _typeof3 = _interopRequireDefault(_typeof2); | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _require = require('eosjs-ecc'), | ||
@@ -35,3 +41,3 @@ Signature = _require.Signature, | ||
var structLookup = function structLookup(lookupName, account) { | ||
var cachedCode = new Set(['eosio', 'eosio.token']); | ||
var cachedCode = new Set(['eosio', 'eosio.token', 'eosio.null']); | ||
if (cachedCode.has(account)) { | ||
@@ -269,3 +275,3 @@ return structs[lookupName]; | ||
var _symbolInfo$amount$sp = symbolInfo.amount.split('.'), | ||
_symbolInfo$amount$sp2 = _slicedToArray(_symbolInfo$amount$sp, 2), | ||
_symbolInfo$amount$sp2 = (0, _slicedToArray3.default)(_symbolInfo$amount$sp, 2), | ||
_symbolInfo$amount$sp3 = _symbolInfo$amount$sp2[1], | ||
@@ -285,2 +291,7 @@ decimalstr = _symbolInfo$amount$sp3 === undefined ? '' : _symbolInfo$amount$sp3; | ||
if (precision == null && symbolInfo.amount != null) { | ||
var part = symbolInfo.amount.split('.'); | ||
precision = part.length === 1 ? 0 : part[1].length; | ||
} | ||
var pc = Object.assign({}, symbolInfo, { contract: contract }); | ||
@@ -392,6 +403,6 @@ if (precision != null) { | ||
appendByteBuffer: function appendByteBuffer(b, value) { | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'Invalid extended symbol: ' + value); | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value), 'string', 'Invalid extended symbol: ' + value); | ||
var _value$split = value.split('@'), | ||
_value$split2 = _slicedToArray(_value$split, 2), | ||
_value$split2 = (0, _slicedToArray3.default)(_value$split, 2), | ||
symbol = _value$split2[0], | ||
@@ -421,3 +432,3 @@ contract = _value$split2[1]; | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'expecting asset string, got ' + (typeof value === 'undefined' ? 'undefined' : _typeof(value))); | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value), 'string', 'expecting asset string, got ' + (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value))); | ||
@@ -478,3 +489,3 @@ var _precisionCache3 = precisionCache(assetCache, value), | ||
appendByteBuffer: function appendByteBuffer(b, value) { | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'expecting asset string, got ' + (typeof value === 'undefined' ? 'undefined' : _typeof(value))); | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value), 'string', 'expecting asset string, got ' + (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value))); | ||
@@ -518,3 +529,3 @@ var _precisionCache5 = precisionCache(assetCache, value), | ||
appendByteBuffer: function appendByteBuffer(b, value) { | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'object', 'expecting extended_asset object, got ' + (typeof value === 'undefined' ? 'undefined' : _typeof(value))); | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value), 'object', 'expecting extended_asset object, got ' + (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value))); | ||
@@ -524,6 +535,6 @@ var asset = joinAssetString(value); | ||
var _asset$split = asset.split('@'), | ||
_asset$split2 = _slicedToArray(_asset$split, 2), | ||
_asset$split2 = (0, _slicedToArray3.default)(_asset$split, 2), | ||
contract = _asset$split2[1]; | ||
assert.equal(typeof contract === 'undefined' ? 'undefined' : _typeof(contract), 'string', 'Invalid extended asset: ' + value); | ||
assert.equal(typeof contract === 'undefined' ? 'undefined' : (0, _typeof3.default)(contract), 'string', 'Invalid extended asset: ' + value); | ||
@@ -539,6 +550,6 @@ // asset includes contract (assetType needs this) | ||
Object.assign(asset, parseExtendedAsset(value)); | ||
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
} else if ((typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)) === 'object') { | ||
Object.assign(asset, value); | ||
} else { | ||
assert(false, 'expecting extended_asset<object|string>, got: ' + (typeof value === 'undefined' ? 'undefined' : _typeof(value))); | ||
assert(false, 'expecting extended_asset<object|string>, got: ' + (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value))); | ||
} | ||
@@ -569,3 +580,3 @@ | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'object', 'expecting extended_asset object'); | ||
assert.equal(typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value), 'object', 'expecting extended_asset object'); | ||
@@ -626,3 +637,3 @@ var _precisionCache6 = precisionCache(assetCache, joinAssetString(value)), | ||
var _value$split3 = value.split('@'), | ||
_value$split4 = _slicedToArray(_value$split3, 2), | ||
_value$split4 = (0, _slicedToArray3.default)(_value$split3, 2), | ||
account = _value$split4[0], | ||
@@ -753,3 +764,3 @@ _value$split4$ = _value$split4[1], | ||
if (ser) { | ||
if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
if ((typeof data === 'undefined' ? 'undefined' : (0, _typeof3.default)(data)) === 'object') { | ||
result.data = ser.fromObject(data); // resolve shorthand | ||
@@ -756,0 +767,0 @@ } else if (typeof data === 'string') { |
'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 _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
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 _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var assert = require('assert'); | ||
@@ -57,3 +67,3 @@ var ecc = require('eosjs-ecc'); | ||
@example eos.contract('mycontract', [options], [callback]) | ||
@example eos.contract('mycontract').then(mycontract => mycontract.action(...)) | ||
@example eos.contract('mycontract').then(mycontract => mycontract.myaction(...)) | ||
*/ | ||
@@ -102,3 +112,3 @@ merge.contract = function () { | ||
return regeneratorRuntime.async(function _callee$(_context) { | ||
return _regenerator2.default.async(function _callee$(_context) { | ||
while (1) { | ||
@@ -139,3 +149,3 @@ switch (_context.prev = _context.next) { | ||
case 13: | ||
if (!(_typeof(args[0]) === 'object' && _typeof(Array.isArray(args[0].actions)))) { | ||
if (!((0, _typeof3.default)(args[0]) === 'object' && (0, _typeof3.default)(Array.isArray(args[0].actions)))) { | ||
_context.next = 39; | ||
@@ -195,3 +205,3 @@ break; | ||
cachedCode = new Set(['eosio', 'eosio.token']); | ||
cachedCode = new Set(['eosio', 'eosio.token', 'eosio.null']); | ||
@@ -204,3 +214,3 @@ accounts.forEach(function (account) { | ||
_context.next = 39; | ||
return regeneratorRuntime.awrap(Promise.all(abiPromises)); | ||
return _regenerator2.default.awrap(Promise.all(abiPromises)); | ||
@@ -213,3 +223,3 @@ case 39: | ||
if (args.length > 1 && _typeof(args[args.length - 1]) === 'object') { | ||
if (args.length > 1 && (0, _typeof3.default)(args[args.length - 1]) === 'object') { | ||
options = args.pop(); | ||
@@ -227,3 +237,3 @@ } | ||
assert(!callback, 'callback with contracts are not supported'); | ||
assert.equal('function', typeof arg === 'undefined' ? 'undefined' : _typeof(arg), 'provide function callback following contracts array parameter'); | ||
assert.equal('function', typeof arg === 'undefined' ? 'undefined' : (0, _typeof3.default)(arg), 'provide function callback following contracts array parameter'); | ||
@@ -296,3 +306,3 @@ contractPromises = []; | ||
case 69: | ||
if (!((typeof arg === 'undefined' ? 'undefined' : _typeof(arg)) === 'object')) { | ||
if (!((typeof arg === 'undefined' ? 'undefined' : (0, _typeof3.default)(arg)) === 'object')) { | ||
_context.next = 71; | ||
@@ -349,3 +359,3 @@ break; | ||
if (args.length === 0) { | ||
console.error(usage(type, definition, Network, account, config)); | ||
console.log(usage(type, definition, Network, account, config)); | ||
return; | ||
@@ -358,3 +368,3 @@ } | ||
var lastArg = args[args.length - 1]; | ||
if ((typeof lastArg === 'undefined' ? 'undefined' : _typeof(lastArg)) === 'object' && _typeof(lastArg.__optionOverrides) === 'object') { | ||
if ((typeof lastArg === 'undefined' ? 'undefined' : (0, _typeof3.default)(lastArg)) === 'object' && (0, _typeof3.default)(lastArg.__optionOverrides) === 'object') { | ||
// pop() fixes the args.length | ||
@@ -392,3 +402,3 @@ Object.assign(optionOverrides, args.pop().__optionOverrides); | ||
var _auth$split = auth.split('@'), | ||
_auth$split2 = _slicedToArray(_auth$split, 2), | ||
_auth$split2 = (0, _slicedToArray3.default)(_auth$split, 2), | ||
actor = _auth$split2[0], | ||
@@ -399,3 +409,3 @@ _auth$split2$ = _auth$split2[1], | ||
authorization.push({ actor: actor, permission: permission }); | ||
} else if ((typeof auth === 'undefined' ? 'undefined' : _typeof(auth)) === 'object') { | ||
} else if ((typeof auth === 'undefined' ? 'undefined' : (0, _typeof3.default)(auth)) === 'object') { | ||
authorization.push(auth); | ||
@@ -453,7 +463,7 @@ } | ||
assert.equal('function', typeof trCallback === 'undefined' ? 'undefined' : _typeof(trCallback), 'trCallback'); | ||
assert.equal('object', typeof options === 'undefined' ? 'undefined' : _typeof(options), 'options'); | ||
assert.equal('object', typeof merges === 'undefined' ? 'undefined' : _typeof(merges), 'merges'); | ||
assert.equal('function', typeof trCallback === 'undefined' ? 'undefined' : (0, _typeof3.default)(trCallback), 'trCallback'); | ||
assert.equal('object', typeof options === 'undefined' ? 'undefined' : (0, _typeof3.default)(options), 'options'); | ||
assert.equal('object', typeof merges === 'undefined' ? 'undefined' : (0, _typeof3.default)(merges), 'merges'); | ||
assert(!Array.isArray(merges), 'merges should not be an array'); | ||
assert.equal('function', typeof transaction === 'undefined' ? 'undefined' : _typeof(transaction), 'transaction'); | ||
assert.equal('function', typeof transaction === 'undefined' ? 'undefined' : (0, _typeof3.default)(transaction), 'transaction'); | ||
@@ -493,3 +503,3 @@ var messageList = []; | ||
messageCollector[variableName] = wrap(value); | ||
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
} else if ((typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)) === 'object') { | ||
// other contract(s) (currency contract for example) | ||
@@ -527,3 +537,3 @@ if (messageCollector[variableName] == null) { | ||
var _m$actions = _slicedToArray(m.actions, 1), | ||
var _m$actions = (0, _slicedToArray3.default)(m.actions, 1), | ||
action = _m$actions[0]; | ||
@@ -573,3 +583,3 @@ | ||
if ((typeof arg === 'undefined' ? 'undefined' : _typeof(arg)) !== 'object') { | ||
if ((typeof arg === 'undefined' ? 'undefined' : (0, _typeof3.default)(arg)) !== 'object') { | ||
throw new TypeError('First transaction argument should be an object or function'); | ||
@@ -582,11 +592,12 @@ } | ||
if (config.transactionLog) { | ||
if (config.logger.log || config.logger.error) { | ||
// wrap the callback with the logger | ||
var superCallback = callback; | ||
callback = function callback(error, tr) { | ||
if (error) { | ||
config.transactionLog(error); | ||
} else { | ||
config.transactionLog(null, tr); | ||
if (error && config.logger.error) { | ||
config.logger.error(error); | ||
} | ||
if (config.logger.log) { | ||
config.logger.log(JSON.stringify(tr)); | ||
} | ||
superCallback(error, tr); | ||
@@ -606,7 +617,41 @@ }; | ||
var headers = config.transactionHeaders ? config.transactionHeaders : network.createTransaction; | ||
var argHeaders = null; | ||
if ( // minimum required headers | ||
arg.expiration != null && arg.ref_block_num != null && arg.ref_block_prefix != null) { | ||
var expiration = arg.expiration, | ||
ref_block_num = arg.ref_block_num, | ||
ref_block_prefix = arg.ref_block_prefix, | ||
_arg$net_usage_words = arg.net_usage_words, | ||
net_usage_words = _arg$net_usage_words === undefined ? 0 : _arg$net_usage_words, | ||
_arg$max_cpu_usage_ms = arg.max_cpu_usage_ms, | ||
max_cpu_usage_ms = _arg$max_cpu_usage_ms === undefined ? 0 : _arg$max_cpu_usage_ms, | ||
_arg$delay_sec = arg.delay_sec, | ||
delay_sec = _arg$delay_sec === undefined ? 0 : _arg$delay_sec; | ||
headers(options.expireInSeconds, checkError(callback, function _callee2(rawTx) { | ||
argHeaders = { | ||
expiration: expiration, | ||
ref_block_num: ref_block_num, | ||
ref_block_prefix: ref_block_prefix, | ||
net_usage_words: net_usage_words, | ||
max_cpu_usage_ms: max_cpu_usage_ms, | ||
delay_sec: delay_sec | ||
}; | ||
} | ||
var headers = void 0; | ||
if (argHeaders) { | ||
headers = function headers(expireInSeconds, callback) { | ||
return callback(null, argHeaders); | ||
}; | ||
} else if (config.transactionHeaders) { | ||
assert.equal((0, _typeof3.default)(config.transactionHeaders), 'function', 'config.transactionHeaders'); | ||
headers = config.transactionHeaders; | ||
} else { | ||
assert(network, 'Network is required, provide config.httpEndpoint'); | ||
headers = network.createTransaction; | ||
} | ||
headers(options.expireInSeconds, checkError(callback, config.logger, function _callee2(rawTx) { | ||
var txObject, buf, tr, transactionId, sigs, chainIdBuf, signBuf; | ||
return regeneratorRuntime.async(function _callee2$(_context2) { | ||
return _regenerator2.default.async(function _callee2$(_context2) { | ||
while (1) { | ||
@@ -616,6 +661,6 @@ switch (_context2.prev = _context2.next) { | ||
// console.log('rawTx', rawTx) | ||
assert.equal(typeof rawTx === 'undefined' ? 'undefined' : _typeof(rawTx), 'object', 'expecting transaction header object'); | ||
assert.equal(_typeof(rawTx.expiration), 'string', 'expecting expiration: iso date time string'); | ||
assert.equal(_typeof(rawTx.ref_block_num), 'number', 'expecting ref_block_num number'); | ||
assert.equal(_typeof(rawTx.ref_block_prefix), 'number', 'expecting ref_block_prefix number'); | ||
assert.equal(typeof rawTx === 'undefined' ? 'undefined' : (0, _typeof3.default)(rawTx), 'object', 'expecting transaction header object'); | ||
assert.equal((0, _typeof3.default)(rawTx.expiration), 'string', 'expecting expiration: iso date time string'); | ||
assert.equal((0, _typeof3.default)(rawTx.ref_block_num), 'number', 'expecting ref_block_num number'); | ||
assert.equal((0, _typeof3.default)(rawTx.ref_block_prefix), 'number', 'expecting ref_block_prefix number'); | ||
@@ -637,3 +682,3 @@ rawTx = Object.assign({}, rawTx); | ||
_context2.next = 10; | ||
return regeneratorRuntime.awrap(AssetCache.resolve()); | ||
return _regenerator2.default.awrap(AssetCache.resolve()); | ||
@@ -691,4 +736,9 @@ case 10: | ||
if (mock === 'fail') { | ||
console.error('[push_transaction mock error] \'fake error\', digest \'' + buf.toString('hex') + '\''); | ||
callback('fake error'); | ||
var error = '[push_transaction mock error] \'fake error\', digest \'' + buf.toString('hex') + '\''; | ||
if (config.logger.error) { | ||
config.logger.error(error); | ||
} | ||
callback(error); | ||
} | ||
@@ -698,3 +748,3 @@ return; | ||
if (!options.broadcast) { | ||
if (!options.broadcast || !network) { | ||
callback(null, { | ||
@@ -714,3 +764,7 @@ transaction_id: transactionId, | ||
} else { | ||
console.error('[push_transaction error] \'' + error.message + '\', transaction \'' + buf.toString('hex') + '\''); | ||
if (config.logger.error) { | ||
config.logger.error('[push_transaction error] \'' + error.message + '\', transaction \'' + buf.toString('hex') + '\''); | ||
} | ||
callback(error.message); | ||
@@ -721,3 +775,5 @@ } | ||
}).catch(function (error) { | ||
console.error(error); | ||
if (config.logger.error) { | ||
config.logger.error(error); | ||
} | ||
callback(error); | ||
@@ -752,3 +808,3 @@ }); | ||
var optionsFormatter = function optionsFormatter(option) { | ||
if ((typeof option === 'undefined' ? 'undefined' : _typeof(option)) === 'object') { | ||
if ((typeof option === 'undefined' ? 'undefined' : (0, _typeof3.default)(option)) === 'object') { | ||
return option; // {debug, broadcast, etc} (etc my overwrite tr below) | ||
@@ -806,6 +862,8 @@ } | ||
var checkError = function checkError(parentErr, parrentRes) { | ||
var checkError = function checkError(parentErr, logger, parrentRes) { | ||
return function (error, result) { | ||
if (error) { | ||
console.log('error', error); | ||
if (logger.error) { | ||
logger.error('error', error); | ||
} | ||
parentErr(error); | ||
@@ -812,0 +870,0 @@ } else { |
{ | ||
"name": "eosjs", | ||
"version": "14.1.1", | ||
"version": "14.2.0", | ||
"description": "General purpose library for the EOS blockchain.", | ||
@@ -33,5 +33,6 @@ "main": "lib/index.js", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-plugin-syntax-async-functions": "^6.13.0", | ||
"babel-plugin-transform-regenerator": "^6.26.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
@@ -47,6 +48,6 @@ "browserify": "^14.4.0", | ||
"dependencies": { | ||
"babel-polyfill": "^6.26.0", | ||
"babel-runtime": "^6.26.0", | ||
"binaryen": "^37.0.0", | ||
"create-hash": "^1.1.3", | ||
"eosjs-api": "6.1.3", | ||
"eosjs-api": "6.2.1", | ||
"eosjs-ecc": "4.0.1", | ||
@@ -61,5 +62,12 @@ "fcbuffer": "2.2.0" | ||
"syntax-async-functions", | ||
"transform-regenerator" | ||
"transform-regenerator", | ||
[ | ||
"transform-runtime", | ||
{ | ||
"polyfill": false, | ||
"regenerator": true | ||
} | ||
] | ||
] | ||
} | ||
} |
483
README.md
@@ -16,41 +16,88 @@ [](https://travis-ci.org/EOSIO/eosjs) | ||
General purpose library for the EOS blockchain. | ||
General purpose library for EOSIO blockchains. | ||
### Usage (read-only) | ||
### Usage | ||
```javascript | ||
Eos = require('eosjs') // Eos = require('./src') | ||
Ways to instantiate eosjs. | ||
eos = Eos() // 127.0.0.1:8888 | ||
```js | ||
Eos = require('eosjs') | ||
// All API methods print help when called with no-arguments. | ||
// Private key or keys (array) provided statically or by way of a function. | ||
// For multiple keys, the get_required_keys API is used (more on that below). | ||
keyProvider: '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' | ||
// Localhost Testnet (run ./docker/up.sh) | ||
eos = Eos({keyProvider}) | ||
// Connect to a testnet or mainnet | ||
eos = Eos({httpEndpoint, chainId, keyProvider}) | ||
// Cold-storage | ||
eos = Eos({httpEndpoint: null, chainId, keyProvider}) | ||
// Read-only instance when 'eosjs' is already a dependency | ||
eos = Eos.modules.api({/*config*/}) | ||
// Read-only instance when an application never needs to write (smaller library) | ||
EosApi = require('eosjs-api') | ||
eos = EosApi({/*config*/}) | ||
``` | ||
No-arguments prints usage. | ||
```js | ||
eos.getBlock() | ||
``` | ||
```json | ||
USAGE | ||
getBlock - Fetch a block from the blockchain. | ||
// Next, you're going to need nodeosd running on localhost:8888 (see ./docker) | ||
PARAMETERS | ||
{ | ||
"block_num_or_id": "string" | ||
} | ||
``` | ||
Start a nodeosd process. The docker in this repository provides a setup | ||
the supports the examples in this README. | ||
```bash | ||
cd ./docker && ./up.sh | ||
``` | ||
All functions read only or transactional follow this pattern for parameters. | ||
```js | ||
// If the last argument is a function it is treated as a callback | ||
eos.getBlock(1, (error, result) => {}) | ||
// If a callback is not provided, a Promise is returned | ||
eos.getBlock(1).then(result => {console.log(result)}) | ||
eos.getBlock(1) // @returns {Promise} | ||
// Parameters can be sequential or an object | ||
eos.getBlock({block_num_or_id: 1}).then(result => console.log(result)) | ||
// Parameters can be positional or an object | ||
eos.getBlock({block_num_or_id: 1}) | ||
// Callbacks are similar | ||
callback = (err, res) => {err ? console.error(err) : console.log(res)} | ||
eos.getBlock(1, callback) | ||
eos.getBlock({block_num_or_id: 1}, callback) | ||
// Provide an empty object or a callback if an API call has no arguments | ||
eos.getInfo({}).then(result => {console.log(result)}) | ||
// An API with no parameters is invoked with an empty object or callback (avoids logging usage) | ||
eos.getInfo({}) // @returns {Promise} | ||
eos.getInfo((error, result) => { console.log(error, result) }) | ||
``` | ||
API methods and documentation are generated from: | ||
Chain and history API functions are available after creating the `eos` object. | ||
API methods and documentation are generated from the chain and history json files. | ||
* [chain.json](https://github.com/EOSIO/eosjs-api/blob/master/src/api/v1/chain.json) | ||
* [history.json](https://github.com/EOSIO/eosjs-api/blob/master/src/api/v1/history.json) | ||
Until we generate a markdown for these, please convert the names in these | ||
json to camel case functions. | ||
* `"get_info": ..` is `eos.getInfo(..)` | ||
### Configuration | ||
```js | ||
Eos = require('eosjs') // Eos = require('./src') | ||
Eos = require('eosjs') | ||
// Optional configuration.. | ||
// Default configuration (additional options below) | ||
config = { | ||
@@ -60,9 +107,5 @@ chainId: null, // 32 byte (64 char) hex string | ||
httpEndpoint: 'http://127.0.0.1:8888', | ||
mockTransactions: () => 'pass', // or 'fail' | ||
transactionHeaders: (expireInSeconds, callback) => { | ||
callback(null/*error*/, headers) | ||
}, | ||
expireInSeconds: 60, | ||
broadcast: true, | ||
debug: false, // API and transactions | ||
verbose: false, // API activity | ||
sign: true | ||
@@ -74,7 +117,39 @@ } | ||
* **chainId** - Unique ID for the blockchain you're connecting too. This is | ||
required for valid transaction signing. The chainId is provided via the | ||
* **chainId** `hex` - Unique ID for the blockchain you're connecting too. This | ||
is required for valid transaction signing. The chainId is provided via the | ||
[get_info](http://ayeaye.cypherglass.com:8888/v1/chain/get_info) API call. | ||
* `mockTransactions` (optional) | ||
Identifies a chain by its initial genesis block. All transactions signed will | ||
only be valid the blockchain with this chainId. Verify the chainId for | ||
security reasons. | ||
* **keyProvider** `[array<string>|string|function]` - Provides private keys | ||
used to sign transaction. If multiple private keys are found, the API | ||
`get_required_keys` is called to discover which signing keys to use. If a | ||
function is provided, this function is called for each transaction. | ||
* **httpEndpoint** `string` - http or https location of a nodeosd server | ||
providing a chain API. When using eosjs from a browser remember to configure | ||
the same origin policy in nodeosd or proxy server. For testing, nodeosd | ||
configuration `access-control-allow-origin = *` could be used. | ||
Set this value to **null** for a cold-storage (no network) configuration. | ||
* **expireInSeconds** `number` - number of seconds before the transaction | ||
will expire. The time is based on the nodeosd's clock. An unexpired | ||
transaction that may have had an error is a liability until the expiration | ||
is reached, this time should be brief. | ||
* **broadcast** `[boolean=true]` - post the transaction to | ||
the blockchain. Use false to obtain a fully signed transaction. | ||
* **verbose** `[boolean=false]` - verbose logging such as API activity. | ||
* **debug** `[boolean=false]` - low level debug logging (serialization). | ||
* **sign** `[boolean=true]` - sign the transaction with a private key. Leaving | ||
a transaction unsigned avoids the need to provide a private key. | ||
* **mockTransactions** (advanced) | ||
* `mockTransactions: () => null // 'pass', or 'fail'` | ||
* `pass` - do not broadcast, always pretend that the transaction worked | ||
@@ -84,23 +159,36 @@ * `fail` - do not broadcast, pretend the transaction failed | ||
* `transactionHeaders` (optional) - manually calculate transaction header. This | ||
* **transactionHeaders** (advanced) - manually calculate transaction header. This | ||
may be provided so eosjs does not need to make header related API calls to | ||
nodeos. This callback is called for every transaction. | ||
Headers are documented here [eosjs-api#headers](https://github.com/EOSIO/eosjs-api/blob/HEAD/docs/index.md#headers--object). | ||
nodeos. Used in environments like cold-storage. This callback is called for | ||
every transaction. Headers are documented here [eosjs-api#headers](https://github.com/EOSIO/eosjs-api/blob/HEAD/docs/index.md#headers--object). | ||
* `transactionHeaders: (expireInSeconds, callback) => {callback(null/*error*/, headers)}` | ||
* **logger** - default logging configuration. | ||
```js | ||
logger: { | ||
log: config.verbose ? console.log : null, | ||
error: console.error // null to disable | ||
} | ||
``` | ||
Turn off all error logging: `config.logger = {error: null}` | ||
### Options | ||
Options may be provided immediately after parameters. | ||
Options may be provided after parameters. | ||
Example: `eos.transfer(params, options)` | ||
```js | ||
options = { | ||
authorization: 'alice@active', | ||
broadcast: true, | ||
sign: true, | ||
authorization: null | ||
sign: true | ||
} | ||
``` | ||
* **authorization** `{array<auth>|auth}` - identifies the | ||
signing account and permission typically in a multi-sig | ||
```js | ||
eos.transfer('alice', 'bob', '1 SYS', '', options) | ||
``` | ||
* **authorization** `[array<auth>|auth]` - identifies the | ||
signing account and permission typically in a multisig | ||
configuration. Authorization may be a string formatted as | ||
@@ -110,75 +198,132 @@ `account@permission` or an `object<{actor: account, permission}>`. | ||
* If provided additional authorizations will not be added. | ||
* Sorting is always performed (by account name). | ||
* Performs deterministic sorting by account name | ||
### Usage (read/write) | ||
If a default authorization is calculated the action's 1st field must be | ||
an account_name. The account_name in the 1st field gets added as the | ||
active key authorization for the action. | ||
You'll need to provide the private key in keyProvider. | ||
* **broadcast** `[boolean=true]` - post the transaction to | ||
the blockchain. Use false to obtain a fully signed transaction. | ||
* **sign** `[boolean=true]` - sign the transaction with a private key. Leaving | ||
a transaction unsigned avoids the need to provide a private key. | ||
### Transaction | ||
The transaction function accepts the standard blockchain transaction. | ||
Required transaction header fields will be added unless your signing without a | ||
network connection (httpEndpoint == null). In that case provide you own headers: | ||
```js | ||
// only needed in cold-storage or for offline transactions | ||
const headers = { | ||
expiration: '2018-06-14T18:16:10' | ||
ref_block_num: 1, | ||
ref_block_prefix: 452435776 | ||
} | ||
``` | ||
Create and send (broadcast) a transaction: | ||
```javascript | ||
Eos = require('eosjs') // Eos = require('./src') | ||
/** @return {Promise} */ | ||
eos.transaction( | ||
{ | ||
// ...headers, | ||
actions: [ | ||
{ | ||
account: 'eosio.token', | ||
name: 'transfer', | ||
authorization: [{ | ||
actor: 'inita', | ||
permission: 'active' | ||
}], | ||
data: { | ||
from: 'inita', | ||
to: 'initb', | ||
quantity: '7 SYS', | ||
memo: '' | ||
} | ||
} | ||
] | ||
} | ||
// options -- example: {broadcast: false} | ||
) | ||
``` | ||
eos = Eos({keyProvider: '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'}) | ||
### Named action functions | ||
More concise functions are provided for applications that may use actions | ||
more frequently. This avoids having lots of JSON in the code. | ||
```javascript | ||
// Run with no arguments to print usage. | ||
eos.transfer() | ||
// Usage with options (options are always optional) | ||
options = {broadcast: false} | ||
// Callback is last, when omitted a promise is returned | ||
eos.transfer('inita', 'initb', '1 SYS', '', (error, result) => {}) | ||
eos.transfer('inita', 'initb', '1.1 SYS', '') // @returns {Promise} | ||
eos.transfer({from: 'inita', to: 'initb', quantity: '1 SYS', memo: ''}, options) | ||
// positional parameters | ||
eos.transfer('inita', 'initb', '1.2 SYS', '') | ||
// Object or ordered args may be used. | ||
eos.transfer('inita', 'initb', '2 SYS', 'memo', options) | ||
// named parameters | ||
eos.transfer({from: 'inita', to: 'initb', quantity: '1.3 SYS', memo: ''}) | ||
// A broadcast boolean may be provided as a shortcut for {broadcast: false} | ||
eos.transfer('inita', 'initb', '1 SYS', '', false) | ||
// options appear after parameters but before | ||
options = {broadcast: true, sign: true} | ||
// `false` is a shortcut for {broadcast: false} | ||
eos.transfer('inita', 'initb', '1.4 SYS', '', false) | ||
``` | ||
Read-write API methods and documentation are generated from the [eosio_system](https://github.com/EOSIO/eosjs/blob/master/src/schema/eosio_token.json) schema. | ||
Read-write API methods and documentation are generated from the eosio | ||
[token](https://github.com/EOSIO/eosjs/blob/master/src/schema/eosio_token.json) and | ||
[system](https://github.com/EOSIO/eosjs/blob/master/src/schema/eosio_system.json). | ||
For more advanced signing, see `keyProvider` in | ||
[eosjs-keygen](https://github.com/eosio/eosjs-keygen) or | ||
[unit test](https://github.com/EOSIO/eosjs/blob/master/src/index.test.js). | ||
For more advanced signing, see `keyProvider` and `signProvider` in | ||
[index.test.js](https://github.com/EOSIO/eosjs/blob/master/src/index.test.js). | ||
### Shorthand | ||
Shorthand is available for some types such as Asset and Authority. | ||
Shorthand is available for some types such as Asset and Authority. This syntax | ||
is only for concise functions and does not work in `eos.transaction`. | ||
For example: | ||
* stake_net_quantity: `'1 SYS'` is shorthand for `1.0000 SYS` | ||
* owner: `'EOS6MRy..'` is shorthand for `{threshold: 1, keys: [key: 'EOS6MRy..', weight: 1]}` | ||
* active: `inita` or `inita@active` is shorthand for | ||
* `{{threshold: 1, accounts: [..actor: inita, permission: active, weight: 1]}}` | ||
* `inita@other` would replace the permission `active` with `other` | ||
* asset `'10 SYS'` resolves `10.0000 SYS` | ||
* permission `inita` defaults `inita@active` | ||
* authority `'EOS6MRy..'` expands `{threshold: 1, keys: [key: 'EOS6MRy..', weight: 1]}` | ||
* authority `inita` expands `{{threshold: 1, accounts: [..actor: 'inita', permission: 'active', weight: 1]}}` | ||
### New Account | ||
New accounts will likely require some staked tokens for RAM and bandwidth. | ||
```javascript | ||
Eos = require('eosjs') // Eos = require('./src') | ||
wif = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' | ||
pubkey = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV' | ||
eos = Eos({keyProvider: wif}) | ||
eos.transaction(tr => { | ||
tr.newaccount({ | ||
creator: 'inita', | ||
name: 'mycontract11', | ||
creator: 'eosio', | ||
name: 'myaccount', | ||
owner: pubkey, | ||
active: pubkey | ||
}) | ||
tr.buyrambytes({ | ||
payer: 'inita', | ||
receiver: 'mycontract11', | ||
payer: 'eosio', | ||
receiver: 'myaccount', | ||
bytes: 8192 | ||
}) | ||
tr.delegatebw({ | ||
from: 'inita', | ||
receiver: 'mycontract11', | ||
stake_net_quantity: '100.0000 SYS', | ||
stake_cpu_quantity: '100.0000 SYS', | ||
from: 'eosio', | ||
receiver: 'myaccount', | ||
stake_net_quantity: '10.0000 SYS', | ||
stake_cpu_quantity: '10.0000 SYS', | ||
transfer: 0 | ||
}) | ||
}) | ||
``` | ||
@@ -188,132 +333,121 @@ | ||
Deploy a smart contract. | ||
Deploy and call smart contracts. | ||
The `setcode` command accepts WASM text and converts this to binary before | ||
signing and broadcasting. For this, the Binaryen library is used. Because | ||
this is a large library it is not included in `eosjs` by default. | ||
#### Compile | ||
Add binaryen to your project: | ||
If you're loading a **wasm** file, you do not need binaryen. If you're loading | ||
a **wast** file you can include and configure the binaryen compiler, this is | ||
used to compile to **wasm** automatically when calling **setcode**. | ||
Versions of binaryen may be [problematic](https://github.com/EOSIO/eos/issues/2187). | ||
```bash | ||
npm i binaryen@37.0.0 | ||
$ npm install binaryen@37.0.0 | ||
``` | ||
Although the EOS back-end does seek to be up-to-date and have | ||
binaryen backwards compatibility, new versions of binaryen may be | ||
[problematic](https://github.com/EOSIO/eos/issues/2187). | ||
Import and include the library when you configure Eos: | ||
```javascript | ||
```js | ||
binaryen = require('binaryen') | ||
eos = Eos({..., binaryen}) | ||
eos = Eos({keyProvider, binaryen}) | ||
``` | ||
Complete example: | ||
#### Deploy | ||
```javascript | ||
Eos = require('eosjs') // Eos = require('./src') | ||
wasm = fs.readFileSync(`docker/contracts/eosio.token/eosio.token.wasm`) | ||
abi = fs.readFileSync(`docker/contracts/eosio.token/eosio.token.abi`) | ||
keyProvider = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' | ||
// Publish contract to the blockchain | ||
eos.setcode('myaccount', 0, 0, wasm) // @returns {Promise} | ||
eos.setabi('myaccount', JSON.parse(abi)) // @returns {Promise} | ||
``` | ||
// If you're loading a wasm file, you do not need binaryen. If you're loading | ||
// a "wast" file you can include and configure the binaryen compiler: | ||
// | ||
// $ npm install binaryen@37.0.0 | ||
// binaryen = require('binaryen') | ||
// eos = Eos({keyProvider, binaryen}) | ||
#### Fetch a smart contract | ||
eos = Eos({keyProvider}) | ||
```js | ||
// @returns {Promise} | ||
eos.contract('myaccount', [options], [callback]) | ||
wasm = fs.readFileSync(`docker/contracts/eosio.token/eosio.token.wasm`) | ||
abi = fs.readFileSync(`docker/contracts/eosio.token/eosio.token.abi`) | ||
// Run immediately, `myaction` returns a Promise | ||
eos.contract('myaccount').then(myaccount => myaccount.myaction(..)) | ||
// Publish contract to the blockchain | ||
eos.setcode('inita', 0, 0, wasm) | ||
eos.setabi('inita', JSON.parse(abi)) | ||
// Group actions. `transaction` returns a Promise but `myaction` does not | ||
eos.transaction('myaccount', myaccount => { myaccount.myaction(..) }) | ||
// Error reading contract; https://github.com/EOSIO/eos/issues/3159 | ||
eos.contract('inita').then(c => inita = c) | ||
inita.create('inita', '1000.0000 CUR', {authorization: 'inita'}) | ||
// Transaction with multiple contracts | ||
eos.transaction(['myaccount', 'myaccount2'], ({myaccount, myaccount2}) => { | ||
myaccount.myaction(..) | ||
myaccount2.myaction(..) | ||
}) | ||
``` | ||
### Atomic Operations | ||
#### Custom Token | ||
Blockchain level atomic operations. All will pass or fail. | ||
```js | ||
(async function() { | ||
```javascript | ||
Eos = require('eosjs') // Eos = require('./src') | ||
// more on the contract / transaction syntax below | ||
keyProvider = [ | ||
'5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', | ||
Eos.modules.ecc.seedPrivate('currency') | ||
] | ||
await eos.transaction('myaccount', myaccount => { | ||
eos = Eos({keyProvider}) | ||
// Create the initial token with its max supply | ||
// const options = {authorization: 'myaccount'} // default | ||
myaccount.create('myaccount', '10000000.000 TOK')//, options) | ||
// if either transfer fails, both will fail (1 transaction, 2 messages) | ||
eos.transaction(eos => | ||
{ | ||
eos.transfer('inita', 'initb', '1 SYS', '') | ||
eos.transfer('inita', 'initc', '1 SYS', '') | ||
// Returning a promise is optional (but handled as expected) | ||
} | ||
// [options], | ||
// [callback] | ||
) | ||
// NOTE: the TOK@myaccount behavior is being defined and | ||
// may change in a future "major" eosjs version release. | ||
// transaction on a single contract | ||
eos.transaction('currency', currency => { | ||
currency.transfer('inita', 'initb', '1 CUR', '') | ||
}) | ||
// mix contracts in the same transaction | ||
eos.transaction(['currency', 'eosio.token'], ({currency, eosio_token}) => { | ||
currency.transfer('inita', 'initb', '1 CUR', '') | ||
eosio_token.transfer('inita', 'initb', '1 SYS', '') | ||
}) | ||
// contract lookups then transactions | ||
eos.contract('currency').then(currency => { | ||
currency.transaction(cur => { | ||
cur.transfer('inita', 'initb', '1 CUR', '') | ||
cur.transfer('initb', 'initc', '1 CUR', '') | ||
// Issue some of the max supply for circulation into an arbitrary account | ||
myaccount.issue('myaccount', '10000.000 TOK', 'issue') | ||
}) | ||
currency.transfer('inita', 'initb', '1 CUR', '') | ||
}) | ||
// Note, the contract method does not take an array. Just use Await or yield | ||
// if multiple contracts are needed outside of a transaction. | ||
const balance = await eos.getCurrencyBalance('myaccount', 'myaccount', 'TOK') | ||
console.log('Currency Balance', balance) | ||
})() | ||
``` | ||
### Usage (manual) | ||
### Calling Actions | ||
A manual transaction provides for more flexibility. | ||
Other ways to use contracts and transactions. | ||
```javascript | ||
Eos = require('eosjs') // Eos = require('./src') | ||
(async function() { | ||
eos = Eos({keyProvider: '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'}) | ||
// returns Promise | ||
eos.transaction({ | ||
actions: [ | ||
// if either transfer fails, both will fail (1 transaction, 2 messages) | ||
await eos.transaction(eos => | ||
{ | ||
account: 'eosio.token', | ||
name: 'transfer', | ||
authorization: [{ | ||
actor: 'inita', | ||
permission: 'active' | ||
}], | ||
data: { | ||
from: 'inita', | ||
to: 'initb', | ||
quantity: '7 SYS', | ||
memo: '' | ||
} | ||
eos.transfer('inita', 'initb', '1 SYS', ''/*memo*/) | ||
eos.transfer('inita', 'initc', '1 SYS', ''/*memo*/) | ||
// Returning a promise is optional (but handled as expected) | ||
} | ||
] | ||
}) | ||
// [options], | ||
// [callback] | ||
) | ||
// NOTE: the TOK@myaccount behavior is being defined and | ||
// may change in a future "major" eosjs version release. | ||
// transaction on a single contract | ||
await eos.transaction('myaccount', myaccount => { | ||
myaccount.transfer('myaccount', 'inita', '10 TOK@myaccount', '') | ||
}) | ||
// mix contracts in the same transaction | ||
await eos.transaction(['myaccount', 'eosio.token'], ({myaccount, eosio_token}) => { | ||
myaccount.transfer('inita', 'initb', '1 TOK@myaccount', '') | ||
eosio_token.transfer('inita', 'initb', '1 SYS', '') | ||
}) | ||
// The contract method does not take an array so must be called once for | ||
// each contract that is needed. | ||
const myaccount = await eos.contract('myaccount') | ||
await myaccount.transfer('myaccount', 'inita', '1.000 TOK', '') | ||
// a transaction to a contract instance can specify multiple actions | ||
await myaccount.transaction(myaccountTr => { | ||
myaccountTr.transfer('inita', 'initb', '1.000 TOK', '') | ||
myaccountTr.transfer('initb', 'inita', '1.000 TOK', '') | ||
}) | ||
})() | ||
``` | ||
@@ -333,3 +467,7 @@ | ||
Eos = require('./src') | ||
eos = Eos() | ||
// forceActionDataHex = false helps transaction readability but may trigger back-end bugs | ||
config = {debug: false, broadcast: true, forceActionDataHex: true, keyProvider} | ||
eos = Eos(config) | ||
``` | ||
@@ -348,9 +486,10 @@ | ||
// ABI Serialization | ||
eos.contract('eosio.token', (error, c) => eosio_token = c) | ||
create = {issuer: 'inita', maximum_supply: '1.0000 SYS'} | ||
buffer = eosio_token.fc.toBuffer('create', create) | ||
assert.deepEqual(create, eosio_token.fc.fromBuffer('create', buffer)) | ||
eos.contract('eosio.token', (error, eosio_token) => { | ||
create = {issuer: 'inita', maximum_supply: '1.0000 SYS'} | ||
buffer = eosio_token.fc.toBuffer('create', create) | ||
assert.deepEqual(create, eosio_token.fc.fromBuffer('create', buffer)) | ||
}) | ||
``` | ||
Use Node v8+ to `package-lock.json`. | ||
Use Node v8+ for `package-lock.json`. | ||
@@ -357,0 +496,0 @@ # Related Libraries |
Sorry, the diff of this file is not supported yet
1377523
36070
548
13
+ Addedbabel-runtime@^6.26.0
+ Addedeosjs-api@6.2.1(transitive)
- Removedbabel-polyfill@^6.26.0
- Removedbabel-polyfill@6.26.0(transitive)
- Removedeosjs-api@6.1.3(transitive)
- Removedregenerator-runtime@0.10.5(transitive)
Updatedeosjs-api@6.2.1