New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eosjs

Package Overview
Dependencies
Maintainers
2
Versions
292
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eosjs - npm Package Compare versions

Comparing version 6.1.8 to 7.0.0

mocha

57

lib/abi-cache.js
'use strict';
var assert = require('assert');
var Structs = require('./structs');

@@ -12,21 +13,28 @@

function abiAsync(code) {
var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
/**
@arg {boolean} force false when ABI is immutable. When force is true, API
user is still free to cache the contract object returned by eosjs.
*/
function abiAsync(account) {
var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (force == false && cache[code] != null) {
return Promise.resolve(cache[code]);
assert(account, 'required account');
if (force == false && cache[account] != null) {
return Promise.resolve(cache[account]);
}
return network.getCode(code).then(function (_ref) {
return network.getCode(account).then(function (_ref) {
var abi = _ref.abi;
assert(abi, 'Missing ABI for account: ' + account);
var schema = abiToFcSchema(abi);
var structs = Structs(config, schema); // structs = {structs, types}
return cache[code] = Object.assign({ abi: abi, schema: schema }, structs);
return cache[account] = Object.assign({ abi: abi, schema: schema }, structs);
});
}
function abi(code) {
var c = cache[code];
function abi(account) {
var c = cache[account];
if (c == null) {
throw new Error('Abi \'' + code + '\' is not cached, call abiAsync(\'' + code + '\')');
throw new Error('Abi \'' + account + '\' is not cached, call abiAsync(\'' + account + '\')');
}

@@ -57,7 +65,30 @@ return c;

abi.structs.forEach(function (e) {
var base = e.base,
fields = e.fields;
var fields = {};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
abiSchema[e.name] = { base: base, fields: fields };
if (base === '') {
try {
for (var _iterator = e.fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var field = _step.value;
fields[field.name] = field.type;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
abiSchema[e.name] = { base: e.base, fields: fields };
if (e.base === '') {
delete abiSchema[e.name].base;

@@ -64,0 +95,0 @@ }

@@ -73,4 +73,17 @@ 'use strict';

var eos = mergeWriteFunctions(config, Network);
var _Structs = Structs(config),
structs = _Structs.structs,
types = _Structs.types,
fromBuffer = _Structs.fromBuffer,
toBuffer = _Structs.toBuffer;
var eos = mergeWriteFunctions(config, Network, structs);
Object.assign(eos, { fc: {
structs: structs,
types: types,
fromBuffer: fromBuffer,
toBuffer: toBuffer
} });
if (!config.signProvider) {

@@ -110,18 +123,11 @@ config.signProvider = defaultSignProvider(eos, config);

*/
function mergeWriteFunctions(config, Network) {
function mergeWriteFunctions(config, Network, structs) {
assert(config.network, 'network instance required');
var network = config.network;
var _Structs = Structs(config),
structs = _Structs.structs,
types = _Structs.types;
var merge = Object.assign({}, { fc: { structs: structs, types: types } });
var merge = Object.assign({}, network);
throwOnDuplicate(merge, network, 'Conflicting methods in Eos and Network Api');
Object.assign(merge, network);
var writeApi = writeApiGen(Network, network, structs, config);
throwOnDuplicate(merge, writeApi, 'Conflicting methods in Eos and Transaction Api');
throwOnDuplicate(merge, writeApi, 'Conflicting methods in Network Api and Transaction Api');
Object.assign(merge, writeApi);

@@ -128,0 +134,0 @@

@@ -22,5 +22,9 @@ 'use strict';

var headers = {
expiration: new Date().toISOString().split('.')[0],
region: 0,
ref_block_num: 1,
ref_block_prefix: 452435776,
expiration: new Date().toISOString().split('.')[0]
context_free_cpu_bandwidth: 0,
packed_bandwidth_words: 0,
context_free_actions: []
};

@@ -42,8 +46,12 @@

var memo = '';
var trx = await eos.transfer('bankers', 'people', 1000000000000, memo);
var trx = await eos.transfer('bankers', 'people', '1000000 EOS', memo);
assert.deepEqual({
ref_block_num: trx.transaction.ref_block_num,
ref_block_prefix: trx.transaction.ref_block_prefix,
expiration: trx.transaction.expiration
expiration: trx.transaction.data.expiration,
region: 0,
ref_block_num: trx.transaction.data.ref_block_num,
ref_block_prefix: trx.transaction.data.ref_block_prefix,
context_free_cpu_bandwidth: 0,
packed_bandwidth_words: 0,
context_free_actions: []
}, headers);

@@ -97,3 +105,3 @@

return eos.transfer('inita', 'initb', 1, '', false).then(function (tr) {
return eos.transfer('inita', 'initb', '1 EOS', '', false).then(function (tr) {
assert.equal(tr.transaction.signatures.length, 1);

@@ -115,3 +123,3 @@ assert.equal(_typeof(tr.transaction.signatures[0]), 'string');

if (!pubkeys) {
assert.equal(transaction.messages[0].type, 'transfer');
assert.equal(transaction.actions[0].name, 'transfer');
return [pubkey];

@@ -129,3 +137,3 @@ }

return eos.transfer('inita', 'initb', 9, '', false).then(function (tr) {
return eos.transfer('inita', 'initb', '9 EOS', '', false).then(function (tr) {
assert.equal(tr.transaction.signatures.length, 1);

@@ -140,3 +148,3 @@ assert.equal(_typeof(tr.transaction.signatures[0]), 'string');

var eos = Eos.Localnet({ keyProvider: keystore.keyProvider });
return eos.transfer('inita', 'initb', 12, '', true);
return eos.transfer('inita', 'initb', '12 EOS', '', true);
});

@@ -161,3 +169,3 @@

var eos = Eos.Localnet({ signProvider: customSignProvider });
return eos.transfer('inita', 'initb', 2, '', false);
return eos.transfer('inita', 'initb', '2 EOS', '', false);
});

@@ -176,4 +184,3 @@

active: pubkey,
recovery: 'inita',
deposit: '1.0000 EOS'
recovery: 'inita'
});

@@ -184,3 +191,3 @@ });

var eos = Eos.Localnet({ signProvider: signProvider, mockTransactions: 'pass' });
return eos.transfer('inita', 'initb', 1, '').then(function (transfer) {
return eos.transfer('inita', 'initb', '1 EOS', '').then(function (transfer) {
assert(transfer.mockTransaction, 'transfer.mockTransaction');

@@ -192,3 +199,3 @@ });

var eos = Eos.Localnet({ signProvider: signProvider, mockTransactions: 'fail' });
return eos.transfer('inita', 'initb', 1, '').catch(function (error) {
return eos.transfer('inita', 'initb', '1 EOS', '').catch(function (error) {
assert(error.indexOf('fake error') !== -1, 'expecting: fake error');

@@ -200,3 +207,3 @@ });

var eos = Eos.Localnet({ signProvider: signProvider });
return eos.transfer('inita', 'initb', 1, '');
return eos.transfer('inita', 'initb', '1 EOS', '');
});

@@ -206,3 +213,3 @@

var eos = Eos.Localnet({ signProvider: signProvider });
return eos.transfer('inita', 'initb', 1, '', { authorization: 'inita@owner' });
return eos.transfer('inita', 'initb', '1 EOS', '', { authorization: 'inita@owner' });
});

@@ -212,29 +219,13 @@

var eos = Eos.Localnet({ signProvider: signProvider });
return eos.transfer('inita', 'initb', 1, '', { authorization: ['initb@owner', 'inita@owner'], broadcast: false }).then(function (_ref4) {
return eos.transfer('inita', 'initb', '1 EOS', '', { authorization: ['initb@owner', 'inita@owner'], broadcast: false }).then(function (_ref4) {
var transaction = _ref4.transaction;
var ans = [{ account: 'inita', permission: 'owner' }, { account: 'initb', permission: 'owner' }];
assert.deepEqual(transaction.messages[0].authorization, ans);
var ans = [{ actor: 'inita', permission: 'owner' }, { actor: 'initb', permission: 'owner' }];
assert.deepEqual(transaction.data.actions[0].authorization, ans);
});
});
it('transfer custom scope (broadcast)', function () {
var eos = Eos.Localnet({ signProvider: signProvider });
// To pass: initb, inita must get sorted to: inita, initb
return eos.transfer('inita', 'initb', 2, '', { scope: ['initb', 'inita'] });
});
it('transfer custom scope array (no broadcast)', function () {
var eos = Eos.Localnet({ signProvider: signProvider });
// To pass: scopes must get sorted
return eos.transfer('inita', 'initb', 1, '', { scope: ['joe', 'billy'], broadcast: false }).then(function (_ref5) {
var transaction = _ref5.transaction;
assert.deepEqual(transaction.scope, ['billy', 'joe']);
});
});
it('transfer (no broadcast)', function () {
var eos = Eos.Localnet({ signProvider: signProvider });
return eos.transfer('inita', 'initb', 1, '', { broadcast: false });
return eos.transfer('inita', 'initb', '1 EOS', '', { broadcast: false });
});

@@ -245,3 +236,3 @@

var opts = { broadcast: false, sign: false };
return eos.transfer('inita', 'initb', 1, '', opts).then(function (tr) {
return eos.transfer('inita', 'initb', '1 EOS', '', opts).then(function (tr) {
return assert.deepEqual(tr.transaction.signatures, []);

@@ -253,6 +244,6 @@ });

var eos = Eos.Localnet({ signProvider: promiseSigner });
return eos.transfer('inita', 'initb', 1, '', false);
return eos.transfer('inita', 'initb', '1 EOS', '', false);
});
it('message to unknown contract', function () {
it('action to unknown contract', function () {
var name = 'acdef513521';

@@ -262,19 +253,19 @@ return Eos.Localnet({ signProvider: signProvider }).contract(name).then(function () {

}).catch(function (error) {
assert(/unknown key/.test(error.toString()), 'expecting "unknown key" error message, instead got: ' + error);
assert(/unknown key/.test(error.toString()), 'expecting "unknown key" error action, instead got: ' + error);
});
});
it('message to contract', function () {
it('action to contract', function () {
// initaPrivate = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'
// eos is a bad test case, but it was the only native contract
var name = 'eos';
var name = 'eosio';
return Eos.Localnet({ signProvider: signProvider }).contract(name).then(function (contract) {
contract.transfer('inita', 'initd', 1, '')
contract.transfer('inita', 'initb', '1 EOS', '')
// transaction sent on each command
.then(function (tr) {
assert.equal(1, tr.transaction.messages.length);
});
assert.equal(1, tr.transaction.data.actions.length);
contract.transfer('initd', 'inita', 1, '').then(function (tr) {
assert.equal(1, tr.transaction.messages.length);
return contract.transfer('initb', 'inita', '1 EOS', '').then(function (tr) {
assert.equal(1, tr.transaction.data.actions.length);
});
});

@@ -286,3 +277,3 @@ }).then(function (r) {

it('message to contract atomic', function () {
it('action to contract atomic', function () {
var amt = 1; // for unique transactions

@@ -292,4 +283,4 @@ var testnet = Eos.Localnet({ signProvider: signProvider });

var trTest = function trTest(eos) {
assert(eos.transfer('inita', 'initf', amt, '') == null);
assert(eos.transfer('initf', 'inita', amt++, '') == null);
assert(eos.transfer('inita', 'initb', amt + ' EOS', '') == null);
assert(eos.transfer('initb', 'inita', amt++ + ' EOS', '') == null);
};

@@ -299,3 +290,3 @@

return test.then(function (tr) {
assert.equal(2, tr.transaction.messages.length);
assert.equal(2, tr.transaction.data.actions.length);
});

@@ -305,36 +296,37 @@ };

// contracts can be a string or array
assertTr(testnet.transaction(['eos'], function (_ref6) {
var eos = _ref6.eos;
return trTest(eos);
assertTr(testnet.transaction(['eosio'], function (_ref5) {
var eosio = _ref5.eosio;
return trTest(eosio);
}));
assertTr(testnet.transaction('eos', function (eos) {
return trTest(eos);
assertTr(testnet.transaction('eosio', function (eosio) {
return trTest(eosio);
}));
});
it('message to contract (contract tr nesting)', function () {
it('action to contract (contract tr nesting)', function () {
var tn = Eos.Localnet({ signProvider: signProvider });
return tn.contract('eos').then(function (eos) {
eos.transaction(function (tr) {
tr.transfer('inita', 'initd', 1, '');
tr.transfer('inita', 'inite', 1, '');
return tn.contract('eosio').then(function (eosio) {
return eosio.transaction(function (tr) {
tr.transfer('inita', 'initb', '1 EOS', '');
tr.transfer('inita', 'initc', '2 EOS', '');
}).then(function () {
return eosio.transfer('inita', 'initb', '3 EOS', '');
});
eos.transfer('inita', 'initf', 1, '');
});
});
it('multi-message transaction (broadcast)', function () {
it('multi-action transaction (broadcast)', function () {
var eos = Eos.Localnet({ signProvider: signProvider });
return eos.transaction(function (tr) {
assert(tr.transfer('inita', 'initb', 1, '') == null);
assert(tr.transfer({ from: 'inita', to: 'initc', amount: 1, memo: '' }) == null);
assert(tr.transfer('inita', 'initb', '1 EOS', '') == null);
assert(tr.transfer({ from: 'inita', to: 'initc', quantity: '1 EOS', memo: '' }) == null);
}).then(function (tr) {
assert.equal(2, tr.transaction.messages.length);
assert.equal(2, tr.transaction.data.actions.length);
});
});
it('multi-message transaction no inner callback', function () {
it('multi-action transaction no inner callback', function () {
var eos = Eos.Localnet({ signProvider: signProvider });
eos.transaction(function (tr) {
tr.okproducer('inita', 'inita', 1, function (cb) {});
return eos.transaction(function (tr) {
tr.transfer('inita', 'inita', '1 EOS', '', function (cb) {});
}).then(function () {

@@ -347,3 +339,3 @@ throw 'expecting rollback';

it('multi-message transaction error rollback', function () {
it('multi-action transaction error rollback', function () {
var eos = Eos.Localnet({ signProvider: signProvider });

@@ -359,5 +351,5 @@ return eos.transaction(function (tr) {

it('multi-message transaction Promise.reject rollback', function () {
it('multi-action transaction Promise.reject rollback', function () {
var eos = Eos.Localnet({ signProvider: signProvider });
eos.transaction(function (tr) {
return eos.transaction(function (tr) {
return Promise.reject('rollback');

@@ -374,14 +366,13 @@ }).then(function () {

return eos.transaction({
scope: ['inita', 'initb'],
messages: [{
code: 'eos',
type: 'transfer',
actions: [{
account: 'eosio',
name: 'transfer',
data: {
from: 'inita',
to: 'initb',
amount: '13',
quantity: '13 EOS',
memo: '爱'
},
authorization: [{
account: 'inita',
actor: 'inita',
permission: 'active'

@@ -394,2 +385,3 @@ }]

// ./eosioc set contract currency build/contracts/currency/currency.wast build/contracts/currency/currency.abi
if (process.env['CURRENCY_ABI'] != null) {

@@ -399,13 +391,13 @@ it('Transaction ABI lookup', async function () {

var tx = await eos.transaction({
scope: ['inita', 'initb'],
messages: [{
code: 'currency',
type: 'transfer',
actions: [{
account: 'currency',
name: 'transfer',
data: {
from: 'inita',
to: 'initb',
quantity: '13'
quantity: '13 CUR',
memo: ''
},
authorization: [{
account: 'inita',
actor: 'inita',
permission: 'active'

@@ -415,4 +407,3 @@ }]

}, { sign: false, broadcast: false });
console.log('tx', tx);
assert.equal(tx.transaction.messages[0].code, 'currency');
assert.equal(tx.transaction.data.actions[0].account, 'currency');
});

@@ -419,0 +410,0 @@ } else {

@@ -30,11 +30,12 @@ 'use strict';

var structLookup = function structLookup(name, code) {
if (code === 'eos') {
return structs[name];
var structLookup = function structLookup(lookupName, account) {
if (account === 'eosio') {
return structs[lookupName];
}
var abi = config.abiCache.abi(code);
var struct = abi.structs[name];
var abi = config.abiCache.abi(account);
var struct = abi.structs[lookupName];
if (struct != null) {
return struct;
}
// TODO: move up (before `const struct = abi.structs[lookupName]`)
var _iteratorNormalCompletion = true;

@@ -47,6 +48,6 @@ var _didIteratorError = false;

var action = _step.value;
var action_name = action.action_name,
var name = action.name,
type = action.type;
if (action_name === name) {
if (name === lookupName) {
var _struct = abi.structs[type];

@@ -73,12 +74,17 @@ if (_struct != null) {

throw new Error('Missing ABI struct or action: ' + name);
throw new Error('Missing ABI struct or action: ' + lookupName);
};
// If eosd does not have an ABI setup for a certain message.type, it will throw
// an error: `Invalid cast from object_type to string` .. forceMessageDataHex
// If eosd does not have an ABI setup for a certain action.type, it will throw
// an error: `Invalid cast from object_type to string` .. forceActionDataHex
// may be used to until native ABI is added or fixed.
var forceMessageDataHex = config.forceMessageDataHex != null ? config.forceMessageDataHex : false;
var forceActionDataHex = config.forceActionDataHex != null ? config.forceActionDataHex : true;
var override = Object.assign({}, authorityOverride, abiOverride, wasmCodeOverride(config), messageDataOverride(structLookup, forceMessageDataHex), config.override);
var override = Object.assign({}, authorityOverride, abiOverride, wasmCodeOverride(config), actionDataOverride(structLookup, forceActionDataHex), config.override);
// eosTypes reconciled with:
// eos::abi_serializer.cpp
// eosjs-json::base.json
// eosjs-json::generated.json
var eosTypes = {

@@ -91,3 +97,3 @@ name: function name() {

},
asset_symbol: function asset_symbol() {
symbol: function symbol() {
return [AssetSymbol];

@@ -97,3 +103,6 @@ },

return [Asset];
} // must come after AssetSymbol
}, // must come after AssetSymbol
signature: function signature() {
return [Signature];
}
};

@@ -104,5 +113,8 @@

// Do not sort transaction messages
config.nosort = Object.assign({}, config.nosort);
config.nosort['transaction.message'] = true;
// Do not sort transaction actions
config.sort = Object.assign({}, config.sort);
config.sort['action.authorization'] = true;
config.sort['signed_transaction.signature'] = true;
config.sort['authority.accounts'] = true;
config.sort['authority.keys'] = true;

@@ -114,3 +126,5 @@ var schema = Object.assign({}, json.schema, extendedSchema);

types = _Fcbuffer.types,
errors = _Fcbuffer.errors;
errors = _Fcbuffer.errors,
fromBuffer = _Fcbuffer.fromBuffer,
toBuffer = _Fcbuffer.toBuffer;

@@ -121,3 +135,3 @@ if (errors.length !== 0) {

return { structs: structs, types: types };
return { structs: structs, types: types, fromBuffer: fromBuffer, toBuffer: toBuffer };
};

@@ -155,5 +169,35 @@

var PublicKeyType = function PublicKeyType(validation) {
var PublicKeyType = function PublicKeyType(validation, baseTypes) {
var staticVariant = baseTypes.static_variant([PublicKeyEcc(validation)]
// PublicKeyR1(validation)
);
return {
fromByteBuffer: function fromByteBuffer(b) {
return staticVariant.fromByteBuffer(b);
},
appendByteBuffer: function appendByteBuffer(b, value) {
if (!Array.isArray(value)) {
value = [0, value];
}
staticVariant.appendByteBuffer(b, value);
},
fromObject: function fromObject(value) {
if (!Array.isArray(value)) {
value = [0, value];
}
return staticVariant.fromObject(value)[1];
},
toObject: function toObject(value) {
if (!Array.isArray(value)) {
value = [0, value];
}
return staticVariant.toObject(value)[1];
}
};
};
var PublicKeyEcc = function PublicKeyEcc(validation) {
return {
fromByteBuffer: function fromByteBuffer(b) {
var bcopy = b.copy(b.offset, b.offset + 33);

@@ -193,9 +237,10 @@ b.skip(33);

var prefix = '\x04';
var prefix = '\x04'; // 4 decimals in EOS
return {
fromByteBuffer: function fromByteBuffer(b) {
var bcopy = b.copy(b.offset, b.offset + 7);
b.skip(7);
var bcopy = b.copy(b.offset, b.offset + 8);
b.skip(8);
// TODO
// const precision = bcopy.readUint8()

@@ -206,3 +251,3 @@ // console.log('precision', precision)

if (bin.slice(0, 1) !== prefix) {
throw new TypeError('Asset precision does not match');
throw new TypeError('Asset precision does not match: ' + bin.slice(0, 1));
}

@@ -259,5 +304,6 @@ var symbol = '';

/** @example '0.0001 CUR' */
var Asset = function Asset(validation, baseTypes, customTypes) {
var amountType = baseTypes.int64(validation);
var symbolType = customTypes.asset_symbol(validation);
var symbolType = customTypes.symbol(validation);

@@ -296,2 +342,4 @@ var symbolCache = function symbolCache(symbol) {

appendByteBuffer: function appendByteBuffer(b, value) {
assert.equal(typeof value === 'undefined' ? 'undefined' : _typeof(value), 'string', 'value');
var _value$split3 = value.split(' '),

@@ -317,2 +365,32 @@ _value$split4 = _slicedToArray(_value$split3, 2),

var Signature = function Signature(validation, baseTypes, customTypes) {
var signatureType = baseTypes.fixed_bytes65(validation);
return {
fromByteBuffer: function fromByteBuffer(b) {
console.log(1);
var signatureBuffer = signatureType.fromByteBuffer(b);
var signature = ecc.Signature.from(signatureBuffer);
return signature.toString();
},
appendByteBuffer: function appendByteBuffer(b, value) {
console.log(2);
var signature = ecc.Signature.from(value);
signatureType.appendByteBuffer(b, signature.toBuffer());
},
fromObject: function fromObject(value) {
console.log(3);
var signature = ecc.Signature.from(value);
return signature.toString();
},
toObject: function toObject(value) {
console.log(4);
if (validation.defaults && value == null) {
return 'SIGnature..';
}
var signature = ecc.Signature.from(value);
return signature.toString();
}
};
};
var authorityOverride = {

@@ -340,3 +418,3 @@ /** shorthand `EOS6MRyAj..` */

permission: {
account: account,
actor: account,
permission: permission

@@ -390,5 +468,5 @@ },

*/
var messageDataOverride = function messageDataOverride(structLookup, forceMessageDataHex) {
var actionDataOverride = function actionDataOverride(structLookup, forceActionDataHex) {
return {
'message.data.fromByteBuffer': function messageDataFromByteBuffer(_ref2) {
'action.data.fromByteBuffer': function actionDataFromByteBuffer(_ref2) {
var fields = _ref2.fields,

@@ -399,8 +477,8 @@ object = _ref2.object,

var ser = (object.type || '') == '' ? fields.data : structLookup(object.type, object.code);
var ser = (object.name || '') == '' ? fields.data : structLookup(object.name, object.account);
if (ser) {
b.readVarint32(); // length prefix (usefull if object.type is unknown)
b.readVarint32(); // length prefix (usefull if object.name is unknown)
object.data = ser.fromByteBuffer(b, config);
} else {
// console.log(`Unknown Message.type ${object.type}`)
// console.log(`Unknown Action.name ${object.name}`)
var lenPrefix = b.readVarint32();

@@ -413,3 +491,3 @@ var bCopy = b.copy(b.offset, b.offset + lenPrefix);

'message.data.appendByteBuffer': function messageDataAppendByteBuffer(_ref3) {
'action.data.appendByteBuffer': function actionDataAppendByteBuffer(_ref3) {
var fields = _ref3.fields,

@@ -419,3 +497,3 @@ object = _ref3.object,

var ser = (object.type || '') == '' ? fields.data : structLookup(object.type, object.code);
var ser = (object.name || '') == '' ? fields.data : structLookup(object.name, object.account);
if (ser) {

@@ -427,6 +505,6 @@ var b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);

} else {
// console.log(`Unknown Message.type ${object.type}`)
// 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('Expecting hex string or buffer in message.data');
throw new TypeError('Expecting hex string or buffer in action.data');
}

@@ -438,3 +516,3 @@ b.writeVarint32(data.length);

'message.data.fromObject': function messageDataFromObject(_ref4) {
'action.data.fromObject': function actionDataFromObject(_ref4) {
var fields = _ref4.fields,

@@ -444,5 +522,5 @@ object = _ref4.object,

var data = object.data,
type = object.type;
name = object.name;
var ser = (type || '') == '' ? fields.data : structLookup(type, object.code);
var ser = (name || '') == '' ? fields.data : structLookup(name, object.account);
if (ser) {

@@ -456,6 +534,6 @@ if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') {

} else {
throw new TypeError('Expecting hex string or object in message.data');
throw new TypeError('Expecting hex string or object in action.data');
}
} else {
// console.log(`Unknown Message.type ${object.type}`)
// console.log(`Unknown Action.name ${object.name}`)
result.data = data;

@@ -465,3 +543,3 @@ }

'message.data.toObject': function messageDataToObject(_ref5) {
'action.data.toObject': function actionDataToObject(_ref5) {
var fields = _ref5.fields,

@@ -474,5 +552,5 @@ object = _ref5.object,

data = _ref6.data,
type = _ref6.type;
name = _ref6.name;
var ser = (type || '') == '' ? fields.data : structLookup(type, object.code);
var ser = (name || '') == '' ? fields.data : structLookup(name, object.account);
if (!ser) {

@@ -489,3 +567,3 @@ // Types without an ABI will accept hex

if (forceMessageDataHex) {
if (forceActionDataHex) {
var b2 = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN);

@@ -492,0 +570,0 @@ if (data) {

@@ -65,7 +65,7 @@ 'use strict';

it('asset_symbol', function () {
it('symbol', function () {
var eos = Eos.Localnet();
var types = eos.fc.types;
var AssetSymbolType = types.asset_symbol();
var AssetSymbolType = types.symbol();

@@ -85,11 +85,11 @@ assertSerializer(AssetSymbolType, 'EOS');

var opts = { sign: false, broadcast: false };
var tx = await local.transaction(['currency', 'eos'], function (_ref) {
var tx = await local.transaction(['currency', 'eosio'], function (_ref) {
var currency = _ref.currency,
eos = _ref.eos;
eosio = _ref.eosio;
eos.transfer('inita', 'initd', 1, ''); // make sure {code: 'eos', ..} remains first
currency.transfer('inita', 'initd', 1); // {code: 'currency', ..} remains second
eosio.transfer('inita', 'initd', '1 EOS', ''); // make sure {account: 'eosio', ..} remains first
currency.transfer('inita', 'initd', '1 CUR', ''); // {account: 'currency', ..} remains second
}, opts);
assert.equal(tx.transaction.messages[0].code, 'eos');
assert.equal(tx.transaction.messages[1].code, 'currency');
assert.equal(tx.transaction.data.actions[0].account, 'eosio');
assert.equal(tx.transaction.data.actions[1].account, 'currency');
});

@@ -103,3 +103,3 @@ });

it('json', function () {
var eos = Eos.Localnet({ forceMessageDataHex: false });
var eos = Eos.Localnet({ forceActionDataHex: false });
var _eos$fc2 = eos.fc,

@@ -110,8 +110,8 @@ structs = _eos$fc2.structs,

var value = {
code: 'eos',
type: 'transfer',
account: 'eosio',
name: 'transfer',
data: {
from: 'inita',
to: 'initb',
amount: '1',
quantity: '1.0000 EOS',
memo: ''

@@ -121,7 +121,7 @@ },

};
assertSerializer(structs.message, value);
assertSerializer(structs.action, value);
});
it('hex', function () {
var eos = Eos.Localnet({ forceMessageDataHex: false, debug: false });
var eos = Eos.Localnet({ forceActionDataHex: false, debug: false });
var _eos$fc3 = eos.fc,

@@ -132,3 +132,3 @@ structs = _eos$fc3.structs,

var tr = { from: 'inita', to: 'initb', amount: '1', memo: '' };
var tr = { from: 'inita', to: 'initb', quantity: '1.0000 EOS', memo: '' };
var hex = Fcbuffer.toBuffer(structs.transfer, tr).toString('hex');

@@ -138,4 +138,4 @@ // const lenPrefixHex = Number(hex.length / 2).toString(16) + hex.toString('hex')

var value = {
code: 'eos',
type: 'transfer',
account: 'eosio',
name: 'transfer',
data: hex,

@@ -145,3 +145,3 @@ authorization: []

var type = structs.message;
var type = structs.action;
var obj = type.fromObject(value); // tests fromObject

@@ -157,3 +157,3 @@ var buf = Fcbuffer.toBuffer(type, obj); // tests appendByteBuffer

it('force hex', function () {
var eos = Eos.Localnet({ forceMessageDataHex: true });
var eos = Eos.Localnet({ forceActionDataHex: true });
var _eos$fc4 = eos.fc,

@@ -164,8 +164,8 @@ structs = _eos$fc4.structs,

var value = {
code: 'eos',
type: 'transfer',
account: 'eosio',
name: 'transfer',
data: {
from: 'inita',
to: 'initb',
amount: '1',
quantity: '1 EOS',
memo: ''

@@ -175,3 +175,3 @@ },

};
var type = structs.message;
var type = structs.action;
var obj = type.fromObject(value); // tests fromObject

@@ -191,3 +191,3 @@ var buf = Fcbuffer.toBuffer(type, obj); // tests appendByteBuffer

it('unknown type', function () {
var eos = Eos.Localnet({ forceMessageDataHex: false });
var eos = Eos.Localnet({ forceActionDataHex: false });
var _eos$fc5 = eos.fc,

@@ -198,8 +198,8 @@ structs = _eos$fc5.structs,

var value = {
code: 'eos',
type: 'mytype',
account: 'eosio',
name: 'mytype',
data: '030a0b0c',
authorization: []
};
assertSerializer(structs.message, value);
assertSerializer(structs.action, value);
});

@@ -206,0 +206,0 @@ });

@@ -31,3 +31,3 @@ 'use strict';

// sends transactions, also a message collecting wrapper functions
// sends transactions, also a action collecting wrapper functions
merge.transaction = writeApi.genTransaction(structs, merge);

@@ -37,15 +37,13 @@

for (var type in Network.schema) {
if (!/^[a-z]/.test(type)) {
// Only lower case structs will work in a transaction message
// See eosjs-json generated.json
var schema = Network.schema[type];
if (schema.type !== 'action') {
continue;
}
if (type === 'transaction') {
continue;
}
if (reserveFunctions.has(type)) {
throw new TypeError('Conflicting Api function: ' + type);
}
var struct = structs[type];
if (struct == null || type === 'struct_t' || tmpRemoveSet.has(type)) {
if (struct == null) {
continue;

@@ -67,3 +65,3 @@ }

var _processArgs = processArgs(args, ['code'], 'contract', optionsFormatter),
var _processArgs = processArgs(args, ['account'], 'contract', optionsFormatter),
params = _processArgs.params,

@@ -74,7 +72,7 @@ options = _processArgs.options,

var code = params.code;
var account = params.account;
// sends transactions via its own transaction function
writeApi.genContractActions(code).then(function (r) {
writeApi.genContractActions(account).then(function (r) {
callback(null, r);

@@ -91,5 +89,2 @@ }).catch(function (r) {

/** TODO: tag in the eosjs-json */
var tmpRemoveSet = new Set('account_permission message account_permission_weight signed_transaction ' + 'key_permission_weight authority blockchain_configuration type_def action ' + 'table abi nonce'.split(' '));
function WriteApi(Network, network, config, Transaction) {

@@ -124,5 +119,5 @@ /**

args = args.slice(1);
} else if (_typeof(args[0]) === 'object' && _typeof(Array.isArray(args[0].messages))) {
// full transaction, lookup ABIs used by each message
var codes = new Set(); // make a unique list
} else if (_typeof(args[0]) === 'object' && _typeof(Array.isArray(args[0].actions))) {
// full transaction, lookup ABIs used by each action
var accounts = new Set(); // make a unique list
var _iteratorNormalCompletion = true;

@@ -133,6 +128,6 @@ var _didIteratorError = false;

try {
for (var _iterator = args[0].messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var message = _step.value;
for (var _iterator = args[0].actions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var action = _step.value;
codes.add(message.code);
accounts.add(action.account);
}

@@ -154,10 +149,10 @@ } catch (err) {

var codePromises = [];
codes.forEach(function (code) {
if (code !== 'eos') {
var abiPromises = [];
accounts.forEach(function (account) {
if (account !== 'eosio') {
// Eos contract operations are cached in eosjs-json (allows for offline transactions)
codePromises.push(config.abiCache.abiAsync(code));
abiPromises.push(config.abiCache.abiAsync(account));
}
});
await Promise.all(codePromises);
await Promise.all(abiPromises);
}

@@ -187,6 +182,6 @@

for (var _iterator2 = contracts[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var code = _step2.value;
var account = _step2.value;
// setup wrapper functions to collect contract api calls
contractPromises.push(genContractActions(code, merge.transaction));
contractPromises.push(genContractActions(account, merge.transaction));
}

@@ -231,6 +226,6 @@ } catch (err) {

function genContractActions(code) {
function genContractActions(account) {
var transaction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
return config.abiCache.abiAsync(code).then(function (cache) {
return config.abiCache.abiAsync(account).then(function (cache) {
assert(Array.isArray(cache.abi.actions) && cache.abi.actions.length, 'No actions');

@@ -242,7 +237,7 @@

cache.abi.actions.forEach(function (_ref) {
var action_name = _ref.action_name,
var name = _ref.name,
type = _ref.type;
var definition = schemaFields(cache.schema, type);
contractMerge[action_name] = genMethod(type, definition, contractMerge.transaction, code, action_name);
contractMerge[name] = genMethod(type, definition, contractMerge.transaction, account, name);
});

@@ -257,4 +252,4 @@

function genMethod(type, definition, transactionArg) {
var code = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'eos';
var action_name = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : type;
var account = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'eosio';
var name = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : type;

@@ -267,7 +262,7 @@ return function () {

if (args.length === 0) {
console.error(usage(type, definition, Network, code, config));
console.error(usage(type, definition, Network, account, config));
return;
}
// Special case like multi-message transactions where this lib needs
// Special case like multi-action transactions where this lib needs
// to be sure the broadcast is off.

@@ -293,3 +288,3 @@ var optionOverrides = {};

// internal options (ex: multi-message transaction)
// internal options (ex: multi-action transaction)
};options = Object.assign({}, optionDefaults, options, optionOverrides);

@@ -300,9 +295,4 @@ if (optionOverrides.noCallback && !returnPromise) {

var addDefaultScope = options.scope == null;
var addDefaultAuths = options.authorization == null;
if (typeof options.scope === 'string') {
options.scope = [options.scope];
}
var authorization = [];

@@ -317,7 +307,7 @@ if (options.authorization) {

_auth$split2 = _slicedToArray(_auth$split, 2),
account = _auth$split2[0],
actor = _auth$split2[0],
_auth$split2$ = _auth$split2[1],
permission = _auth$split2$ === undefined ? 'active' : _auth$split2$;
authorization.push({ account: account, permission: permission });
authorization.push({ actor: actor, permission: permission });
} else if ((typeof auth === 'undefined' ? 'undefined' : _typeof(auth)) === 'object') {

@@ -331,12 +321,11 @@ authorization.push(auth);

var tr = {
scope: options.scope || [],
messages: [{
code: code,
type: action_name,
data: params,
authorization: authorization
actions: [{
account: account,
name: name,
authorization: authorization,
data: params
}]
};
if (addDefaultScope || addDefaultAuths) {
if (addDefaultAuths) {
var fieldKeys = Object.keys(definition);

@@ -346,31 +335,15 @@ var f1 = fieldKeys[0];

if (definition[f1] === 'account_name') {
if (addDefaultScope) {
// Make a simple guess based on ABI conventions.
tr.scope.push(params[f1]);
}
if (addDefaultAuths) {
// Default authorization (since user did not provide one)
tr.messages[0].authorization.push({
account: params[f1],
permission: 'active'
});
}
// Default authorization (since user did not provide one)
tr.actions[0].authorization.push({
actor: params[f1],
permission: 'active'
});
}
if (addDefaultScope) {
if (fieldKeys.length > 1 && !/newaccount/.test(type)) {
var f2 = fieldKeys[1];
if (definition[f2] === 'account_name') {
tr.scope.push(params[f2]);
}
}
}
}
tr.scope = tr.scope.sort();
tr.messages[0].authorization.sort(function (a, b) {
return a.account > b.account ? 1 : a.account < b.account ? -1 : 0;
tr.actions[0].authorization.sort(function (a, b) {
return a.actor > b.actor ? 1 : a.actor < b.actor ? -1 : 0;
});
// multi-message transaction support
// multi-action transaction support
if (!optionOverrides.messageOnly) {

@@ -401,3 +374,2 @@ transactionArg(tr, options, callback);

var scope = {};
var messageList = [];

@@ -422,3 +394,3 @@ var messageCollector = {};

// double-check (code can change)
throw new Error('Callbacks can not be used when creating a multi-message transaction');
throw new Error('Callbacks can not be used when creating a multi-action transaction');
}

@@ -452,3 +424,3 @@ messageList.push(ret);

try {
// caller will load this up with messages
// caller will load this up with actions
promiseCollector = trCallback(messageCollector);

@@ -461,4 +433,3 @@ } catch (error) {

return Promise.all(messageList).then(function (resolvedMessageList) {
var scopes = new Set();
var messages = [];
var actions = [];
var _iteratorNormalCompletion3 = true;

@@ -472,10 +443,6 @@ var _didIteratorError3 = false;

var _scope = m.scope,
_m$messages = _slicedToArray(m.messages, 1),
message = _m$messages[0];
var _m$actions = _slicedToArray(m.actions, 1),
action = _m$actions[0];
_scope.forEach(function (s) {
scopes.add(s);
});
messages.push(message);
actions.push(action);
}

@@ -498,4 +465,3 @@ } catch (err) {

var trObject = {};
trObject.scope = Array.from(scopes).sort();
trObject.messages = messages;
trObject.actions = actions;
return transaction(trObject, options);

@@ -527,8 +493,5 @@ });

if (!Array.isArray(arg.scope)) {
throw new TypeError('Expecting scope array');
if (!Array.isArray(arg.actions)) {
throw new TypeError('Expecting actions array');
}
if (!Array.isArray(arg.messages)) {
throw new TypeError('Expecting messages array');
}

@@ -548,5 +511,5 @@ if (config.transactionLog) {

arg.messages.forEach(function (message) {
if (!Array.isArray(message.authorization)) {
throw new TypeError('Expecting message.authorization array', message);
arg.actions.forEach(function (action) {
if (!Array.isArray(action.authorization)) {
throw new TypeError('Expecting action.authorization array', action);
}

@@ -562,14 +525,11 @@ });

headers(options.expireInSeconds, checkError(callback, function (rawTx) {
// 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.expiration), 'string', 'expecting expiration: iso date time string');
rawTx = Object.assign({}, rawTx, {
read_scope: [],
signatures: []
});
rawTx = Object.assign({}, rawTx);
rawTx.scope = arg.scope;
rawTx.messages = arg.messages;
rawTx.actions = arg.actions;

@@ -582,2 +542,21 @@ // console.log('rawTx', JSON.stringify(rawTx,null,4))

// 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)
// }
if (txObject.packed_bandwidth_words === 0 || txObject.packed_bandwidth_words == null) {
var txBandwidth = Object.assign({}, txObject);
// do not include context-free data
txBandwidth.context_free_actions = [];
var size = Fcbuffer.toBuffer(Transaction, txBandwidth).length;
// +2 extra bytes for uint16 packed_bandwidth_words
// number of 8 byte words this transaction can compress into
txObject.packed_bandwidth_words = Math.ceil((size + 2) / 8); // compression = none
}
// console.log('txObject', JSON.stringify(txObject,null,4))

@@ -604,4 +583,18 @@

sigs = [].concat.apply([], sigs); //flatten arrays in array
tr.signatures = sigs;
// tr.signatures = sigs // replaced by packedTr
for (var i = 0; i < sigs.length; i++) {
var sig = sigs[i];
// convert from hex to base58 format
if (typeof sig === 'string' && sig.length === 130) {
sigs[i] = ecc.Signature.from(sig).toString();
}
}
var packedTr = {
compression: 'none',
data: tr,
signatures: sigs
};
var mock = config.mockTransactions ? config.mockTransactions() : null;

@@ -615,3 +608,3 @@ if (mock != null) {

broadcast: false,
transaction: tr
transaction: packedTr
});

@@ -630,6 +623,6 @@ }

broadcast: false,
transaction: tr
transaction: packedTr
});
} else {
network.pushTransaction(tr, function (error) {
network.pushTransaction(packedTr, function (error) {
if (!error) {

@@ -639,6 +632,6 @@ callback(null, {

broadcast: true,
transaction: tr
transaction: packedTr
});
} else {
console.error('[push_transaction error] \'' + error.message + '\', digest \'' + buf.toString('hex') + '\'');
console.error('[push_transaction error] \'' + error.message + '\', transaction \'' + buf.toString('hex') + '\'');
callback(error.message);

@@ -673,3 +666,3 @@ }

if ((typeof option === 'undefined' ? 'undefined' : _typeof(option)) === 'object') {
return option; // {debug, broadcast, scope, etc} (scope, etc my overwrite tr below)
return option; // {debug, broadcast, etc} (etc my overwrite tr below)
}

@@ -682,3 +675,3 @@ if (typeof option === 'boolean') {

function usage(type, definition, Network, code, config) {
function usage(type, definition, Network, account, config) {
var usage = '';

@@ -691,3 +684,3 @@ var out = function out() {

out('CONTRACT');
out('' + code);
out(account);
out();

@@ -700,3 +693,3 @@

var struct = void 0;
if (code === 'eos') {
if (account === 'eosio') {
var _Structs = Structs({ defaults: true, network: Network }),

@@ -708,9 +701,9 @@ structs = _Structs.structs;

out('PARAMETERS');
out('' + JSON.stringify(definition, null, 4));
out(JSON.stringify(definition, null, 4));
out();
out('EXAMPLE');
out('' + JSON.stringify(struct.toObject(), null, 4));
out(JSON.stringify(struct.toObject(), null, 4));
} else {
var cache = config.abiCache.abi(code);
var cache = config.abiCache.abi(account);
out('PARAMETERS');

@@ -722,3 +715,3 @@ out(JSON.stringify(schemaFields(cache.schema, type), null, 4));

out('EXAMPLE');
out('' + JSON.stringify(struct.toObject(), null, 4));
out(JSON.stringify(struct.toObject(), null, 4));
}

@@ -725,0 +718,0 @@ if (struct == null) {

{
"name": "eosjs",
"version": "6.1.8",
"version": "7.0.0",
"description": "General purpose library for the EOS blockchain.",

@@ -46,6 +46,6 @@ "main": "lib/index.js",

"create-hash": "^1.1.3",
"eosjs-api": "^3.0.1",
"eosjs-ecc": "^2.0.1",
"eosjs-json": "^2.0.3",
"fcbuffer": "^2.0.6"
"eosjs-api": "^4.0.0",
"eosjs-ecc": "^3.0.0",
"eosjs-json": "^3.0.0",
"fcbuffer": "^2.1.0"
},

@@ -52,0 +52,0 @@ "babel": {

@@ -83,3 +83,2 @@ [![Build Status](https://travis-ci.org/EOSIO/eosjs.svg?branch=master)](https://travis-ci.org/EOSIO/eosjs)

sign: true,
scope: null,
authorization: null

@@ -89,12 +88,6 @@ }

* **scope** `{array<string>|string}` - account name or names that may
undergo a change in state.
* If missing default scopes will be calculated.
* If provided additional scopes will not be added.
* Sorting is always performed.
* **authorization** `{array<auth>|auth}` - identifies the
signing account and permission typically in a multi-sig
configuration. Authorization may be a string formatted as
`account@permission` or an `object<{account, permission}>`.
`account@permission` or an `object<{actor: account, permission}>`.
* If missing default authorizations will be calculated.

@@ -118,9 +111,9 @@ * If provided additional authorizations will not be added.

options = {broadcast: false}
eos.transfer({from: 'inita', to: 'initb', amount: 1, memo: ''}, options)
eos.transfer({from: 'inita', to: 'initb', quantity: '1 EOS', memo: ''}, options)
// Object or ordered args may be used.
eos.transfer('inita', 'initb', 1, 'memo', options)
eos.transfer('inita', 'initb', '2 EOS', 'memo', options)
// A broadcast boolean may be provided as a shortcut for {broadcast: false}
eos.transfer('inita', 'initb', 1, '', false)
eos.transfer('inita', 'initb', '1 EOS', '', false)
```

@@ -142,3 +135,3 @@

* recovery: `inita` or `inita@active` is shorthand
* `{{threshold: 1, accounts: [..account: inita, permission: active, weight: 1]}}`
* `{{threshold: 1, accounts: [..actor: inita, permission: active, weight: 1]}}`
* `inita@other` would replace the permission `active` with `other`

@@ -161,4 +154,3 @@

active: initaPublic,
recovery: 'inita',
deposit: '1 EOS'
recovery: 'inita'
})

@@ -184,3 +176,3 @@

```javascript
const binaryen = require('binaryen')
binaryen = require('binaryen')
eos = Eos.Testnet({..., binaryen})

@@ -215,7 +207,6 @@ ```

active: currencyPublic,
recovery: 'inita',
deposit: '1 EOS'
recovery: 'inita'
})
contractDir = `${process.env.HOME}/eosio/eos/build/contracts/currency`
contractDir = `${process.env.HOME}/eosio/dawn3/build/contracts/currency`
wast = fs.readFileSync(`${contractDir}/currency.wast`)

@@ -225,10 +216,12 @@ abi = fs.readFileSync(`${contractDir}/currency.abi`)

// Publish contract to the blockchain
eos.setcode('currency', 0, 0, wast, abi)
eos.setcode('currency', 0, 0, wast)
eos.setabi('currency', JSON.parse(abi))
// eos.contract(code<string>, [options], [callback])
eos.contract('currency').then(currency => {
// Transfer is one of the actions in currency.abi
currency.transfer('currency', 'inita', 100)
})
currency = null
// eos.contract(account<string>, [options], [callback])
eos.contract('currency').then(contract => currency = contract)
// Issue is one of the actions in currency.abi
currency.issue('inita', '1000.0000 CUR', {authorization: 'currency'})
```

@@ -248,9 +241,9 @@

testnet = Eos.Localnet({keyProvider})
eos = Eos.Localnet({keyProvider})
// if either transfer fails, both will fail (1 transaction, 2 messages)
testnet.transaction(eos =>
eos.transaction(eos =>
{
eos.transfer('inita', 'initb', 1, '')
eos.transfer('inita', 'initc', 1, '')
eos.transfer('inita', 'initb', '1 EOS', '')
eos.transfer('inita', 'initc', '1 EOS', '')
// Returning a promise is optional (but handled as expected)

@@ -263,19 +256,19 @@ }

// transaction on a single contract
testnet.transaction('currency', currency => {
currency.transfer('inita', 'initd', 1)
eos.transaction('currency', currency => {
currency.transfer('inita', 'initb', '1 CUR', '')
})
// mix contracts in the same transaction
testnet.transaction(['currency', 'eos'], ({currency, eos}) => {
currency.transfer('inita', 'initd', 1)
eos.transfer('inita', 'initd', 1, '')
eos.transaction(['currency', 'eosio'], ({currency, eosio}) => {
currency.transfer('inita', 'initb', '1 CUR', '')
eosio.transfer('inita', 'initb', '1 EOS', '')
})
// contract lookups then transactions
testnet.contract('currency').then(currency => {
currency.transaction(tr => {
tr.transfer('inita', 'initd', 1)
tr.transfer('initd', 'inita', 1)
eos.contract('currency').then(currency => {
currency.transaction(cur => {
cur.transfer('inita', 'initb', '1 CUR', '')
cur.transfer('initb', 'initc', '1 CUR', '')
})
currency.transfer('inita', 'inite', 1)
currency.transfer('inita', 'initb', '1 CUR', '')
})

@@ -297,10 +290,10 @@

// returns Promise
eos.transaction({
scope: ['inita', 'initb'],
messages: [
actions: [
{
code: 'eos',
type: 'transfer',
account: 'eosio',
name: 'transfer',
authorization: [{
account: 'inita',
actor: 'inita',
permission: 'active'

@@ -311,3 +304,3 @@ }],

to: 'initb',
amount: 7,
quantity: '7 EOS',
memo: ''

@@ -314,0 +307,0 @@ }

@@ -7,6 +7,6 @@ /* eslint-env mocha */

const keyProvider = [
'5JCMLHSyJcx6mUCfJpvVod8WMAycq8v3bewrJbvzhp5nhfiVYsk',
'5JGByospJ5mUkameanYCwLzeYW9QUKLvu8Qvr3PTnj3LV35oXA8',
'5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3',
'5JMJebgWSzY9aU7SRKk7r9J1r8znkUSdUA5kUNUtzUZnVwjFn7V'
// '5JCMLHSyJcx6mUCfJpvVod8WMAycq8v3bewrJbvzhp5nhfiVYsk',
// '5JGByospJ5mUkameanYCwLzeYW9QUKLvu8Qvr3PTnj3LV35oXA8',
// '5JMJebgWSzY9aU7SRKk7r9J1r8znkUSdUA5kUNUtzUZnVwjFn7V'
]

@@ -18,18 +18,32 @@

it('actions', async function() {
const msg = {
"buyer":{ "name": "inita", "number": "1516073924"},
"at_price":"5000000000000000",
"expiration":"2018-12-31T23:59:59",
"quantity": "100",
"fill_or_kill": 0
}
it('dawn3', async function() {
const eos = Eos.Localnet({keyProvider, forceActionDataHex: false})
const options = {broadcast: true}
const eos = Eos.Localnet({keyProvider})
const ex = await eos.contract('exchange')
const options = {scope: ['exchange'], authorization: ['inita@active']}
ex.buy(msg, options)
// const r = eos.fc.fromBuffer('transfer', '0000000000ea3055000000000093dd74010000000000000004454f5300000000046d656d6f')
// console.log('r', r)
// const abi = await eos.getCode('eosio')
// console.log('code', abi)
const t = await eos.transfer('inita', 'initb', '2.0001 EOS', 'memo', options)
console.log('t', JSON.stringify(t.transaction, null, 0))
})
// it('actions', async function() {
// const msg = {
// "buyer":{ "name": "inita", "number": "1516073924"},
// "at_price":"5000000000000000",
// "expiration":"2018-12-31T23:59:59",
// "quantity": "100",
// "fill_or_kill": 0
// }
//
// const eos = Eos.Localnet({keyProvider})
// const ex = await eos.contract('exchange')
// const options = {authorization: ['inita@active']}
// return ex.buy(msg, options)
// })
// it('tic.tac.toe', async function() {

@@ -47,3 +61,2 @@

// broadcast: true,
// scope: ['inita', 'initb'],
// authorization: ['initb@active']

@@ -50,0 +63,0 @@ // }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc