Comparing version 21.0.3-18-7739b8c to 21.0.3
@@ -6,5 +6,2 @@ /** | ||
import { Abi, PushTransactionArgs } from './eosjs-rpc-interfaces'; | ||
import { Anyvar, Authorization } from './eosjs-serialize'; | ||
import { WasmAbi } from './eosjs-wasmabi'; | ||
import { ActionBuilder } from './eosjs-api'; | ||
/** Arguments to `getRequiredKeys` */ | ||
@@ -27,9 +24,2 @@ export interface AuthorityProviderArgs { | ||
} | ||
/** Stores and retrieves WASM Abis */ | ||
export interface WasmAbiProvider { | ||
/** WasmAbi objects associated with account name */ | ||
wasmAbis: Map<string, WasmAbi>; | ||
/** Set an array of WasmAbis */ | ||
setWasmAbis: (wasmAbis: WasmAbi[]) => void; | ||
} | ||
/** Structure for the raw form of ABIs */ | ||
@@ -73,3 +63,2 @@ export interface BinaryAbi { | ||
sign?: boolean; | ||
requiredKeys?: string[]; | ||
compression?: boolean; | ||
@@ -80,30 +69,1 @@ blocksBehind?: number; | ||
} | ||
/** Optional query configuration object */ | ||
export interface QueryConfig { | ||
sign?: boolean; | ||
requiredKeys?: string[]; | ||
authorization?: Authorization[]; | ||
} | ||
/** | ||
* A Query may be any of the following: | ||
* * string: method | ||
* * [string, Query[]]: [method, filter] | ||
* * [string, Anyvar, Query[]]: [method, arg, filter] | ||
* * {method: string, arg?: Anyvar, filter?: Query[]} explicit form | ||
*/ | ||
export declare type Query = string | [string, Query[]] | [string, Anyvar, Query[]] | { | ||
method: string; | ||
arg?: Anyvar; | ||
filter?: Query[]; | ||
}; | ||
export declare type ContextFreeGroupCallback = (index: { | ||
cfa: number; | ||
cfd: number; | ||
}) => { | ||
action?: ActionBuilder; | ||
contextFreeAction?: ActionBuilder; | ||
contextFreeData?: any; | ||
}; | ||
export interface ActionSerializerType { | ||
[actionName: string]: any; | ||
} |
@@ -7,3 +7,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
; | ||
//# sourceMappingURL=eosjs-api-interfaces.js.map |
/** | ||
* @module API | ||
*/ | ||
import { AbiProvider, ActionSerializerType, AuthorityProvider, BinaryAbi, CachedAbi, ContextFreeGroupCallback, Query, QueryConfig, SignatureProvider, TransactConfig, WasmAbiProvider } from './eosjs-api-interfaces'; | ||
import { AbiProvider, AuthorityProvider, BinaryAbi, CachedAbi, SignatureProvider, TransactConfig } from './eosjs-api-interfaces'; | ||
import { JsonRpc } from './eosjs-jsonrpc'; | ||
import { Abi, PushTransactionArgs } from './eosjs-rpc-interfaces'; | ||
import * as ser from './eosjs-serialize'; | ||
import { WasmAbi } from './eosjs-wasmabi'; | ||
export declare class Api { | ||
@@ -18,4 +17,2 @@ /** Issues RPC calls */ | ||
signatureProvider: SignatureProvider; | ||
/** Manages WASM Abis */ | ||
wasmAbiProvider: WasmAbiProvider; | ||
/** Identifies chain */ | ||
@@ -39,3 +36,2 @@ chainId: string; | ||
* * `signatureProvider`: Signs transactions | ||
* * `wasmAbiProvider`: Manages WASM Abis | ||
* * `chainId`: Identifies chain | ||
@@ -50,3 +46,2 @@ * * `textEncoder`: `TextEncoder` instance to use. Pass in `null` if running in a browser | ||
signatureProvider: SignatureProvider; | ||
wasmAbiProvider?: WasmAbiProvider; | ||
chainId?: string; | ||
@@ -106,4 +101,3 @@ textEncoder?: TextEncoder; | ||
*/ | ||
transact(transaction: any, { broadcast, sign, requiredKeys, compression, blocksBehind, useLastIrreversible, expireSeconds }?: TransactConfig): Promise<any>; | ||
query(account: string, short: boolean, query: Query, { sign, requiredKeys, authorization }: QueryConfig): Promise<any>; | ||
transact(transaction: any, { broadcast, sign, compression, blocksBehind, useLastIrreversible, expireSeconds }?: TransactConfig): Promise<any>; | ||
/** Broadcast a signed transaction */ | ||
@@ -115,24 +109,2 @@ pushSignedTransaction({ signatures, serializedTransaction, serializedContextFreeData }: PushTransactionArgs): Promise<any>; | ||
private tryGetBlockHeaderState; | ||
with(accountName: string): ActionBuilder; | ||
buildTransaction(cb?: (tx: TransactionBuilder) => void): void | TransactionBuilder; | ||
} | ||
export declare class TransactionBuilder { | ||
private api; | ||
private actions; | ||
private contextFreeGroups; | ||
constructor(api: Api); | ||
with(accountName: string): ActionBuilder; | ||
associateContextFree(contextFreeGroup: ContextFreeGroupCallback): this; | ||
send(config?: TransactConfig): Promise<any>; | ||
} | ||
export declare class ActionBuilder { | ||
private api; | ||
private readonly accountName; | ||
serializedData: any; | ||
constructor(api: Api, accountName: string); | ||
as(actorName?: string | ser.Authorization[]): ActionSerializer; | ||
} | ||
declare class ActionSerializer implements ActionSerializerType { | ||
constructor(parent: ActionBuilder, api: Api, accountName: string, authorization: ser.Authorization[], wasmAbi: WasmAbi); | ||
} | ||
export {}; |
@@ -86,6 +86,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ActionBuilder = exports.TransactionBuilder = exports.Api = void 0; | ||
exports.Api = void 0; | ||
var pako_1 = require("pako"); | ||
var ser = require("./eosjs-serialize"); | ||
var eosjs_rpcerror_1 = require("./eosjs-rpcerror"); | ||
var abiAbi = require('../src/abi.abi.json'); | ||
@@ -100,3 +99,2 @@ var transactionAbi = require('../src/transaction.abi.json'); | ||
* * `signatureProvider`: Signs transactions | ||
* * `wasmAbiProvider`: Manages WASM Abis | ||
* * `chainId`: Identifies chain | ||
@@ -115,3 +113,2 @@ * * `textEncoder`: `TextEncoder` instance to use. Pass in `null` if running in a browser | ||
this.signatureProvider = args.signatureProvider; | ||
this.wasmAbiProvider = args.wasmAbiProvider; | ||
this.chainId = args.chainId; | ||
@@ -204,4 +201,3 @@ this.textEncoder = args.textEncoder; | ||
uniqueAccounts = new Set(accounts); | ||
actionPromises = __spread(uniqueAccounts).filter(function (account) { return !_this.wasmAbiProvider || !_this.wasmAbiProvider.wasmAbis.get(account); }) | ||
.map(function (account) { return __awaiter(_this, void 0, void 0, function () { | ||
actionPromises = __spread(uniqueAccounts).map(function (account) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a; | ||
@@ -310,26 +306,16 @@ return __generator(this, function (_b) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(actions.map(function (action) { return __awaiter(_this, void 0, void 0, function () { | ||
var account, name, authorization, data, wasmAbi, contract; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
account = action.account, name = action.name, authorization = action.authorization, data = action.data; | ||
if (!(this.wasmAbiProvider && this.wasmAbiProvider.wasmAbis.get(account))) return [3 /*break*/, 3]; | ||
wasmAbi = this.wasmAbiProvider.wasmAbis.get(account); | ||
if (!(wasmAbi.inst.exports.memory.buffer.length > wasmAbi.memoryThreshold)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, wasmAbi.reset()]; | ||
case 1: | ||
_a.sent(); | ||
_a.label = 2; | ||
case 2: return [2 /*return*/, action]; | ||
case 3: return [4 /*yield*/, this.getContract(account)]; | ||
case 4: | ||
contract = _a.sent(); | ||
if (typeof data !== 'object') { | ||
return [2 /*return*/, action]; | ||
} | ||
return [2 /*return*/, ser.serializeAction(contract, account, name, authorization, data, this.textEncoder, this.textDecoder)]; | ||
} | ||
case 0: return [4 /*yield*/, Promise.all(actions.map(function (_a) { | ||
var account = _a.account, name = _a.name, authorization = _a.authorization, data = _a.data; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var contract; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.getContract(account)]; | ||
case 1: | ||
contract = _b.sent(); | ||
return [2 /*return*/, ser.serializeAction(contract, account, name, authorization, data, this.textEncoder, this.textDecoder)]; | ||
} | ||
}); | ||
}); | ||
}); }))]; | ||
}))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -346,18 +332,16 @@ } | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(actions.map(function (action) { return __awaiter(_this, void 0, void 0, function () { | ||
var account, name, authorization, data, contract; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
account = action.account, name = action.name, authorization = action.authorization, data = action.data; | ||
if (this.wasmAbiProvider && this.wasmAbiProvider.wasmAbis.get(account)) { | ||
return [2 /*return*/, action]; | ||
} | ||
return [4 /*yield*/, this.getContract(account)]; | ||
case 1: | ||
contract = _a.sent(); | ||
return [2 /*return*/, ser.deserializeAction(contract, account, name, authorization, data, this.textEncoder, this.textDecoder)]; | ||
} | ||
case 0: return [4 /*yield*/, Promise.all(actions.map(function (_a) { | ||
var account = _a.account, name = _a.name, authorization = _a.authorization, data = _a.data; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var contract; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.getContract(account)]; | ||
case 1: | ||
contract = _b.sent(); | ||
return [2 /*return*/, ser.deserializeAction(contract, account, name, authorization, data, this.textEncoder, this.textDecoder)]; | ||
} | ||
}); | ||
}); | ||
}); }))]; | ||
}))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -417,8 +401,7 @@ } | ||
Api.prototype.transact = function (transaction, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.broadcast, broadcast = _c === void 0 ? true : _c, _d = _b.sign, sign = _d === void 0 ? true : _d, requiredKeys = _b.requiredKeys, compression = _b.compression, blocksBehind = _b.blocksBehind, useLastIrreversible = _b.useLastIrreversible, expireSeconds = _b.expireSeconds; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.broadcast, broadcast = _c === void 0 ? true : _c, _d = _b.sign, sign = _d === void 0 ? true : _d, compression = _b.compression, blocksBehind = _b.blocksBehind, useLastIrreversible = _b.useLastIrreversible, expireSeconds = _b.expireSeconds; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var info, abis, _e, _f, serializedTransaction, serializedContextFreeData, pushTransactionArgs, availableKeys, result, _g, _h, at, abi, name_2, j, j; | ||
var e_4, _j; | ||
return __generator(this, function (_k) { | ||
switch (_k.label) { | ||
var info, abis, _e, _f, serializedTransaction, serializedContextFreeData, pushTransactionArgs, availableKeys, requiredKeys; | ||
return __generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: | ||
@@ -431,5 +414,5 @@ if (typeof blocksBehind === 'number' && useLastIrreversible) { | ||
case 1: | ||
info = _k.sent(); | ||
info = _g.sent(); | ||
this.chainId = info.chain_id; | ||
_k.label = 2; | ||
_g.label = 2; | ||
case 2: | ||
@@ -439,4 +422,4 @@ if (!((typeof blocksBehind === 'number' || useLastIrreversible) && expireSeconds)) return [3 /*break*/, 4]; | ||
case 3: | ||
transaction = _k.sent(); | ||
_k.label = 4; | ||
transaction = _g.sent(); | ||
_g.label = 4; | ||
case 4: | ||
@@ -448,3 +431,3 @@ if (!this.hasRequiredTaposFields(transaction)) { | ||
case 5: | ||
abis = _k.sent(); | ||
abis = _g.sent(); | ||
_e = [__assign({}, transaction)]; | ||
@@ -454,6 +437,6 @@ _f = {}; | ||
case 6: | ||
_f.context_free_actions = _k.sent(); | ||
_f.context_free_actions = _g.sent(); | ||
return [4 /*yield*/, this.serializeActions(transaction.actions)]; | ||
case 7: | ||
transaction = __assign.apply(void 0, _e.concat([(_f.actions = _k.sent(), _f)])); | ||
transaction = __assign.apply(void 0, _e.concat([(_f.actions = _g.sent(), _f)])); | ||
serializedTransaction = this.serializeTransaction(transaction); | ||
@@ -465,70 +448,27 @@ serializedContextFreeData = this.serializeContextFreeData(transaction.context_free_data); | ||
}; | ||
if (!sign) return [3 /*break*/, 12]; | ||
if (!!requiredKeys) return [3 /*break*/, 10]; | ||
if (!sign) return [3 /*break*/, 11]; | ||
return [4 /*yield*/, this.signatureProvider.getAvailableKeys()]; | ||
case 8: | ||
availableKeys = _k.sent(); | ||
availableKeys = _g.sent(); | ||
return [4 /*yield*/, this.authorityProvider.getRequiredKeys({ transaction: transaction, availableKeys: availableKeys })]; | ||
case 9: | ||
requiredKeys = _k.sent(); | ||
_k.label = 10; | ||
case 10: return [4 /*yield*/, this.signatureProvider.sign({ | ||
chainId: this.chainId, | ||
requiredKeys: requiredKeys, | ||
serializedTransaction: serializedTransaction, | ||
serializedContextFreeData: serializedContextFreeData, | ||
abis: abis, | ||
})]; | ||
requiredKeys = _g.sent(); | ||
return [4 /*yield*/, this.signatureProvider.sign({ | ||
chainId: this.chainId, | ||
requiredKeys: requiredKeys, | ||
serializedTransaction: serializedTransaction, | ||
serializedContextFreeData: serializedContextFreeData, | ||
abis: abis, | ||
})]; | ||
case 10: | ||
pushTransactionArgs = _g.sent(); | ||
_g.label = 11; | ||
case 11: | ||
pushTransactionArgs = _k.sent(); | ||
_k.label = 12; | ||
case 12: | ||
if (!broadcast) return [3 /*break*/, 17]; | ||
result = void 0; | ||
if (!compression) return [3 /*break*/, 14]; | ||
return [4 /*yield*/, this.pushCompressedSignedTransaction(pushTransactionArgs)]; | ||
case 13: | ||
result = _k.sent(); | ||
return [3 /*break*/, 16]; | ||
case 14: return [4 /*yield*/, this.pushSignedTransaction(pushTransactionArgs)]; | ||
case 15: | ||
result = _k.sent(); | ||
_k.label = 16; | ||
case 16: | ||
if (this.wasmAbiProvider && result.processed && result.processed.action_traces) { | ||
try { | ||
for (_g = __values(result.processed.action_traces), _h = _g.next(); !_h.done; _h = _g.next()) { | ||
at = _h.value; | ||
if (at.act && this.wasmAbiProvider.wasmAbis.get(at.act.account)) { | ||
abi = this.wasmAbiProvider.wasmAbis.get(at.act.account); | ||
name_2 = at.act.name; | ||
if (at.act.hasOwnProperty('data')) { | ||
try { | ||
j = abi.action_args_bin_to_json(name_2, ser.hexToUint8Array(at.act.data)); | ||
at.act.name = j.long_name; | ||
at.act.data = j.args; | ||
} | ||
catch (e) { } // eslint-disable-line no-empty | ||
} | ||
if (at.hasOwnProperty('return_value')) { | ||
try { | ||
j = abi.action_ret_bin_to_json(name_2, ser.hexToUint8Array(at.return_value)); | ||
at.act.name = j.long_name; | ||
at.return_value = j.return_value; | ||
} | ||
catch (e) { } // eslint-disable-line no-empty | ||
} | ||
} | ||
} | ||
if (broadcast) { | ||
if (compression) { | ||
return [2 /*return*/, this.pushCompressedSignedTransaction(pushTransactionArgs)]; | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
try { | ||
if (_h && !_h.done && (_j = _g.return)) _j.call(_g); | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
return [2 /*return*/, this.pushSignedTransaction(pushTransactionArgs)]; | ||
} | ||
return [2 /*return*/, result]; | ||
case 17: return [2 /*return*/, pushTransactionArgs]; | ||
return [2 /*return*/, pushTransactionArgs]; | ||
} | ||
@@ -538,76 +478,2 @@ }); | ||
}; | ||
Api.prototype.query = function (account, short, query, _a) { | ||
var sign = _a.sign, requiredKeys = _a.requiredKeys, _b = _a.authorization, authorization = _b === void 0 ? [] : _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var info, refBlock, queryBuffer, transaction, serializedTransaction, signatures, abis, availableKeys, signResponse, response, json, returnBuffer; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4 /*yield*/, this.rpc.get_info()]; | ||
case 1: | ||
info = _c.sent(); | ||
return [4 /*yield*/, this.rpc.get_block(info.last_irreversible_block_num)]; | ||
case 2: | ||
refBlock = _c.sent(); | ||
queryBuffer = new ser.SerialBuffer({ textEncoder: this.textEncoder, textDecoder: this.textDecoder }); | ||
ser.serializeQuery(queryBuffer, query); | ||
transaction = __assign(__assign({}, ser.transactionHeader(refBlock, 60 * 30)), { context_free_actions: [], actions: [{ | ||
account: account, | ||
name: 'queryit', | ||
authorization: authorization, | ||
data: ser.arrayToHex(queryBuffer.asUint8Array()), | ||
}] }); | ||
serializedTransaction = this.serializeTransaction(transaction); | ||
signatures = []; | ||
if (!sign) return [3 /*break*/, 8]; | ||
return [4 /*yield*/, this.getTransactionAbis(transaction)]; | ||
case 3: | ||
abis = _c.sent(); | ||
if (!!requiredKeys) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, this.signatureProvider.getAvailableKeys()]; | ||
case 4: | ||
availableKeys = _c.sent(); | ||
return [4 /*yield*/, this.authorityProvider.getRequiredKeys({ transaction: transaction, availableKeys: availableKeys })]; | ||
case 5: | ||
requiredKeys = _c.sent(); | ||
_c.label = 6; | ||
case 6: return [4 /*yield*/, this.signatureProvider.sign({ | ||
chainId: this.chainId, | ||
requiredKeys: requiredKeys, | ||
serializedTransaction: serializedTransaction, | ||
serializedContextFreeData: null, | ||
abis: abis, | ||
})]; | ||
case 7: | ||
signResponse = _c.sent(); | ||
signatures = signResponse.signatures; | ||
_c.label = 8; | ||
case 8: return [4 /*yield*/, this.rpc.send_transaction({ | ||
signatures: signatures, | ||
compression: 0, | ||
serializedTransaction: serializedTransaction | ||
})]; | ||
case 9: | ||
response = _c.sent(); | ||
return [4 /*yield*/, response.json()]; | ||
case 10: | ||
json = _c.sent(); | ||
if (json.code) { | ||
throw new eosjs_rpcerror_1.RpcError(json); | ||
} | ||
returnBuffer = new ser.SerialBuffer({ | ||
textEncoder: this.textEncoder, | ||
textDecoder: this.textDecoder, | ||
array: ser.hexToUint8Array(json.processed.action_traces[0][1].return_value) | ||
}); | ||
if (short) { | ||
return [2 /*return*/, ser.deserializeAnyvarShort(returnBuffer)]; | ||
} | ||
else { | ||
return [2 /*return*/, ser.deserializeAnyvar(returnBuffer)]; | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Broadcast a signed transaction */ | ||
@@ -695,160 +561,5 @@ Api.prototype.pushSignedTransaction = function (_a) { | ||
}; | ||
Api.prototype.with = function (accountName) { | ||
return new ActionBuilder(this, accountName); | ||
}; | ||
Api.prototype.buildTransaction = function (cb) { | ||
var tx = new TransactionBuilder(this); | ||
if (cb) { | ||
return cb(tx); | ||
} | ||
return tx; | ||
}; | ||
return Api; | ||
}()); // Api | ||
exports.Api = Api; | ||
var TransactionBuilder = /** @class */ (function () { | ||
function TransactionBuilder(api) { | ||
this.actions = []; | ||
this.contextFreeGroups = []; | ||
this.api = api; | ||
} | ||
TransactionBuilder.prototype.with = function (accountName) { | ||
var actionBuilder = new ActionBuilder(this.api, accountName); | ||
this.actions.push(actionBuilder); | ||
return actionBuilder; | ||
}; | ||
TransactionBuilder.prototype.associateContextFree = function (contextFreeGroup) { | ||
this.contextFreeGroups.push(contextFreeGroup); | ||
return this; | ||
}; | ||
TransactionBuilder.prototype.send = function (config) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var contextFreeDataSet, contextFreeActions, actions; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
contextFreeDataSet = []; | ||
contextFreeActions = []; | ||
actions = this.actions.map(function (actionBuilder) { return actionBuilder.serializedData; }); | ||
return [4 /*yield*/, Promise.all(this.contextFreeGroups.map(function (contextFreeCallback) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, action, contextFreeAction, contextFreeData; | ||
return __generator(this, function (_b) { | ||
_a = contextFreeCallback({ | ||
cfd: contextFreeDataSet.length, | ||
cfa: contextFreeActions.length | ||
}), action = _a.action, contextFreeAction = _a.contextFreeAction, contextFreeData = _a.contextFreeData; | ||
if (action) { | ||
actions.push(action); | ||
} | ||
if (contextFreeAction) { | ||
contextFreeActions.push(contextFreeAction); | ||
} | ||
if (contextFreeData) { | ||
contextFreeDataSet.push(contextFreeData); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); }))]; | ||
case 1: | ||
_a.sent(); | ||
this.contextFreeGroups = []; | ||
this.actions = []; | ||
return [4 /*yield*/, this.api.transact({ | ||
contextFreeData: contextFreeDataSet, | ||
contextFreeActions: contextFreeActions, | ||
actions: actions | ||
}, config)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return TransactionBuilder; | ||
}()); | ||
exports.TransactionBuilder = TransactionBuilder; | ||
var ActionBuilder = /** @class */ (function () { | ||
function ActionBuilder(api, accountName) { | ||
this.api = api; | ||
this.accountName = accountName; | ||
} | ||
ActionBuilder.prototype.as = function (actorName) { | ||
var authorization = []; | ||
if (actorName && typeof actorName === 'string') { | ||
authorization = [{ actor: actorName, permission: 'active' }]; | ||
} | ||
else { | ||
authorization = actorName; | ||
} | ||
var wasmAbi = this.api.wasmAbiProvider.wasmAbis.get(this.accountName); | ||
return new ActionSerializer(this, this.api, this.accountName, authorization, wasmAbi); | ||
}; | ||
return ActionBuilder; | ||
}()); | ||
exports.ActionBuilder = ActionBuilder; | ||
var ActionSerializer = /** @class */ (function () { | ||
function ActionSerializer(parent, api, accountName, authorization, wasmAbi) { | ||
var e_5, _a; | ||
var _this = this; | ||
if (wasmAbi) { | ||
Object.keys(wasmAbi.actions).forEach(function (action) { | ||
var _a; | ||
Object.assign(_this, (_a = {}, | ||
_a[action] = function () { | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var serializedData = (_a = wasmAbi.actions)[action].apply(_a, __spread([authorization], args)); | ||
serializedData.data = ser.arrayToHex(serializedData.data); | ||
parent.serializedData = serializedData; | ||
return serializedData; | ||
}, | ||
_a)); | ||
}); | ||
} | ||
else { | ||
var jsonAbi = api.cachedAbis.get(accountName); | ||
if (!jsonAbi) { | ||
throw new Error('ABI must be cached before using ActionBuilder, run api.getAbi()'); | ||
} | ||
var types_1 = ser.getTypesFromAbi(ser.createInitialTypes(), jsonAbi.abi); | ||
var actions_1 = new Map(); | ||
try { | ||
for (var _b = __values(jsonAbi.abi.actions), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = _c.value, name_3 = _d.name, type = _d.type; | ||
actions_1.set(name_3, ser.getType(types_1, type)); | ||
} | ||
} | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_5) throw e_5.error; } | ||
} | ||
actions_1.forEach(function (type, name) { | ||
var _a; | ||
Object.assign(_this, (_a = {}, | ||
_a[name] = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var data = {}; | ||
args.forEach(function (arg, index) { | ||
var field = type.fields[index]; | ||
data[field.name] = arg; | ||
}); | ||
var serializedData = ser.serializeAction({ types: types_1, actions: actions_1 }, accountName, name, authorization, data, api.textEncoder, api.textDecoder); | ||
parent.serializedData = serializedData; | ||
return serializedData; | ||
}, | ||
_a)); | ||
}); | ||
} | ||
} | ||
return ActionSerializer; | ||
}()); | ||
//# sourceMappingURL=eosjs-api.js.map |
@@ -5,3 +5,2 @@ /** | ||
import { Abi, BlockTaposInfo } from './eosjs-rpc-interfaces'; | ||
import { Query } from './eosjs-api-interfaces'; | ||
/** A field in an abi */ | ||
@@ -27,25 +26,2 @@ export interface Field { | ||
} | ||
/** | ||
* An Anyvar (non-short form) may be any of the following: | ||
* * null | ||
* * string | ||
* * number | ||
* * Caution: assumes number is int32. Use {type, value} form for other numeric types | ||
* * an array of anyvar | ||
* * {type, value} | ||
* * type is a string matching one of the predefined types in anyvarDefs | ||
* * value: | ||
* * If type === 'any_object', then value is an object. The values within the object are anyvar. | ||
* * If type === 'any_array', then value is an array of anyvar. | ||
* * Else, value must be eosjs-compatible with the specified type (e.g. uint64 should be a string | ||
* containing the value in decimal). | ||
* * Other object. The values within the object are anyvar. | ||
* | ||
* The short form is more convenient, but it can't be converted back to binary (serialized). | ||
* Wherever the anyvar would have {type, value}, it has just the value instead. | ||
*/ | ||
export declare type Anyvar = null | string | number | Anyvar[] | { | ||
type: string; | ||
value: any; | ||
} | {}; | ||
/** A type in an abi */ | ||
@@ -271,9 +247,1 @@ export interface Type { | ||
export declare const deserializeAction: (contract: Contract, account: string, name: string, authorization: Authorization[], data: string | Uint8Array | number[], textEncoder: TextEncoder, textDecoder: TextDecoder) => Action; | ||
export declare const serializeAnyvar: (buffer: SerialBuffer, anyvar: Anyvar) => void; | ||
export declare const deserializeAnyvar: (buffer: SerialBuffer, state?: SerializerState) => any; | ||
export declare const deserializeAnyvarShort: (buffer: SerialBuffer) => any; | ||
export declare const serializeAnyObject: (buffer: SerialBuffer, obj: any) => void; | ||
export declare const deserializeAnyObject: (buffer: SerialBuffer, state?: SerializerState) => {}; | ||
export declare const serializeAnyArray: (buffer: SerialBuffer, arr: Anyvar[]) => void; | ||
export declare const deserializeAnyArray: (buffer: SerialBuffer, state?: SerializerState) => any[]; | ||
export declare const serializeQuery: (buffer: SerialBuffer, query: Query) => void; |
@@ -51,3 +51,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serializeQuery = exports.deserializeAnyArray = exports.serializeAnyArray = exports.deserializeAnyObject = exports.serializeAnyObject = exports.deserializeAnyvarShort = exports.deserializeAnyvar = exports.serializeAnyvar = exports.deserializeAction = exports.deserializeActionData = exports.serializeAction = exports.serializeActionData = exports.transactionHeader = exports.getTypesFromAbi = exports.getType = exports.createInitialTypes = exports.hexToUint8Array = exports.arrayToHex = exports.symbolToString = exports.stringToSymbol = exports.blockTimestampToDate = exports.dateToBlockTimestamp = exports.timePointSecToDate = exports.dateToTimePointSec = exports.timePointToDate = exports.dateToTimePoint = exports.supportedAbiVersion = exports.SerialBuffer = exports.SerializerState = void 0; | ||
exports.deserializeAction = exports.deserializeActionData = exports.serializeAction = exports.serializeActionData = exports.transactionHeader = exports.getTypesFromAbi = exports.getType = exports.createInitialTypes = exports.hexToUint8Array = exports.arrayToHex = exports.symbolToString = exports.stringToSymbol = exports.blockTimestampToDate = exports.dateToBlockTimestamp = exports.timePointSecToDate = exports.dateToTimePointSec = exports.timePointToDate = exports.dateToTimePoint = exports.supportedAbiVersion = exports.SerialBuffer = exports.SerializerState = void 0; | ||
var numeric = require("./eosjs-numeric"); | ||
@@ -1104,214 +1104,2 @@ /** State for serialize() and deserialize() */ | ||
}; | ||
exports.serializeAnyvar = function (buffer, anyvar) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var def; | ||
var value; | ||
if (anyvar === null) { | ||
_a = __read([anyvarDefs.null_t, anyvar], 2), def = _a[0], value = _a[1]; | ||
} | ||
else if (typeof anyvar === 'string') { | ||
_b = __read([anyvarDefs.string, anyvar], 2), def = _b[0], value = _b[1]; | ||
} | ||
else if (typeof anyvar === 'number') { | ||
_c = __read([anyvarDefs.int32, anyvar], 2), def = _c[0], value = _c[1]; | ||
} | ||
else if (anyvar instanceof Uint8Array) { | ||
_d = __read([anyvarDefs.bytes, anyvar], 2), def = _d[0], value = _d[1]; | ||
} | ||
else if (Array.isArray(anyvar)) { | ||
_e = __read([anyvarDefs.any_array, anyvar], 2), def = _e[0], value = _e[1]; | ||
} | ||
else if (Object.keys(anyvar).length === 2 && anyvar.hasOwnProperty('type') && anyvar.hasOwnProperty('value')) { | ||
_f = __read([anyvarDefs[anyvar.type], anyvar.value], 2), def = _f[0], value = _f[1]; | ||
} | ||
else { | ||
_g = __read([anyvarDefs.any_object, anyvar], 2), def = _g[0], value = _g[1]; | ||
} | ||
buffer.pushVaruint32(def.index); | ||
def.type.serialize(buffer, value); | ||
}; | ||
exports.deserializeAnyvar = function (buffer, state) { | ||
var defIndex = buffer.getVaruint32(); | ||
if (defIndex >= anyvarDefsByIndex.length) { | ||
throw new Error('Tried to deserialize unknown anyvar type'); | ||
} | ||
var def = anyvarDefsByIndex[defIndex]; | ||
var value = def.type.deserialize(buffer, state); | ||
if (state && state.options.useShortForm || def.useShortForm) { | ||
return value; | ||
} | ||
else { | ||
return { type: def.type.name, value: value }; | ||
} | ||
}; | ||
exports.deserializeAnyvarShort = function (buffer) { | ||
return exports.deserializeAnyvar(buffer, new SerializerState({ useShortForm: true })); | ||
}; | ||
exports.serializeAnyObject = function (buffer, obj) { | ||
var e_10, _a; | ||
var entries = Object.entries(obj); | ||
buffer.pushVaruint32(entries.length); | ||
try { | ||
for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) { | ||
var _b = __read(entries_1_1.value, 2), key = _b[0], value = _b[1]; | ||
buffer.pushString(key); | ||
exports.serializeAnyvar(buffer, value); | ||
} | ||
} | ||
catch (e_10_1) { e_10 = { error: e_10_1 }; } | ||
finally { | ||
try { | ||
if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1); | ||
} | ||
finally { if (e_10) throw e_10.error; } | ||
} | ||
}; | ||
exports.deserializeAnyObject = function (buffer, state) { | ||
var len = buffer.getVaruint32(); | ||
var result = {}; | ||
for (var i = 0; i < len; ++i) { | ||
var key = buffer.getString(); | ||
if (key in result) { | ||
var j = 1; | ||
while (key + '_' + j in result) { | ||
++j; | ||
} | ||
key = key + '_' + j; | ||
} | ||
result[key] = exports.deserializeAnyvar(buffer, state); | ||
} | ||
return result; | ||
}; | ||
exports.serializeAnyArray = function (buffer, arr) { | ||
var e_11, _a; | ||
buffer.pushVaruint32(arr.length); | ||
try { | ||
for (var arr_1 = __values(arr), arr_1_1 = arr_1.next(); !arr_1_1.done; arr_1_1 = arr_1.next()) { | ||
var x = arr_1_1.value; | ||
exports.serializeAnyvar(buffer, x); | ||
} | ||
} | ||
catch (e_11_1) { e_11 = { error: e_11_1 }; } | ||
finally { | ||
try { | ||
if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) _a.call(arr_1); | ||
} | ||
finally { if (e_11) throw e_11.error; } | ||
} | ||
}; | ||
exports.deserializeAnyArray = function (buffer, state) { | ||
var len = buffer.getVaruint32(); | ||
var result = []; | ||
for (var i = 0; i < len; ++i) { | ||
result.push(exports.deserializeAnyvar(buffer, state)); | ||
} | ||
return result; | ||
}; | ||
var addAdditionalTypes = function () { | ||
var initialTypes = exports.createInitialTypes(); | ||
initialTypes.set('null_t', createType({ | ||
name: 'null_t', | ||
serialize: function (buffer, anyvar) { }, | ||
deserialize: function (buffer, state) { } | ||
})); | ||
initialTypes.set('any_object', createType({ | ||
name: 'any_object', | ||
serialize: exports.serializeAnyObject, | ||
deserialize: exports.deserializeAnyObject | ||
})); | ||
initialTypes.set('any_array', createType({ | ||
name: 'any_array', | ||
serialize: exports.serializeAnyArray, | ||
deserialize: exports.deserializeAnyArray | ||
})); | ||
return initialTypes; | ||
}; | ||
var additionalTypes = addAdditionalTypes(); | ||
var anyvarDefs = { | ||
null_t: { index: 0, useShortForm: true, type: additionalTypes.get('null_t') }, | ||
int64: { index: 1, useShortForm: false, type: additionalTypes.get('int64') }, | ||
uint64: { index: 2, useShortForm: false, type: additionalTypes.get('uint64') }, | ||
int32: { index: 3, useShortForm: true, type: additionalTypes.get('int32') }, | ||
uint32: { index: 4, useShortForm: false, type: additionalTypes.get('uint32') }, | ||
int16: { index: 5, useShortForm: false, type: additionalTypes.get('int16') }, | ||
uint16: { index: 6, useShortForm: false, type: additionalTypes.get('uint16') }, | ||
int8: { index: 7, useShortForm: false, type: additionalTypes.get('int8') }, | ||
uint8: { index: 8, useShortForm: false, type: additionalTypes.get('uint8') }, | ||
time_point: { index: 9, useShortForm: false, type: additionalTypes.get('time_point') }, | ||
checksum256: { index: 10, useShortForm: false, type: additionalTypes.get('checksum256') }, | ||
float64: { index: 11, useShortForm: false, type: additionalTypes.get('float64') }, | ||
string: { index: 12, useShortForm: true, type: additionalTypes.get('string') }, | ||
any_object: { index: 13, useShortForm: true, type: additionalTypes.get('any_object') }, | ||
any_array: { index: 14, useShortForm: true, type: additionalTypes.get('any_array') }, | ||
bytes: { index: 15, useShortForm: false, type: additionalTypes.get('bytes') }, | ||
symbol: { index: 16, useShortForm: false, type: additionalTypes.get('symbol') }, | ||
symbol_code: { index: 17, useShortForm: false, type: additionalTypes.get('symbol_code') }, | ||
asset: { index: 18, useShortForm: false, type: additionalTypes.get('asset') }, | ||
}; | ||
var anyvarDefsByIndex = [ | ||
anyvarDefs.null_t, | ||
anyvarDefs.int64, | ||
anyvarDefs.uint64, | ||
anyvarDefs.int32, | ||
anyvarDefs.uint32, | ||
anyvarDefs.int16, | ||
anyvarDefs.uint16, | ||
anyvarDefs.int8, | ||
anyvarDefs.uint8, | ||
anyvarDefs.time_point, | ||
anyvarDefs.checksum256, | ||
anyvarDefs.float64, | ||
anyvarDefs.string, | ||
anyvarDefs.any_object, | ||
anyvarDefs.any_array, | ||
anyvarDefs.bytes, | ||
anyvarDefs.symbol, | ||
anyvarDefs.symbol_code, | ||
anyvarDefs.asset, | ||
]; | ||
exports.serializeQuery = function (buffer, query) { | ||
var _a, _b, _c, e_12, _d; | ||
var method; | ||
var arg; | ||
var filter; | ||
if (typeof query === 'string') { | ||
method = query; | ||
} | ||
else if (Array.isArray(query) && query.length === 2) { | ||
_a = __read(query, 2), method = _a[0], filter = _a[1]; | ||
} | ||
else if (Array.isArray(query) && query.length === 3) { | ||
_b = __read(query, 3), method = _b[0], arg = _b[1], filter = _b[2]; | ||
} | ||
else { | ||
_c = __read([query.method, query.arg, query.filter], 3), method = _c[0], arg = _c[1], filter = _c[2]; | ||
} | ||
buffer.pushString(method); | ||
if (arg === undefined) { | ||
buffer.push(0); | ||
} | ||
else { | ||
buffer.push(1); | ||
exports.serializeAnyvar(buffer, arg); | ||
} | ||
if (filter === undefined) { | ||
buffer.push(0); | ||
} | ||
else { | ||
buffer.pushVaruint32(filter.length); | ||
try { | ||
for (var filter_1 = __values(filter), filter_1_1 = filter_1.next(); !filter_1_1.done; filter_1_1 = filter_1.next()) { | ||
var q = filter_1_1.value; | ||
exports.serializeQuery(buffer, q); | ||
} | ||
} | ||
catch (e_12_1) { e_12 = { error: e_12_1 }; } | ||
finally { | ||
try { | ||
if (filter_1_1 && !filter_1_1.done && (_d = filter_1.return)) _d.call(filter_1); | ||
} | ||
finally { if (e_12) throw e_12.error; } | ||
} | ||
} | ||
}; | ||
//# sourceMappingURL=eosjs-serialize.js.map |
@@ -8,3 +8,2 @@ import { Api } from './eosjs-api'; | ||
import * as Serialize from './eosjs-serialize'; | ||
import { WasmAbi } from './eosjs-wasmabi'; | ||
export { Api, ApiInterfaces, JsonRpc, Numeric, RpcInterfaces, RpcError, Serialize, WasmAbi }; | ||
export { Api, ApiInterfaces, JsonRpc, Numeric, RpcInterfaces, RpcError, Serialize }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WasmAbi = exports.Serialize = exports.RpcError = exports.RpcInterfaces = exports.Numeric = exports.JsonRpc = exports.ApiInterfaces = exports.Api = void 0; | ||
exports.Serialize = exports.RpcError = exports.RpcInterfaces = exports.Numeric = exports.JsonRpc = exports.ApiInterfaces = exports.Api = void 0; | ||
var eosjs_api_1 = require("./eosjs-api"); | ||
@@ -18,4 +18,2 @@ Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return eosjs_api_1.Api; } }); | ||
exports.Serialize = Serialize; | ||
var eosjs_wasmabi_1 = require("./eosjs-wasmabi"); | ||
Object.defineProperty(exports, "WasmAbi", { enumerable: true, get: function () { return eosjs_wasmabi_1.WasmAbi; } }); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "eosjs", | ||
"version": "21.0.3-18-7739b8c", | ||
"version": "21.0.3", | ||
"description": "Talk to eos API", | ||
@@ -29,3 +29,2 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"bn.js": "5.1.2", | ||
"elliptic": "6.5.3", | ||
@@ -46,3 +45,3 @@ "hash.js": "1.1.7", | ||
"jest-fetch-mock": "^3.0.3", | ||
"ts-jest": "^26.1.4", | ||
"ts-jest": "^26.2.0", | ||
"ts-loader": "^7.0.5", | ||
@@ -49,0 +48,0 @@ "typescript": "^3.9.7", |
{ | ||
"version": "eosio::abi/1.2", | ||
"version": "eosio::abi/1.1", | ||
"structs": [ | ||
@@ -151,16 +151,2 @@ { | ||
{ | ||
"name": "action_result", | ||
"base": "", | ||
"fields": [ | ||
{ | ||
"name": "name", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "result_type", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "abi_def", | ||
@@ -204,6 +190,2 @@ "base": "", | ||
"type": "variant_def[]$" | ||
}, | ||
{ | ||
"name": "action_results", | ||
"type": "action_result[]$" | ||
} | ||
@@ -210,0 +192,0 @@ ] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3
1
324671
55
5002
- Removedbn.js@5.1.2
- Removedbn.js@5.1.2(transitive)