Comparing version 22.1.0-66-ee54e3b to 22.1.0-67-9dafdfa
@@ -58,2 +58,8 @@ /** | ||
} | ||
export interface ResourcePayer { | ||
payer: string; | ||
max_net_bytes: number | string; | ||
max_cpu_us: number | string; | ||
max_memory_bytes: number | string; | ||
} | ||
export interface Transaction { | ||
@@ -70,2 +76,3 @@ expiration?: string; | ||
transaction_extensions?: [number, string][]; | ||
resource_payer?: ResourcePayer; | ||
} | ||
@@ -72,0 +79,0 @@ /** Optional transact configuration object */ |
@@ -70,2 +70,6 @@ /** | ||
deserializeTransaction(transaction: Uint8Array): Transaction; | ||
private transactionExtensions; | ||
serializeTransactionExtensions(transaction: Transaction): [number, string][]; | ||
deserializeTransactionExtensions(data: [number, string][]): any[]; | ||
deleteTransactionExtensionObjects(transaction: Transaction): Transaction; | ||
/** Convert actions to hex */ | ||
@@ -72,0 +76,0 @@ serializeActions(actions: ser.Action[]): Promise<ser.SerializedAction[]>; |
@@ -90,3 +90,2 @@ "use strict"; | ||
var ser = require("./eosjs-serialize"); | ||
var transactionAbi = require('../src/transaction.abi.json'); | ||
var Api = /** @class */ (function () { | ||
@@ -108,2 +107,5 @@ /** | ||
this.cachedAbis = new Map(); | ||
this.transactionExtensions = [ | ||
{ id: 1, type: 'resource_payer', keys: ['payer', 'max_net_bytes', 'max_cpu_us', 'max_memory_bytes'] }, | ||
]; | ||
this.rpc = args.rpc; | ||
@@ -117,3 +119,3 @@ this.authorityProvider = args.authorityProvider || args.rpc; | ||
this.abiTypes = ser.getTypesFromAbi(ser.createAbiTypes()); | ||
this.transactionTypes = ser.getTypesFromAbi(ser.createInitialTypes(), transactionAbi); | ||
this.transactionTypes = ser.getTypesFromAbi(ser.createTransactionTypes()); | ||
} | ||
@@ -299,2 +301,39 @@ /** Decodes an abi as Uint8Array into json. */ | ||
}; | ||
// Order of adding to transaction_extension is transaction_extension id ascending | ||
Api.prototype.serializeTransactionExtensions = function (transaction) { | ||
var transaction_extensions = []; | ||
if (transaction.resource_payer) { | ||
var extensionBuffer = new ser.SerialBuffer({ textEncoder: this.textEncoder, textDecoder: this.textDecoder }); | ||
var types = ser.getTypesFromAbi(ser.createTransactionExtensionTypes()); | ||
types.get('resource_payer').serialize(extensionBuffer, transaction.resource_payer); | ||
transaction_extensions = __spreadArray(__spreadArray([], __read(transaction_extensions)), [[1, ser.arrayToHex(extensionBuffer.asUint8Array())]]); | ||
} | ||
return transaction_extensions; | ||
}; | ||
; | ||
// Usage: transaction = {...transaction, ...this.deserializeTransactionExtensions(transaction.transaction_extensions)} | ||
Api.prototype.deserializeTransactionExtensions = function (data) { | ||
var _this = this; | ||
var transaction = {}; | ||
data.forEach(function (extensionData) { | ||
var transactionExtension = _this.transactionExtensions.find(function (extension) { return extension.id === extensionData[0]; }); | ||
if (transactionExtension === undefined) { | ||
throw new Error("Transaction Extension could not be determined: " + extensionData); | ||
} | ||
var types = ser.getTypesFromAbi(ser.createTransactionExtensionTypes()); | ||
var extensionBuffer = new ser.SerialBuffer({ textEncoder: _this.textEncoder, textDecoder: _this.textDecoder }); | ||
extensionBuffer.pushArray(ser.hexToUint8Array(extensionData[1])); | ||
var deserializedObj = types.get(transactionExtension.type).deserialize(extensionBuffer); | ||
if (extensionData[0] === 1) { | ||
transaction.resource_payer = deserializedObj; | ||
} | ||
}); | ||
return transaction; | ||
}; | ||
; | ||
// Transaction extensions are serialized and moved to `transaction_extensions`, deserialized objects are not needed on the transaction | ||
Api.prototype.deleteTransactionExtensionObjects = function (transaction) { | ||
delete transaction.resource_payer; | ||
return transaction; | ||
}; | ||
/** Convert actions to hex */ | ||
@@ -434,8 +473,12 @@ Api.prototype.serializeActions = function (actions) { | ||
_f = {}; | ||
return [4 /*yield*/, this.serializeTransactionExtensions(transaction)]; | ||
case 6: | ||
_f.transaction_extensions = _g.sent(); | ||
return [4 /*yield*/, this.serializeActions(transaction.context_free_actions || [])]; | ||
case 6: | ||
case 7: | ||
_f.context_free_actions = _g.sent(); | ||
return [4 /*yield*/, this.serializeActions(transaction.actions)]; | ||
case 7: | ||
case 8: | ||
transaction = __assign.apply(void 0, _e.concat([(_f.actions = _g.sent(), _f)])); | ||
transaction = this.deleteTransactionExtensionObjects(transaction); | ||
serializedTransaction = this.serializeTransaction(transaction); | ||
@@ -448,12 +491,12 @@ serializedContextFreeData = this.serializeContextFreeData(transaction.context_free_data); | ||
}; | ||
if (!sign) return [3 /*break*/, 12]; | ||
if (!!requiredKeys) return [3 /*break*/, 10]; | ||
if (!sign) return [3 /*break*/, 13]; | ||
if (!!requiredKeys) return [3 /*break*/, 11]; | ||
return [4 /*yield*/, this.signatureProvider.getAvailableKeys()]; | ||
case 8: | ||
case 9: | ||
availableKeys = _g.sent(); | ||
return [4 /*yield*/, this.authorityProvider.getRequiredKeys({ transaction: transaction, availableKeys: availableKeys })]; | ||
case 9: | ||
case 10: | ||
requiredKeys = _g.sent(); | ||
_g.label = 10; | ||
case 10: return [4 /*yield*/, this.signatureProvider.sign({ | ||
_g.label = 11; | ||
case 11: return [4 /*yield*/, this.signatureProvider.sign({ | ||
chainId: this.chainId, | ||
@@ -465,6 +508,6 @@ requiredKeys: requiredKeys, | ||
})]; | ||
case 11: | ||
case 12: | ||
pushTransactionArgs = _g.sent(); | ||
_g.label = 12; | ||
case 12: | ||
_g.label = 13; | ||
case 13: | ||
if (broadcast) { | ||
@@ -471,0 +514,0 @@ result = void 0; |
@@ -249,2 +249,4 @@ /** | ||
export declare const createAbiTypes: () => Map<string, Type>; | ||
export declare const createTransactionExtensionTypes: () => Map<string, Type>; | ||
export declare const createTransactionTypes: () => Map<string, Type>; | ||
/** Get type from `types` */ | ||
@@ -251,0 +253,0 @@ export declare const getType: (types: Map<string, Type>, name: string) => Type; |
{ | ||
"name": "eosjs", | ||
"version": "22.1.0-66-ee54e3b", | ||
"version": "22.1.0-67-9dafdfa", | ||
"description": "Talk to eos API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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 too big to display
Sorry, the diff of this file is not supported yet
416677
6371
53