From 222a5184200b7625a5f4832136ccb7513a80dbfc Mon Sep 17 00:00:00 2001 From: Illia Polosukhin Date: Tue, 13 Aug 2019 19:44:29 -0700 Subject: [PATCH 1/8] WIP: Adopting nearlib to NEP-8 --- lib/account.d.ts | 4 +- lib/account.js | 48 +- lib/protos.js | 4748 +++++++++++++------------ lib/providers/json-rpc-provider.js | 1 + lib/signer.js | 1 + lib/transaction.d.ts | 25 +- lib/transaction.js | 79 +- src.ts/account.ts | 49 +- src.ts/protos.d.ts | 1811 +++++----- src.ts/providers/json-rpc-provider.ts | 1 + src.ts/signer.ts | 1 + src.ts/transaction.ts | 91 +- test/account.test.js | 228 +- test/test-utils.js | 1 + 14 files changed, 3665 insertions(+), 3423 deletions(-) diff --git a/lib/account.d.ts b/lib/account.d.ts index 9c27a79a6c..580ead93fb 100644 --- a/lib/account.d.ts +++ b/lib/account.d.ts @@ -22,10 +22,10 @@ export declare class Account { private retryTxResult; private signAndSendTransaction; createAndDeployContract(contractId: string, publicKey: string, data: Uint8Array, amount: BN): Promise; - sendMoney(receiver: string, amount: BN): Promise; + sendMoney(receiverId: string, amount: BN): Promise; createAccount(newAccountId: string, publicKey: string, amount: BN): Promise; deployContract(data: Uint8Array): Promise; - functionCall(contractId: string, methodName: string, args: any, amount?: BN): Promise; + functionCall(contractId: string, methodName: string, args: any, gas: number, amount?: BN): Promise; addKey(publicKey: string, contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): Promise; deleteKey(publicKey: string): Promise; stake(publicKey: string, amount: BN): Promise; diff --git a/lib/account.js b/lib/account.js index 39fc1fe9fa..5a5861bc54 100644 --- a/lib/account.js +++ b/lib/account.js @@ -58,8 +58,10 @@ class Account { } throw new Error(`Exceeded ${TX_STATUS_RETRY_NUMBER} status check attempts for transaction ${serialize_1.base_encode(txHash)}.`); } - async signAndSendTransaction(transaction) { - const [txHash, signedTx] = await transaction_1.signTransaction(this.connection.signer, transaction, this.accountId, this.connection.networkId); + async signAndSendTransaction(receiverId, actions) { + await this.ready; + console.warn(`receiverId: ${receiverId}, actions: ${actions}, signer: ${this.connection.signer}`); + const [txHash, signedTx] = await transaction_1.signTransaction(receiverId, ++this._state.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); let result; try { result = await this.connection.provider.sendTransaction(signedTx); @@ -73,12 +75,7 @@ class Account { } } const flatLogs = result.logs.reduce((acc, it) => acc.concat(it.lines), []); - if (transaction.hasOwnProperty('contractId')) { - this.printLogs(transaction['contractId'], flatLogs); - } - else if (transaction.hasOwnProperty('originator')) { - this.printLogs(transaction['originator'], flatLogs); - } + this.printLogs(signedTx.transaction.receiverId, flatLogs); if (result.status === provider_1.FinalTransactionStatus.Failed) { if (result.logs) { console.warn(flatLogs); @@ -97,44 +94,31 @@ class Account { await contractAccount.deployContract(data); return contractAccount; } - async sendMoney(receiver, amount) { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(transaction_1.sendMoney(this._state.nonce, this.accountId, receiver, amount)); + async sendMoney(receiverId, amount) { + return this.signAndSendTransaction(receiverId, [transaction_1.transfer(amount)]); } async createAccount(newAccountId, publicKey, amount) { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(transaction_1.createAccount(this._state.nonce, this.accountId, newAccountId, publicKey, amount)); + const accessKey = transaction_1.createAccessKey(null, "", newAccountId, new bn_js_1.default(0)); + return this.signAndSendTransaction(newAccountId, [transaction_1.createAccount(), transaction_1.transfer(amount), transaction_1.addKey(publicKey, accessKey)]); } async deployContract(data) { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(transaction_1.deployContract(this._state.nonce, this.accountId, data)); + return this.signAndSendTransaction(this.accountId, [transaction_1.deployContract(data)]); } - async functionCall(contractId, methodName, args, amount) { + async functionCall(contractId, methodName, args, gas, amount) { if (!args) { args = {}; } - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(transaction_1.functionCall(this._state.nonce, this.accountId, contractId, methodName, Buffer.from(JSON.stringify(args)), amount || DEFAULT_FUNC_CALL_AMOUNT)); + return this.signAndSendTransaction(contractId, [transaction_1.functionCall(methodName, Buffer.from(JSON.stringify(args)), gas, amount || DEFAULT_FUNC_CALL_AMOUNT)]); } async addKey(publicKey, contractId, methodName, balanceOwner, amount) { - await this.ready; - this._state.nonce++; - const accessKey = contractId ? transaction_1.createAccessKey(contractId, methodName, balanceOwner, amount) : null; - return this.signAndSendTransaction(transaction_1.addKey(this._state.nonce, this.accountId, publicKey, accessKey)); + const accessKey = transaction_1.createAccessKey(contractId ? contractId : null, methodName, balanceOwner, amount); + return this.signAndSendTransaction(this.accountId, [transaction_1.addKey(publicKey, accessKey)]); } async deleteKey(publicKey) { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(transaction_1.deleteKey(this._state.nonce, this.accountId, publicKey)); + return this.signAndSendTransaction(this.accountId, [transaction_1.deleteKey(publicKey)]); } async stake(publicKey, amount) { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(transaction_1.stake(this._state.nonce, this.accountId, amount, publicKey)); + return this.signAndSendTransaction(this.accountId, [transaction_1.stake(amount, publicKey)]); } async viewFunction(contractId, methodName, args) { const result = await this.connection.provider.query(`call/${contractId}/${methodName}`, serialize_1.base_encode(JSON.stringify(args))); diff --git a/lib/protos.js b/lib/protos.js index 1fa7543dec..85cccfa4fe 100644 --- a/lib/protos.js +++ b/lib/protos.js @@ -9,28 +9,31 @@ var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.ut // Exported root namespace var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); -$root.CreateAccountTransaction = (function() { +$root.Action = (function() { /** - * Properties of a CreateAccountTransaction. - * @exports ICreateAccountTransaction - * @interface ICreateAccountTransaction - * @property {number|Long|null} [nonce] CreateAccountTransaction nonce - * @property {string|null} [originator] CreateAccountTransaction originator - * @property {string|null} [newAccountId] CreateAccountTransaction newAccountId - * @property {IUint128|null} [amount] CreateAccountTransaction amount - * @property {Uint8Array|null} [publicKey] CreateAccountTransaction publicKey + * Properties of an Action. + * @exports IAction + * @interface IAction + * @property {Action.ICreateAccount|null} [createAccount] Action createAccount + * @property {Action.IDeployContract|null} [deployContract] Action deployContract + * @property {Action.IFunctionCall|null} [functionCall] Action functionCall + * @property {Action.ITransfer|null} [transfer] Action transfer + * @property {Action.IStake|null} [stake] Action stake + * @property {Action.IAddKey|null} [addKey] Action addKey + * @property {Action.IDeleteKey|null} [deleteKey] Action deleteKey + * @property {Action.IDeleteAccount|null} [deleteAccount] Action deleteAccount */ /** - * Constructs a new CreateAccountTransaction. - * @exports CreateAccountTransaction - * @classdesc Represents a CreateAccountTransaction. - * @implements ICreateAccountTransaction + * Constructs a new Action. + * @exports Action + * @classdesc Represents an Action. + * @implements IAction * @constructor - * @param {ICreateAccountTransaction=} [properties] Properties to set + * @param {IAction=} [properties] Properties to set */ - function CreateAccountTransaction(properties) { + function Action(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -38,127 +41,180 @@ $root.CreateAccountTransaction = (function() { } /** - * CreateAccountTransaction nonce. - * @member {number|Long} nonce - * @memberof CreateAccountTransaction + * Action createAccount. + * @member {Action.ICreateAccount|null|undefined} createAccount + * @memberof Action * @instance */ - CreateAccountTransaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + Action.prototype.createAccount = null; /** - * CreateAccountTransaction originator. - * @member {string} originator - * @memberof CreateAccountTransaction + * Action deployContract. + * @member {Action.IDeployContract|null|undefined} deployContract + * @memberof Action * @instance */ - CreateAccountTransaction.prototype.originator = ""; + Action.prototype.deployContract = null; /** - * CreateAccountTransaction newAccountId. - * @member {string} newAccountId - * @memberof CreateAccountTransaction + * Action functionCall. + * @member {Action.IFunctionCall|null|undefined} functionCall + * @memberof Action * @instance */ - CreateAccountTransaction.prototype.newAccountId = ""; + Action.prototype.functionCall = null; /** - * CreateAccountTransaction amount. - * @member {IUint128|null|undefined} amount - * @memberof CreateAccountTransaction + * Action transfer. + * @member {Action.ITransfer|null|undefined} transfer + * @memberof Action + * @instance + */ + Action.prototype.transfer = null; + + /** + * Action stake. + * @member {Action.IStake|null|undefined} stake + * @memberof Action + * @instance + */ + Action.prototype.stake = null; + + /** + * Action addKey. + * @member {Action.IAddKey|null|undefined} addKey + * @memberof Action + * @instance + */ + Action.prototype.addKey = null; + + /** + * Action deleteKey. + * @member {Action.IDeleteKey|null|undefined} deleteKey + * @memberof Action + * @instance + */ + Action.prototype.deleteKey = null; + + /** + * Action deleteAccount. + * @member {Action.IDeleteAccount|null|undefined} deleteAccount + * @memberof Action * @instance */ - CreateAccountTransaction.prototype.amount = null; + Action.prototype.deleteAccount = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; /** - * CreateAccountTransaction publicKey. - * @member {Uint8Array} publicKey - * @memberof CreateAccountTransaction + * Action action. + * @member {"createAccount"|"deployContract"|"functionCall"|"transfer"|"stake"|"addKey"|"deleteKey"|"deleteAccount"|undefined} action + * @memberof Action * @instance */ - CreateAccountTransaction.prototype.publicKey = $util.newBuffer([]); + Object.defineProperty(Action.prototype, "action", { + get: $util.oneOfGetter($oneOfFields = ["createAccount", "deployContract", "functionCall", "transfer", "stake", "addKey", "deleteKey", "deleteAccount"]), + set: $util.oneOfSetter($oneOfFields) + }); /** - * Creates a new CreateAccountTransaction instance using the specified properties. + * Creates a new Action instance using the specified properties. * @function create - * @memberof CreateAccountTransaction + * @memberof Action * @static - * @param {ICreateAccountTransaction=} [properties] Properties to set - * @returns {CreateAccountTransaction} CreateAccountTransaction instance + * @param {IAction=} [properties] Properties to set + * @returns {Action} Action instance */ - CreateAccountTransaction.create = function create(properties) { - return new CreateAccountTransaction(properties); + Action.create = function create(properties) { + return new Action(properties); }; /** - * Encodes the specified CreateAccountTransaction message. Does not implicitly {@link CreateAccountTransaction.verify|verify} messages. + * Encodes the specified Action message. Does not implicitly {@link Action.verify|verify} messages. * @function encode - * @memberof CreateAccountTransaction + * @memberof Action * @static - * @param {ICreateAccountTransaction} message CreateAccountTransaction message or plain object to encode + * @param {IAction} message Action message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - CreateAccountTransaction.encode = function encode(message, writer) { + Action.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.nonce != null && message.hasOwnProperty("nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.nonce); - if (message.originator != null && message.hasOwnProperty("originator")) - writer.uint32(/* id 2, wireType 2 =*/18).string(message.originator); - if (message.newAccountId != null && message.hasOwnProperty("newAccountId")) - writer.uint32(/* id 3, wireType 2 =*/26).string(message.newAccountId); - if (message.amount != null && message.hasOwnProperty("amount")) - $root.Uint128.encode(message.amount, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); - if (message.publicKey != null && message.hasOwnProperty("publicKey")) - writer.uint32(/* id 5, wireType 2 =*/42).bytes(message.publicKey); + if (message.createAccount != null && message.hasOwnProperty("createAccount")) + $root.Action.CreateAccount.encode(message.createAccount, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.deployContract != null && message.hasOwnProperty("deployContract")) + $root.Action.DeployContract.encode(message.deployContract, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + if (message.functionCall != null && message.hasOwnProperty("functionCall")) + $root.Action.FunctionCall.encode(message.functionCall, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); + if (message.transfer != null && message.hasOwnProperty("transfer")) + $root.Action.Transfer.encode(message.transfer, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); + if (message.stake != null && message.hasOwnProperty("stake")) + $root.Action.Stake.encode(message.stake, writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); + if (message.addKey != null && message.hasOwnProperty("addKey")) + $root.Action.AddKey.encode(message.addKey, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim(); + if (message.deleteKey != null && message.hasOwnProperty("deleteKey")) + $root.Action.DeleteKey.encode(message.deleteKey, writer.uint32(/* id 7, wireType 2 =*/58).fork()).ldelim(); + if (message.deleteAccount != null && message.hasOwnProperty("deleteAccount")) + $root.Action.DeleteAccount.encode(message.deleteAccount, writer.uint32(/* id 8, wireType 2 =*/66).fork()).ldelim(); return writer; }; /** - * Encodes the specified CreateAccountTransaction message, length delimited. Does not implicitly {@link CreateAccountTransaction.verify|verify} messages. + * Encodes the specified Action message, length delimited. Does not implicitly {@link Action.verify|verify} messages. * @function encodeDelimited - * @memberof CreateAccountTransaction + * @memberof Action * @static - * @param {ICreateAccountTransaction} message CreateAccountTransaction message or plain object to encode + * @param {IAction} message Action message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - CreateAccountTransaction.encodeDelimited = function encodeDelimited(message, writer) { + Action.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** - * Decodes a CreateAccountTransaction message from the specified reader or buffer. + * Decodes an Action message from the specified reader or buffer. * @function decode - * @memberof CreateAccountTransaction + * @memberof Action * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand - * @returns {CreateAccountTransaction} CreateAccountTransaction + * @returns {Action} Action * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - CreateAccountTransaction.decode = function decode(reader, length) { + Action.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.CreateAccountTransaction(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.nonce = reader.uint64(); + message.createAccount = $root.Action.CreateAccount.decode(reader, reader.uint32()); break; case 2: - message.originator = reader.string(); + message.deployContract = $root.Action.DeployContract.decode(reader, reader.uint32()); break; case 3: - message.newAccountId = reader.string(); + message.functionCall = $root.Action.FunctionCall.decode(reader, reader.uint32()); break; case 4: - message.amount = $root.Uint128.decode(reader, reader.uint32()); + message.transfer = $root.Action.Transfer.decode(reader, reader.uint32()); break; case 5: - message.publicKey = reader.bytes(); + message.stake = $root.Action.Stake.decode(reader, reader.uint32()); + break; + case 6: + message.addKey = $root.Action.AddKey.decode(reader, reader.uint32()); + break; + case 7: + message.deleteKey = $root.Action.DeleteKey.decode(reader, reader.uint32()); + break; + case 8: + message.deleteAccount = $root.Action.DeleteAccount.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -169,1615 +225,1911 @@ $root.CreateAccountTransaction = (function() { }; /** - * Decodes a CreateAccountTransaction message from the specified reader or buffer, length delimited. + * Decodes an Action message from the specified reader or buffer, length delimited. * @function decodeDelimited - * @memberof CreateAccountTransaction + * @memberof Action * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {CreateAccountTransaction} CreateAccountTransaction + * @returns {Action} Action * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - CreateAccountTransaction.decodeDelimited = function decodeDelimited(reader) { + Action.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** - * Verifies a CreateAccountTransaction message. + * Verifies an Action message. * @function verify - * @memberof CreateAccountTransaction + * @memberof Action * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ - CreateAccountTransaction.verify = function verify(message) { + Action.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (!$util.isInteger(message.nonce) && !(message.nonce && $util.isInteger(message.nonce.low) && $util.isInteger(message.nonce.high))) - return "nonce: integer|Long expected"; - if (message.originator != null && message.hasOwnProperty("originator")) - if (!$util.isString(message.originator)) - return "originator: string expected"; - if (message.newAccountId != null && message.hasOwnProperty("newAccountId")) - if (!$util.isString(message.newAccountId)) - return "newAccountId: string expected"; - if (message.amount != null && message.hasOwnProperty("amount")) { - var error = $root.Uint128.verify(message.amount); - if (error) - return "amount." + error; + var properties = {}; + if (message.createAccount != null && message.hasOwnProperty("createAccount")) { + properties.action = 1; + { + var error = $root.Action.CreateAccount.verify(message.createAccount); + if (error) + return "createAccount." + error; + } + } + if (message.deployContract != null && message.hasOwnProperty("deployContract")) { + if (properties.action === 1) + return "action: multiple values"; + properties.action = 1; + { + var error = $root.Action.DeployContract.verify(message.deployContract); + if (error) + return "deployContract." + error; + } + } + if (message.functionCall != null && message.hasOwnProperty("functionCall")) { + if (properties.action === 1) + return "action: multiple values"; + properties.action = 1; + { + var error = $root.Action.FunctionCall.verify(message.functionCall); + if (error) + return "functionCall." + error; + } + } + if (message.transfer != null && message.hasOwnProperty("transfer")) { + if (properties.action === 1) + return "action: multiple values"; + properties.action = 1; + { + var error = $root.Action.Transfer.verify(message.transfer); + if (error) + return "transfer." + error; + } + } + if (message.stake != null && message.hasOwnProperty("stake")) { + if (properties.action === 1) + return "action: multiple values"; + properties.action = 1; + { + var error = $root.Action.Stake.verify(message.stake); + if (error) + return "stake." + error; + } + } + if (message.addKey != null && message.hasOwnProperty("addKey")) { + if (properties.action === 1) + return "action: multiple values"; + properties.action = 1; + { + var error = $root.Action.AddKey.verify(message.addKey); + if (error) + return "addKey." + error; + } + } + if (message.deleteKey != null && message.hasOwnProperty("deleteKey")) { + if (properties.action === 1) + return "action: multiple values"; + properties.action = 1; + { + var error = $root.Action.DeleteKey.verify(message.deleteKey); + if (error) + return "deleteKey." + error; + } + } + if (message.deleteAccount != null && message.hasOwnProperty("deleteAccount")) { + if (properties.action === 1) + return "action: multiple values"; + properties.action = 1; + { + var error = $root.Action.DeleteAccount.verify(message.deleteAccount); + if (error) + return "deleteAccount." + error; + } } - if (message.publicKey != null && message.hasOwnProperty("publicKey")) - if (!(message.publicKey && typeof message.publicKey.length === "number" || $util.isString(message.publicKey))) - return "publicKey: buffer expected"; return null; }; /** - * Creates a CreateAccountTransaction message from a plain object. Also converts values to their respective internal types. + * Creates an Action message from a plain object. Also converts values to their respective internal types. * @function fromObject - * @memberof CreateAccountTransaction + * @memberof Action * @static * @param {Object.} object Plain object - * @returns {CreateAccountTransaction} CreateAccountTransaction + * @returns {Action} Action */ - CreateAccountTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.CreateAccountTransaction) + Action.fromObject = function fromObject(object) { + if (object instanceof $root.Action) return object; - var message = new $root.CreateAccountTransaction(); - if (object.nonce != null) - if ($util.Long) - (message.nonce = $util.Long.fromValue(object.nonce)).unsigned = true; - else if (typeof object.nonce === "string") - message.nonce = parseInt(object.nonce, 10); - else if (typeof object.nonce === "number") - message.nonce = object.nonce; - else if (typeof object.nonce === "object") - message.nonce = new $util.LongBits(object.nonce.low >>> 0, object.nonce.high >>> 0).toNumber(true); - if (object.originator != null) - message.originator = String(object.originator); - if (object.newAccountId != null) - message.newAccountId = String(object.newAccountId); - if (object.amount != null) { - if (typeof object.amount !== "object") - throw TypeError(".CreateAccountTransaction.amount: object expected"); - message.amount = $root.Uint128.fromObject(object.amount); + var message = new $root.Action(); + if (object.createAccount != null) { + if (typeof object.createAccount !== "object") + throw TypeError(".Action.createAccount: object expected"); + message.createAccount = $root.Action.CreateAccount.fromObject(object.createAccount); + } + if (object.deployContract != null) { + if (typeof object.deployContract !== "object") + throw TypeError(".Action.deployContract: object expected"); + message.deployContract = $root.Action.DeployContract.fromObject(object.deployContract); + } + if (object.functionCall != null) { + if (typeof object.functionCall !== "object") + throw TypeError(".Action.functionCall: object expected"); + message.functionCall = $root.Action.FunctionCall.fromObject(object.functionCall); + } + if (object.transfer != null) { + if (typeof object.transfer !== "object") + throw TypeError(".Action.transfer: object expected"); + message.transfer = $root.Action.Transfer.fromObject(object.transfer); + } + if (object.stake != null) { + if (typeof object.stake !== "object") + throw TypeError(".Action.stake: object expected"); + message.stake = $root.Action.Stake.fromObject(object.stake); + } + if (object.addKey != null) { + if (typeof object.addKey !== "object") + throw TypeError(".Action.addKey: object expected"); + message.addKey = $root.Action.AddKey.fromObject(object.addKey); + } + if (object.deleteKey != null) { + if (typeof object.deleteKey !== "object") + throw TypeError(".Action.deleteKey: object expected"); + message.deleteKey = $root.Action.DeleteKey.fromObject(object.deleteKey); + } + if (object.deleteAccount != null) { + if (typeof object.deleteAccount !== "object") + throw TypeError(".Action.deleteAccount: object expected"); + message.deleteAccount = $root.Action.DeleteAccount.fromObject(object.deleteAccount); } - if (object.publicKey != null) - if (typeof object.publicKey === "string") - $util.base64.decode(object.publicKey, message.publicKey = $util.newBuffer($util.base64.length(object.publicKey)), 0); - else if (object.publicKey.length) - message.publicKey = object.publicKey; return message; }; /** - * Creates a plain object from a CreateAccountTransaction message. Also converts values to other types if specified. + * Creates a plain object from an Action message. Also converts values to other types if specified. * @function toObject - * @memberof CreateAccountTransaction + * @memberof Action * @static - * @param {CreateAccountTransaction} message CreateAccountTransaction + * @param {Action} message Action * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - CreateAccountTransaction.toObject = function toObject(message, options) { + Action.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; - if (options.defaults) { - if ($util.Long) { - var long = new $util.Long(0, 0, true); - object.nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.nonce = options.longs === String ? "0" : 0; - object.originator = ""; - object.newAccountId = ""; - object.amount = null; - if (options.bytes === String) - object.publicKey = ""; - else { - object.publicKey = []; - if (options.bytes !== Array) - object.publicKey = $util.newBuffer(object.publicKey); - } + if (message.createAccount != null && message.hasOwnProperty("createAccount")) { + object.createAccount = $root.Action.CreateAccount.toObject(message.createAccount, options); + if (options.oneofs) + object.action = "createAccount"; + } + if (message.deployContract != null && message.hasOwnProperty("deployContract")) { + object.deployContract = $root.Action.DeployContract.toObject(message.deployContract, options); + if (options.oneofs) + object.action = "deployContract"; + } + if (message.functionCall != null && message.hasOwnProperty("functionCall")) { + object.functionCall = $root.Action.FunctionCall.toObject(message.functionCall, options); + if (options.oneofs) + object.action = "functionCall"; + } + if (message.transfer != null && message.hasOwnProperty("transfer")) { + object.transfer = $root.Action.Transfer.toObject(message.transfer, options); + if (options.oneofs) + object.action = "transfer"; + } + if (message.stake != null && message.hasOwnProperty("stake")) { + object.stake = $root.Action.Stake.toObject(message.stake, options); + if (options.oneofs) + object.action = "stake"; + } + if (message.addKey != null && message.hasOwnProperty("addKey")) { + object.addKey = $root.Action.AddKey.toObject(message.addKey, options); + if (options.oneofs) + object.action = "addKey"; + } + if (message.deleteKey != null && message.hasOwnProperty("deleteKey")) { + object.deleteKey = $root.Action.DeleteKey.toObject(message.deleteKey, options); + if (options.oneofs) + object.action = "deleteKey"; + } + if (message.deleteAccount != null && message.hasOwnProperty("deleteAccount")) { + object.deleteAccount = $root.Action.DeleteAccount.toObject(message.deleteAccount, options); + if (options.oneofs) + object.action = "deleteAccount"; } - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (typeof message.nonce === "number") - object.nonce = options.longs === String ? String(message.nonce) : message.nonce; - else - object.nonce = options.longs === String ? $util.Long.prototype.toString.call(message.nonce) : options.longs === Number ? new $util.LongBits(message.nonce.low >>> 0, message.nonce.high >>> 0).toNumber(true) : message.nonce; - if (message.originator != null && message.hasOwnProperty("originator")) - object.originator = message.originator; - if (message.newAccountId != null && message.hasOwnProperty("newAccountId")) - object.newAccountId = message.newAccountId; - if (message.amount != null && message.hasOwnProperty("amount")) - object.amount = $root.Uint128.toObject(message.amount, options); - if (message.publicKey != null && message.hasOwnProperty("publicKey")) - object.publicKey = options.bytes === String ? $util.base64.encode(message.publicKey, 0, message.publicKey.length) : options.bytes === Array ? Array.prototype.slice.call(message.publicKey) : message.publicKey; return object; }; /** - * Converts this CreateAccountTransaction to JSON. + * Converts this Action to JSON. * @function toJSON - * @memberof CreateAccountTransaction + * @memberof Action * @instance * @returns {Object.} JSON object */ - CreateAccountTransaction.prototype.toJSON = function toJSON() { + Action.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; - return CreateAccountTransaction; -})(); + Action.CreateAccount = (function() { -$root.DeployContractTransaction = (function() { + /** + * Properties of a CreateAccount. + * @memberof Action + * @interface ICreateAccount + */ - /** - * Properties of a DeployContractTransaction. - * @exports IDeployContractTransaction - * @interface IDeployContractTransaction - * @property {number|Long|null} [nonce] DeployContractTransaction nonce - * @property {string|null} [contractId] DeployContractTransaction contractId - * @property {Uint8Array|null} [wasmByteArray] DeployContractTransaction wasmByteArray - */ + /** + * Constructs a new CreateAccount. + * @memberof Action + * @classdesc Represents a CreateAccount. + * @implements ICreateAccount + * @constructor + * @param {Action.ICreateAccount=} [properties] Properties to set + */ + function CreateAccount(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } - /** - * Constructs a new DeployContractTransaction. - * @exports DeployContractTransaction - * @classdesc Represents a DeployContractTransaction. - * @implements IDeployContractTransaction - * @constructor - * @param {IDeployContractTransaction=} [properties] Properties to set - */ - function DeployContractTransaction(properties) { - if (properties) - for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) - if (properties[keys[i]] != null) - this[keys[i]] = properties[keys[i]]; - } + /** + * Creates a new CreateAccount instance using the specified properties. + * @function create + * @memberof Action.CreateAccount + * @static + * @param {Action.ICreateAccount=} [properties] Properties to set + * @returns {Action.CreateAccount} CreateAccount instance + */ + CreateAccount.create = function create(properties) { + return new CreateAccount(properties); + }; - /** - * DeployContractTransaction nonce. - * @member {number|Long} nonce - * @memberof DeployContractTransaction - * @instance - */ - DeployContractTransaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** + * Encodes the specified CreateAccount message. Does not implicitly {@link Action.CreateAccount.verify|verify} messages. + * @function encode + * @memberof Action.CreateAccount + * @static + * @param {Action.ICreateAccount} message CreateAccount message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + CreateAccount.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + return writer; + }; - /** - * DeployContractTransaction contractId. - * @member {string} contractId - * @memberof DeployContractTransaction - * @instance - */ - DeployContractTransaction.prototype.contractId = ""; + /** + * Encodes the specified CreateAccount message, length delimited. Does not implicitly {@link Action.CreateAccount.verify|verify} messages. + * @function encodeDelimited + * @memberof Action.CreateAccount + * @static + * @param {Action.ICreateAccount} message CreateAccount message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + CreateAccount.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; - /** - * DeployContractTransaction wasmByteArray. - * @member {Uint8Array} wasmByteArray - * @memberof DeployContractTransaction - * @instance - */ - DeployContractTransaction.prototype.wasmByteArray = $util.newBuffer([]); + /** + * Decodes a CreateAccount message from the specified reader or buffer. + * @function decode + * @memberof Action.CreateAccount + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {Action.CreateAccount} CreateAccount + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + CreateAccount.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action.CreateAccount(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; - /** - * Creates a new DeployContractTransaction instance using the specified properties. - * @function create - * @memberof DeployContractTransaction - * @static - * @param {IDeployContractTransaction=} [properties] Properties to set - * @returns {DeployContractTransaction} DeployContractTransaction instance - */ - DeployContractTransaction.create = function create(properties) { - return new DeployContractTransaction(properties); - }; + /** + * Decodes a CreateAccount message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof Action.CreateAccount + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {Action.CreateAccount} CreateAccount + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + CreateAccount.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; - /** - * Encodes the specified DeployContractTransaction message. Does not implicitly {@link DeployContractTransaction.verify|verify} messages. - * @function encode - * @memberof DeployContractTransaction - * @static - * @param {IDeployContractTransaction} message DeployContractTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - DeployContractTransaction.encode = function encode(message, writer) { - if (!writer) - writer = $Writer.create(); - if (message.nonce != null && message.hasOwnProperty("nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.nonce); - if (message.contractId != null && message.hasOwnProperty("contractId")) - writer.uint32(/* id 2, wireType 2 =*/18).string(message.contractId); - if (message.wasmByteArray != null && message.hasOwnProperty("wasmByteArray")) - writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.wasmByteArray); - return writer; - }; + /** + * Verifies a CreateAccount message. + * @function verify + * @memberof Action.CreateAccount + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + CreateAccount.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + return null; + }; - /** - * Encodes the specified DeployContractTransaction message, length delimited. Does not implicitly {@link DeployContractTransaction.verify|verify} messages. - * @function encodeDelimited - * @memberof DeployContractTransaction - * @static - * @param {IDeployContractTransaction} message DeployContractTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - DeployContractTransaction.encodeDelimited = function encodeDelimited(message, writer) { - return this.encode(message, writer).ldelim(); - }; + /** + * Creates a CreateAccount message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Action.CreateAccount + * @static + * @param {Object.} object Plain object + * @returns {Action.CreateAccount} CreateAccount + */ + CreateAccount.fromObject = function fromObject(object) { + if (object instanceof $root.Action.CreateAccount) + return object; + return new $root.Action.CreateAccount(); + }; - /** - * Decodes a DeployContractTransaction message from the specified reader or buffer. - * @function decode - * @memberof DeployContractTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @param {number} [length] Message length if known beforehand - * @returns {DeployContractTransaction} DeployContractTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - DeployContractTransaction.decode = function decode(reader, length) { - if (!(reader instanceof $Reader)) - reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.DeployContractTransaction(); - while (reader.pos < end) { - var tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.nonce = reader.uint64(); - break; - case 2: - message.contractId = reader.string(); - break; - case 3: - message.wasmByteArray = reader.bytes(); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }; + /** + * Creates a plain object from a CreateAccount message. Also converts values to other types if specified. + * @function toObject + * @memberof Action.CreateAccount + * @static + * @param {Action.CreateAccount} message CreateAccount + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + CreateAccount.toObject = function toObject() { + return {}; + }; - /** - * Decodes a DeployContractTransaction message from the specified reader or buffer, length delimited. - * @function decodeDelimited - * @memberof DeployContractTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {DeployContractTransaction} DeployContractTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - DeployContractTransaction.decodeDelimited = function decodeDelimited(reader) { - if (!(reader instanceof $Reader)) - reader = new $Reader(reader); - return this.decode(reader, reader.uint32()); - }; + /** + * Converts this CreateAccount to JSON. + * @function toJSON + * @memberof Action.CreateAccount + * @instance + * @returns {Object.} JSON object + */ + CreateAccount.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; - /** - * Verifies a DeployContractTransaction message. - * @function verify - * @memberof DeployContractTransaction - * @static - * @param {Object.} message Plain object to verify - * @returns {string|null} `null` if valid, otherwise the reason why it is not - */ - DeployContractTransaction.verify = function verify(message) { - if (typeof message !== "object" || message === null) - return "object expected"; - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (!$util.isInteger(message.nonce) && !(message.nonce && $util.isInteger(message.nonce.low) && $util.isInteger(message.nonce.high))) - return "nonce: integer|Long expected"; - if (message.contractId != null && message.hasOwnProperty("contractId")) - if (!$util.isString(message.contractId)) - return "contractId: string expected"; - if (message.wasmByteArray != null && message.hasOwnProperty("wasmByteArray")) - if (!(message.wasmByteArray && typeof message.wasmByteArray.length === "number" || $util.isString(message.wasmByteArray))) - return "wasmByteArray: buffer expected"; - return null; - }; + return CreateAccount; + })(); - /** - * Creates a DeployContractTransaction message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof DeployContractTransaction - * @static - * @param {Object.} object Plain object - * @returns {DeployContractTransaction} DeployContractTransaction - */ - DeployContractTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.DeployContractTransaction) - return object; - var message = new $root.DeployContractTransaction(); - if (object.nonce != null) - if ($util.Long) - (message.nonce = $util.Long.fromValue(object.nonce)).unsigned = true; - else if (typeof object.nonce === "string") - message.nonce = parseInt(object.nonce, 10); - else if (typeof object.nonce === "number") - message.nonce = object.nonce; - else if (typeof object.nonce === "object") - message.nonce = new $util.LongBits(object.nonce.low >>> 0, object.nonce.high >>> 0).toNumber(true); - if (object.contractId != null) - message.contractId = String(object.contractId); - if (object.wasmByteArray != null) - if (typeof object.wasmByteArray === "string") - $util.base64.decode(object.wasmByteArray, message.wasmByteArray = $util.newBuffer($util.base64.length(object.wasmByteArray)), 0); - else if (object.wasmByteArray.length) - message.wasmByteArray = object.wasmByteArray; - return message; - }; + Action.DeployContract = (function() { - /** - * Creates a plain object from a DeployContractTransaction message. Also converts values to other types if specified. - * @function toObject - * @memberof DeployContractTransaction - * @static - * @param {DeployContractTransaction} message DeployContractTransaction - * @param {$protobuf.IConversionOptions} [options] Conversion options - * @returns {Object.} Plain object - */ - DeployContractTransaction.toObject = function toObject(message, options) { - if (!options) - options = {}; - var object = {}; - if (options.defaults) { - if ($util.Long) { - var long = new $util.Long(0, 0, true); - object.nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.nonce = options.longs === String ? "0" : 0; - object.contractId = ""; - if (options.bytes === String) - object.wasmByteArray = ""; - else { - object.wasmByteArray = []; - if (options.bytes !== Array) - object.wasmByteArray = $util.newBuffer(object.wasmByteArray); - } - } - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (typeof message.nonce === "number") - object.nonce = options.longs === String ? String(message.nonce) : message.nonce; - else - object.nonce = options.longs === String ? $util.Long.prototype.toString.call(message.nonce) : options.longs === Number ? new $util.LongBits(message.nonce.low >>> 0, message.nonce.high >>> 0).toNumber(true) : message.nonce; - if (message.contractId != null && message.hasOwnProperty("contractId")) - object.contractId = message.contractId; - if (message.wasmByteArray != null && message.hasOwnProperty("wasmByteArray")) - object.wasmByteArray = options.bytes === String ? $util.base64.encode(message.wasmByteArray, 0, message.wasmByteArray.length) : options.bytes === Array ? Array.prototype.slice.call(message.wasmByteArray) : message.wasmByteArray; - return object; - }; + /** + * Properties of a DeployContract. + * @memberof Action + * @interface IDeployContract + * @property {Uint8Array|null} [code] DeployContract code + */ - /** - * Converts this DeployContractTransaction to JSON. - * @function toJSON - * @memberof DeployContractTransaction - * @instance - * @returns {Object.} JSON object - */ - DeployContractTransaction.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; + /** + * Constructs a new DeployContract. + * @memberof Action + * @classdesc Represents a DeployContract. + * @implements IDeployContract + * @constructor + * @param {Action.IDeployContract=} [properties] Properties to set + */ + function DeployContract(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } - return DeployContractTransaction; -})(); + /** + * DeployContract code. + * @member {Uint8Array} code + * @memberof Action.DeployContract + * @instance + */ + DeployContract.prototype.code = $util.newBuffer([]); -$root.FunctionCallTransaction = (function() { + /** + * Creates a new DeployContract instance using the specified properties. + * @function create + * @memberof Action.DeployContract + * @static + * @param {Action.IDeployContract=} [properties] Properties to set + * @returns {Action.DeployContract} DeployContract instance + */ + DeployContract.create = function create(properties) { + return new DeployContract(properties); + }; - /** - * Properties of a FunctionCallTransaction. - * @exports IFunctionCallTransaction - * @interface IFunctionCallTransaction - * @property {number|Long|null} [nonce] FunctionCallTransaction nonce - * @property {string|null} [originator] FunctionCallTransaction originator - * @property {string|null} [contractId] FunctionCallTransaction contractId - * @property {Uint8Array|null} [methodName] FunctionCallTransaction methodName - * @property {Uint8Array|null} [args] FunctionCallTransaction args - * @property {IUint128|null} [amount] FunctionCallTransaction amount - */ + /** + * Encodes the specified DeployContract message. Does not implicitly {@link Action.DeployContract.verify|verify} messages. + * @function encode + * @memberof Action.DeployContract + * @static + * @param {Action.IDeployContract} message DeployContract message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DeployContract.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.code != null && message.hasOwnProperty("code")) + writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.code); + return writer; + }; - /** - * Constructs a new FunctionCallTransaction. - * @exports FunctionCallTransaction - * @classdesc Represents a FunctionCallTransaction. - * @implements IFunctionCallTransaction - * @constructor - * @param {IFunctionCallTransaction=} [properties] Properties to set - */ - function FunctionCallTransaction(properties) { - if (properties) - for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) - if (properties[keys[i]] != null) - this[keys[i]] = properties[keys[i]]; - } + /** + * Encodes the specified DeployContract message, length delimited. Does not implicitly {@link Action.DeployContract.verify|verify} messages. + * @function encodeDelimited + * @memberof Action.DeployContract + * @static + * @param {Action.IDeployContract} message DeployContract message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DeployContract.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; - /** - * FunctionCallTransaction nonce. - * @member {number|Long} nonce - * @memberof FunctionCallTransaction - * @instance - */ - FunctionCallTransaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** + * Decodes a DeployContract message from the specified reader or buffer. + * @function decode + * @memberof Action.DeployContract + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {Action.DeployContract} DeployContract + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DeployContract.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action.DeployContract(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.code = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; - /** - * FunctionCallTransaction originator. - * @member {string} originator - * @memberof FunctionCallTransaction - * @instance - */ - FunctionCallTransaction.prototype.originator = ""; + /** + * Decodes a DeployContract message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof Action.DeployContract + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {Action.DeployContract} DeployContract + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DeployContract.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; - /** - * FunctionCallTransaction contractId. - * @member {string} contractId - * @memberof FunctionCallTransaction - * @instance - */ - FunctionCallTransaction.prototype.contractId = ""; + /** + * Verifies a DeployContract message. + * @function verify + * @memberof Action.DeployContract + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + DeployContract.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.code != null && message.hasOwnProperty("code")) + if (!(message.code && typeof message.code.length === "number" || $util.isString(message.code))) + return "code: buffer expected"; + return null; + }; - /** - * FunctionCallTransaction methodName. - * @member {Uint8Array} methodName - * @memberof FunctionCallTransaction - * @instance - */ - FunctionCallTransaction.prototype.methodName = $util.newBuffer([]); + /** + * Creates a DeployContract message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Action.DeployContract + * @static + * @param {Object.} object Plain object + * @returns {Action.DeployContract} DeployContract + */ + DeployContract.fromObject = function fromObject(object) { + if (object instanceof $root.Action.DeployContract) + return object; + var message = new $root.Action.DeployContract(); + if (object.code != null) + if (typeof object.code === "string") + $util.base64.decode(object.code, message.code = $util.newBuffer($util.base64.length(object.code)), 0); + else if (object.code.length) + message.code = object.code; + return message; + }; - /** - * FunctionCallTransaction args. - * @member {Uint8Array} args - * @memberof FunctionCallTransaction - * @instance - */ - FunctionCallTransaction.prototype.args = $util.newBuffer([]); + /** + * Creates a plain object from a DeployContract message. Also converts values to other types if specified. + * @function toObject + * @memberof Action.DeployContract + * @static + * @param {Action.DeployContract} message DeployContract + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + DeployContract.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + if (options.bytes === String) + object.code = ""; + else { + object.code = []; + if (options.bytes !== Array) + object.code = $util.newBuffer(object.code); + } + if (message.code != null && message.hasOwnProperty("code")) + object.code = options.bytes === String ? $util.base64.encode(message.code, 0, message.code.length) : options.bytes === Array ? Array.prototype.slice.call(message.code) : message.code; + return object; + }; - /** - * FunctionCallTransaction amount. - * @member {IUint128|null|undefined} amount - * @memberof FunctionCallTransaction - * @instance - */ - FunctionCallTransaction.prototype.amount = null; + /** + * Converts this DeployContract to JSON. + * @function toJSON + * @memberof Action.DeployContract + * @instance + * @returns {Object.} JSON object + */ + DeployContract.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; - /** - * Creates a new FunctionCallTransaction instance using the specified properties. - * @function create - * @memberof FunctionCallTransaction - * @static - * @param {IFunctionCallTransaction=} [properties] Properties to set - * @returns {FunctionCallTransaction} FunctionCallTransaction instance - */ - FunctionCallTransaction.create = function create(properties) { - return new FunctionCallTransaction(properties); - }; + return DeployContract; + })(); - /** - * Encodes the specified FunctionCallTransaction message. Does not implicitly {@link FunctionCallTransaction.verify|verify} messages. - * @function encode - * @memberof FunctionCallTransaction - * @static - * @param {IFunctionCallTransaction} message FunctionCallTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - FunctionCallTransaction.encode = function encode(message, writer) { - if (!writer) - writer = $Writer.create(); - if (message.nonce != null && message.hasOwnProperty("nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.nonce); - if (message.originator != null && message.hasOwnProperty("originator")) - writer.uint32(/* id 2, wireType 2 =*/18).string(message.originator); - if (message.contractId != null && message.hasOwnProperty("contractId")) - writer.uint32(/* id 3, wireType 2 =*/26).string(message.contractId); - if (message.methodName != null && message.hasOwnProperty("methodName")) - writer.uint32(/* id 4, wireType 2 =*/34).bytes(message.methodName); - if (message.args != null && message.hasOwnProperty("args")) - writer.uint32(/* id 5, wireType 2 =*/42).bytes(message.args); - if (message.amount != null && message.hasOwnProperty("amount")) - $root.Uint128.encode(message.amount, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim(); - return writer; - }; + Action.FunctionCall = (function() { - /** - * Encodes the specified FunctionCallTransaction message, length delimited. Does not implicitly {@link FunctionCallTransaction.verify|verify} messages. - * @function encodeDelimited - * @memberof FunctionCallTransaction - * @static - * @param {IFunctionCallTransaction} message FunctionCallTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - FunctionCallTransaction.encodeDelimited = function encodeDelimited(message, writer) { - return this.encode(message, writer).ldelim(); - }; + /** + * Properties of a FunctionCall. + * @memberof Action + * @interface IFunctionCall + * @property {string|null} [methodName] FunctionCall methodName + * @property {Uint8Array|null} [args] FunctionCall args + * @property {number|Long|null} [gas] FunctionCall gas + * @property {IUint128|null} [deposit] FunctionCall deposit + */ - /** - * Decodes a FunctionCallTransaction message from the specified reader or buffer. - * @function decode - * @memberof FunctionCallTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @param {number} [length] Message length if known beforehand - * @returns {FunctionCallTransaction} FunctionCallTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - FunctionCallTransaction.decode = function decode(reader, length) { - if (!(reader instanceof $Reader)) - reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.FunctionCallTransaction(); - while (reader.pos < end) { - var tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.nonce = reader.uint64(); - break; - case 2: - message.originator = reader.string(); - break; - case 3: - message.contractId = reader.string(); - break; - case 4: - message.methodName = reader.bytes(); - break; - case 5: - message.args = reader.bytes(); - break; - case 6: - message.amount = $root.Uint128.decode(reader, reader.uint32()); - break; - default: - reader.skipType(tag & 7); - break; - } + /** + * Constructs a new FunctionCall. + * @memberof Action + * @classdesc Represents a FunctionCall. + * @implements IFunctionCall + * @constructor + * @param {Action.IFunctionCall=} [properties] Properties to set + */ + function FunctionCall(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; } - return message; - }; - /** - * Decodes a FunctionCallTransaction message from the specified reader or buffer, length delimited. - * @function decodeDelimited - * @memberof FunctionCallTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {FunctionCallTransaction} FunctionCallTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - FunctionCallTransaction.decodeDelimited = function decodeDelimited(reader) { - if (!(reader instanceof $Reader)) - reader = new $Reader(reader); - return this.decode(reader, reader.uint32()); - }; + /** + * FunctionCall methodName. + * @member {string} methodName + * @memberof Action.FunctionCall + * @instance + */ + FunctionCall.prototype.methodName = ""; - /** - * Verifies a FunctionCallTransaction message. - * @function verify - * @memberof FunctionCallTransaction - * @static - * @param {Object.} message Plain object to verify - * @returns {string|null} `null` if valid, otherwise the reason why it is not - */ - FunctionCallTransaction.verify = function verify(message) { - if (typeof message !== "object" || message === null) - return "object expected"; - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (!$util.isInteger(message.nonce) && !(message.nonce && $util.isInteger(message.nonce.low) && $util.isInteger(message.nonce.high))) - return "nonce: integer|Long expected"; - if (message.originator != null && message.hasOwnProperty("originator")) - if (!$util.isString(message.originator)) - return "originator: string expected"; - if (message.contractId != null && message.hasOwnProperty("contractId")) - if (!$util.isString(message.contractId)) - return "contractId: string expected"; - if (message.methodName != null && message.hasOwnProperty("methodName")) - if (!(message.methodName && typeof message.methodName.length === "number" || $util.isString(message.methodName))) - return "methodName: buffer expected"; - if (message.args != null && message.hasOwnProperty("args")) - if (!(message.args && typeof message.args.length === "number" || $util.isString(message.args))) - return "args: buffer expected"; - if (message.amount != null && message.hasOwnProperty("amount")) { - var error = $root.Uint128.verify(message.amount); - if (error) - return "amount." + error; - } - return null; - }; + /** + * FunctionCall args. + * @member {Uint8Array} args + * @memberof Action.FunctionCall + * @instance + */ + FunctionCall.prototype.args = $util.newBuffer([]); - /** - * Creates a FunctionCallTransaction message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof FunctionCallTransaction - * @static - * @param {Object.} object Plain object - * @returns {FunctionCallTransaction} FunctionCallTransaction - */ - FunctionCallTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.FunctionCallTransaction) - return object; - var message = new $root.FunctionCallTransaction(); - if (object.nonce != null) - if ($util.Long) - (message.nonce = $util.Long.fromValue(object.nonce)).unsigned = true; - else if (typeof object.nonce === "string") - message.nonce = parseInt(object.nonce, 10); - else if (typeof object.nonce === "number") - message.nonce = object.nonce; - else if (typeof object.nonce === "object") - message.nonce = new $util.LongBits(object.nonce.low >>> 0, object.nonce.high >>> 0).toNumber(true); - if (object.originator != null) - message.originator = String(object.originator); - if (object.contractId != null) - message.contractId = String(object.contractId); - if (object.methodName != null) - if (typeof object.methodName === "string") - $util.base64.decode(object.methodName, message.methodName = $util.newBuffer($util.base64.length(object.methodName)), 0); - else if (object.methodName.length) - message.methodName = object.methodName; - if (object.args != null) - if (typeof object.args === "string") - $util.base64.decode(object.args, message.args = $util.newBuffer($util.base64.length(object.args)), 0); - else if (object.args.length) - message.args = object.args; - if (object.amount != null) { - if (typeof object.amount !== "object") - throw TypeError(".FunctionCallTransaction.amount: object expected"); - message.amount = $root.Uint128.fromObject(object.amount); - } - return message; - }; + /** + * FunctionCall gas. + * @member {number|Long} gas + * @memberof Action.FunctionCall + * @instance + */ + FunctionCall.prototype.gas = $util.Long ? $util.Long.fromBits(0,0,true) : 0; - /** - * Creates a plain object from a FunctionCallTransaction message. Also converts values to other types if specified. - * @function toObject - * @memberof FunctionCallTransaction - * @static - * @param {FunctionCallTransaction} message FunctionCallTransaction - * @param {$protobuf.IConversionOptions} [options] Conversion options - * @returns {Object.} Plain object - */ - FunctionCallTransaction.toObject = function toObject(message, options) { - if (!options) - options = {}; - var object = {}; - if (options.defaults) { - if ($util.Long) { - var long = new $util.Long(0, 0, true); - object.nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.nonce = options.longs === String ? "0" : 0; - object.originator = ""; - object.contractId = ""; - if (options.bytes === String) - object.methodName = ""; - else { - object.methodName = []; - if (options.bytes !== Array) - object.methodName = $util.newBuffer(object.methodName); - } - if (options.bytes === String) - object.args = ""; - else { - object.args = []; - if (options.bytes !== Array) - object.args = $util.newBuffer(object.args); + /** + * FunctionCall deposit. + * @member {IUint128|null|undefined} deposit + * @memberof Action.FunctionCall + * @instance + */ + FunctionCall.prototype.deposit = null; + + /** + * Creates a new FunctionCall instance using the specified properties. + * @function create + * @memberof Action.FunctionCall + * @static + * @param {Action.IFunctionCall=} [properties] Properties to set + * @returns {Action.FunctionCall} FunctionCall instance + */ + FunctionCall.create = function create(properties) { + return new FunctionCall(properties); + }; + + /** + * Encodes the specified FunctionCall message. Does not implicitly {@link Action.FunctionCall.verify|verify} messages. + * @function encode + * @memberof Action.FunctionCall + * @static + * @param {Action.IFunctionCall} message FunctionCall message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FunctionCall.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.methodName != null && message.hasOwnProperty("methodName")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.methodName); + if (message.args != null && message.hasOwnProperty("args")) + writer.uint32(/* id 2, wireType 2 =*/18).bytes(message.args); + if (message.gas != null && message.hasOwnProperty("gas")) + writer.uint32(/* id 3, wireType 0 =*/24).uint64(message.gas); + if (message.deposit != null && message.hasOwnProperty("deposit")) + $root.Uint128.encode(message.deposit, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified FunctionCall message, length delimited. Does not implicitly {@link Action.FunctionCall.verify|verify} messages. + * @function encodeDelimited + * @memberof Action.FunctionCall + * @static + * @param {Action.IFunctionCall} message FunctionCall message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FunctionCall.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a FunctionCall message from the specified reader or buffer. + * @function decode + * @memberof Action.FunctionCall + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {Action.FunctionCall} FunctionCall + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FunctionCall.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action.FunctionCall(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.methodName = reader.string(); + break; + case 2: + message.args = reader.bytes(); + break; + case 3: + message.gas = reader.uint64(); + break; + case 4: + message.deposit = $root.Uint128.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } } - object.amount = null; - } - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (typeof message.nonce === "number") - object.nonce = options.longs === String ? String(message.nonce) : message.nonce; - else - object.nonce = options.longs === String ? $util.Long.prototype.toString.call(message.nonce) : options.longs === Number ? new $util.LongBits(message.nonce.low >>> 0, message.nonce.high >>> 0).toNumber(true) : message.nonce; - if (message.originator != null && message.hasOwnProperty("originator")) - object.originator = message.originator; - if (message.contractId != null && message.hasOwnProperty("contractId")) - object.contractId = message.contractId; - if (message.methodName != null && message.hasOwnProperty("methodName")) - object.methodName = options.bytes === String ? $util.base64.encode(message.methodName, 0, message.methodName.length) : options.bytes === Array ? Array.prototype.slice.call(message.methodName) : message.methodName; - if (message.args != null && message.hasOwnProperty("args")) - object.args = options.bytes === String ? $util.base64.encode(message.args, 0, message.args.length) : options.bytes === Array ? Array.prototype.slice.call(message.args) : message.args; - if (message.amount != null && message.hasOwnProperty("amount")) - object.amount = $root.Uint128.toObject(message.amount, options); - return object; - }; + return message; + }; - /** - * Converts this FunctionCallTransaction to JSON. - * @function toJSON - * @memberof FunctionCallTransaction - * @instance - * @returns {Object.} JSON object - */ - FunctionCallTransaction.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; + /** + * Decodes a FunctionCall message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof Action.FunctionCall + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {Action.FunctionCall} FunctionCall + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FunctionCall.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; - return FunctionCallTransaction; -})(); + /** + * Verifies a FunctionCall message. + * @function verify + * @memberof Action.FunctionCall + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + FunctionCall.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.methodName != null && message.hasOwnProperty("methodName")) + if (!$util.isString(message.methodName)) + return "methodName: string expected"; + if (message.args != null && message.hasOwnProperty("args")) + if (!(message.args && typeof message.args.length === "number" || $util.isString(message.args))) + return "args: buffer expected"; + if (message.gas != null && message.hasOwnProperty("gas")) + if (!$util.isInteger(message.gas) && !(message.gas && $util.isInteger(message.gas.low) && $util.isInteger(message.gas.high))) + return "gas: integer|Long expected"; + if (message.deposit != null && message.hasOwnProperty("deposit")) { + var error = $root.Uint128.verify(message.deposit); + if (error) + return "deposit." + error; + } + return null; + }; -$root.SendMoneyTransaction = (function() { + /** + * Creates a FunctionCall message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Action.FunctionCall + * @static + * @param {Object.} object Plain object + * @returns {Action.FunctionCall} FunctionCall + */ + FunctionCall.fromObject = function fromObject(object) { + if (object instanceof $root.Action.FunctionCall) + return object; + var message = new $root.Action.FunctionCall(); + if (object.methodName != null) + message.methodName = String(object.methodName); + if (object.args != null) + if (typeof object.args === "string") + $util.base64.decode(object.args, message.args = $util.newBuffer($util.base64.length(object.args)), 0); + else if (object.args.length) + message.args = object.args; + if (object.gas != null) + if ($util.Long) + (message.gas = $util.Long.fromValue(object.gas)).unsigned = true; + else if (typeof object.gas === "string") + message.gas = parseInt(object.gas, 10); + else if (typeof object.gas === "number") + message.gas = object.gas; + else if (typeof object.gas === "object") + message.gas = new $util.LongBits(object.gas.low >>> 0, object.gas.high >>> 0).toNumber(true); + if (object.deposit != null) { + if (typeof object.deposit !== "object") + throw TypeError(".Action.FunctionCall.deposit: object expected"); + message.deposit = $root.Uint128.fromObject(object.deposit); + } + return message; + }; - /** - * Properties of a SendMoneyTransaction. - * @exports ISendMoneyTransaction - * @interface ISendMoneyTransaction - * @property {number|Long|null} [nonce] SendMoneyTransaction nonce - * @property {string|null} [originator] SendMoneyTransaction originator - * @property {string|null} [receiver] SendMoneyTransaction receiver - * @property {IUint128|null} [amount] SendMoneyTransaction amount - */ + /** + * Creates a plain object from a FunctionCall message. Also converts values to other types if specified. + * @function toObject + * @memberof Action.FunctionCall + * @static + * @param {Action.FunctionCall} message FunctionCall + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + FunctionCall.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.methodName = ""; + if (options.bytes === String) + object.args = ""; + else { + object.args = []; + if (options.bytes !== Array) + object.args = $util.newBuffer(object.args); + } + if ($util.Long) { + var long = new $util.Long(0, 0, true); + object.gas = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.gas = options.longs === String ? "0" : 0; + object.deposit = null; + } + if (message.methodName != null && message.hasOwnProperty("methodName")) + object.methodName = message.methodName; + if (message.args != null && message.hasOwnProperty("args")) + object.args = options.bytes === String ? $util.base64.encode(message.args, 0, message.args.length) : options.bytes === Array ? Array.prototype.slice.call(message.args) : message.args; + if (message.gas != null && message.hasOwnProperty("gas")) + if (typeof message.gas === "number") + object.gas = options.longs === String ? String(message.gas) : message.gas; + else + object.gas = options.longs === String ? $util.Long.prototype.toString.call(message.gas) : options.longs === Number ? new $util.LongBits(message.gas.low >>> 0, message.gas.high >>> 0).toNumber(true) : message.gas; + if (message.deposit != null && message.hasOwnProperty("deposit")) + object.deposit = $root.Uint128.toObject(message.deposit, options); + return object; + }; - /** - * Constructs a new SendMoneyTransaction. - * @exports SendMoneyTransaction - * @classdesc Represents a SendMoneyTransaction. - * @implements ISendMoneyTransaction - * @constructor - * @param {ISendMoneyTransaction=} [properties] Properties to set - */ - function SendMoneyTransaction(properties) { - if (properties) - for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) - if (properties[keys[i]] != null) - this[keys[i]] = properties[keys[i]]; - } + /** + * Converts this FunctionCall to JSON. + * @function toJSON + * @memberof Action.FunctionCall + * @instance + * @returns {Object.} JSON object + */ + FunctionCall.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; - /** - * SendMoneyTransaction nonce. - * @member {number|Long} nonce - * @memberof SendMoneyTransaction - * @instance - */ - SendMoneyTransaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + return FunctionCall; + })(); - /** - * SendMoneyTransaction originator. - * @member {string} originator - * @memberof SendMoneyTransaction - * @instance - */ - SendMoneyTransaction.prototype.originator = ""; + Action.Transfer = (function() { - /** - * SendMoneyTransaction receiver. - * @member {string} receiver - * @memberof SendMoneyTransaction - * @instance - */ - SendMoneyTransaction.prototype.receiver = ""; + /** + * Properties of a Transfer. + * @memberof Action + * @interface ITransfer + * @property {IUint128|null} [deposit] Transfer deposit + */ - /** - * SendMoneyTransaction amount. - * @member {IUint128|null|undefined} amount - * @memberof SendMoneyTransaction - * @instance - */ - SendMoneyTransaction.prototype.amount = null; + /** + * Constructs a new Transfer. + * @memberof Action + * @classdesc Represents a Transfer. + * @implements ITransfer + * @constructor + * @param {Action.ITransfer=} [properties] Properties to set + */ + function Transfer(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } - /** - * Creates a new SendMoneyTransaction instance using the specified properties. - * @function create - * @memberof SendMoneyTransaction - * @static - * @param {ISendMoneyTransaction=} [properties] Properties to set - * @returns {SendMoneyTransaction} SendMoneyTransaction instance - */ - SendMoneyTransaction.create = function create(properties) { - return new SendMoneyTransaction(properties); - }; + /** + * Transfer deposit. + * @member {IUint128|null|undefined} deposit + * @memberof Action.Transfer + * @instance + */ + Transfer.prototype.deposit = null; - /** - * Encodes the specified SendMoneyTransaction message. Does not implicitly {@link SendMoneyTransaction.verify|verify} messages. - * @function encode - * @memberof SendMoneyTransaction - * @static - * @param {ISendMoneyTransaction} message SendMoneyTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - SendMoneyTransaction.encode = function encode(message, writer) { - if (!writer) - writer = $Writer.create(); - if (message.nonce != null && message.hasOwnProperty("nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.nonce); - if (message.originator != null && message.hasOwnProperty("originator")) - writer.uint32(/* id 2, wireType 2 =*/18).string(message.originator); - if (message.receiver != null && message.hasOwnProperty("receiver")) - writer.uint32(/* id 3, wireType 2 =*/26).string(message.receiver); - if (message.amount != null && message.hasOwnProperty("amount")) - $root.Uint128.encode(message.amount, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); - return writer; - }; + /** + * Creates a new Transfer instance using the specified properties. + * @function create + * @memberof Action.Transfer + * @static + * @param {Action.ITransfer=} [properties] Properties to set + * @returns {Action.Transfer} Transfer instance + */ + Transfer.create = function create(properties) { + return new Transfer(properties); + }; - /** - * Encodes the specified SendMoneyTransaction message, length delimited. Does not implicitly {@link SendMoneyTransaction.verify|verify} messages. - * @function encodeDelimited - * @memberof SendMoneyTransaction - * @static - * @param {ISendMoneyTransaction} message SendMoneyTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - SendMoneyTransaction.encodeDelimited = function encodeDelimited(message, writer) { - return this.encode(message, writer).ldelim(); - }; + /** + * Encodes the specified Transfer message. Does not implicitly {@link Action.Transfer.verify|verify} messages. + * @function encode + * @memberof Action.Transfer + * @static + * @param {Action.ITransfer} message Transfer message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Transfer.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.deposit != null && message.hasOwnProperty("deposit")) + $root.Uint128.encode(message.deposit, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + return writer; + }; - /** - * Decodes a SendMoneyTransaction message from the specified reader or buffer. - * @function decode - * @memberof SendMoneyTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @param {number} [length] Message length if known beforehand - * @returns {SendMoneyTransaction} SendMoneyTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - SendMoneyTransaction.decode = function decode(reader, length) { - if (!(reader instanceof $Reader)) - reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.SendMoneyTransaction(); - while (reader.pos < end) { - var tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.nonce = reader.uint64(); - break; - case 2: - message.originator = reader.string(); - break; - case 3: - message.receiver = reader.string(); - break; - case 4: - message.amount = $root.Uint128.decode(reader, reader.uint32()); - break; - default: - reader.skipType(tag & 7); - break; + /** + * Encodes the specified Transfer message, length delimited. Does not implicitly {@link Action.Transfer.verify|verify} messages. + * @function encodeDelimited + * @memberof Action.Transfer + * @static + * @param {Action.ITransfer} message Transfer message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Transfer.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Transfer message from the specified reader or buffer. + * @function decode + * @memberof Action.Transfer + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {Action.Transfer} Transfer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Transfer.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action.Transfer(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.deposit = $root.Uint128.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } } - } - return message; - }; + return message; + }; - /** - * Decodes a SendMoneyTransaction message from the specified reader or buffer, length delimited. - * @function decodeDelimited - * @memberof SendMoneyTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {SendMoneyTransaction} SendMoneyTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - SendMoneyTransaction.decodeDelimited = function decodeDelimited(reader) { - if (!(reader instanceof $Reader)) - reader = new $Reader(reader); - return this.decode(reader, reader.uint32()); - }; + /** + * Decodes a Transfer message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof Action.Transfer + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {Action.Transfer} Transfer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Transfer.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; - /** - * Verifies a SendMoneyTransaction message. - * @function verify - * @memberof SendMoneyTransaction - * @static - * @param {Object.} message Plain object to verify - * @returns {string|null} `null` if valid, otherwise the reason why it is not - */ - SendMoneyTransaction.verify = function verify(message) { - if (typeof message !== "object" || message === null) - return "object expected"; - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (!$util.isInteger(message.nonce) && !(message.nonce && $util.isInteger(message.nonce.low) && $util.isInteger(message.nonce.high))) - return "nonce: integer|Long expected"; - if (message.originator != null && message.hasOwnProperty("originator")) - if (!$util.isString(message.originator)) - return "originator: string expected"; - if (message.receiver != null && message.hasOwnProperty("receiver")) - if (!$util.isString(message.receiver)) - return "receiver: string expected"; - if (message.amount != null && message.hasOwnProperty("amount")) { - var error = $root.Uint128.verify(message.amount); - if (error) - return "amount." + error; - } - return null; - }; + /** + * Verifies a Transfer message. + * @function verify + * @memberof Action.Transfer + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Transfer.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.deposit != null && message.hasOwnProperty("deposit")) { + var error = $root.Uint128.verify(message.deposit); + if (error) + return "deposit." + error; + } + return null; + }; - /** - * Creates a SendMoneyTransaction message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof SendMoneyTransaction - * @static - * @param {Object.} object Plain object - * @returns {SendMoneyTransaction} SendMoneyTransaction - */ - SendMoneyTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.SendMoneyTransaction) + /** + * Creates a Transfer message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Action.Transfer + * @static + * @param {Object.} object Plain object + * @returns {Action.Transfer} Transfer + */ + Transfer.fromObject = function fromObject(object) { + if (object instanceof $root.Action.Transfer) + return object; + var message = new $root.Action.Transfer(); + if (object.deposit != null) { + if (typeof object.deposit !== "object") + throw TypeError(".Action.Transfer.deposit: object expected"); + message.deposit = $root.Uint128.fromObject(object.deposit); + } + return message; + }; + + /** + * Creates a plain object from a Transfer message. Also converts values to other types if specified. + * @function toObject + * @memberof Action.Transfer + * @static + * @param {Action.Transfer} message Transfer + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Transfer.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.deposit = null; + if (message.deposit != null && message.hasOwnProperty("deposit")) + object.deposit = $root.Uint128.toObject(message.deposit, options); return object; - var message = new $root.SendMoneyTransaction(); - if (object.nonce != null) - if ($util.Long) - (message.nonce = $util.Long.fromValue(object.nonce)).unsigned = true; - else if (typeof object.nonce === "string") - message.nonce = parseInt(object.nonce, 10); - else if (typeof object.nonce === "number") - message.nonce = object.nonce; - else if (typeof object.nonce === "object") - message.nonce = new $util.LongBits(object.nonce.low >>> 0, object.nonce.high >>> 0).toNumber(true); - if (object.originator != null) - message.originator = String(object.originator); - if (object.receiver != null) - message.receiver = String(object.receiver); - if (object.amount != null) { - if (typeof object.amount !== "object") - throw TypeError(".SendMoneyTransaction.amount: object expected"); - message.amount = $root.Uint128.fromObject(object.amount); - } - return message; - }; + }; - /** - * Creates a plain object from a SendMoneyTransaction message. Also converts values to other types if specified. - * @function toObject - * @memberof SendMoneyTransaction - * @static - * @param {SendMoneyTransaction} message SendMoneyTransaction - * @param {$protobuf.IConversionOptions} [options] Conversion options - * @returns {Object.} Plain object - */ - SendMoneyTransaction.toObject = function toObject(message, options) { - if (!options) - options = {}; - var object = {}; - if (options.defaults) { - if ($util.Long) { - var long = new $util.Long(0, 0, true); - object.nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.nonce = options.longs === String ? "0" : 0; - object.originator = ""; - object.receiver = ""; - object.amount = null; + /** + * Converts this Transfer to JSON. + * @function toJSON + * @memberof Action.Transfer + * @instance + * @returns {Object.} JSON object + */ + Transfer.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Transfer; + })(); + + Action.Stake = (function() { + + /** + * Properties of a Stake. + * @memberof Action + * @interface IStake + * @property {IUint128|null} [stake] Stake stake + * @property {IPublicKey|null} [publicKey] Stake publicKey + */ + + /** + * Constructs a new Stake. + * @memberof Action + * @classdesc Represents a Stake. + * @implements IStake + * @constructor + * @param {Action.IStake=} [properties] Properties to set + */ + function Stake(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; } - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (typeof message.nonce === "number") - object.nonce = options.longs === String ? String(message.nonce) : message.nonce; - else - object.nonce = options.longs === String ? $util.Long.prototype.toString.call(message.nonce) : options.longs === Number ? new $util.LongBits(message.nonce.low >>> 0, message.nonce.high >>> 0).toNumber(true) : message.nonce; - if (message.originator != null && message.hasOwnProperty("originator")) - object.originator = message.originator; - if (message.receiver != null && message.hasOwnProperty("receiver")) - object.receiver = message.receiver; - if (message.amount != null && message.hasOwnProperty("amount")) - object.amount = $root.Uint128.toObject(message.amount, options); - return object; - }; - /** - * Converts this SendMoneyTransaction to JSON. - * @function toJSON - * @memberof SendMoneyTransaction - * @instance - * @returns {Object.} JSON object - */ - SendMoneyTransaction.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; + /** + * Stake stake. + * @member {IUint128|null|undefined} stake + * @memberof Action.Stake + * @instance + */ + Stake.prototype.stake = null; + + /** + * Stake publicKey. + * @member {IPublicKey|null|undefined} publicKey + * @memberof Action.Stake + * @instance + */ + Stake.prototype.publicKey = null; + + /** + * Creates a new Stake instance using the specified properties. + * @function create + * @memberof Action.Stake + * @static + * @param {Action.IStake=} [properties] Properties to set + * @returns {Action.Stake} Stake instance + */ + Stake.create = function create(properties) { + return new Stake(properties); + }; - return SendMoneyTransaction; -})(); + /** + * Encodes the specified Stake message. Does not implicitly {@link Action.Stake.verify|verify} messages. + * @function encode + * @memberof Action.Stake + * @static + * @param {Action.IStake} message Stake message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Stake.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.stake != null && message.hasOwnProperty("stake")) + $root.Uint128.encode(message.stake, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.publicKey != null && message.hasOwnProperty("publicKey")) + $root.PublicKey.encode(message.publicKey, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + return writer; + }; -$root.StakeTransaction = (function() { + /** + * Encodes the specified Stake message, length delimited. Does not implicitly {@link Action.Stake.verify|verify} messages. + * @function encodeDelimited + * @memberof Action.Stake + * @static + * @param {Action.IStake} message Stake message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Stake.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; - /** - * Properties of a StakeTransaction. - * @exports IStakeTransaction - * @interface IStakeTransaction - * @property {number|Long|null} [nonce] StakeTransaction nonce - * @property {string|null} [originator] StakeTransaction originator - * @property {IUint128|null} [amount] StakeTransaction amount - * @property {string|null} [publicKey] StakeTransaction publicKey - * @property {string|null} [blsPublicKey] StakeTransaction blsPublicKey - */ + /** + * Decodes a Stake message from the specified reader or buffer. + * @function decode + * @memberof Action.Stake + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {Action.Stake} Stake + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Stake.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action.Stake(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.stake = $root.Uint128.decode(reader, reader.uint32()); + break; + case 2: + message.publicKey = $root.PublicKey.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; - /** - * Constructs a new StakeTransaction. - * @exports StakeTransaction - * @classdesc Represents a StakeTransaction. - * @implements IStakeTransaction - * @constructor - * @param {IStakeTransaction=} [properties] Properties to set - */ - function StakeTransaction(properties) { - if (properties) - for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) - if (properties[keys[i]] != null) - this[keys[i]] = properties[keys[i]]; - } + /** + * Decodes a Stake message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof Action.Stake + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {Action.Stake} Stake + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Stake.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; - /** - * StakeTransaction nonce. - * @member {number|Long} nonce - * @memberof StakeTransaction - * @instance - */ - StakeTransaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** + * Verifies a Stake message. + * @function verify + * @memberof Action.Stake + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Stake.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.stake != null && message.hasOwnProperty("stake")) { + var error = $root.Uint128.verify(message.stake); + if (error) + return "stake." + error; + } + if (message.publicKey != null && message.hasOwnProperty("publicKey")) { + var error = $root.PublicKey.verify(message.publicKey); + if (error) + return "publicKey." + error; + } + return null; + }; - /** - * StakeTransaction originator. - * @member {string} originator - * @memberof StakeTransaction - * @instance - */ - StakeTransaction.prototype.originator = ""; + /** + * Creates a Stake message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Action.Stake + * @static + * @param {Object.} object Plain object + * @returns {Action.Stake} Stake + */ + Stake.fromObject = function fromObject(object) { + if (object instanceof $root.Action.Stake) + return object; + var message = new $root.Action.Stake(); + if (object.stake != null) { + if (typeof object.stake !== "object") + throw TypeError(".Action.Stake.stake: object expected"); + message.stake = $root.Uint128.fromObject(object.stake); + } + if (object.publicKey != null) { + if (typeof object.publicKey !== "object") + throw TypeError(".Action.Stake.publicKey: object expected"); + message.publicKey = $root.PublicKey.fromObject(object.publicKey); + } + return message; + }; - /** - * StakeTransaction amount. - * @member {IUint128|null|undefined} amount - * @memberof StakeTransaction - * @instance - */ - StakeTransaction.prototype.amount = null; + /** + * Creates a plain object from a Stake message. Also converts values to other types if specified. + * @function toObject + * @memberof Action.Stake + * @static + * @param {Action.Stake} message Stake + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Stake.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.stake = null; + object.publicKey = null; + } + if (message.stake != null && message.hasOwnProperty("stake")) + object.stake = $root.Uint128.toObject(message.stake, options); + if (message.publicKey != null && message.hasOwnProperty("publicKey")) + object.publicKey = $root.PublicKey.toObject(message.publicKey, options); + return object; + }; - /** - * StakeTransaction publicKey. - * @member {string} publicKey - * @memberof StakeTransaction - * @instance - */ - StakeTransaction.prototype.publicKey = ""; + /** + * Converts this Stake to JSON. + * @function toJSON + * @memberof Action.Stake + * @instance + * @returns {Object.} JSON object + */ + Stake.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; - /** - * StakeTransaction blsPublicKey. - * @member {string} blsPublicKey - * @memberof StakeTransaction - * @instance - */ - StakeTransaction.prototype.blsPublicKey = ""; + return Stake; + })(); - /** - * Creates a new StakeTransaction instance using the specified properties. - * @function create - * @memberof StakeTransaction - * @static - * @param {IStakeTransaction=} [properties] Properties to set - * @returns {StakeTransaction} StakeTransaction instance - */ - StakeTransaction.create = function create(properties) { - return new StakeTransaction(properties); - }; + Action.AddKey = (function() { - /** - * Encodes the specified StakeTransaction message. Does not implicitly {@link StakeTransaction.verify|verify} messages. - * @function encode - * @memberof StakeTransaction - * @static - * @param {IStakeTransaction} message StakeTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - StakeTransaction.encode = function encode(message, writer) { - if (!writer) - writer = $Writer.create(); - if (message.nonce != null && message.hasOwnProperty("nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.nonce); - if (message.originator != null && message.hasOwnProperty("originator")) - writer.uint32(/* id 2, wireType 2 =*/18).string(message.originator); - if (message.amount != null && message.hasOwnProperty("amount")) - $root.Uint128.encode(message.amount, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); - if (message.publicKey != null && message.hasOwnProperty("publicKey")) - writer.uint32(/* id 4, wireType 2 =*/34).string(message.publicKey); - if (message.blsPublicKey != null && message.hasOwnProperty("blsPublicKey")) - writer.uint32(/* id 5, wireType 2 =*/42).string(message.blsPublicKey); - return writer; - }; + /** + * Properties of an AddKey. + * @memberof Action + * @interface IAddKey + * @property {IPublicKey|null} [publicKey] AddKey publicKey + * @property {IAccessKey|null} [accessKey] AddKey accessKey + */ - /** - * Encodes the specified StakeTransaction message, length delimited. Does not implicitly {@link StakeTransaction.verify|verify} messages. - * @function encodeDelimited - * @memberof StakeTransaction - * @static - * @param {IStakeTransaction} message StakeTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - StakeTransaction.encodeDelimited = function encodeDelimited(message, writer) { - return this.encode(message, writer).ldelim(); - }; + /** + * Constructs a new AddKey. + * @memberof Action + * @classdesc Represents an AddKey. + * @implements IAddKey + * @constructor + * @param {Action.IAddKey=} [properties] Properties to set + */ + function AddKey(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } - /** - * Decodes a StakeTransaction message from the specified reader or buffer. - * @function decode - * @memberof StakeTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @param {number} [length] Message length if known beforehand - * @returns {StakeTransaction} StakeTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - StakeTransaction.decode = function decode(reader, length) { - if (!(reader instanceof $Reader)) - reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.StakeTransaction(); - while (reader.pos < end) { - var tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.nonce = reader.uint64(); - break; - case 2: - message.originator = reader.string(); - break; - case 3: - message.amount = $root.Uint128.decode(reader, reader.uint32()); - break; - case 4: - message.publicKey = reader.string(); - break; - case 5: - message.blsPublicKey = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; + /** + * AddKey publicKey. + * @member {IPublicKey|null|undefined} publicKey + * @memberof Action.AddKey + * @instance + */ + AddKey.prototype.publicKey = null; + + /** + * AddKey accessKey. + * @member {IAccessKey|null|undefined} accessKey + * @memberof Action.AddKey + * @instance + */ + AddKey.prototype.accessKey = null; + + /** + * Creates a new AddKey instance using the specified properties. + * @function create + * @memberof Action.AddKey + * @static + * @param {Action.IAddKey=} [properties] Properties to set + * @returns {Action.AddKey} AddKey instance + */ + AddKey.create = function create(properties) { + return new AddKey(properties); + }; + + /** + * Encodes the specified AddKey message. Does not implicitly {@link Action.AddKey.verify|verify} messages. + * @function encode + * @memberof Action.AddKey + * @static + * @param {Action.IAddKey} message AddKey message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + AddKey.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.publicKey != null && message.hasOwnProperty("publicKey")) + $root.PublicKey.encode(message.publicKey, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.accessKey != null && message.hasOwnProperty("accessKey")) + $root.AccessKey.encode(message.accessKey, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified AddKey message, length delimited. Does not implicitly {@link Action.AddKey.verify|verify} messages. + * @function encodeDelimited + * @memberof Action.AddKey + * @static + * @param {Action.IAddKey} message AddKey message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + AddKey.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an AddKey message from the specified reader or buffer. + * @function decode + * @memberof Action.AddKey + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {Action.AddKey} AddKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + AddKey.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action.AddKey(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.publicKey = $root.PublicKey.decode(reader, reader.uint32()); + break; + case 2: + message.accessKey = $root.AccessKey.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } } - } - return message; - }; + return message; + }; - /** - * Decodes a StakeTransaction message from the specified reader or buffer, length delimited. - * @function decodeDelimited - * @memberof StakeTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {StakeTransaction} StakeTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - StakeTransaction.decodeDelimited = function decodeDelimited(reader) { - if (!(reader instanceof $Reader)) - reader = new $Reader(reader); - return this.decode(reader, reader.uint32()); - }; + /** + * Decodes an AddKey message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof Action.AddKey + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {Action.AddKey} AddKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + AddKey.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; - /** - * Verifies a StakeTransaction message. - * @function verify - * @memberof StakeTransaction - * @static - * @param {Object.} message Plain object to verify - * @returns {string|null} `null` if valid, otherwise the reason why it is not - */ - StakeTransaction.verify = function verify(message) { - if (typeof message !== "object" || message === null) - return "object expected"; - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (!$util.isInteger(message.nonce) && !(message.nonce && $util.isInteger(message.nonce.low) && $util.isInteger(message.nonce.high))) - return "nonce: integer|Long expected"; - if (message.originator != null && message.hasOwnProperty("originator")) - if (!$util.isString(message.originator)) - return "originator: string expected"; - if (message.amount != null && message.hasOwnProperty("amount")) { - var error = $root.Uint128.verify(message.amount); - if (error) - return "amount." + error; - } - if (message.publicKey != null && message.hasOwnProperty("publicKey")) - if (!$util.isString(message.publicKey)) - return "publicKey: string expected"; - if (message.blsPublicKey != null && message.hasOwnProperty("blsPublicKey")) - if (!$util.isString(message.blsPublicKey)) - return "blsPublicKey: string expected"; - return null; - }; + /** + * Verifies an AddKey message. + * @function verify + * @memberof Action.AddKey + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + AddKey.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.publicKey != null && message.hasOwnProperty("publicKey")) { + var error = $root.PublicKey.verify(message.publicKey); + if (error) + return "publicKey." + error; + } + if (message.accessKey != null && message.hasOwnProperty("accessKey")) { + var error = $root.AccessKey.verify(message.accessKey); + if (error) + return "accessKey." + error; + } + return null; + }; - /** - * Creates a StakeTransaction message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof StakeTransaction - * @static - * @param {Object.} object Plain object - * @returns {StakeTransaction} StakeTransaction - */ - StakeTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.StakeTransaction) + /** + * Creates an AddKey message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Action.AddKey + * @static + * @param {Object.} object Plain object + * @returns {Action.AddKey} AddKey + */ + AddKey.fromObject = function fromObject(object) { + if (object instanceof $root.Action.AddKey) + return object; + var message = new $root.Action.AddKey(); + if (object.publicKey != null) { + if (typeof object.publicKey !== "object") + throw TypeError(".Action.AddKey.publicKey: object expected"); + message.publicKey = $root.PublicKey.fromObject(object.publicKey); + } + if (object.accessKey != null) { + if (typeof object.accessKey !== "object") + throw TypeError(".Action.AddKey.accessKey: object expected"); + message.accessKey = $root.AccessKey.fromObject(object.accessKey); + } + return message; + }; + + /** + * Creates a plain object from an AddKey message. Also converts values to other types if specified. + * @function toObject + * @memberof Action.AddKey + * @static + * @param {Action.AddKey} message AddKey + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + AddKey.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.publicKey = null; + object.accessKey = null; + } + if (message.publicKey != null && message.hasOwnProperty("publicKey")) + object.publicKey = $root.PublicKey.toObject(message.publicKey, options); + if (message.accessKey != null && message.hasOwnProperty("accessKey")) + object.accessKey = $root.AccessKey.toObject(message.accessKey, options); return object; - var message = new $root.StakeTransaction(); - if (object.nonce != null) - if ($util.Long) - (message.nonce = $util.Long.fromValue(object.nonce)).unsigned = true; - else if (typeof object.nonce === "string") - message.nonce = parseInt(object.nonce, 10); - else if (typeof object.nonce === "number") - message.nonce = object.nonce; - else if (typeof object.nonce === "object") - message.nonce = new $util.LongBits(object.nonce.low >>> 0, object.nonce.high >>> 0).toNumber(true); - if (object.originator != null) - message.originator = String(object.originator); - if (object.amount != null) { - if (typeof object.amount !== "object") - throw TypeError(".StakeTransaction.amount: object expected"); - message.amount = $root.Uint128.fromObject(object.amount); - } - if (object.publicKey != null) - message.publicKey = String(object.publicKey); - if (object.blsPublicKey != null) - message.blsPublicKey = String(object.blsPublicKey); - return message; - }; + }; - /** - * Creates a plain object from a StakeTransaction message. Also converts values to other types if specified. - * @function toObject - * @memberof StakeTransaction - * @static - * @param {StakeTransaction} message StakeTransaction - * @param {$protobuf.IConversionOptions} [options] Conversion options - * @returns {Object.} Plain object - */ - StakeTransaction.toObject = function toObject(message, options) { - if (!options) - options = {}; - var object = {}; - if (options.defaults) { - if ($util.Long) { - var long = new $util.Long(0, 0, true); - object.nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.nonce = options.longs === String ? "0" : 0; - object.originator = ""; - object.amount = null; - object.publicKey = ""; - object.blsPublicKey = ""; + /** + * Converts this AddKey to JSON. + * @function toJSON + * @memberof Action.AddKey + * @instance + * @returns {Object.} JSON object + */ + AddKey.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return AddKey; + })(); + + Action.DeleteKey = (function() { + + /** + * Properties of a DeleteKey. + * @memberof Action + * @interface IDeleteKey + * @property {IPublicKey|null} [publicKey] DeleteKey publicKey + */ + + /** + * Constructs a new DeleteKey. + * @memberof Action + * @classdesc Represents a DeleteKey. + * @implements IDeleteKey + * @constructor + * @param {Action.IDeleteKey=} [properties] Properties to set + */ + function DeleteKey(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; } - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (typeof message.nonce === "number") - object.nonce = options.longs === String ? String(message.nonce) : message.nonce; - else - object.nonce = options.longs === String ? $util.Long.prototype.toString.call(message.nonce) : options.longs === Number ? new $util.LongBits(message.nonce.low >>> 0, message.nonce.high >>> 0).toNumber(true) : message.nonce; - if (message.originator != null && message.hasOwnProperty("originator")) - object.originator = message.originator; - if (message.amount != null && message.hasOwnProperty("amount")) - object.amount = $root.Uint128.toObject(message.amount, options); - if (message.publicKey != null && message.hasOwnProperty("publicKey")) - object.publicKey = message.publicKey; - if (message.blsPublicKey != null && message.hasOwnProperty("blsPublicKey")) - object.blsPublicKey = message.blsPublicKey; - return object; - }; - /** - * Converts this StakeTransaction to JSON. - * @function toJSON - * @memberof StakeTransaction - * @instance - * @returns {Object.} JSON object - */ - StakeTransaction.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; + /** + * DeleteKey publicKey. + * @member {IPublicKey|null|undefined} publicKey + * @memberof Action.DeleteKey + * @instance + */ + DeleteKey.prototype.publicKey = null; + + /** + * Creates a new DeleteKey instance using the specified properties. + * @function create + * @memberof Action.DeleteKey + * @static + * @param {Action.IDeleteKey=} [properties] Properties to set + * @returns {Action.DeleteKey} DeleteKey instance + */ + DeleteKey.create = function create(properties) { + return new DeleteKey(properties); + }; + + /** + * Encodes the specified DeleteKey message. Does not implicitly {@link Action.DeleteKey.verify|verify} messages. + * @function encode + * @memberof Action.DeleteKey + * @static + * @param {Action.IDeleteKey} message DeleteKey message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DeleteKey.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.publicKey != null && message.hasOwnProperty("publicKey")) + $root.PublicKey.encode(message.publicKey, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + return writer; + }; - return StakeTransaction; -})(); + /** + * Encodes the specified DeleteKey message, length delimited. Does not implicitly {@link Action.DeleteKey.verify|verify} messages. + * @function encodeDelimited + * @memberof Action.DeleteKey + * @static + * @param {Action.IDeleteKey} message DeleteKey message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DeleteKey.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; -$root.SwapKeyTransaction = (function() { + /** + * Decodes a DeleteKey message from the specified reader or buffer. + * @function decode + * @memberof Action.DeleteKey + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {Action.DeleteKey} DeleteKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DeleteKey.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action.DeleteKey(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.publicKey = $root.PublicKey.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; - /** - * Properties of a SwapKeyTransaction. - * @exports ISwapKeyTransaction - * @interface ISwapKeyTransaction - * @property {number|Long|null} [nonce] SwapKeyTransaction nonce - * @property {string|null} [originator] SwapKeyTransaction originator - * @property {Uint8Array|null} [curKey] SwapKeyTransaction curKey - * @property {Uint8Array|null} [newKey] SwapKeyTransaction newKey - */ + /** + * Decodes a DeleteKey message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof Action.DeleteKey + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {Action.DeleteKey} DeleteKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DeleteKey.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; - /** - * Constructs a new SwapKeyTransaction. - * @exports SwapKeyTransaction - * @classdesc Represents a SwapKeyTransaction. - * @implements ISwapKeyTransaction - * @constructor - * @param {ISwapKeyTransaction=} [properties] Properties to set - */ - function SwapKeyTransaction(properties) { - if (properties) - for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) - if (properties[keys[i]] != null) - this[keys[i]] = properties[keys[i]]; - } + /** + * Verifies a DeleteKey message. + * @function verify + * @memberof Action.DeleteKey + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + DeleteKey.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.publicKey != null && message.hasOwnProperty("publicKey")) { + var error = $root.PublicKey.verify(message.publicKey); + if (error) + return "publicKey." + error; + } + return null; + }; - /** - * SwapKeyTransaction nonce. - * @member {number|Long} nonce - * @memberof SwapKeyTransaction - * @instance - */ - SwapKeyTransaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + /** + * Creates a DeleteKey message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Action.DeleteKey + * @static + * @param {Object.} object Plain object + * @returns {Action.DeleteKey} DeleteKey + */ + DeleteKey.fromObject = function fromObject(object) { + if (object instanceof $root.Action.DeleteKey) + return object; + var message = new $root.Action.DeleteKey(); + if (object.publicKey != null) { + if (typeof object.publicKey !== "object") + throw TypeError(".Action.DeleteKey.publicKey: object expected"); + message.publicKey = $root.PublicKey.fromObject(object.publicKey); + } + return message; + }; - /** - * SwapKeyTransaction originator. - * @member {string} originator - * @memberof SwapKeyTransaction - * @instance - */ - SwapKeyTransaction.prototype.originator = ""; + /** + * Creates a plain object from a DeleteKey message. Also converts values to other types if specified. + * @function toObject + * @memberof Action.DeleteKey + * @static + * @param {Action.DeleteKey} message DeleteKey + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + DeleteKey.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.publicKey = null; + if (message.publicKey != null && message.hasOwnProperty("publicKey")) + object.publicKey = $root.PublicKey.toObject(message.publicKey, options); + return object; + }; - /** - * SwapKeyTransaction curKey. - * @member {Uint8Array} curKey - * @memberof SwapKeyTransaction - * @instance - */ - SwapKeyTransaction.prototype.curKey = $util.newBuffer([]); + /** + * Converts this DeleteKey to JSON. + * @function toJSON + * @memberof Action.DeleteKey + * @instance + * @returns {Object.} JSON object + */ + DeleteKey.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; - /** - * SwapKeyTransaction newKey. - * @member {Uint8Array} newKey - * @memberof SwapKeyTransaction - * @instance - */ - SwapKeyTransaction.prototype.newKey = $util.newBuffer([]); + return DeleteKey; + })(); - /** - * Creates a new SwapKeyTransaction instance using the specified properties. - * @function create - * @memberof SwapKeyTransaction - * @static - * @param {ISwapKeyTransaction=} [properties] Properties to set - * @returns {SwapKeyTransaction} SwapKeyTransaction instance - */ - SwapKeyTransaction.create = function create(properties) { - return new SwapKeyTransaction(properties); - }; + Action.DeleteAccount = (function() { - /** - * Encodes the specified SwapKeyTransaction message. Does not implicitly {@link SwapKeyTransaction.verify|verify} messages. - * @function encode - * @memberof SwapKeyTransaction - * @static - * @param {ISwapKeyTransaction} message SwapKeyTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - SwapKeyTransaction.encode = function encode(message, writer) { - if (!writer) - writer = $Writer.create(); - if (message.nonce != null && message.hasOwnProperty("nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.nonce); - if (message.originator != null && message.hasOwnProperty("originator")) - writer.uint32(/* id 2, wireType 2 =*/18).string(message.originator); - if (message.curKey != null && message.hasOwnProperty("curKey")) - writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.curKey); - if (message.newKey != null && message.hasOwnProperty("newKey")) - writer.uint32(/* id 4, wireType 2 =*/34).bytes(message.newKey); - return writer; - }; + /** + * Properties of a DeleteAccount. + * @memberof Action + * @interface IDeleteAccount + * @property {string|null} [beneficiaryId] DeleteAccount beneficiaryId + */ - /** - * Encodes the specified SwapKeyTransaction message, length delimited. Does not implicitly {@link SwapKeyTransaction.verify|verify} messages. - * @function encodeDelimited - * @memberof SwapKeyTransaction - * @static - * @param {ISwapKeyTransaction} message SwapKeyTransaction message or plain object to encode - * @param {$protobuf.Writer} [writer] Writer to encode to - * @returns {$protobuf.Writer} Writer - */ - SwapKeyTransaction.encodeDelimited = function encodeDelimited(message, writer) { - return this.encode(message, writer).ldelim(); - }; + /** + * Constructs a new DeleteAccount. + * @memberof Action + * @classdesc Represents a DeleteAccount. + * @implements IDeleteAccount + * @constructor + * @param {Action.IDeleteAccount=} [properties] Properties to set + */ + function DeleteAccount(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } - /** - * Decodes a SwapKeyTransaction message from the specified reader or buffer. - * @function decode - * @memberof SwapKeyTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @param {number} [length] Message length if known beforehand - * @returns {SwapKeyTransaction} SwapKeyTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - SwapKeyTransaction.decode = function decode(reader, length) { - if (!(reader instanceof $Reader)) - reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.SwapKeyTransaction(); - while (reader.pos < end) { - var tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.nonce = reader.uint64(); - break; - case 2: - message.originator = reader.string(); - break; - case 3: - message.curKey = reader.bytes(); - break; - case 4: - message.newKey = reader.bytes(); - break; - default: - reader.skipType(tag & 7); - break; + /** + * DeleteAccount beneficiaryId. + * @member {string} beneficiaryId + * @memberof Action.DeleteAccount + * @instance + */ + DeleteAccount.prototype.beneficiaryId = ""; + + /** + * Creates a new DeleteAccount instance using the specified properties. + * @function create + * @memberof Action.DeleteAccount + * @static + * @param {Action.IDeleteAccount=} [properties] Properties to set + * @returns {Action.DeleteAccount} DeleteAccount instance + */ + DeleteAccount.create = function create(properties) { + return new DeleteAccount(properties); + }; + + /** + * Encodes the specified DeleteAccount message. Does not implicitly {@link Action.DeleteAccount.verify|verify} messages. + * @function encode + * @memberof Action.DeleteAccount + * @static + * @param {Action.IDeleteAccount} message DeleteAccount message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DeleteAccount.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.beneficiaryId != null && message.hasOwnProperty("beneficiaryId")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.beneficiaryId); + return writer; + }; + + /** + * Encodes the specified DeleteAccount message, length delimited. Does not implicitly {@link Action.DeleteAccount.verify|verify} messages. + * @function encodeDelimited + * @memberof Action.DeleteAccount + * @static + * @param {Action.IDeleteAccount} message DeleteAccount message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DeleteAccount.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a DeleteAccount message from the specified reader or buffer. + * @function decode + * @memberof Action.DeleteAccount + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {Action.DeleteAccount} DeleteAccount + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DeleteAccount.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Action.DeleteAccount(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.beneficiaryId = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } } - } - return message; - }; + return message; + }; - /** - * Decodes a SwapKeyTransaction message from the specified reader or buffer, length delimited. - * @function decodeDelimited - * @memberof SwapKeyTransaction - * @static - * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {SwapKeyTransaction} SwapKeyTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - SwapKeyTransaction.decodeDelimited = function decodeDelimited(reader) { - if (!(reader instanceof $Reader)) - reader = new $Reader(reader); - return this.decode(reader, reader.uint32()); - }; + /** + * Decodes a DeleteAccount message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof Action.DeleteAccount + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {Action.DeleteAccount} DeleteAccount + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DeleteAccount.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; - /** - * Verifies a SwapKeyTransaction message. - * @function verify - * @memberof SwapKeyTransaction - * @static - * @param {Object.} message Plain object to verify - * @returns {string|null} `null` if valid, otherwise the reason why it is not - */ - SwapKeyTransaction.verify = function verify(message) { - if (typeof message !== "object" || message === null) - return "object expected"; - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (!$util.isInteger(message.nonce) && !(message.nonce && $util.isInteger(message.nonce.low) && $util.isInteger(message.nonce.high))) - return "nonce: integer|Long expected"; - if (message.originator != null && message.hasOwnProperty("originator")) - if (!$util.isString(message.originator)) - return "originator: string expected"; - if (message.curKey != null && message.hasOwnProperty("curKey")) - if (!(message.curKey && typeof message.curKey.length === "number" || $util.isString(message.curKey))) - return "curKey: buffer expected"; - if (message.newKey != null && message.hasOwnProperty("newKey")) - if (!(message.newKey && typeof message.newKey.length === "number" || $util.isString(message.newKey))) - return "newKey: buffer expected"; - return null; - }; + /** + * Verifies a DeleteAccount message. + * @function verify + * @memberof Action.DeleteAccount + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + DeleteAccount.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.beneficiaryId != null && message.hasOwnProperty("beneficiaryId")) + if (!$util.isString(message.beneficiaryId)) + return "beneficiaryId: string expected"; + return null; + }; - /** - * Creates a SwapKeyTransaction message from a plain object. Also converts values to their respective internal types. - * @function fromObject - * @memberof SwapKeyTransaction - * @static - * @param {Object.} object Plain object - * @returns {SwapKeyTransaction} SwapKeyTransaction - */ - SwapKeyTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.SwapKeyTransaction) + /** + * Creates a DeleteAccount message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof Action.DeleteAccount + * @static + * @param {Object.} object Plain object + * @returns {Action.DeleteAccount} DeleteAccount + */ + DeleteAccount.fromObject = function fromObject(object) { + if (object instanceof $root.Action.DeleteAccount) + return object; + var message = new $root.Action.DeleteAccount(); + if (object.beneficiaryId != null) + message.beneficiaryId = String(object.beneficiaryId); + return message; + }; + + /** + * Creates a plain object from a DeleteAccount message. Also converts values to other types if specified. + * @function toObject + * @memberof Action.DeleteAccount + * @static + * @param {Action.DeleteAccount} message DeleteAccount + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + DeleteAccount.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.beneficiaryId = ""; + if (message.beneficiaryId != null && message.hasOwnProperty("beneficiaryId")) + object.beneficiaryId = message.beneficiaryId; return object; - var message = new $root.SwapKeyTransaction(); - if (object.nonce != null) - if ($util.Long) - (message.nonce = $util.Long.fromValue(object.nonce)).unsigned = true; - else if (typeof object.nonce === "string") - message.nonce = parseInt(object.nonce, 10); - else if (typeof object.nonce === "number") - message.nonce = object.nonce; - else if (typeof object.nonce === "object") - message.nonce = new $util.LongBits(object.nonce.low >>> 0, object.nonce.high >>> 0).toNumber(true); - if (object.originator != null) - message.originator = String(object.originator); - if (object.curKey != null) - if (typeof object.curKey === "string") - $util.base64.decode(object.curKey, message.curKey = $util.newBuffer($util.base64.length(object.curKey)), 0); - else if (object.curKey.length) - message.curKey = object.curKey; - if (object.newKey != null) - if (typeof object.newKey === "string") - $util.base64.decode(object.newKey, message.newKey = $util.newBuffer($util.base64.length(object.newKey)), 0); - else if (object.newKey.length) - message.newKey = object.newKey; - return message; - }; + }; - /** - * Creates a plain object from a SwapKeyTransaction message. Also converts values to other types if specified. - * @function toObject - * @memberof SwapKeyTransaction - * @static - * @param {SwapKeyTransaction} message SwapKeyTransaction - * @param {$protobuf.IConversionOptions} [options] Conversion options - * @returns {Object.} Plain object - */ - SwapKeyTransaction.toObject = function toObject(message, options) { - if (!options) - options = {}; - var object = {}; - if (options.defaults) { - if ($util.Long) { - var long = new $util.Long(0, 0, true); - object.nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.nonce = options.longs === String ? "0" : 0; - object.originator = ""; - if (options.bytes === String) - object.curKey = ""; - else { - object.curKey = []; - if (options.bytes !== Array) - object.curKey = $util.newBuffer(object.curKey); - } - if (options.bytes === String) - object.newKey = ""; - else { - object.newKey = []; - if (options.bytes !== Array) - object.newKey = $util.newBuffer(object.newKey); - } - } - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (typeof message.nonce === "number") - object.nonce = options.longs === String ? String(message.nonce) : message.nonce; - else - object.nonce = options.longs === String ? $util.Long.prototype.toString.call(message.nonce) : options.longs === Number ? new $util.LongBits(message.nonce.low >>> 0, message.nonce.high >>> 0).toNumber(true) : message.nonce; - if (message.originator != null && message.hasOwnProperty("originator")) - object.originator = message.originator; - if (message.curKey != null && message.hasOwnProperty("curKey")) - object.curKey = options.bytes === String ? $util.base64.encode(message.curKey, 0, message.curKey.length) : options.bytes === Array ? Array.prototype.slice.call(message.curKey) : message.curKey; - if (message.newKey != null && message.hasOwnProperty("newKey")) - object.newKey = options.bytes === String ? $util.base64.encode(message.newKey, 0, message.newKey.length) : options.bytes === Array ? Array.prototype.slice.call(message.newKey) : message.newKey; - return object; - }; + /** + * Converts this DeleteAccount to JSON. + * @function toJSON + * @memberof Action.DeleteAccount + * @instance + * @returns {Object.} JSON object + */ + DeleteAccount.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; - /** - * Converts this SwapKeyTransaction to JSON. - * @function toJSON - * @memberof SwapKeyTransaction - * @instance - * @returns {Object.} JSON object - */ - SwapKeyTransaction.prototype.toJSON = function toJSON() { - return this.constructor.toObject(this, $protobuf.util.toJSONOptions); - }; + return DeleteAccount; + })(); - return SwapKeyTransaction; + return Action; })(); -$root.AddKeyTransaction = (function() { +$root.Transaction = (function() { /** - * Properties of an AddKeyTransaction. - * @exports IAddKeyTransaction - * @interface IAddKeyTransaction - * @property {number|Long|null} [nonce] AddKeyTransaction nonce - * @property {string|null} [originator] AddKeyTransaction originator - * @property {Uint8Array|null} [newKey] AddKeyTransaction newKey - * @property {IAccessKey|null} [accessKey] AddKeyTransaction accessKey + * Properties of a Transaction. + * @exports ITransaction + * @interface ITransaction + * @property {string|null} [signerId] Transaction signerId + * @property {IPublicKey|null} [publicKey] Transaction publicKey + * @property {number|Long|null} [nonce] Transaction nonce + * @property {string|null} [receiverId] Transaction receiverId + * @property {Array.|null} [actions] Transaction actions */ /** - * Constructs a new AddKeyTransaction. - * @exports AddKeyTransaction - * @classdesc Represents an AddKeyTransaction. - * @implements IAddKeyTransaction + * Constructs a new Transaction. + * @exports Transaction + * @classdesc Represents a Transaction. + * @implements ITransaction * @constructor - * @param {IAddKeyTransaction=} [properties] Properties to set + * @param {ITransaction=} [properties] Properties to set */ - function AddKeyTransaction(properties) { + function Transaction(properties) { + this.actions = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -1785,114 +2137,130 @@ $root.AddKeyTransaction = (function() { } /** - * AddKeyTransaction nonce. - * @member {number|Long} nonce - * @memberof AddKeyTransaction + * Transaction signerId. + * @member {string} signerId + * @memberof Transaction + * @instance + */ + Transaction.prototype.signerId = ""; + + /** + * Transaction publicKey. + * @member {IPublicKey|null|undefined} publicKey + * @memberof Transaction * @instance */ - AddKeyTransaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; + Transaction.prototype.publicKey = null; /** - * AddKeyTransaction originator. - * @member {string} originator - * @memberof AddKeyTransaction + * Transaction nonce. + * @member {number|Long} nonce + * @memberof Transaction * @instance */ - AddKeyTransaction.prototype.originator = ""; + Transaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; /** - * AddKeyTransaction newKey. - * @member {Uint8Array} newKey - * @memberof AddKeyTransaction + * Transaction receiverId. + * @member {string} receiverId + * @memberof Transaction * @instance */ - AddKeyTransaction.prototype.newKey = $util.newBuffer([]); + Transaction.prototype.receiverId = ""; /** - * AddKeyTransaction accessKey. - * @member {IAccessKey|null|undefined} accessKey - * @memberof AddKeyTransaction + * Transaction actions. + * @member {Array.} actions + * @memberof Transaction * @instance */ - AddKeyTransaction.prototype.accessKey = null; + Transaction.prototype.actions = $util.emptyArray; /** - * Creates a new AddKeyTransaction instance using the specified properties. + * Creates a new Transaction instance using the specified properties. * @function create - * @memberof AddKeyTransaction + * @memberof Transaction * @static - * @param {IAddKeyTransaction=} [properties] Properties to set - * @returns {AddKeyTransaction} AddKeyTransaction instance + * @param {ITransaction=} [properties] Properties to set + * @returns {Transaction} Transaction instance */ - AddKeyTransaction.create = function create(properties) { - return new AddKeyTransaction(properties); + Transaction.create = function create(properties) { + return new Transaction(properties); }; /** - * Encodes the specified AddKeyTransaction message. Does not implicitly {@link AddKeyTransaction.verify|verify} messages. + * Encodes the specified Transaction message. Does not implicitly {@link Transaction.verify|verify} messages. * @function encode - * @memberof AddKeyTransaction + * @memberof Transaction * @static - * @param {IAddKeyTransaction} message AddKeyTransaction message or plain object to encode + * @param {ITransaction} message Transaction message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - AddKeyTransaction.encode = function encode(message, writer) { + Transaction.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); + if (message.signerId != null && message.hasOwnProperty("signerId")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.signerId); + if (message.publicKey != null && message.hasOwnProperty("publicKey")) + $root.PublicKey.encode(message.publicKey, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); if (message.nonce != null && message.hasOwnProperty("nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.nonce); - if (message.originator != null && message.hasOwnProperty("originator")) - writer.uint32(/* id 2, wireType 2 =*/18).string(message.originator); - if (message.newKey != null && message.hasOwnProperty("newKey")) - writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.newKey); - if (message.accessKey != null && message.hasOwnProperty("accessKey")) - $root.AccessKey.encode(message.accessKey, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); + writer.uint32(/* id 3, wireType 0 =*/24).uint64(message.nonce); + if (message.receiverId != null && message.hasOwnProperty("receiverId")) + writer.uint32(/* id 4, wireType 2 =*/34).string(message.receiverId); + if (message.actions != null && message.actions.length) + for (var i = 0; i < message.actions.length; ++i) + $root.Action.encode(message.actions[i], writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); return writer; }; /** - * Encodes the specified AddKeyTransaction message, length delimited. Does not implicitly {@link AddKeyTransaction.verify|verify} messages. + * Encodes the specified Transaction message, length delimited. Does not implicitly {@link Transaction.verify|verify} messages. * @function encodeDelimited - * @memberof AddKeyTransaction + * @memberof Transaction * @static - * @param {IAddKeyTransaction} message AddKeyTransaction message or plain object to encode + * @param {ITransaction} message Transaction message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - AddKeyTransaction.encodeDelimited = function encodeDelimited(message, writer) { + Transaction.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** - * Decodes an AddKeyTransaction message from the specified reader or buffer. + * Decodes a Transaction message from the specified reader or buffer. * @function decode - * @memberof AddKeyTransaction + * @memberof Transaction * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand - * @returns {AddKeyTransaction} AddKeyTransaction + * @returns {Transaction} Transaction * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - AddKeyTransaction.decode = function decode(reader, length) { + Transaction.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.AddKeyTransaction(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Transaction(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.nonce = reader.uint64(); + message.signerId = reader.string(); break; case 2: - message.originator = reader.string(); + message.publicKey = $root.PublicKey.decode(reader, reader.uint32()); break; case 3: - message.newKey = reader.bytes(); + message.nonce = reader.uint64(); break; case 4: - message.accessKey = $root.AccessKey.decode(reader, reader.uint32()); + message.receiverId = reader.string(); + break; + case 5: + if (!(message.actions && message.actions.length)) + message.actions = []; + message.actions.push($root.Action.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); @@ -1903,61 +2271,77 @@ $root.AddKeyTransaction = (function() { }; /** - * Decodes an AddKeyTransaction message from the specified reader or buffer, length delimited. + * Decodes a Transaction message from the specified reader or buffer, length delimited. * @function decodeDelimited - * @memberof AddKeyTransaction + * @memberof Transaction * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {AddKeyTransaction} AddKeyTransaction + * @returns {Transaction} Transaction * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - AddKeyTransaction.decodeDelimited = function decodeDelimited(reader) { + Transaction.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** - * Verifies an AddKeyTransaction message. + * Verifies a Transaction message. * @function verify - * @memberof AddKeyTransaction + * @memberof Transaction * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ - AddKeyTransaction.verify = function verify(message) { + Transaction.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; + if (message.signerId != null && message.hasOwnProperty("signerId")) + if (!$util.isString(message.signerId)) + return "signerId: string expected"; + if (message.publicKey != null && message.hasOwnProperty("publicKey")) { + var error = $root.PublicKey.verify(message.publicKey); + if (error) + return "publicKey." + error; + } if (message.nonce != null && message.hasOwnProperty("nonce")) if (!$util.isInteger(message.nonce) && !(message.nonce && $util.isInteger(message.nonce.low) && $util.isInteger(message.nonce.high))) return "nonce: integer|Long expected"; - if (message.originator != null && message.hasOwnProperty("originator")) - if (!$util.isString(message.originator)) - return "originator: string expected"; - if (message.newKey != null && message.hasOwnProperty("newKey")) - if (!(message.newKey && typeof message.newKey.length === "number" || $util.isString(message.newKey))) - return "newKey: buffer expected"; - if (message.accessKey != null && message.hasOwnProperty("accessKey")) { - var error = $root.AccessKey.verify(message.accessKey); - if (error) - return "accessKey." + error; + if (message.receiverId != null && message.hasOwnProperty("receiverId")) + if (!$util.isString(message.receiverId)) + return "receiverId: string expected"; + if (message.actions != null && message.hasOwnProperty("actions")) { + if (!Array.isArray(message.actions)) + return "actions: array expected"; + for (var i = 0; i < message.actions.length; ++i) { + var error = $root.Action.verify(message.actions[i]); + if (error) + return "actions." + error; + } } return null; }; /** - * Creates an AddKeyTransaction message from a plain object. Also converts values to their respective internal types. + * Creates a Transaction message from a plain object. Also converts values to their respective internal types. * @function fromObject - * @memberof AddKeyTransaction + * @memberof Transaction * @static * @param {Object.} object Plain object - * @returns {AddKeyTransaction} AddKeyTransaction + * @returns {Transaction} Transaction */ - AddKeyTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.AddKeyTransaction) + Transaction.fromObject = function fromObject(object) { + if (object instanceof $root.Transaction) return object; - var message = new $root.AddKeyTransaction(); + var message = new $root.Transaction(); + if (object.signerId != null) + message.signerId = String(object.signerId); + if (object.publicKey != null) { + if (typeof object.publicKey !== "object") + throw TypeError(".Transaction.publicKey: object expected"); + message.publicKey = $root.PublicKey.fromObject(object.publicKey); + } if (object.nonce != null) if ($util.Long) (message.nonce = $util.Long.fromValue(object.nonce)).unsigned = true; @@ -1967,98 +2351,98 @@ $root.AddKeyTransaction = (function() { message.nonce = object.nonce; else if (typeof object.nonce === "object") message.nonce = new $util.LongBits(object.nonce.low >>> 0, object.nonce.high >>> 0).toNumber(true); - if (object.originator != null) - message.originator = String(object.originator); - if (object.newKey != null) - if (typeof object.newKey === "string") - $util.base64.decode(object.newKey, message.newKey = $util.newBuffer($util.base64.length(object.newKey)), 0); - else if (object.newKey.length) - message.newKey = object.newKey; - if (object.accessKey != null) { - if (typeof object.accessKey !== "object") - throw TypeError(".AddKeyTransaction.accessKey: object expected"); - message.accessKey = $root.AccessKey.fromObject(object.accessKey); + if (object.receiverId != null) + message.receiverId = String(object.receiverId); + if (object.actions) { + if (!Array.isArray(object.actions)) + throw TypeError(".Transaction.actions: array expected"); + message.actions = []; + for (var i = 0; i < object.actions.length; ++i) { + if (typeof object.actions[i] !== "object") + throw TypeError(".Transaction.actions: object expected"); + message.actions[i] = $root.Action.fromObject(object.actions[i]); + } } return message; }; /** - * Creates a plain object from an AddKeyTransaction message. Also converts values to other types if specified. + * Creates a plain object from a Transaction message. Also converts values to other types if specified. * @function toObject - * @memberof AddKeyTransaction + * @memberof Transaction * @static - * @param {AddKeyTransaction} message AddKeyTransaction + * @param {Transaction} message Transaction * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - AddKeyTransaction.toObject = function toObject(message, options) { + Transaction.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; + if (options.arrays || options.defaults) + object.actions = []; if (options.defaults) { + object.signerId = ""; + object.publicKey = null; if ($util.Long) { var long = new $util.Long(0, 0, true); object.nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; } else object.nonce = options.longs === String ? "0" : 0; - object.originator = ""; - if (options.bytes === String) - object.newKey = ""; - else { - object.newKey = []; - if (options.bytes !== Array) - object.newKey = $util.newBuffer(object.newKey); - } - object.accessKey = null; + object.receiverId = ""; } + if (message.signerId != null && message.hasOwnProperty("signerId")) + object.signerId = message.signerId; + if (message.publicKey != null && message.hasOwnProperty("publicKey")) + object.publicKey = $root.PublicKey.toObject(message.publicKey, options); if (message.nonce != null && message.hasOwnProperty("nonce")) if (typeof message.nonce === "number") object.nonce = options.longs === String ? String(message.nonce) : message.nonce; else object.nonce = options.longs === String ? $util.Long.prototype.toString.call(message.nonce) : options.longs === Number ? new $util.LongBits(message.nonce.low >>> 0, message.nonce.high >>> 0).toNumber(true) : message.nonce; - if (message.originator != null && message.hasOwnProperty("originator")) - object.originator = message.originator; - if (message.newKey != null && message.hasOwnProperty("newKey")) - object.newKey = options.bytes === String ? $util.base64.encode(message.newKey, 0, message.newKey.length) : options.bytes === Array ? Array.prototype.slice.call(message.newKey) : message.newKey; - if (message.accessKey != null && message.hasOwnProperty("accessKey")) - object.accessKey = $root.AccessKey.toObject(message.accessKey, options); + if (message.receiverId != null && message.hasOwnProperty("receiverId")) + object.receiverId = message.receiverId; + if (message.actions && message.actions.length) { + object.actions = []; + for (var j = 0; j < message.actions.length; ++j) + object.actions[j] = $root.Action.toObject(message.actions[j], options); + } return object; }; /** - * Converts this AddKeyTransaction to JSON. + * Converts this Transaction to JSON. * @function toJSON - * @memberof AddKeyTransaction + * @memberof Transaction * @instance * @returns {Object.} JSON object */ - AddKeyTransaction.prototype.toJSON = function toJSON() { + Transaction.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; - return AddKeyTransaction; + return Transaction; })(); -$root.DeleteKeyTransaction = (function() { +$root.SignedTransaction = (function() { /** - * Properties of a DeleteKeyTransaction. - * @exports IDeleteKeyTransaction - * @interface IDeleteKeyTransaction - * @property {number|Long|null} [nonce] DeleteKeyTransaction nonce - * @property {string|null} [originator] DeleteKeyTransaction originator - * @property {Uint8Array|null} [curKey] DeleteKeyTransaction curKey + * Properties of a SignedTransaction. + * @exports ISignedTransaction + * @interface ISignedTransaction + * @property {Uint8Array|null} [signature] SignedTransaction signature + * @property {ITransaction|null} [transaction] SignedTransaction transaction */ /** - * Constructs a new DeleteKeyTransaction. - * @exports DeleteKeyTransaction - * @classdesc Represents a DeleteKeyTransaction. - * @implements IDeleteKeyTransaction + * Constructs a new SignedTransaction. + * @exports SignedTransaction + * @classdesc Represents a SignedTransaction. + * @implements ISignedTransaction * @constructor - * @param {IDeleteKeyTransaction=} [properties] Properties to set + * @param {ISignedTransaction=} [properties] Properties to set */ - function DeleteKeyTransaction(properties) { + function SignedTransaction(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -2066,101 +2450,88 @@ $root.DeleteKeyTransaction = (function() { } /** - * DeleteKeyTransaction nonce. - * @member {number|Long} nonce - * @memberof DeleteKeyTransaction - * @instance - */ - DeleteKeyTransaction.prototype.nonce = $util.Long ? $util.Long.fromBits(0,0,true) : 0; - - /** - * DeleteKeyTransaction originator. - * @member {string} originator - * @memberof DeleteKeyTransaction + * SignedTransaction signature. + * @member {Uint8Array} signature + * @memberof SignedTransaction * @instance */ - DeleteKeyTransaction.prototype.originator = ""; + SignedTransaction.prototype.signature = $util.newBuffer([]); /** - * DeleteKeyTransaction curKey. - * @member {Uint8Array} curKey - * @memberof DeleteKeyTransaction + * SignedTransaction transaction. + * @member {ITransaction|null|undefined} transaction + * @memberof SignedTransaction * @instance */ - DeleteKeyTransaction.prototype.curKey = $util.newBuffer([]); + SignedTransaction.prototype.transaction = null; /** - * Creates a new DeleteKeyTransaction instance using the specified properties. + * Creates a new SignedTransaction instance using the specified properties. * @function create - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @static - * @param {IDeleteKeyTransaction=} [properties] Properties to set - * @returns {DeleteKeyTransaction} DeleteKeyTransaction instance + * @param {ISignedTransaction=} [properties] Properties to set + * @returns {SignedTransaction} SignedTransaction instance */ - DeleteKeyTransaction.create = function create(properties) { - return new DeleteKeyTransaction(properties); + SignedTransaction.create = function create(properties) { + return new SignedTransaction(properties); }; /** - * Encodes the specified DeleteKeyTransaction message. Does not implicitly {@link DeleteKeyTransaction.verify|verify} messages. + * Encodes the specified SignedTransaction message. Does not implicitly {@link SignedTransaction.verify|verify} messages. * @function encode - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @static - * @param {IDeleteKeyTransaction} message DeleteKeyTransaction message or plain object to encode + * @param {ISignedTransaction} message SignedTransaction message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - DeleteKeyTransaction.encode = function encode(message, writer) { + SignedTransaction.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.nonce != null && message.hasOwnProperty("nonce")) - writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.nonce); - if (message.originator != null && message.hasOwnProperty("originator")) - writer.uint32(/* id 2, wireType 2 =*/18).string(message.originator); - if (message.curKey != null && message.hasOwnProperty("curKey")) - writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.curKey); + if (message.signature != null && message.hasOwnProperty("signature")) + writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.signature); + if (message.transaction != null && message.hasOwnProperty("transaction")) + $root.Transaction.encode(message.transaction, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); return writer; }; /** - * Encodes the specified DeleteKeyTransaction message, length delimited. Does not implicitly {@link DeleteKeyTransaction.verify|verify} messages. + * Encodes the specified SignedTransaction message, length delimited. Does not implicitly {@link SignedTransaction.verify|verify} messages. * @function encodeDelimited - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @static - * @param {IDeleteKeyTransaction} message DeleteKeyTransaction message or plain object to encode + * @param {ISignedTransaction} message SignedTransaction message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - DeleteKeyTransaction.encodeDelimited = function encodeDelimited(message, writer) { + SignedTransaction.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** - * Decodes a DeleteKeyTransaction message from the specified reader or buffer. + * Decodes a SignedTransaction message from the specified reader or buffer. * @function decode - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand - * @returns {DeleteKeyTransaction} DeleteKeyTransaction + * @returns {SignedTransaction} SignedTransaction * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - DeleteKeyTransaction.decode = function decode(reader, length) { + SignedTransaction.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.DeleteKeyTransaction(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.SignedTransaction(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.nonce = reader.uint64(); + message.signature = reader.bytes(); break; case 2: - message.originator = reader.string(); - break; - case 3: - message.curKey = reader.bytes(); + message.transaction = $root.Transaction.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -2171,156 +2542,133 @@ $root.DeleteKeyTransaction = (function() { }; /** - * Decodes a DeleteKeyTransaction message from the specified reader or buffer, length delimited. + * Decodes a SignedTransaction message from the specified reader or buffer, length delimited. * @function decodeDelimited - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {DeleteKeyTransaction} DeleteKeyTransaction + * @returns {SignedTransaction} SignedTransaction * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - DeleteKeyTransaction.decodeDelimited = function decodeDelimited(reader) { + SignedTransaction.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** - * Verifies a DeleteKeyTransaction message. + * Verifies a SignedTransaction message. * @function verify - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ - DeleteKeyTransaction.verify = function verify(message) { + SignedTransaction.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (!$util.isInteger(message.nonce) && !(message.nonce && $util.isInteger(message.nonce.low) && $util.isInteger(message.nonce.high))) - return "nonce: integer|Long expected"; - if (message.originator != null && message.hasOwnProperty("originator")) - if (!$util.isString(message.originator)) - return "originator: string expected"; - if (message.curKey != null && message.hasOwnProperty("curKey")) - if (!(message.curKey && typeof message.curKey.length === "number" || $util.isString(message.curKey))) - return "curKey: buffer expected"; + if (message.signature != null && message.hasOwnProperty("signature")) + if (!(message.signature && typeof message.signature.length === "number" || $util.isString(message.signature))) + return "signature: buffer expected"; + if (message.transaction != null && message.hasOwnProperty("transaction")) { + var error = $root.Transaction.verify(message.transaction); + if (error) + return "transaction." + error; + } return null; }; /** - * Creates a DeleteKeyTransaction message from a plain object. Also converts values to their respective internal types. + * Creates a SignedTransaction message from a plain object. Also converts values to their respective internal types. * @function fromObject - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @static * @param {Object.} object Plain object - * @returns {DeleteKeyTransaction} DeleteKeyTransaction + * @returns {SignedTransaction} SignedTransaction */ - DeleteKeyTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.DeleteKeyTransaction) + SignedTransaction.fromObject = function fromObject(object) { + if (object instanceof $root.SignedTransaction) return object; - var message = new $root.DeleteKeyTransaction(); - if (object.nonce != null) - if ($util.Long) - (message.nonce = $util.Long.fromValue(object.nonce)).unsigned = true; - else if (typeof object.nonce === "string") - message.nonce = parseInt(object.nonce, 10); - else if (typeof object.nonce === "number") - message.nonce = object.nonce; - else if (typeof object.nonce === "object") - message.nonce = new $util.LongBits(object.nonce.low >>> 0, object.nonce.high >>> 0).toNumber(true); - if (object.originator != null) - message.originator = String(object.originator); - if (object.curKey != null) - if (typeof object.curKey === "string") - $util.base64.decode(object.curKey, message.curKey = $util.newBuffer($util.base64.length(object.curKey)), 0); - else if (object.curKey.length) - message.curKey = object.curKey; + var message = new $root.SignedTransaction(); + if (object.signature != null) + if (typeof object.signature === "string") + $util.base64.decode(object.signature, message.signature = $util.newBuffer($util.base64.length(object.signature)), 0); + else if (object.signature.length) + message.signature = object.signature; + if (object.transaction != null) { + if (typeof object.transaction !== "object") + throw TypeError(".SignedTransaction.transaction: object expected"); + message.transaction = $root.Transaction.fromObject(object.transaction); + } return message; }; /** - * Creates a plain object from a DeleteKeyTransaction message. Also converts values to other types if specified. + * Creates a plain object from a SignedTransaction message. Also converts values to other types if specified. * @function toObject - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @static - * @param {DeleteKeyTransaction} message DeleteKeyTransaction + * @param {SignedTransaction} message SignedTransaction * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - DeleteKeyTransaction.toObject = function toObject(message, options) { + SignedTransaction.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.defaults) { - if ($util.Long) { - var long = new $util.Long(0, 0, true); - object.nonce = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; - } else - object.nonce = options.longs === String ? "0" : 0; - object.originator = ""; if (options.bytes === String) - object.curKey = ""; + object.signature = ""; else { - object.curKey = []; + object.signature = []; if (options.bytes !== Array) - object.curKey = $util.newBuffer(object.curKey); + object.signature = $util.newBuffer(object.signature); } + object.transaction = null; } - if (message.nonce != null && message.hasOwnProperty("nonce")) - if (typeof message.nonce === "number") - object.nonce = options.longs === String ? String(message.nonce) : message.nonce; - else - object.nonce = options.longs === String ? $util.Long.prototype.toString.call(message.nonce) : options.longs === Number ? new $util.LongBits(message.nonce.low >>> 0, message.nonce.high >>> 0).toNumber(true) : message.nonce; - if (message.originator != null && message.hasOwnProperty("originator")) - object.originator = message.originator; - if (message.curKey != null && message.hasOwnProperty("curKey")) - object.curKey = options.bytes === String ? $util.base64.encode(message.curKey, 0, message.curKey.length) : options.bytes === Array ? Array.prototype.slice.call(message.curKey) : message.curKey; + if (message.signature != null && message.hasOwnProperty("signature")) + object.signature = options.bytes === String ? $util.base64.encode(message.signature, 0, message.signature.length) : options.bytes === Array ? Array.prototype.slice.call(message.signature) : message.signature; + if (message.transaction != null && message.hasOwnProperty("transaction")) + object.transaction = $root.Transaction.toObject(message.transaction, options); return object; }; /** - * Converts this DeleteKeyTransaction to JSON. + * Converts this SignedTransaction to JSON. * @function toJSON - * @memberof DeleteKeyTransaction + * @memberof SignedTransaction * @instance * @returns {Object.} JSON object */ - DeleteKeyTransaction.prototype.toJSON = function toJSON() { + SignedTransaction.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; - return DeleteKeyTransaction; + return SignedTransaction; })(); -$root.SignedTransaction = (function() { +$root.AccessKey = (function() { /** - * Properties of a SignedTransaction. - * @exports ISignedTransaction - * @interface ISignedTransaction - * @property {Uint8Array|null} [signature] SignedTransaction signature - * @property {google.protobuf.IBytesValue|null} [publicKey] SignedTransaction publicKey - * @property {ICreateAccountTransaction|null} [createAccount] SignedTransaction createAccount - * @property {IDeployContractTransaction|null} [deployContract] SignedTransaction deployContract - * @property {IFunctionCallTransaction|null} [functionCall] SignedTransaction functionCall - * @property {ISendMoneyTransaction|null} [sendMoney] SignedTransaction sendMoney - * @property {IStakeTransaction|null} [stake] SignedTransaction stake - * @property {ISwapKeyTransaction|null} [swapKey] SignedTransaction swapKey - * @property {IAddKeyTransaction|null} [addKey] SignedTransaction addKey - * @property {IDeleteKeyTransaction|null} [deleteKey] SignedTransaction deleteKey + * Properties of an AccessKey. + * @exports IAccessKey + * @interface IAccessKey + * @property {IUint128|null} [amount] AccessKey amount + * @property {google.protobuf.IStringValue|null} [balanceOwner] AccessKey balanceOwner + * @property {google.protobuf.IStringValue|null} [contractId] AccessKey contractId + * @property {google.protobuf.IBytesValue|null} [methodName] AccessKey methodName */ /** - * Constructs a new SignedTransaction. - * @exports SignedTransaction - * @classdesc Represents a SignedTransaction. - * @implements ISignedTransaction + * Constructs a new AccessKey. + * @exports AccessKey + * @classdesc Represents an AccessKey. + * @implements IAccessKey * @constructor - * @param {ISignedTransaction=} [properties] Properties to set + * @param {IAccessKey=} [properties] Properties to set */ - function SignedTransaction(properties) { + function AccessKey(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -2328,206 +2676,114 @@ $root.SignedTransaction = (function() { } /** - * SignedTransaction signature. - * @member {Uint8Array} signature - * @memberof SignedTransaction - * @instance - */ - SignedTransaction.prototype.signature = $util.newBuffer([]); - - /** - * SignedTransaction publicKey. - * @member {google.protobuf.IBytesValue|null|undefined} publicKey - * @memberof SignedTransaction - * @instance - */ - SignedTransaction.prototype.publicKey = null; - - /** - * SignedTransaction createAccount. - * @member {ICreateAccountTransaction|null|undefined} createAccount - * @memberof SignedTransaction - * @instance - */ - SignedTransaction.prototype.createAccount = null; - - /** - * SignedTransaction deployContract. - * @member {IDeployContractTransaction|null|undefined} deployContract - * @memberof SignedTransaction - * @instance - */ - SignedTransaction.prototype.deployContract = null; - - /** - * SignedTransaction functionCall. - * @member {IFunctionCallTransaction|null|undefined} functionCall - * @memberof SignedTransaction - * @instance - */ - SignedTransaction.prototype.functionCall = null; - - /** - * SignedTransaction sendMoney. - * @member {ISendMoneyTransaction|null|undefined} sendMoney - * @memberof SignedTransaction - * @instance - */ - SignedTransaction.prototype.sendMoney = null; - - /** - * SignedTransaction stake. - * @member {IStakeTransaction|null|undefined} stake - * @memberof SignedTransaction - * @instance - */ - SignedTransaction.prototype.stake = null; - - /** - * SignedTransaction swapKey. - * @member {ISwapKeyTransaction|null|undefined} swapKey - * @memberof SignedTransaction + * AccessKey amount. + * @member {IUint128|null|undefined} amount + * @memberof AccessKey * @instance */ - SignedTransaction.prototype.swapKey = null; + AccessKey.prototype.amount = null; /** - * SignedTransaction addKey. - * @member {IAddKeyTransaction|null|undefined} addKey - * @memberof SignedTransaction + * AccessKey balanceOwner. + * @member {google.protobuf.IStringValue|null|undefined} balanceOwner + * @memberof AccessKey * @instance */ - SignedTransaction.prototype.addKey = null; + AccessKey.prototype.balanceOwner = null; /** - * SignedTransaction deleteKey. - * @member {IDeleteKeyTransaction|null|undefined} deleteKey - * @memberof SignedTransaction + * AccessKey contractId. + * @member {google.protobuf.IStringValue|null|undefined} contractId + * @memberof AccessKey * @instance */ - SignedTransaction.prototype.deleteKey = null; - - // OneOf field names bound to virtual getters and setters - var $oneOfFields; + AccessKey.prototype.contractId = null; /** - * SignedTransaction body. - * @member {"createAccount"|"deployContract"|"functionCall"|"sendMoney"|"stake"|"swapKey"|"addKey"|"deleteKey"|undefined} body - * @memberof SignedTransaction + * AccessKey methodName. + * @member {google.protobuf.IBytesValue|null|undefined} methodName + * @memberof AccessKey * @instance */ - Object.defineProperty(SignedTransaction.prototype, "body", { - get: $util.oneOfGetter($oneOfFields = ["createAccount", "deployContract", "functionCall", "sendMoney", "stake", "swapKey", "addKey", "deleteKey"]), - set: $util.oneOfSetter($oneOfFields) - }); + AccessKey.prototype.methodName = null; /** - * Creates a new SignedTransaction instance using the specified properties. + * Creates a new AccessKey instance using the specified properties. * @function create - * @memberof SignedTransaction + * @memberof AccessKey * @static - * @param {ISignedTransaction=} [properties] Properties to set - * @returns {SignedTransaction} SignedTransaction instance + * @param {IAccessKey=} [properties] Properties to set + * @returns {AccessKey} AccessKey instance */ - SignedTransaction.create = function create(properties) { - return new SignedTransaction(properties); + AccessKey.create = function create(properties) { + return new AccessKey(properties); }; /** - * Encodes the specified SignedTransaction message. Does not implicitly {@link SignedTransaction.verify|verify} messages. + * Encodes the specified AccessKey message. Does not implicitly {@link AccessKey.verify|verify} messages. * @function encode - * @memberof SignedTransaction + * @memberof AccessKey * @static - * @param {ISignedTransaction} message SignedTransaction message or plain object to encode + * @param {IAccessKey} message AccessKey message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - SignedTransaction.encode = function encode(message, writer) { + AccessKey.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.signature != null && message.hasOwnProperty("signature")) - writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.signature); - if (message.createAccount != null && message.hasOwnProperty("createAccount")) - $root.CreateAccountTransaction.encode(message.createAccount, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); - if (message.deployContract != null && message.hasOwnProperty("deployContract")) - $root.DeployContractTransaction.encode(message.deployContract, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); - if (message.functionCall != null && message.hasOwnProperty("functionCall")) - $root.FunctionCallTransaction.encode(message.functionCall, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); - if (message.sendMoney != null && message.hasOwnProperty("sendMoney")) - $root.SendMoneyTransaction.encode(message.sendMoney, writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); - if (message.stake != null && message.hasOwnProperty("stake")) - $root.StakeTransaction.encode(message.stake, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim(); - if (message.swapKey != null && message.hasOwnProperty("swapKey")) - $root.SwapKeyTransaction.encode(message.swapKey, writer.uint32(/* id 7, wireType 2 =*/58).fork()).ldelim(); - if (message.addKey != null && message.hasOwnProperty("addKey")) - $root.AddKeyTransaction.encode(message.addKey, writer.uint32(/* id 8, wireType 2 =*/66).fork()).ldelim(); - if (message.deleteKey != null && message.hasOwnProperty("deleteKey")) - $root.DeleteKeyTransaction.encode(message.deleteKey, writer.uint32(/* id 9, wireType 2 =*/74).fork()).ldelim(); - if (message.publicKey != null && message.hasOwnProperty("publicKey")) - $root.google.protobuf.BytesValue.encode(message.publicKey, writer.uint32(/* id 10, wireType 2 =*/82).fork()).ldelim(); + if (message.amount != null && message.hasOwnProperty("amount")) + $root.Uint128.encode(message.amount, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.balanceOwner != null && message.hasOwnProperty("balanceOwner")) + $root.google.protobuf.StringValue.encode(message.balanceOwner, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); + if (message.contractId != null && message.hasOwnProperty("contractId")) + $root.google.protobuf.StringValue.encode(message.contractId, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); + if (message.methodName != null && message.hasOwnProperty("methodName")) + $root.google.protobuf.BytesValue.encode(message.methodName, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); return writer; }; /** - * Encodes the specified SignedTransaction message, length delimited. Does not implicitly {@link SignedTransaction.verify|verify} messages. + * Encodes the specified AccessKey message, length delimited. Does not implicitly {@link AccessKey.verify|verify} messages. * @function encodeDelimited - * @memberof SignedTransaction + * @memberof AccessKey * @static - * @param {ISignedTransaction} message SignedTransaction message or plain object to encode + * @param {IAccessKey} message AccessKey message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - SignedTransaction.encodeDelimited = function encodeDelimited(message, writer) { + AccessKey.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** - * Decodes a SignedTransaction message from the specified reader or buffer. + * Decodes an AccessKey message from the specified reader or buffer. * @function decode - * @memberof SignedTransaction + * @memberof AccessKey * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand - * @returns {SignedTransaction} SignedTransaction + * @returns {AccessKey} AccessKey * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - SignedTransaction.decode = function decode(reader, length) { + AccessKey.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.SignedTransaction(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.AccessKey(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.signature = reader.bytes(); - break; - case 10: - message.publicKey = $root.google.protobuf.BytesValue.decode(reader, reader.uint32()); + message.amount = $root.Uint128.decode(reader, reader.uint32()); break; case 2: - message.createAccount = $root.CreateAccountTransaction.decode(reader, reader.uint32()); + message.balanceOwner = $root.google.protobuf.StringValue.decode(reader, reader.uint32()); break; case 3: - message.deployContract = $root.DeployContractTransaction.decode(reader, reader.uint32()); - break; - case 4: - message.functionCall = $root.FunctionCallTransaction.decode(reader, reader.uint32()); - break; - case 5: - message.sendMoney = $root.SendMoneyTransaction.decode(reader, reader.uint32()); - break; - case 6: - message.stake = $root.StakeTransaction.decode(reader, reader.uint32()); - break; - case 7: - message.swapKey = $root.SwapKeyTransaction.decode(reader, reader.uint32()); - break; - case 8: - message.addKey = $root.AddKeyTransaction.decode(reader, reader.uint32()); + message.contractId = $root.google.protobuf.StringValue.decode(reader, reader.uint32()); break; - case 9: - message.deleteKey = $root.DeleteKeyTransaction.decode(reader, reader.uint32()); + case 4: + message.methodName = $root.google.protobuf.BytesValue.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -2538,269 +2794,132 @@ $root.SignedTransaction = (function() { }; /** - * Decodes a SignedTransaction message from the specified reader or buffer, length delimited. + * Decodes an AccessKey message from the specified reader or buffer, length delimited. * @function decodeDelimited - * @memberof SignedTransaction + * @memberof AccessKey * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {SignedTransaction} SignedTransaction + * @returns {AccessKey} AccessKey * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - SignedTransaction.decodeDelimited = function decodeDelimited(reader) { + AccessKey.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** - * Verifies a SignedTransaction message. + * Verifies an AccessKey message. * @function verify - * @memberof SignedTransaction + * @memberof AccessKey * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ - SignedTransaction.verify = function verify(message) { + AccessKey.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; - var properties = {}; - if (message.signature != null && message.hasOwnProperty("signature")) - if (!(message.signature && typeof message.signature.length === "number" || $util.isString(message.signature))) - return "signature: buffer expected"; - if (message.publicKey != null && message.hasOwnProperty("publicKey")) { - var error = $root.google.protobuf.BytesValue.verify(message.publicKey); + if (message.amount != null && message.hasOwnProperty("amount")) { + var error = $root.Uint128.verify(message.amount); if (error) - return "publicKey." + error; - } - if (message.createAccount != null && message.hasOwnProperty("createAccount")) { - properties.body = 1; - { - var error = $root.CreateAccountTransaction.verify(message.createAccount); - if (error) - return "createAccount." + error; - } - } - if (message.deployContract != null && message.hasOwnProperty("deployContract")) { - if (properties.body === 1) - return "body: multiple values"; - properties.body = 1; - { - var error = $root.DeployContractTransaction.verify(message.deployContract); - if (error) - return "deployContract." + error; - } - } - if (message.functionCall != null && message.hasOwnProperty("functionCall")) { - if (properties.body === 1) - return "body: multiple values"; - properties.body = 1; - { - var error = $root.FunctionCallTransaction.verify(message.functionCall); - if (error) - return "functionCall." + error; - } - } - if (message.sendMoney != null && message.hasOwnProperty("sendMoney")) { - if (properties.body === 1) - return "body: multiple values"; - properties.body = 1; - { - var error = $root.SendMoneyTransaction.verify(message.sendMoney); - if (error) - return "sendMoney." + error; - } - } - if (message.stake != null && message.hasOwnProperty("stake")) { - if (properties.body === 1) - return "body: multiple values"; - properties.body = 1; - { - var error = $root.StakeTransaction.verify(message.stake); - if (error) - return "stake." + error; - } + return "amount." + error; } - if (message.swapKey != null && message.hasOwnProperty("swapKey")) { - if (properties.body === 1) - return "body: multiple values"; - properties.body = 1; - { - var error = $root.SwapKeyTransaction.verify(message.swapKey); - if (error) - return "swapKey." + error; - } + if (message.balanceOwner != null && message.hasOwnProperty("balanceOwner")) { + var error = $root.google.protobuf.StringValue.verify(message.balanceOwner); + if (error) + return "balanceOwner." + error; } - if (message.addKey != null && message.hasOwnProperty("addKey")) { - if (properties.body === 1) - return "body: multiple values"; - properties.body = 1; - { - var error = $root.AddKeyTransaction.verify(message.addKey); - if (error) - return "addKey." + error; - } + if (message.contractId != null && message.hasOwnProperty("contractId")) { + var error = $root.google.protobuf.StringValue.verify(message.contractId); + if (error) + return "contractId." + error; } - if (message.deleteKey != null && message.hasOwnProperty("deleteKey")) { - if (properties.body === 1) - return "body: multiple values"; - properties.body = 1; - { - var error = $root.DeleteKeyTransaction.verify(message.deleteKey); - if (error) - return "deleteKey." + error; - } + if (message.methodName != null && message.hasOwnProperty("methodName")) { + var error = $root.google.protobuf.BytesValue.verify(message.methodName); + if (error) + return "methodName." + error; } return null; }; /** - * Creates a SignedTransaction message from a plain object. Also converts values to their respective internal types. + * Creates an AccessKey message from a plain object. Also converts values to their respective internal types. * @function fromObject - * @memberof SignedTransaction + * @memberof AccessKey * @static * @param {Object.} object Plain object - * @returns {SignedTransaction} SignedTransaction + * @returns {AccessKey} AccessKey */ - SignedTransaction.fromObject = function fromObject(object) { - if (object instanceof $root.SignedTransaction) + AccessKey.fromObject = function fromObject(object) { + if (object instanceof $root.AccessKey) return object; - var message = new $root.SignedTransaction(); - if (object.signature != null) - if (typeof object.signature === "string") - $util.base64.decode(object.signature, message.signature = $util.newBuffer($util.base64.length(object.signature)), 0); - else if (object.signature.length) - message.signature = object.signature; - if (object.publicKey != null) { - if (typeof object.publicKey !== "object") - throw TypeError(".SignedTransaction.publicKey: object expected"); - message.publicKey = $root.google.protobuf.BytesValue.fromObject(object.publicKey); - } - if (object.createAccount != null) { - if (typeof object.createAccount !== "object") - throw TypeError(".SignedTransaction.createAccount: object expected"); - message.createAccount = $root.CreateAccountTransaction.fromObject(object.createAccount); - } - if (object.deployContract != null) { - if (typeof object.deployContract !== "object") - throw TypeError(".SignedTransaction.deployContract: object expected"); - message.deployContract = $root.DeployContractTransaction.fromObject(object.deployContract); - } - if (object.functionCall != null) { - if (typeof object.functionCall !== "object") - throw TypeError(".SignedTransaction.functionCall: object expected"); - message.functionCall = $root.FunctionCallTransaction.fromObject(object.functionCall); - } - if (object.sendMoney != null) { - if (typeof object.sendMoney !== "object") - throw TypeError(".SignedTransaction.sendMoney: object expected"); - message.sendMoney = $root.SendMoneyTransaction.fromObject(object.sendMoney); - } - if (object.stake != null) { - if (typeof object.stake !== "object") - throw TypeError(".SignedTransaction.stake: object expected"); - message.stake = $root.StakeTransaction.fromObject(object.stake); + var message = new $root.AccessKey(); + if (object.amount != null) { + if (typeof object.amount !== "object") + throw TypeError(".AccessKey.amount: object expected"); + message.amount = $root.Uint128.fromObject(object.amount); } - if (object.swapKey != null) { - if (typeof object.swapKey !== "object") - throw TypeError(".SignedTransaction.swapKey: object expected"); - message.swapKey = $root.SwapKeyTransaction.fromObject(object.swapKey); + if (object.balanceOwner != null) { + if (typeof object.balanceOwner !== "object") + throw TypeError(".AccessKey.balanceOwner: object expected"); + message.balanceOwner = $root.google.protobuf.StringValue.fromObject(object.balanceOwner); } - if (object.addKey != null) { - if (typeof object.addKey !== "object") - throw TypeError(".SignedTransaction.addKey: object expected"); - message.addKey = $root.AddKeyTransaction.fromObject(object.addKey); + if (object.contractId != null) { + if (typeof object.contractId !== "object") + throw TypeError(".AccessKey.contractId: object expected"); + message.contractId = $root.google.protobuf.StringValue.fromObject(object.contractId); } - if (object.deleteKey != null) { - if (typeof object.deleteKey !== "object") - throw TypeError(".SignedTransaction.deleteKey: object expected"); - message.deleteKey = $root.DeleteKeyTransaction.fromObject(object.deleteKey); + if (object.methodName != null) { + if (typeof object.methodName !== "object") + throw TypeError(".AccessKey.methodName: object expected"); + message.methodName = $root.google.protobuf.BytesValue.fromObject(object.methodName); } return message; }; /** - * Creates a plain object from a SignedTransaction message. Also converts values to other types if specified. + * Creates a plain object from an AccessKey message. Also converts values to other types if specified. * @function toObject - * @memberof SignedTransaction + * @memberof AccessKey * @static - * @param {SignedTransaction} message SignedTransaction + * @param {AccessKey} message AccessKey * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - SignedTransaction.toObject = function toObject(message, options) { + AccessKey.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.defaults) { - if (options.bytes === String) - object.signature = ""; - else { - object.signature = []; - if (options.bytes !== Array) - object.signature = $util.newBuffer(object.signature); - } - object.publicKey = null; - } - if (message.signature != null && message.hasOwnProperty("signature")) - object.signature = options.bytes === String ? $util.base64.encode(message.signature, 0, message.signature.length) : options.bytes === Array ? Array.prototype.slice.call(message.signature) : message.signature; - if (message.createAccount != null && message.hasOwnProperty("createAccount")) { - object.createAccount = $root.CreateAccountTransaction.toObject(message.createAccount, options); - if (options.oneofs) - object.body = "createAccount"; - } - if (message.deployContract != null && message.hasOwnProperty("deployContract")) { - object.deployContract = $root.DeployContractTransaction.toObject(message.deployContract, options); - if (options.oneofs) - object.body = "deployContract"; - } - if (message.functionCall != null && message.hasOwnProperty("functionCall")) { - object.functionCall = $root.FunctionCallTransaction.toObject(message.functionCall, options); - if (options.oneofs) - object.body = "functionCall"; - } - if (message.sendMoney != null && message.hasOwnProperty("sendMoney")) { - object.sendMoney = $root.SendMoneyTransaction.toObject(message.sendMoney, options); - if (options.oneofs) - object.body = "sendMoney"; - } - if (message.stake != null && message.hasOwnProperty("stake")) { - object.stake = $root.StakeTransaction.toObject(message.stake, options); - if (options.oneofs) - object.body = "stake"; - } - if (message.swapKey != null && message.hasOwnProperty("swapKey")) { - object.swapKey = $root.SwapKeyTransaction.toObject(message.swapKey, options); - if (options.oneofs) - object.body = "swapKey"; - } - if (message.addKey != null && message.hasOwnProperty("addKey")) { - object.addKey = $root.AddKeyTransaction.toObject(message.addKey, options); - if (options.oneofs) - object.body = "addKey"; - } - if (message.deleteKey != null && message.hasOwnProperty("deleteKey")) { - object.deleteKey = $root.DeleteKeyTransaction.toObject(message.deleteKey, options); - if (options.oneofs) - object.body = "deleteKey"; + object.amount = null; + object.balanceOwner = null; + object.contractId = null; + object.methodName = null; } - if (message.publicKey != null && message.hasOwnProperty("publicKey")) - object.publicKey = $root.google.protobuf.BytesValue.toObject(message.publicKey, options); + if (message.amount != null && message.hasOwnProperty("amount")) + object.amount = $root.Uint128.toObject(message.amount, options); + if (message.balanceOwner != null && message.hasOwnProperty("balanceOwner")) + object.balanceOwner = $root.google.protobuf.StringValue.toObject(message.balanceOwner, options); + if (message.contractId != null && message.hasOwnProperty("contractId")) + object.contractId = $root.google.protobuf.StringValue.toObject(message.contractId, options); + if (message.methodName != null && message.hasOwnProperty("methodName")) + object.methodName = $root.google.protobuf.BytesValue.toObject(message.methodName, options); return object; }; /** - * Converts this SignedTransaction to JSON. + * Converts this AccessKey to JSON. * @function toJSON - * @memberof SignedTransaction + * @memberof AccessKey * @instance * @returns {Object.} JSON object */ - SignedTransaction.prototype.toJSON = function toJSON() { + AccessKey.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; - return SignedTransaction; + return AccessKey; })(); $root.google = (function() { @@ -4547,27 +4666,24 @@ $root.google = (function() { return google; })(); -$root.AccessKey = (function() { +$root.Uint128 = (function() { /** - * Properties of an AccessKey. - * @exports IAccessKey - * @interface IAccessKey - * @property {IUint128|null} [amount] AccessKey amount - * @property {google.protobuf.IStringValue|null} [balanceOwner] AccessKey balanceOwner - * @property {google.protobuf.IStringValue|null} [contractId] AccessKey contractId - * @property {google.protobuf.IBytesValue|null} [methodName] AccessKey methodName + * Properties of an Uint128. + * @exports IUint128 + * @interface IUint128 + * @property {Uint8Array|null} [number] Uint128 number */ /** - * Constructs a new AccessKey. - * @exports AccessKey - * @classdesc Represents an AccessKey. - * @implements IAccessKey + * Constructs a new Uint128. + * @exports Uint128 + * @classdesc Provides container for unsigned 128 bit integers. + * @implements IUint128 * @constructor - * @param {IAccessKey=} [properties] Properties to set + * @param {IUint128=} [properties] Properties to set */ - function AccessKey(properties) { + function Uint128(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -4575,114 +4691,75 @@ $root.AccessKey = (function() { } /** - * AccessKey amount. - * @member {IUint128|null|undefined} amount - * @memberof AccessKey - * @instance - */ - AccessKey.prototype.amount = null; - - /** - * AccessKey balanceOwner. - * @member {google.protobuf.IStringValue|null|undefined} balanceOwner - * @memberof AccessKey - * @instance - */ - AccessKey.prototype.balanceOwner = null; - - /** - * AccessKey contractId. - * @member {google.protobuf.IStringValue|null|undefined} contractId - * @memberof AccessKey - * @instance - */ - AccessKey.prototype.contractId = null; - - /** - * AccessKey methodName. - * @member {google.protobuf.IBytesValue|null|undefined} methodName - * @memberof AccessKey + * Uint128 number. + * @member {Uint8Array} number + * @memberof Uint128 * @instance */ - AccessKey.prototype.methodName = null; + Uint128.prototype.number = $util.newBuffer([]); /** - * Creates a new AccessKey instance using the specified properties. + * Creates a new Uint128 instance using the specified properties. * @function create - * @memberof AccessKey - * @static - * @param {IAccessKey=} [properties] Properties to set - * @returns {AccessKey} AccessKey instance + * @memberof Uint128 + * @static + * @param {IUint128=} [properties] Properties to set + * @returns {Uint128} Uint128 instance */ - AccessKey.create = function create(properties) { - return new AccessKey(properties); + Uint128.create = function create(properties) { + return new Uint128(properties); }; /** - * Encodes the specified AccessKey message. Does not implicitly {@link AccessKey.verify|verify} messages. + * Encodes the specified Uint128 message. Does not implicitly {@link Uint128.verify|verify} messages. * @function encode - * @memberof AccessKey + * @memberof Uint128 * @static - * @param {IAccessKey} message AccessKey message or plain object to encode + * @param {IUint128} message Uint128 message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - AccessKey.encode = function encode(message, writer) { + Uint128.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.amount != null && message.hasOwnProperty("amount")) - $root.Uint128.encode(message.amount, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); - if (message.balanceOwner != null && message.hasOwnProperty("balanceOwner")) - $root.google.protobuf.StringValue.encode(message.balanceOwner, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); - if (message.contractId != null && message.hasOwnProperty("contractId")) - $root.google.protobuf.StringValue.encode(message.contractId, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); - if (message.methodName != null && message.hasOwnProperty("methodName")) - $root.google.protobuf.BytesValue.encode(message.methodName, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); + if (message.number != null && message.hasOwnProperty("number")) + writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.number); return writer; }; /** - * Encodes the specified AccessKey message, length delimited. Does not implicitly {@link AccessKey.verify|verify} messages. + * Encodes the specified Uint128 message, length delimited. Does not implicitly {@link Uint128.verify|verify} messages. * @function encodeDelimited - * @memberof AccessKey + * @memberof Uint128 * @static - * @param {IAccessKey} message AccessKey message or plain object to encode + * @param {IUint128} message Uint128 message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - AccessKey.encodeDelimited = function encodeDelimited(message, writer) { + Uint128.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** - * Decodes an AccessKey message from the specified reader or buffer. + * Decodes an Uint128 message from the specified reader or buffer. * @function decode - * @memberof AccessKey + * @memberof Uint128 * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand - * @returns {AccessKey} AccessKey + * @returns {Uint128} Uint128 * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - AccessKey.decode = function decode(reader, length) { + Uint128.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.AccessKey(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Uint128(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.amount = $root.Uint128.decode(reader, reader.uint32()); - break; - case 2: - message.balanceOwner = $root.google.protobuf.StringValue.decode(reader, reader.uint32()); - break; - case 3: - message.contractId = $root.google.protobuf.StringValue.decode(reader, reader.uint32()); - break; - case 4: - message.methodName = $root.google.protobuf.BytesValue.decode(reader, reader.uint32()); + message.number = reader.bytes(); break; default: reader.skipType(tag & 7); @@ -4693,152 +4770,117 @@ $root.AccessKey = (function() { }; /** - * Decodes an AccessKey message from the specified reader or buffer, length delimited. + * Decodes an Uint128 message from the specified reader or buffer, length delimited. * @function decodeDelimited - * @memberof AccessKey + * @memberof Uint128 * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {AccessKey} AccessKey + * @returns {Uint128} Uint128 * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - AccessKey.decodeDelimited = function decodeDelimited(reader) { + Uint128.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** - * Verifies an AccessKey message. + * Verifies an Uint128 message. * @function verify - * @memberof AccessKey + * @memberof Uint128 * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ - AccessKey.verify = function verify(message) { + Uint128.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; - if (message.amount != null && message.hasOwnProperty("amount")) { - var error = $root.Uint128.verify(message.amount); - if (error) - return "amount." + error; - } - if (message.balanceOwner != null && message.hasOwnProperty("balanceOwner")) { - var error = $root.google.protobuf.StringValue.verify(message.balanceOwner); - if (error) - return "balanceOwner." + error; - } - if (message.contractId != null && message.hasOwnProperty("contractId")) { - var error = $root.google.protobuf.StringValue.verify(message.contractId); - if (error) - return "contractId." + error; - } - if (message.methodName != null && message.hasOwnProperty("methodName")) { - var error = $root.google.protobuf.BytesValue.verify(message.methodName); - if (error) - return "methodName." + error; - } + if (message.number != null && message.hasOwnProperty("number")) + if (!(message.number && typeof message.number.length === "number" || $util.isString(message.number))) + return "number: buffer expected"; return null; }; /** - * Creates an AccessKey message from a plain object. Also converts values to their respective internal types. + * Creates an Uint128 message from a plain object. Also converts values to their respective internal types. * @function fromObject - * @memberof AccessKey + * @memberof Uint128 * @static * @param {Object.} object Plain object - * @returns {AccessKey} AccessKey + * @returns {Uint128} Uint128 */ - AccessKey.fromObject = function fromObject(object) { - if (object instanceof $root.AccessKey) + Uint128.fromObject = function fromObject(object) { + if (object instanceof $root.Uint128) return object; - var message = new $root.AccessKey(); - if (object.amount != null) { - if (typeof object.amount !== "object") - throw TypeError(".AccessKey.amount: object expected"); - message.amount = $root.Uint128.fromObject(object.amount); - } - if (object.balanceOwner != null) { - if (typeof object.balanceOwner !== "object") - throw TypeError(".AccessKey.balanceOwner: object expected"); - message.balanceOwner = $root.google.protobuf.StringValue.fromObject(object.balanceOwner); - } - if (object.contractId != null) { - if (typeof object.contractId !== "object") - throw TypeError(".AccessKey.contractId: object expected"); - message.contractId = $root.google.protobuf.StringValue.fromObject(object.contractId); - } - if (object.methodName != null) { - if (typeof object.methodName !== "object") - throw TypeError(".AccessKey.methodName: object expected"); - message.methodName = $root.google.protobuf.BytesValue.fromObject(object.methodName); - } + var message = new $root.Uint128(); + if (object.number != null) + if (typeof object.number === "string") + $util.base64.decode(object.number, message.number = $util.newBuffer($util.base64.length(object.number)), 0); + else if (object.number.length) + message.number = object.number; return message; }; /** - * Creates a plain object from an AccessKey message. Also converts values to other types if specified. + * Creates a plain object from an Uint128 message. Also converts values to other types if specified. * @function toObject - * @memberof AccessKey + * @memberof Uint128 * @static - * @param {AccessKey} message AccessKey + * @param {Uint128} message Uint128 * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - AccessKey.toObject = function toObject(message, options) { + Uint128.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; - if (options.defaults) { - object.amount = null; - object.balanceOwner = null; - object.contractId = null; - object.methodName = null; - } - if (message.amount != null && message.hasOwnProperty("amount")) - object.amount = $root.Uint128.toObject(message.amount, options); - if (message.balanceOwner != null && message.hasOwnProperty("balanceOwner")) - object.balanceOwner = $root.google.protobuf.StringValue.toObject(message.balanceOwner, options); - if (message.contractId != null && message.hasOwnProperty("contractId")) - object.contractId = $root.google.protobuf.StringValue.toObject(message.contractId, options); - if (message.methodName != null && message.hasOwnProperty("methodName")) - object.methodName = $root.google.protobuf.BytesValue.toObject(message.methodName, options); + if (options.defaults) + if (options.bytes === String) + object.number = ""; + else { + object.number = []; + if (options.bytes !== Array) + object.number = $util.newBuffer(object.number); + } + if (message.number != null && message.hasOwnProperty("number")) + object.number = options.bytes === String ? $util.base64.encode(message.number, 0, message.number.length) : options.bytes === Array ? Array.prototype.slice.call(message.number) : message.number; return object; }; /** - * Converts this AccessKey to JSON. + * Converts this Uint128 to JSON. * @function toJSON - * @memberof AccessKey + * @memberof Uint128 * @instance * @returns {Object.} JSON object */ - AccessKey.prototype.toJSON = function toJSON() { + Uint128.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; - return AccessKey; + return Uint128; })(); -$root.Uint128 = (function() { +$root.PublicKey = (function() { /** - * Properties of an Uint128. - * @exports IUint128 - * @interface IUint128 - * @property {Uint8Array|null} [number] Uint128 number + * Properties of a PublicKey. + * @exports IPublicKey + * @interface IPublicKey + * @property {PublicKey.KeyType|null} [keyType] PublicKey keyType + * @property {Uint8Array|null} [data] PublicKey data */ /** - * Constructs a new Uint128. - * @exports Uint128 - * @classdesc Provides container for unsigned 128 bit integers. - * @implements IUint128 + * Constructs a new PublicKey. + * @exports PublicKey + * @classdesc Represents a PublicKey. + * @implements IPublicKey * @constructor - * @param {IUint128=} [properties] Properties to set + * @param {IPublicKey=} [properties] Properties to set */ - function Uint128(properties) { + function PublicKey(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -4846,75 +4888,88 @@ $root.Uint128 = (function() { } /** - * Uint128 number. - * @member {Uint8Array} number - * @memberof Uint128 + * PublicKey keyType. + * @member {PublicKey.KeyType} keyType + * @memberof PublicKey * @instance */ - Uint128.prototype.number = $util.newBuffer([]); + PublicKey.prototype.keyType = 0; /** - * Creates a new Uint128 instance using the specified properties. + * PublicKey data. + * @member {Uint8Array} data + * @memberof PublicKey + * @instance + */ + PublicKey.prototype.data = $util.newBuffer([]); + + /** + * Creates a new PublicKey instance using the specified properties. * @function create - * @memberof Uint128 + * @memberof PublicKey * @static - * @param {IUint128=} [properties] Properties to set - * @returns {Uint128} Uint128 instance + * @param {IPublicKey=} [properties] Properties to set + * @returns {PublicKey} PublicKey instance */ - Uint128.create = function create(properties) { - return new Uint128(properties); + PublicKey.create = function create(properties) { + return new PublicKey(properties); }; /** - * Encodes the specified Uint128 message. Does not implicitly {@link Uint128.verify|verify} messages. + * Encodes the specified PublicKey message. Does not implicitly {@link PublicKey.verify|verify} messages. * @function encode - * @memberof Uint128 + * @memberof PublicKey * @static - * @param {IUint128} message Uint128 message or plain object to encode + * @param {IPublicKey} message PublicKey message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - Uint128.encode = function encode(message, writer) { + PublicKey.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.number != null && message.hasOwnProperty("number")) - writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.number); + if (message.keyType != null && message.hasOwnProperty("keyType")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.keyType); + if (message.data != null && message.hasOwnProperty("data")) + writer.uint32(/* id 2, wireType 2 =*/18).bytes(message.data); return writer; }; /** - * Encodes the specified Uint128 message, length delimited. Does not implicitly {@link Uint128.verify|verify} messages. + * Encodes the specified PublicKey message, length delimited. Does not implicitly {@link PublicKey.verify|verify} messages. * @function encodeDelimited - * @memberof Uint128 + * @memberof PublicKey * @static - * @param {IUint128} message Uint128 message or plain object to encode + * @param {IPublicKey} message PublicKey message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ - Uint128.encodeDelimited = function encodeDelimited(message, writer) { + PublicKey.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** - * Decodes an Uint128 message from the specified reader or buffer. + * Decodes a PublicKey message from the specified reader or buffer. * @function decode - * @memberof Uint128 + * @memberof PublicKey * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand - * @returns {Uint128} Uint128 + * @returns {PublicKey} PublicKey * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - Uint128.decode = function decode(reader, length) { + PublicKey.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Uint128(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.PublicKey(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.number = reader.bytes(); + message.keyType = reader.int32(); + break; + case 2: + message.data = reader.bytes(); break; default: reader.skipType(tag & 7); @@ -4925,96 +4980,125 @@ $root.Uint128 = (function() { }; /** - * Decodes an Uint128 message from the specified reader or buffer, length delimited. + * Decodes a PublicKey message from the specified reader or buffer, length delimited. * @function decodeDelimited - * @memberof Uint128 + * @memberof PublicKey * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from - * @returns {Uint128} Uint128 + * @returns {PublicKey} PublicKey * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - Uint128.decodeDelimited = function decodeDelimited(reader) { + PublicKey.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** - * Verifies an Uint128 message. + * Verifies a PublicKey message. * @function verify - * @memberof Uint128 + * @memberof PublicKey * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ - Uint128.verify = function verify(message) { + PublicKey.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; - if (message.number != null && message.hasOwnProperty("number")) - if (!(message.number && typeof message.number.length === "number" || $util.isString(message.number))) - return "number: buffer expected"; + if (message.keyType != null && message.hasOwnProperty("keyType")) + switch (message.keyType) { + default: + return "keyType: enum value expected"; + case 0: + break; + } + if (message.data != null && message.hasOwnProperty("data")) + if (!(message.data && typeof message.data.length === "number" || $util.isString(message.data))) + return "data: buffer expected"; return null; }; /** - * Creates an Uint128 message from a plain object. Also converts values to their respective internal types. + * Creates a PublicKey message from a plain object. Also converts values to their respective internal types. * @function fromObject - * @memberof Uint128 + * @memberof PublicKey * @static * @param {Object.} object Plain object - * @returns {Uint128} Uint128 + * @returns {PublicKey} PublicKey */ - Uint128.fromObject = function fromObject(object) { - if (object instanceof $root.Uint128) + PublicKey.fromObject = function fromObject(object) { + if (object instanceof $root.PublicKey) return object; - var message = new $root.Uint128(); - if (object.number != null) - if (typeof object.number === "string") - $util.base64.decode(object.number, message.number = $util.newBuffer($util.base64.length(object.number)), 0); - else if (object.number.length) - message.number = object.number; + var message = new $root.PublicKey(); + switch (object.keyType) { + case "ED25519": + case 0: + message.keyType = 0; + break; + } + if (object.data != null) + if (typeof object.data === "string") + $util.base64.decode(object.data, message.data = $util.newBuffer($util.base64.length(object.data)), 0); + else if (object.data.length) + message.data = object.data; return message; }; /** - * Creates a plain object from an Uint128 message. Also converts values to other types if specified. + * Creates a plain object from a PublicKey message. Also converts values to other types if specified. * @function toObject - * @memberof Uint128 + * @memberof PublicKey * @static - * @param {Uint128} message Uint128 + * @param {PublicKey} message PublicKey * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ - Uint128.toObject = function toObject(message, options) { + PublicKey.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; - if (options.defaults) + if (options.defaults) { + object.keyType = options.enums === String ? "ED25519" : 0; if (options.bytes === String) - object.number = ""; + object.data = ""; else { - object.number = []; + object.data = []; if (options.bytes !== Array) - object.number = $util.newBuffer(object.number); + object.data = $util.newBuffer(object.data); } - if (message.number != null && message.hasOwnProperty("number")) - object.number = options.bytes === String ? $util.base64.encode(message.number, 0, message.number.length) : options.bytes === Array ? Array.prototype.slice.call(message.number) : message.number; + } + if (message.keyType != null && message.hasOwnProperty("keyType")) + object.keyType = options.enums === String ? $root.PublicKey.KeyType[message.keyType] : message.keyType; + if (message.data != null && message.hasOwnProperty("data")) + object.data = options.bytes === String ? $util.base64.encode(message.data, 0, message.data.length) : options.bytes === Array ? Array.prototype.slice.call(message.data) : message.data; return object; }; /** - * Converts this Uint128 to JSON. + * Converts this PublicKey to JSON. * @function toJSON - * @memberof Uint128 + * @memberof PublicKey * @instance * @returns {Object.} JSON object */ - Uint128.prototype.toJSON = function toJSON() { + PublicKey.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; - return Uint128; + /** + * KeyType enum. + * @name PublicKey.KeyType + * @enum {string} + * @property {number} ED25519=0 ED25519 value + */ + PublicKey.KeyType = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "ED25519"] = 0; + return values; + })(); + + return PublicKey; })(); module.exports = $root; diff --git a/lib/providers/json-rpc-provider.js b/lib/providers/json-rpc-provider.js index 263c0266a7..db0b1eb826 100644 --- a/lib/providers/json-rpc-provider.js +++ b/lib/providers/json-rpc-provider.js @@ -23,6 +23,7 @@ class JsonRpcProvider extends provider_1.Provider { } async sendTransaction(signedTransaction) { const bytes = protos_1.SignedTransaction.encode(signedTransaction).finish(); + console.warn("Bytes: " + new Uint8Array(bytes)); return this.sendJsonRpc('broadcast_tx_commit', [Buffer.from(bytes).toString('base64')]); } async txStatus(txHash) { diff --git a/lib/signer.js b/lib/signer.js index f2ddc3636a..194e206f6d 100644 --- a/lib/signer.js +++ b/lib/signer.js @@ -35,6 +35,7 @@ class InMemorySigner extends Signer { } async getPublicKey(accountId, networkId) { const keyPair = await this.keyStore.getKey(networkId, accountId); + console.warn(`network: ${networkId}, account: ${accountId}`); return keyPair.getPublicKey(); } async signHash(hash, accountId, networkId) { diff --git a/lib/transaction.d.ts b/lib/transaction.d.ts index a698ddeefa..e19619cb2b 100644 --- a/lib/transaction.d.ts +++ b/lib/transaction.d.ts @@ -1,17 +1,18 @@ import BN from 'bn.js'; -import { SendMoneyTransaction, CreateAccountTransaction, SignedTransaction, DeployContractTransaction, FunctionCallTransaction, StakeTransaction, SwapKeyTransaction, AddKeyTransaction, DeleteKeyTransaction, AccessKey } from './protos'; +import { Action, AccessKey, SignedTransaction, Transaction } from './protos'; import { Signature } from './utils/key_pair'; import { Signer } from './signer'; -export declare type AllTransactions = SendMoneyTransaction | CreateAccountTransaction | DeployContractTransaction | FunctionCallTransaction | StakeTransaction | SwapKeyTransaction | AddKeyTransaction | DeleteKeyTransaction; +export declare type Action = Action; export declare function bignumHex2Dec(num: string): string; -export declare function createAccount(nonce: number, originator: string, newAccountId: string, publicKey: string, amount: BN): CreateAccountTransaction; -export declare function deployContract(nonce: number, contractId: string, wasmByteArray: Uint8Array): DeployContractTransaction; -export declare function functionCall(nonce: number, originator: string, contractId: string, methodName: string, args: Uint8Array, amount: BN): FunctionCallTransaction; -export declare function sendMoney(nonce: number, originator: string, receiver: string, amount: BN): SendMoneyTransaction; -export declare function stake(nonce: number, originator: string, amount: BN, publicKey: string): StakeTransaction; -export declare function swapKey(nonce: number, originator: string, curKey: string, newKey: string): SwapKeyTransaction; +export declare function createAccount(): Action; +export declare function deployContract(code: Uint8Array): Action; +export declare function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action; +export declare function transfer(deposit: BN): Action; +export declare function stake(stake: BN, publicKey: string): Action; export declare function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey; -export declare function addKey(nonce: number, originator: string, newKey: string, accessKey: AccessKey): AddKeyTransaction; -export declare function deleteKey(nonce: number, originator: string, curKey: string): DeleteKeyTransaction; -export declare function signedTransaction(transaction: AllTransactions, signature: Signature): SignedTransaction; -export declare function signTransaction(signer: Signer, transaction: any, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]>; +export declare function addKey(publicKey: string, accessKey: AccessKey): Action; +export declare function deleteKey(publicKey: string): Action; +export declare function deleteAccount(beneficiaryId: string): Action; +export declare function transaction(signerId: string, publicKey: string, nonce: number, receiverId: string, actions: Action[]): Transaction; +export declare function signedTransaction(transaction: Transaction, signature: Signature): SignedTransaction; +export declare function signTransaction(receiverId: string, nonce: number, actions: Action[], signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]>; diff --git a/lib/transaction.js b/lib/transaction.js index 8069bf6807..752c952ef0 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -7,48 +7,37 @@ const js_sha256_1 = __importDefault(require("js-sha256")); const bn_js_1 = __importDefault(require("bn.js")); const protos_1 = require("./protos"); const serialize_1 = require("./utils/serialize"); -const TRANSACTION_FIELD_MAP = new Map([ - [protos_1.CreateAccountTransaction, 'createAccount'], - [protos_1.DeployContractTransaction, 'deployContract'], - [protos_1.FunctionCallTransaction, 'functionCall'], - [protos_1.SendMoneyTransaction, 'sendMoney'], - [protos_1.StakeTransaction, 'stake'], - [protos_1.SwapKeyTransaction, 'swapKey'], - [protos_1.AddKeyTransaction, 'addKey'], - [protos_1.DeleteKeyTransaction, 'deleteKey'], -]); function bigInt(num) { const number = new Uint8Array(new bn_js_1.default(num).toArray('le', 16)); return new protos_1.Uint128({ number }); } +function toPublicKey(publicKey) { + return new protos_1.PublicKey({ keyType: protos_1.PublicKey.KeyType.ED25519, data: serialize_1.base_decode(publicKey) }); +} function bignumHex2Dec(num) { return new bn_js_1.default(num, 16).toString(10); } exports.bignumHex2Dec = bignumHex2Dec; -function createAccount(nonce, originator, newAccountId, publicKey, amount) { - return new protos_1.CreateAccountTransaction({ nonce, originator, newAccountId, publicKey: serialize_1.base_decode(publicKey), amount: bigInt(amount) }); +function createAccount() { + return new protos_1.Action({ createAccount: new protos_1.Action.CreateAccount() }); } exports.createAccount = createAccount; -function deployContract(nonce, contractId, wasmByteArray) { - return new protos_1.DeployContractTransaction({ nonce, contractId, wasmByteArray }); +function deployContract(code) { + return new protos_1.Action({ deployContract: new protos_1.Action.DeployContract({ code }) }); } exports.deployContract = deployContract; -function functionCall(nonce, originator, contractId, methodName, args, amount) { - return new protos_1.FunctionCallTransaction({ nonce, originator, contractId, methodName: Buffer.from(methodName), args, amount: bigInt(amount) }); +function functionCall(methodName, args, gas, deposit) { + return new protos_1.Action({ functionCall: new protos_1.Action.FunctionCall({ methodName, args, gas, deposit: bigInt(deposit) }) }); } exports.functionCall = functionCall; -function sendMoney(nonce, originator, receiver, amount) { - return new protos_1.SendMoneyTransaction({ nonce, originator, receiver, amount: bigInt(amount) }); +function transfer(deposit) { + return new protos_1.Action({ transfer: new protos_1.Action.Transfer({ deposit: bigInt(deposit) }) }); } -exports.sendMoney = sendMoney; -function stake(nonce, originator, amount, publicKey) { - return new protos_1.StakeTransaction({ nonce, originator, amount: bigInt(amount), publicKey, blsPublicKey: null }); +exports.transfer = transfer; +function stake(stake, publicKey) { + return new protos_1.Action({ stake: new protos_1.Action.Stake({ stake: bigInt(stake), publicKey: toPublicKey(publicKey) }) }); } exports.stake = stake; -function swapKey(nonce, originator, curKey, newKey) { - return new protos_1.SwapKeyTransaction({ nonce, originator, curKey: serialize_1.base_decode(curKey), newKey: serialize_1.base_decode(newKey) }); -} -exports.swapKey = swapKey; function createAccessKey(contractId, methodName, balanceOwner, amount) { return new protos_1.AccessKey({ contractId: contractId ? new protos_1.google.protobuf.StringValue({ value: contractId }) : null, @@ -58,28 +47,46 @@ function createAccessKey(contractId, methodName, balanceOwner, amount) { }); } exports.createAccessKey = createAccessKey; -function addKey(nonce, originator, newKey, accessKey) { - return new protos_1.AddKeyTransaction({ nonce, originator, newKey: serialize_1.base_decode(newKey), accessKey }); +function addKey(publicKey, accessKey) { + console.warn(accessKey); + return new protos_1.Action({ addKey: new protos_1.Action.AddKey({ publicKey: toPublicKey(publicKey), accessKey }) }); } exports.addKey = addKey; -function deleteKey(nonce, originator, curKey) { - return new protos_1.DeleteKeyTransaction({ nonce, originator, curKey: serialize_1.base_decode(curKey) }); +function deleteKey(publicKey) { + return new protos_1.Action({ deleteKey: new protos_1.Action.DeleteKey({ publicKey: toPublicKey(publicKey) }) }); } exports.deleteKey = deleteKey; +function deleteAccount(beneficiaryId) { + return new protos_1.Action({ deleteAccount: new protos_1.Action.DeleteAccount({ beneficiaryId }) }); +} +exports.deleteAccount = deleteAccount; +function transaction(signerId, publicKey, nonce, receiverId, actions) { + return new protos_1.Transaction({ signerId, publicKey: toPublicKey(publicKey), nonce, receiverId, actions }); +} +exports.transaction = transaction; function signedTransaction(transaction, signature) { - const fieldName = TRANSACTION_FIELD_MAP.get(transaction.constructor); return new protos_1.SignedTransaction({ signature: signature.signature, - publicKey: protos_1.google.protobuf.BytesValue.create({ value: serialize_1.base_decode(signature.publicKey) }), - [fieldName]: transaction, + transaction }); } exports.signedTransaction = signedTransaction; -async function signTransaction(signer, transaction, accountId, networkId) { - const protoClass = transaction.constructor; - const message = protoClass.encode(transaction).finish(); +async function signTransaction(receiverId, nonce, actions, signer, accountId, networkId) { + console.warn("WTF?" + await signer.getPublicKey(accountId, networkId)); + const tx = transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); + console.warn(tx.publicKey); + console.warn("XX: " + JSON.stringify(tx)); + const message = protos_1.Transaction.encode(tx).finish(); + console.warn("11: " + new Uint8Array(message)); + const tx2 = protos_1.Transaction.decode(message); + console.warn(JSON.stringify(tx2)); + const message2 = protos_1.Transaction.encode(tx2).finish(); + console.warn("33: " + serialize_1.base_encode(message2)); const hash = new Uint8Array(js_sha256_1.default.sha256.array(message)); + console.warn("22: " + serialize_1.base_encode(hash)); const signature = await signer.signHash(hash, accountId, networkId); - return [hash, signedTransaction(transaction, signature)]; + const signedTx = signedTransaction(tx, signature); + console.warn(JSON.stringify(signedTx)); + return [hash, signedTx]; } exports.signTransaction = signTransaction; diff --git a/src.ts/account.ts b/src.ts/account.ts index bf19644bd2..0ea3fa8d1d 100644 --- a/src.ts/account.ts +++ b/src.ts/account.ts @@ -1,7 +1,7 @@ 'use strict'; import BN from 'bn.js'; -import { sendMoney, createAccount, signTransaction, deployContract, +import { Action, transfer, createAccount, signTransaction, deployContract, addKey, functionCall, createAccessKey, deleteKey, stake } from './transaction'; import { FinalTransactionResult, FinalTransactionStatus } from './providers/provider'; import { Connection } from './connection'; @@ -83,9 +83,11 @@ export class Account { throw new Error(`Exceeded ${TX_STATUS_RETRY_NUMBER} status check attempts for transaction ${base_encode(txHash)}.`); } - private async signAndSendTransaction(transaction: any): Promise { + private async signAndSendTransaction(receiverId: string, actions: Array): Promise { + await this.ready; + console.warn(`receiverId: ${receiverId}, actions: ${actions}, signer: ${this.connection.signer}`); const [txHash, signedTx] = await signTransaction( - this.connection.signer, transaction, this.accountId, this.connection.networkId); + receiverId, ++this._state.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); let result; try { @@ -99,11 +101,7 @@ export class Account { } const flatLogs = result.logs.reduce((acc, it) => acc.concat(it.lines), []); - if (transaction.hasOwnProperty('contractId')) { - this.printLogs(transaction['contractId'], flatLogs); - } else if (transaction.hasOwnProperty('originator')) { - this.printLogs(transaction['originator'], flatLogs); - } + this.printLogs(signedTx.transaction.receiverId, flatLogs); if (result.status === FinalTransactionStatus.Failed) { if (result.logs) { @@ -125,50 +123,37 @@ export class Account { return contractAccount; } - async sendMoney(receiver: string, amount: BN): Promise { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(sendMoney(this._state.nonce, this.accountId, receiver, amount)); + async sendMoney(receiverId: string, amount: BN): Promise { + return this.signAndSendTransaction(receiverId, [transfer(amount)]); } async createAccount(newAccountId: string, publicKey: string, amount: BN): Promise { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(createAccount(this._state.nonce, this.accountId, newAccountId, publicKey, amount)); + const accessKey = createAccessKey(null, "", newAccountId, new BN(0)); + return this.signAndSendTransaction(newAccountId, [createAccount(), transfer(amount), addKey(publicKey, accessKey)]); } async deployContract(data: Uint8Array): Promise { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(deployContract(this._state.nonce, this.accountId, data)); + return this.signAndSendTransaction(this.accountId, [deployContract(data)]); } - async functionCall(contractId: string, methodName: string, args: any, amount?: BN): Promise { + async functionCall(contractId: string, methodName: string, args: any, gas: number, amount?: BN): Promise { if (!args) { args = {}; } - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(functionCall(this._state.nonce, this.accountId, contractId, methodName, Buffer.from(JSON.stringify(args)), amount || DEFAULT_FUNC_CALL_AMOUNT)); + return this.signAndSendTransaction(contractId, [functionCall(methodName, Buffer.from(JSON.stringify(args)), gas, amount || DEFAULT_FUNC_CALL_AMOUNT)]); } async addKey(publicKey: string, contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): Promise { - await this.ready; - this._state.nonce++; - const accessKey = contractId ? createAccessKey(contractId, methodName, balanceOwner, amount) : null; - return this.signAndSendTransaction(addKey(this._state.nonce, this.accountId, publicKey, accessKey)); + const accessKey = createAccessKey(contractId ? contractId : null, methodName, balanceOwner, amount); + return this.signAndSendTransaction(this.accountId, [addKey(publicKey, accessKey)]); } async deleteKey(publicKey: string): Promise { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(deleteKey(this._state.nonce, this.accountId, publicKey)); + return this.signAndSendTransaction(this.accountId, [deleteKey(publicKey)]); } async stake(publicKey: string, amount: BN): Promise { - await this.ready; - this._state.nonce++; - return this.signAndSendTransaction(stake(this._state.nonce, this.accountId, amount, publicKey)); + return this.signAndSendTransaction(this.accountId, [stake(amount, publicKey)]); } async viewFunction(contractId: string, methodName: string, args: any): Promise { diff --git a/src.ts/protos.d.ts b/src.ts/protos.d.ts index 8c85a0dd63..24510f75f7 100644 --- a/src.ts/protos.d.ts +++ b/src.ts/protos.d.ts @@ -1,1022 +1,1199 @@ import * as $protobuf from "protobufjs"; -/** Properties of a CreateAccountTransaction. */ -export interface ICreateAccountTransaction { +/** Properties of an Action. */ +export interface IAction { - /** CreateAccountTransaction nonce */ - nonce?: (number|Long|null); - - /** CreateAccountTransaction originator */ - originator?: (string|null); - - /** CreateAccountTransaction newAccountId */ - newAccountId?: (string|null); - - /** CreateAccountTransaction amount */ - amount?: (IUint128|null); - - /** CreateAccountTransaction publicKey */ - publicKey?: (Uint8Array|null); -} - -/** Represents a CreateAccountTransaction. */ -export class CreateAccountTransaction implements ICreateAccountTransaction { - - /** - * Constructs a new CreateAccountTransaction. - * @param [properties] Properties to set - */ - constructor(properties?: ICreateAccountTransaction); - - /** CreateAccountTransaction nonce. */ - public nonce: (number|Long); - - /** CreateAccountTransaction originator. */ - public originator: string; - - /** CreateAccountTransaction newAccountId. */ - public newAccountId: string; - - /** CreateAccountTransaction amount. */ - public amount?: (IUint128|null); - - /** CreateAccountTransaction publicKey. */ - public publicKey: Uint8Array; - - /** - * Creates a new CreateAccountTransaction instance using the specified properties. - * @param [properties] Properties to set - * @returns CreateAccountTransaction instance - */ - public static create(properties?: ICreateAccountTransaction): CreateAccountTransaction; - - /** - * Encodes the specified CreateAccountTransaction message. Does not implicitly {@link CreateAccountTransaction.verify|verify} messages. - * @param message CreateAccountTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: ICreateAccountTransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified CreateAccountTransaction message, length delimited. Does not implicitly {@link CreateAccountTransaction.verify|verify} messages. - * @param message CreateAccountTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: ICreateAccountTransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a CreateAccountTransaction message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns CreateAccountTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): CreateAccountTransaction; + /** Action createAccount */ + createAccount?: (Action.ICreateAccount|null); - /** - * Decodes a CreateAccountTransaction message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns CreateAccountTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): CreateAccountTransaction; - - /** - * Verifies a CreateAccountTransaction message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a CreateAccountTransaction message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns CreateAccountTransaction - */ - public static fromObject(object: { [k: string]: any }): CreateAccountTransaction; + /** Action deployContract */ + deployContract?: (Action.IDeployContract|null); - /** - * Creates a plain object from a CreateAccountTransaction message. Also converts values to other types if specified. - * @param message CreateAccountTransaction - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: CreateAccountTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; + /** Action functionCall */ + functionCall?: (Action.IFunctionCall|null); - /** - * Converts this CreateAccountTransaction to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} + /** Action transfer */ + transfer?: (Action.ITransfer|null); -/** Properties of a DeployContractTransaction. */ -export interface IDeployContractTransaction { + /** Action stake */ + stake?: (Action.IStake|null); - /** DeployContractTransaction nonce */ - nonce?: (number|Long|null); + /** Action addKey */ + addKey?: (Action.IAddKey|null); - /** DeployContractTransaction contractId */ - contractId?: (string|null); + /** Action deleteKey */ + deleteKey?: (Action.IDeleteKey|null); - /** DeployContractTransaction wasmByteArray */ - wasmByteArray?: (Uint8Array|null); + /** Action deleteAccount */ + deleteAccount?: (Action.IDeleteAccount|null); } -/** Represents a DeployContractTransaction. */ -export class DeployContractTransaction implements IDeployContractTransaction { +/** Represents an Action. */ +export class Action implements IAction { /** - * Constructs a new DeployContractTransaction. + * Constructs a new Action. * @param [properties] Properties to set */ - constructor(properties?: IDeployContractTransaction); + constructor(properties?: IAction); - /** DeployContractTransaction nonce. */ - public nonce: (number|Long); + /** Action createAccount. */ + public createAccount?: (Action.ICreateAccount|null); - /** DeployContractTransaction contractId. */ - public contractId: string; + /** Action deployContract. */ + public deployContract?: (Action.IDeployContract|null); - /** DeployContractTransaction wasmByteArray. */ - public wasmByteArray: Uint8Array; + /** Action functionCall. */ + public functionCall?: (Action.IFunctionCall|null); - /** - * Creates a new DeployContractTransaction instance using the specified properties. - * @param [properties] Properties to set - * @returns DeployContractTransaction instance - */ - public static create(properties?: IDeployContractTransaction): DeployContractTransaction; + /** Action transfer. */ + public transfer?: (Action.ITransfer|null); - /** - * Encodes the specified DeployContractTransaction message. Does not implicitly {@link DeployContractTransaction.verify|verify} messages. - * @param message DeployContractTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: IDeployContractTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + /** Action stake. */ + public stake?: (Action.IStake|null); - /** - * Encodes the specified DeployContractTransaction message, length delimited. Does not implicitly {@link DeployContractTransaction.verify|verify} messages. - * @param message DeployContractTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: IDeployContractTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + /** Action addKey. */ + public addKey?: (Action.IAddKey|null); - /** - * Decodes a DeployContractTransaction message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns DeployContractTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): DeployContractTransaction; - - /** - * Decodes a DeployContractTransaction message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns DeployContractTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): DeployContractTransaction; - - /** - * Verifies a DeployContractTransaction message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a DeployContractTransaction message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns DeployContractTransaction - */ - public static fromObject(object: { [k: string]: any }): DeployContractTransaction; - - /** - * Creates a plain object from a DeployContractTransaction message. Also converts values to other types if specified. - * @param message DeployContractTransaction - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: DeployContractTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this DeployContractTransaction to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} + /** Action deleteKey. */ + public deleteKey?: (Action.IDeleteKey|null); -/** Properties of a FunctionCallTransaction. */ -export interface IFunctionCallTransaction { + /** Action deleteAccount. */ + public deleteAccount?: (Action.IDeleteAccount|null); - /** FunctionCallTransaction nonce */ - nonce?: (number|Long|null); - - /** FunctionCallTransaction originator */ - originator?: (string|null); - - /** FunctionCallTransaction contractId */ - contractId?: (string|null); - - /** FunctionCallTransaction methodName */ - methodName?: (Uint8Array|null); - - /** FunctionCallTransaction args */ - args?: (Uint8Array|null); - - /** FunctionCallTransaction amount */ - amount?: (IUint128|null); -} - -/** Represents a FunctionCallTransaction. */ -export class FunctionCallTransaction implements IFunctionCallTransaction { + /** Action action. */ + public action?: ("createAccount"|"deployContract"|"functionCall"|"transfer"|"stake"|"addKey"|"deleteKey"|"deleteAccount"); /** - * Constructs a new FunctionCallTransaction. + * Creates a new Action instance using the specified properties. * @param [properties] Properties to set + * @returns Action instance */ - constructor(properties?: IFunctionCallTransaction); - - /** FunctionCallTransaction nonce. */ - public nonce: (number|Long); - - /** FunctionCallTransaction originator. */ - public originator: string; - - /** FunctionCallTransaction contractId. */ - public contractId: string; - - /** FunctionCallTransaction methodName. */ - public methodName: Uint8Array; - - /** FunctionCallTransaction args. */ - public args: Uint8Array; - - /** FunctionCallTransaction amount. */ - public amount?: (IUint128|null); - - /** - * Creates a new FunctionCallTransaction instance using the specified properties. - * @param [properties] Properties to set - * @returns FunctionCallTransaction instance - */ - public static create(properties?: IFunctionCallTransaction): FunctionCallTransaction; + public static create(properties?: IAction): Action; /** - * Encodes the specified FunctionCallTransaction message. Does not implicitly {@link FunctionCallTransaction.verify|verify} messages. - * @param message FunctionCallTransaction message or plain object to encode + * Encodes the specified Action message. Does not implicitly {@link Action.verify|verify} messages. + * @param message Action message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encode(message: IFunctionCallTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + public static encode(message: IAction, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Encodes the specified FunctionCallTransaction message, length delimited. Does not implicitly {@link FunctionCallTransaction.verify|verify} messages. - * @param message FunctionCallTransaction message or plain object to encode + * Encodes the specified Action message, length delimited. Does not implicitly {@link Action.verify|verify} messages. + * @param message Action message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encodeDelimited(message: IFunctionCallTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + public static encodeDelimited(message: IAction, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Decodes a FunctionCallTransaction message from the specified reader or buffer. + * Decodes an Action message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand - * @returns FunctionCallTransaction + * @returns Action * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): FunctionCallTransaction; + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action; /** - * Decodes a FunctionCallTransaction message from the specified reader or buffer, length delimited. + * Decodes an Action message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from - * @returns FunctionCallTransaction + * @returns Action * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): FunctionCallTransaction; + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action; /** - * Verifies a FunctionCallTransaction message. + * Verifies an Action message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** - * Creates a FunctionCallTransaction message from a plain object. Also converts values to their respective internal types. + * Creates an Action message from a plain object. Also converts values to their respective internal types. * @param object Plain object - * @returns FunctionCallTransaction + * @returns Action */ - public static fromObject(object: { [k: string]: any }): FunctionCallTransaction; + public static fromObject(object: { [k: string]: any }): Action; /** - * Creates a plain object from a FunctionCallTransaction message. Also converts values to other types if specified. - * @param message FunctionCallTransaction + * Creates a plain object from an Action message. Also converts values to other types if specified. + * @param message Action * @param [options] Conversion options * @returns Plain object */ - public static toObject(message: FunctionCallTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; + public static toObject(message: Action, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** - * Converts this FunctionCallTransaction to JSON. + * Converts this Action to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } -/** Properties of a SendMoneyTransaction. */ -export interface ISendMoneyTransaction { - - /** SendMoneyTransaction nonce */ - nonce?: (number|Long|null); - - /** SendMoneyTransaction originator */ - originator?: (string|null); - - /** SendMoneyTransaction receiver */ - receiver?: (string|null); - - /** SendMoneyTransaction amount */ - amount?: (IUint128|null); -} - -/** Represents a SendMoneyTransaction. */ -export class SendMoneyTransaction implements ISendMoneyTransaction { +export namespace Action { - /** - * Constructs a new SendMoneyTransaction. - * @param [properties] Properties to set - */ - constructor(properties?: ISendMoneyTransaction); - - /** SendMoneyTransaction nonce. */ - public nonce: (number|Long); - - /** SendMoneyTransaction originator. */ - public originator: string; - - /** SendMoneyTransaction receiver. */ - public receiver: string; - - /** SendMoneyTransaction amount. */ - public amount?: (IUint128|null); - - /** - * Creates a new SendMoneyTransaction instance using the specified properties. - * @param [properties] Properties to set - * @returns SendMoneyTransaction instance - */ - public static create(properties?: ISendMoneyTransaction): SendMoneyTransaction; - - /** - * Encodes the specified SendMoneyTransaction message. Does not implicitly {@link SendMoneyTransaction.verify|verify} messages. - * @param message SendMoneyTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: ISendMoneyTransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified SendMoneyTransaction message, length delimited. Does not implicitly {@link SendMoneyTransaction.verify|verify} messages. - * @param message SendMoneyTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: ISendMoneyTransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a SendMoneyTransaction message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns SendMoneyTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): SendMoneyTransaction; - - /** - * Decodes a SendMoneyTransaction message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns SendMoneyTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): SendMoneyTransaction; - - /** - * Verifies a SendMoneyTransaction message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a SendMoneyTransaction message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns SendMoneyTransaction - */ - public static fromObject(object: { [k: string]: any }): SendMoneyTransaction; - - /** - * Creates a plain object from a SendMoneyTransaction message. Also converts values to other types if specified. - * @param message SendMoneyTransaction - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: SendMoneyTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this SendMoneyTransaction to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} + /** Properties of a CreateAccount. */ + interface ICreateAccount { + } -/** Properties of a StakeTransaction. */ -export interface IStakeTransaction { + /** Represents a CreateAccount. */ + class CreateAccount implements ICreateAccount { + + /** + * Constructs a new CreateAccount. + * @param [properties] Properties to set + */ + constructor(properties?: Action.ICreateAccount); + + /** + * Creates a new CreateAccount instance using the specified properties. + * @param [properties] Properties to set + * @returns CreateAccount instance + */ + public static create(properties?: Action.ICreateAccount): Action.CreateAccount; + + /** + * Encodes the specified CreateAccount message. Does not implicitly {@link Action.CreateAccount.verify|verify} messages. + * @param message CreateAccount message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: Action.ICreateAccount, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified CreateAccount message, length delimited. Does not implicitly {@link Action.CreateAccount.verify|verify} messages. + * @param message CreateAccount message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: Action.ICreateAccount, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a CreateAccount message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns CreateAccount + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.CreateAccount; + + /** + * Decodes a CreateAccount message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns CreateAccount + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.CreateAccount; + + /** + * Verifies a CreateAccount message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a CreateAccount message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns CreateAccount + */ + public static fromObject(object: { [k: string]: any }): Action.CreateAccount; + + /** + * Creates a plain object from a CreateAccount message. Also converts values to other types if specified. + * @param message CreateAccount + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: Action.CreateAccount, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this CreateAccount to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } - /** StakeTransaction nonce */ - nonce?: (number|Long|null); + /** Properties of a DeployContract. */ + interface IDeployContract { - /** StakeTransaction originator */ - originator?: (string|null); + /** DeployContract code */ + code?: (Uint8Array|null); + } - /** StakeTransaction amount */ - amount?: (IUint128|null); + /** Represents a DeployContract. */ + class DeployContract implements IDeployContract { + + /** + * Constructs a new DeployContract. + * @param [properties] Properties to set + */ + constructor(properties?: Action.IDeployContract); + + /** DeployContract code. */ + public code: Uint8Array; + + /** + * Creates a new DeployContract instance using the specified properties. + * @param [properties] Properties to set + * @returns DeployContract instance + */ + public static create(properties?: Action.IDeployContract): Action.DeployContract; + + /** + * Encodes the specified DeployContract message. Does not implicitly {@link Action.DeployContract.verify|verify} messages. + * @param message DeployContract message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: Action.IDeployContract, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified DeployContract message, length delimited. Does not implicitly {@link Action.DeployContract.verify|verify} messages. + * @param message DeployContract message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: Action.IDeployContract, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a DeployContract message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns DeployContract + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.DeployContract; + + /** + * Decodes a DeployContract message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns DeployContract + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.DeployContract; + + /** + * Verifies a DeployContract message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a DeployContract message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns DeployContract + */ + public static fromObject(object: { [k: string]: any }): Action.DeployContract; + + /** + * Creates a plain object from a DeployContract message. Also converts values to other types if specified. + * @param message DeployContract + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: Action.DeployContract, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this DeployContract to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } - /** StakeTransaction publicKey */ - publicKey?: (string|null); + /** Properties of a FunctionCall. */ + interface IFunctionCall { - /** StakeTransaction blsPublicKey */ - blsPublicKey?: (string|null); -} + /** FunctionCall methodName */ + methodName?: (string|null); -/** Represents a StakeTransaction. */ -export class StakeTransaction implements IStakeTransaction { + /** FunctionCall args */ + args?: (Uint8Array|null); - /** - * Constructs a new StakeTransaction. - * @param [properties] Properties to set - */ - constructor(properties?: IStakeTransaction); + /** FunctionCall gas */ + gas?: (number|Long|null); - /** StakeTransaction nonce. */ - public nonce: (number|Long); + /** FunctionCall deposit */ + deposit?: (IUint128|null); + } - /** StakeTransaction originator. */ - public originator: string; + /** Represents a FunctionCall. */ + class FunctionCall implements IFunctionCall { + + /** + * Constructs a new FunctionCall. + * @param [properties] Properties to set + */ + constructor(properties?: Action.IFunctionCall); + + /** FunctionCall methodName. */ + public methodName: string; + + /** FunctionCall args. */ + public args: Uint8Array; + + /** FunctionCall gas. */ + public gas: (number|Long); + + /** FunctionCall deposit. */ + public deposit?: (IUint128|null); + + /** + * Creates a new FunctionCall instance using the specified properties. + * @param [properties] Properties to set + * @returns FunctionCall instance + */ + public static create(properties?: Action.IFunctionCall): Action.FunctionCall; + + /** + * Encodes the specified FunctionCall message. Does not implicitly {@link Action.FunctionCall.verify|verify} messages. + * @param message FunctionCall message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: Action.IFunctionCall, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified FunctionCall message, length delimited. Does not implicitly {@link Action.FunctionCall.verify|verify} messages. + * @param message FunctionCall message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: Action.IFunctionCall, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a FunctionCall message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns FunctionCall + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.FunctionCall; + + /** + * Decodes a FunctionCall message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns FunctionCall + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.FunctionCall; + + /** + * Verifies a FunctionCall message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a FunctionCall message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns FunctionCall + */ + public static fromObject(object: { [k: string]: any }): Action.FunctionCall; + + /** + * Creates a plain object from a FunctionCall message. Also converts values to other types if specified. + * @param message FunctionCall + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: Action.FunctionCall, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this FunctionCall to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } - /** StakeTransaction amount. */ - public amount?: (IUint128|null); + /** Properties of a Transfer. */ + interface ITransfer { - /** StakeTransaction publicKey. */ - public publicKey: string; + /** Transfer deposit */ + deposit?: (IUint128|null); + } - /** StakeTransaction blsPublicKey. */ - public blsPublicKey: string; + /** Represents a Transfer. */ + class Transfer implements ITransfer { + + /** + * Constructs a new Transfer. + * @param [properties] Properties to set + */ + constructor(properties?: Action.ITransfer); + + /** Transfer deposit. */ + public deposit?: (IUint128|null); + + /** + * Creates a new Transfer instance using the specified properties. + * @param [properties] Properties to set + * @returns Transfer instance + */ + public static create(properties?: Action.ITransfer): Action.Transfer; + + /** + * Encodes the specified Transfer message. Does not implicitly {@link Action.Transfer.verify|verify} messages. + * @param message Transfer message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: Action.ITransfer, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified Transfer message, length delimited. Does not implicitly {@link Action.Transfer.verify|verify} messages. + * @param message Transfer message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: Action.ITransfer, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Transfer message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns Transfer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.Transfer; + + /** + * Decodes a Transfer message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns Transfer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.Transfer; + + /** + * Verifies a Transfer message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a Transfer message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns Transfer + */ + public static fromObject(object: { [k: string]: any }): Action.Transfer; + + /** + * Creates a plain object from a Transfer message. Also converts values to other types if specified. + * @param message Transfer + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: Action.Transfer, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Transfer to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } - /** - * Creates a new StakeTransaction instance using the specified properties. - * @param [properties] Properties to set - * @returns StakeTransaction instance - */ - public static create(properties?: IStakeTransaction): StakeTransaction; + /** Properties of a Stake. */ + interface IStake { - /** - * Encodes the specified StakeTransaction message. Does not implicitly {@link StakeTransaction.verify|verify} messages. - * @param message StakeTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: IStakeTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + /** Stake stake */ + stake?: (IUint128|null); - /** - * Encodes the specified StakeTransaction message, length delimited. Does not implicitly {@link StakeTransaction.verify|verify} messages. - * @param message StakeTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: IStakeTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + /** Stake publicKey */ + publicKey?: (IPublicKey|null); + } - /** - * Decodes a StakeTransaction message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns StakeTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): StakeTransaction; + /** Represents a Stake. */ + class Stake implements IStake { + + /** + * Constructs a new Stake. + * @param [properties] Properties to set + */ + constructor(properties?: Action.IStake); + + /** Stake stake. */ + public stake?: (IUint128|null); + + /** Stake publicKey. */ + public publicKey?: (IPublicKey|null); + + /** + * Creates a new Stake instance using the specified properties. + * @param [properties] Properties to set + * @returns Stake instance + */ + public static create(properties?: Action.IStake): Action.Stake; + + /** + * Encodes the specified Stake message. Does not implicitly {@link Action.Stake.verify|verify} messages. + * @param message Stake message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: Action.IStake, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified Stake message, length delimited. Does not implicitly {@link Action.Stake.verify|verify} messages. + * @param message Stake message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: Action.IStake, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Stake message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns Stake + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.Stake; + + /** + * Decodes a Stake message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns Stake + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.Stake; + + /** + * Verifies a Stake message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a Stake message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns Stake + */ + public static fromObject(object: { [k: string]: any }): Action.Stake; + + /** + * Creates a plain object from a Stake message. Also converts values to other types if specified. + * @param message Stake + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: Action.Stake, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Stake to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } - /** - * Decodes a StakeTransaction message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns StakeTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): StakeTransaction; + /** Properties of an AddKey. */ + interface IAddKey { - /** - * Verifies a StakeTransaction message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); + /** AddKey publicKey */ + publicKey?: (IPublicKey|null); - /** - * Creates a StakeTransaction message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns StakeTransaction - */ - public static fromObject(object: { [k: string]: any }): StakeTransaction; + /** AddKey accessKey */ + accessKey?: (IAccessKey|null); + } - /** - * Creates a plain object from a StakeTransaction message. Also converts values to other types if specified. - * @param message StakeTransaction - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: StakeTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; + /** Represents an AddKey. */ + class AddKey implements IAddKey { + + /** + * Constructs a new AddKey. + * @param [properties] Properties to set + */ + constructor(properties?: Action.IAddKey); + + /** AddKey publicKey. */ + public publicKey?: (IPublicKey|null); + + /** AddKey accessKey. */ + public accessKey?: (IAccessKey|null); + + /** + * Creates a new AddKey instance using the specified properties. + * @param [properties] Properties to set + * @returns AddKey instance + */ + public static create(properties?: Action.IAddKey): Action.AddKey; + + /** + * Encodes the specified AddKey message. Does not implicitly {@link Action.AddKey.verify|verify} messages. + * @param message AddKey message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: Action.IAddKey, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified AddKey message, length delimited. Does not implicitly {@link Action.AddKey.verify|verify} messages. + * @param message AddKey message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: Action.IAddKey, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an AddKey message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns AddKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.AddKey; + + /** + * Decodes an AddKey message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns AddKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.AddKey; + + /** + * Verifies an AddKey message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates an AddKey message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns AddKey + */ + public static fromObject(object: { [k: string]: any }): Action.AddKey; + + /** + * Creates a plain object from an AddKey message. Also converts values to other types if specified. + * @param message AddKey + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: Action.AddKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this AddKey to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } - /** - * Converts this StakeTransaction to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} + /** Properties of a DeleteKey. */ + interface IDeleteKey { -/** Properties of a SwapKeyTransaction. */ -export interface ISwapKeyTransaction { + /** DeleteKey publicKey */ + publicKey?: (IPublicKey|null); + } - /** SwapKeyTransaction nonce */ - nonce?: (number|Long|null); + /** Represents a DeleteKey. */ + class DeleteKey implements IDeleteKey { + + /** + * Constructs a new DeleteKey. + * @param [properties] Properties to set + */ + constructor(properties?: Action.IDeleteKey); + + /** DeleteKey publicKey. */ + public publicKey?: (IPublicKey|null); + + /** + * Creates a new DeleteKey instance using the specified properties. + * @param [properties] Properties to set + * @returns DeleteKey instance + */ + public static create(properties?: Action.IDeleteKey): Action.DeleteKey; + + /** + * Encodes the specified DeleteKey message. Does not implicitly {@link Action.DeleteKey.verify|verify} messages. + * @param message DeleteKey message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: Action.IDeleteKey, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified DeleteKey message, length delimited. Does not implicitly {@link Action.DeleteKey.verify|verify} messages. + * @param message DeleteKey message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: Action.IDeleteKey, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a DeleteKey message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns DeleteKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.DeleteKey; + + /** + * Decodes a DeleteKey message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns DeleteKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.DeleteKey; + + /** + * Verifies a DeleteKey message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a DeleteKey message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns DeleteKey + */ + public static fromObject(object: { [k: string]: any }): Action.DeleteKey; + + /** + * Creates a plain object from a DeleteKey message. Also converts values to other types if specified. + * @param message DeleteKey + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: Action.DeleteKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this DeleteKey to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } - /** SwapKeyTransaction originator */ - originator?: (string|null); + /** Properties of a DeleteAccount. */ + interface IDeleteAccount { - /** SwapKeyTransaction curKey */ - curKey?: (Uint8Array|null); + /** DeleteAccount beneficiaryId */ + beneficiaryId?: (string|null); + } - /** SwapKeyTransaction newKey */ - newKey?: (Uint8Array|null); + /** Represents a DeleteAccount. */ + class DeleteAccount implements IDeleteAccount { + + /** + * Constructs a new DeleteAccount. + * @param [properties] Properties to set + */ + constructor(properties?: Action.IDeleteAccount); + + /** DeleteAccount beneficiaryId. */ + public beneficiaryId: string; + + /** + * Creates a new DeleteAccount instance using the specified properties. + * @param [properties] Properties to set + * @returns DeleteAccount instance + */ + public static create(properties?: Action.IDeleteAccount): Action.DeleteAccount; + + /** + * Encodes the specified DeleteAccount message. Does not implicitly {@link Action.DeleteAccount.verify|verify} messages. + * @param message DeleteAccount message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: Action.IDeleteAccount, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified DeleteAccount message, length delimited. Does not implicitly {@link Action.DeleteAccount.verify|verify} messages. + * @param message DeleteAccount message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: Action.IDeleteAccount, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a DeleteAccount message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns DeleteAccount + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.DeleteAccount; + + /** + * Decodes a DeleteAccount message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns DeleteAccount + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.DeleteAccount; + + /** + * Verifies a DeleteAccount message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a DeleteAccount message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns DeleteAccount + */ + public static fromObject(object: { [k: string]: any }): Action.DeleteAccount; + + /** + * Creates a plain object from a DeleteAccount message. Also converts values to other types if specified. + * @param message DeleteAccount + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: Action.DeleteAccount, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this DeleteAccount to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } } -/** Represents a SwapKeyTransaction. */ -export class SwapKeyTransaction implements ISwapKeyTransaction { - - /** - * Constructs a new SwapKeyTransaction. - * @param [properties] Properties to set - */ - constructor(properties?: ISwapKeyTransaction); - - /** SwapKeyTransaction nonce. */ - public nonce: (number|Long); - - /** SwapKeyTransaction originator. */ - public originator: string; - - /** SwapKeyTransaction curKey. */ - public curKey: Uint8Array; - - /** SwapKeyTransaction newKey. */ - public newKey: Uint8Array; - - /** - * Creates a new SwapKeyTransaction instance using the specified properties. - * @param [properties] Properties to set - * @returns SwapKeyTransaction instance - */ - public static create(properties?: ISwapKeyTransaction): SwapKeyTransaction; - - /** - * Encodes the specified SwapKeyTransaction message. Does not implicitly {@link SwapKeyTransaction.verify|verify} messages. - * @param message SwapKeyTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: ISwapKeyTransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified SwapKeyTransaction message, length delimited. Does not implicitly {@link SwapKeyTransaction.verify|verify} messages. - * @param message SwapKeyTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: ISwapKeyTransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a SwapKeyTransaction message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns SwapKeyTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): SwapKeyTransaction; - - /** - * Decodes a SwapKeyTransaction message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns SwapKeyTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): SwapKeyTransaction; - - /** - * Verifies a SwapKeyTransaction message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a SwapKeyTransaction message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns SwapKeyTransaction - */ - public static fromObject(object: { [k: string]: any }): SwapKeyTransaction; - - /** - * Creates a plain object from a SwapKeyTransaction message. Also converts values to other types if specified. - * @param message SwapKeyTransaction - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: SwapKeyTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this SwapKeyTransaction to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} +/** Properties of a Transaction. */ +export interface ITransaction { -/** Properties of an AddKeyTransaction. */ -export interface IAddKeyTransaction { + /** Transaction signerId */ + signerId?: (string|null); - /** AddKeyTransaction nonce */ - nonce?: (number|Long|null); + /** Transaction publicKey */ + publicKey?: (IPublicKey|null); - /** AddKeyTransaction originator */ - originator?: (string|null); + /** Transaction nonce */ + nonce?: (number|Long|null); - /** AddKeyTransaction newKey */ - newKey?: (Uint8Array|null); + /** Transaction receiverId */ + receiverId?: (string|null); - /** AddKeyTransaction accessKey */ - accessKey?: (IAccessKey|null); + /** Transaction actions */ + actions?: (IAction[]|null); } -/** Represents an AddKeyTransaction. */ -export class AddKeyTransaction implements IAddKeyTransaction { +/** Represents a Transaction. */ +export class Transaction implements ITransaction { /** - * Constructs a new AddKeyTransaction. + * Constructs a new Transaction. * @param [properties] Properties to set */ - constructor(properties?: IAddKeyTransaction); + constructor(properties?: ITransaction); - /** AddKeyTransaction nonce. */ - public nonce: (number|Long); + /** Transaction signerId. */ + public signerId: string; + + /** Transaction publicKey. */ + public publicKey?: (IPublicKey|null); - /** AddKeyTransaction originator. */ - public originator: string; + /** Transaction nonce. */ + public nonce: (number|Long); - /** AddKeyTransaction newKey. */ - public newKey: Uint8Array; + /** Transaction receiverId. */ + public receiverId: string; - /** AddKeyTransaction accessKey. */ - public accessKey?: (IAccessKey|null); + /** Transaction actions. */ + public actions: IAction[]; /** - * Creates a new AddKeyTransaction instance using the specified properties. + * Creates a new Transaction instance using the specified properties. * @param [properties] Properties to set - * @returns AddKeyTransaction instance + * @returns Transaction instance */ - public static create(properties?: IAddKeyTransaction): AddKeyTransaction; + public static create(properties?: ITransaction): Transaction; /** - * Encodes the specified AddKeyTransaction message. Does not implicitly {@link AddKeyTransaction.verify|verify} messages. - * @param message AddKeyTransaction message or plain object to encode + * Encodes the specified Transaction message. Does not implicitly {@link Transaction.verify|verify} messages. + * @param message Transaction message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encode(message: IAddKeyTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + public static encode(message: ITransaction, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Encodes the specified AddKeyTransaction message, length delimited. Does not implicitly {@link AddKeyTransaction.verify|verify} messages. - * @param message AddKeyTransaction message or plain object to encode + * Encodes the specified Transaction message, length delimited. Does not implicitly {@link Transaction.verify|verify} messages. + * @param message Transaction message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encodeDelimited(message: IAddKeyTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + public static encodeDelimited(message: ITransaction, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Decodes an AddKeyTransaction message from the specified reader or buffer. + * Decodes a Transaction message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand - * @returns AddKeyTransaction + * @returns Transaction * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): AddKeyTransaction; + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Transaction; /** - * Decodes an AddKeyTransaction message from the specified reader or buffer, length delimited. + * Decodes a Transaction message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from - * @returns AddKeyTransaction + * @returns Transaction * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): AddKeyTransaction; + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Transaction; /** - * Verifies an AddKeyTransaction message. + * Verifies a Transaction message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** - * Creates an AddKeyTransaction message from a plain object. Also converts values to their respective internal types. + * Creates a Transaction message from a plain object. Also converts values to their respective internal types. * @param object Plain object - * @returns AddKeyTransaction + * @returns Transaction */ - public static fromObject(object: { [k: string]: any }): AddKeyTransaction; + public static fromObject(object: { [k: string]: any }): Transaction; /** - * Creates a plain object from an AddKeyTransaction message. Also converts values to other types if specified. - * @param message AddKeyTransaction + * Creates a plain object from a Transaction message. Also converts values to other types if specified. + * @param message Transaction * @param [options] Conversion options * @returns Plain object */ - public static toObject(message: AddKeyTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; + public static toObject(message: Transaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** - * Converts this AddKeyTransaction to JSON. + * Converts this Transaction to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } -/** Properties of a DeleteKeyTransaction. */ -export interface IDeleteKeyTransaction { - - /** DeleteKeyTransaction nonce */ - nonce?: (number|Long|null); +/** Properties of a SignedTransaction. */ +export interface ISignedTransaction { - /** DeleteKeyTransaction originator */ - originator?: (string|null); + /** SignedTransaction signature */ + signature?: (Uint8Array|null); - /** DeleteKeyTransaction curKey */ - curKey?: (Uint8Array|null); + /** SignedTransaction transaction */ + transaction?: (ITransaction|null); } -/** Represents a DeleteKeyTransaction. */ -export class DeleteKeyTransaction implements IDeleteKeyTransaction { +/** Represents a SignedTransaction. */ +export class SignedTransaction implements ISignedTransaction { /** - * Constructs a new DeleteKeyTransaction. + * Constructs a new SignedTransaction. * @param [properties] Properties to set */ - constructor(properties?: IDeleteKeyTransaction); - - /** DeleteKeyTransaction nonce. */ - public nonce: (number|Long); + constructor(properties?: ISignedTransaction); - /** DeleteKeyTransaction originator. */ - public originator: string; + /** SignedTransaction signature. */ + public signature: Uint8Array; - /** DeleteKeyTransaction curKey. */ - public curKey: Uint8Array; + /** SignedTransaction transaction. */ + public transaction?: (ITransaction|null); /** - * Creates a new DeleteKeyTransaction instance using the specified properties. + * Creates a new SignedTransaction instance using the specified properties. * @param [properties] Properties to set - * @returns DeleteKeyTransaction instance + * @returns SignedTransaction instance */ - public static create(properties?: IDeleteKeyTransaction): DeleteKeyTransaction; + public static create(properties?: ISignedTransaction): SignedTransaction; /** - * Encodes the specified DeleteKeyTransaction message. Does not implicitly {@link DeleteKeyTransaction.verify|verify} messages. - * @param message DeleteKeyTransaction message or plain object to encode + * Encodes the specified SignedTransaction message. Does not implicitly {@link SignedTransaction.verify|verify} messages. + * @param message SignedTransaction message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encode(message: IDeleteKeyTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + public static encode(message: ISignedTransaction, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Encodes the specified DeleteKeyTransaction message, length delimited. Does not implicitly {@link DeleteKeyTransaction.verify|verify} messages. - * @param message DeleteKeyTransaction message or plain object to encode + * Encodes the specified SignedTransaction message, length delimited. Does not implicitly {@link SignedTransaction.verify|verify} messages. + * @param message SignedTransaction message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encodeDelimited(message: IDeleteKeyTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + public static encodeDelimited(message: ISignedTransaction, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Decodes a DeleteKeyTransaction message from the specified reader or buffer. + * Decodes a SignedTransaction message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand - * @returns DeleteKeyTransaction + * @returns SignedTransaction * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): DeleteKeyTransaction; + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): SignedTransaction; /** - * Decodes a DeleteKeyTransaction message from the specified reader or buffer, length delimited. + * Decodes a SignedTransaction message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from - * @returns DeleteKeyTransaction + * @returns SignedTransaction * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): DeleteKeyTransaction; + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): SignedTransaction; /** - * Verifies a DeleteKeyTransaction message. + * Verifies a SignedTransaction message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** - * Creates a DeleteKeyTransaction message from a plain object. Also converts values to their respective internal types. + * Creates a SignedTransaction message from a plain object. Also converts values to their respective internal types. * @param object Plain object - * @returns DeleteKeyTransaction + * @returns SignedTransaction */ - public static fromObject(object: { [k: string]: any }): DeleteKeyTransaction; + public static fromObject(object: { [k: string]: any }): SignedTransaction; /** - * Creates a plain object from a DeleteKeyTransaction message. Also converts values to other types if specified. - * @param message DeleteKeyTransaction + * Creates a plain object from a SignedTransaction message. Also converts values to other types if specified. + * @param message SignedTransaction * @param [options] Conversion options * @returns Plain object */ - public static toObject(message: DeleteKeyTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; + public static toObject(message: SignedTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** - * Converts this DeleteKeyTransaction to JSON. + * Converts this SignedTransaction to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } -/** Properties of a SignedTransaction. */ -export interface ISignedTransaction { - - /** SignedTransaction signature */ - signature?: (Uint8Array|null); - - /** SignedTransaction publicKey */ - publicKey?: (google.protobuf.IBytesValue|null); - - /** SignedTransaction createAccount */ - createAccount?: (ICreateAccountTransaction|null); - - /** SignedTransaction deployContract */ - deployContract?: (IDeployContractTransaction|null); - - /** SignedTransaction functionCall */ - functionCall?: (IFunctionCallTransaction|null); - - /** SignedTransaction sendMoney */ - sendMoney?: (ISendMoneyTransaction|null); +/** Properties of an AccessKey. */ +export interface IAccessKey { - /** SignedTransaction stake */ - stake?: (IStakeTransaction|null); + /** AccessKey amount */ + amount?: (IUint128|null); - /** SignedTransaction swapKey */ - swapKey?: (ISwapKeyTransaction|null); + /** AccessKey balanceOwner */ + balanceOwner?: (google.protobuf.IStringValue|null); - /** SignedTransaction addKey */ - addKey?: (IAddKeyTransaction|null); + /** AccessKey contractId */ + contractId?: (google.protobuf.IStringValue|null); - /** SignedTransaction deleteKey */ - deleteKey?: (IDeleteKeyTransaction|null); + /** AccessKey methodName */ + methodName?: (google.protobuf.IBytesValue|null); } -/** Represents a SignedTransaction. */ -export class SignedTransaction implements ISignedTransaction { +/** Represents an AccessKey. */ +export class AccessKey implements IAccessKey { /** - * Constructs a new SignedTransaction. + * Constructs a new AccessKey. * @param [properties] Properties to set */ - constructor(properties?: ISignedTransaction); - - /** SignedTransaction signature. */ - public signature: Uint8Array; - - /** SignedTransaction publicKey. */ - public publicKey?: (google.protobuf.IBytesValue|null); - - /** SignedTransaction createAccount. */ - public createAccount?: (ICreateAccountTransaction|null); - - /** SignedTransaction deployContract. */ - public deployContract?: (IDeployContractTransaction|null); - - /** SignedTransaction functionCall. */ - public functionCall?: (IFunctionCallTransaction|null); - - /** SignedTransaction sendMoney. */ - public sendMoney?: (ISendMoneyTransaction|null); - - /** SignedTransaction stake. */ - public stake?: (IStakeTransaction|null); + constructor(properties?: IAccessKey); - /** SignedTransaction swapKey. */ - public swapKey?: (ISwapKeyTransaction|null); + /** AccessKey amount. */ + public amount?: (IUint128|null); - /** SignedTransaction addKey. */ - public addKey?: (IAddKeyTransaction|null); + /** AccessKey balanceOwner. */ + public balanceOwner?: (google.protobuf.IStringValue|null); - /** SignedTransaction deleteKey. */ - public deleteKey?: (IDeleteKeyTransaction|null); + /** AccessKey contractId. */ + public contractId?: (google.protobuf.IStringValue|null); - /** SignedTransaction body. */ - public body?: ("createAccount"|"deployContract"|"functionCall"|"sendMoney"|"stake"|"swapKey"|"addKey"|"deleteKey"); + /** AccessKey methodName. */ + public methodName?: (google.protobuf.IBytesValue|null); /** - * Creates a new SignedTransaction instance using the specified properties. + * Creates a new AccessKey instance using the specified properties. * @param [properties] Properties to set - * @returns SignedTransaction instance + * @returns AccessKey instance */ - public static create(properties?: ISignedTransaction): SignedTransaction; + public static create(properties?: IAccessKey): AccessKey; /** - * Encodes the specified SignedTransaction message. Does not implicitly {@link SignedTransaction.verify|verify} messages. - * @param message SignedTransaction message or plain object to encode + * Encodes the specified AccessKey message. Does not implicitly {@link AccessKey.verify|verify} messages. + * @param message AccessKey message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encode(message: ISignedTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + public static encode(message: IAccessKey, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Encodes the specified SignedTransaction message, length delimited. Does not implicitly {@link SignedTransaction.verify|verify} messages. - * @param message SignedTransaction message or plain object to encode + * Encodes the specified AccessKey message, length delimited. Does not implicitly {@link AccessKey.verify|verify} messages. + * @param message AccessKey message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encodeDelimited(message: ISignedTransaction, writer?: $protobuf.Writer): $protobuf.Writer; + public static encodeDelimited(message: IAccessKey, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Decodes a SignedTransaction message from the specified reader or buffer. + * Decodes an AccessKey message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand - * @returns SignedTransaction + * @returns AccessKey * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): SignedTransaction; + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): AccessKey; /** - * Decodes a SignedTransaction message from the specified reader or buffer, length delimited. + * Decodes an AccessKey message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from - * @returns SignedTransaction + * @returns AccessKey * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): SignedTransaction; + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): AccessKey; /** - * Verifies a SignedTransaction message. + * Verifies an AccessKey message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** - * Creates a SignedTransaction message from a plain object. Also converts values to their respective internal types. + * Creates an AccessKey message from a plain object. Also converts values to their respective internal types. * @param object Plain object - * @returns SignedTransaction + * @returns AccessKey */ - public static fromObject(object: { [k: string]: any }): SignedTransaction; + public static fromObject(object: { [k: string]: any }): AccessKey; /** - * Creates a plain object from a SignedTransaction message. Also converts values to other types if specified. - * @param message SignedTransaction + * Creates a plain object from an AccessKey message. Also converts values to other types if specified. + * @param message AccessKey * @param [options] Conversion options * @returns Plain object */ - public static toObject(message: SignedTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; + public static toObject(message: AccessKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** - * Converts this SignedTransaction to JSON. + * Converts this AccessKey to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; @@ -1840,200 +2017,196 @@ export namespace google { } } -/** Properties of an AccessKey. */ -export interface IAccessKey { - - /** AccessKey amount */ - amount?: (IUint128|null); - - /** AccessKey balanceOwner */ - balanceOwner?: (google.protobuf.IStringValue|null); - - /** AccessKey contractId */ - contractId?: (google.protobuf.IStringValue|null); +/** Properties of an Uint128. */ +export interface IUint128 { - /** AccessKey methodName */ - methodName?: (google.protobuf.IBytesValue|null); + /** Uint128 number */ + number?: (Uint8Array|null); } -/** Represents an AccessKey. */ -export class AccessKey implements IAccessKey { +/** Provides container for unsigned 128 bit integers. */ +export class Uint128 implements IUint128 { /** - * Constructs a new AccessKey. + * Constructs a new Uint128. * @param [properties] Properties to set */ - constructor(properties?: IAccessKey); - - /** AccessKey amount. */ - public amount?: (IUint128|null); - - /** AccessKey balanceOwner. */ - public balanceOwner?: (google.protobuf.IStringValue|null); - - /** AccessKey contractId. */ - public contractId?: (google.protobuf.IStringValue|null); + constructor(properties?: IUint128); - /** AccessKey methodName. */ - public methodName?: (google.protobuf.IBytesValue|null); + /** Uint128 number. */ + public number: Uint8Array; /** - * Creates a new AccessKey instance using the specified properties. + * Creates a new Uint128 instance using the specified properties. * @param [properties] Properties to set - * @returns AccessKey instance + * @returns Uint128 instance */ - public static create(properties?: IAccessKey): AccessKey; + public static create(properties?: IUint128): Uint128; /** - * Encodes the specified AccessKey message. Does not implicitly {@link AccessKey.verify|verify} messages. - * @param message AccessKey message or plain object to encode + * Encodes the specified Uint128 message. Does not implicitly {@link Uint128.verify|verify} messages. + * @param message Uint128 message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encode(message: IAccessKey, writer?: $protobuf.Writer): $protobuf.Writer; + public static encode(message: IUint128, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Encodes the specified AccessKey message, length delimited. Does not implicitly {@link AccessKey.verify|verify} messages. - * @param message AccessKey message or plain object to encode + * Encodes the specified Uint128 message, length delimited. Does not implicitly {@link Uint128.verify|verify} messages. + * @param message Uint128 message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encodeDelimited(message: IAccessKey, writer?: $protobuf.Writer): $protobuf.Writer; + public static encodeDelimited(message: IUint128, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Decodes an AccessKey message from the specified reader or buffer. + * Decodes an Uint128 message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand - * @returns AccessKey + * @returns Uint128 * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): AccessKey; + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Uint128; /** - * Decodes an AccessKey message from the specified reader or buffer, length delimited. + * Decodes an Uint128 message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from - * @returns AccessKey + * @returns Uint128 * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): AccessKey; + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Uint128; /** - * Verifies an AccessKey message. + * Verifies an Uint128 message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** - * Creates an AccessKey message from a plain object. Also converts values to their respective internal types. + * Creates an Uint128 message from a plain object. Also converts values to their respective internal types. * @param object Plain object - * @returns AccessKey + * @returns Uint128 */ - public static fromObject(object: { [k: string]: any }): AccessKey; + public static fromObject(object: { [k: string]: any }): Uint128; /** - * Creates a plain object from an AccessKey message. Also converts values to other types if specified. - * @param message AccessKey + * Creates a plain object from an Uint128 message. Also converts values to other types if specified. + * @param message Uint128 * @param [options] Conversion options * @returns Plain object */ - public static toObject(message: AccessKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; + public static toObject(message: Uint128, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** - * Converts this AccessKey to JSON. + * Converts this Uint128 to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } -/** Properties of an Uint128. */ -export interface IUint128 { +/** Properties of a PublicKey. */ +export interface IPublicKey { - /** Uint128 number */ - number?: (Uint8Array|null); + /** PublicKey keyType */ + keyType?: (PublicKey.KeyType|null); + + /** PublicKey data */ + data?: (Uint8Array|null); } -/** Provides container for unsigned 128 bit integers. */ -export class Uint128 implements IUint128 { +/** Represents a PublicKey. */ +export class PublicKey implements IPublicKey { /** - * Constructs a new Uint128. + * Constructs a new PublicKey. * @param [properties] Properties to set */ - constructor(properties?: IUint128); + constructor(properties?: IPublicKey); - /** Uint128 number. */ - public number: Uint8Array; + /** PublicKey keyType. */ + public keyType: PublicKey.KeyType; + + /** PublicKey data. */ + public data: Uint8Array; /** - * Creates a new Uint128 instance using the specified properties. + * Creates a new PublicKey instance using the specified properties. * @param [properties] Properties to set - * @returns Uint128 instance + * @returns PublicKey instance */ - public static create(properties?: IUint128): Uint128; + public static create(properties?: IPublicKey): PublicKey; /** - * Encodes the specified Uint128 message. Does not implicitly {@link Uint128.verify|verify} messages. - * @param message Uint128 message or plain object to encode + * Encodes the specified PublicKey message. Does not implicitly {@link PublicKey.verify|verify} messages. + * @param message PublicKey message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encode(message: IUint128, writer?: $protobuf.Writer): $protobuf.Writer; + public static encode(message: IPublicKey, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Encodes the specified Uint128 message, length delimited. Does not implicitly {@link Uint128.verify|verify} messages. - * @param message Uint128 message or plain object to encode + * Encodes the specified PublicKey message, length delimited. Does not implicitly {@link PublicKey.verify|verify} messages. + * @param message PublicKey message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ - public static encodeDelimited(message: IUint128, writer?: $protobuf.Writer): $protobuf.Writer; + public static encodeDelimited(message: IPublicKey, writer?: $protobuf.Writer): $protobuf.Writer; /** - * Decodes an Uint128 message from the specified reader or buffer. + * Decodes a PublicKey message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand - * @returns Uint128 + * @returns PublicKey * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Uint128; + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): PublicKey; /** - * Decodes an Uint128 message from the specified reader or buffer, length delimited. + * Decodes a PublicKey message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from - * @returns Uint128 + * @returns PublicKey * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Uint128; + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): PublicKey; /** - * Verifies an Uint128 message. + * Verifies a PublicKey message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** - * Creates an Uint128 message from a plain object. Also converts values to their respective internal types. + * Creates a PublicKey message from a plain object. Also converts values to their respective internal types. * @param object Plain object - * @returns Uint128 + * @returns PublicKey */ - public static fromObject(object: { [k: string]: any }): Uint128; + public static fromObject(object: { [k: string]: any }): PublicKey; /** - * Creates a plain object from an Uint128 message. Also converts values to other types if specified. - * @param message Uint128 + * Creates a plain object from a PublicKey message. Also converts values to other types if specified. + * @param message PublicKey * @param [options] Conversion options * @returns Plain object */ - public static toObject(message: Uint128, options?: $protobuf.IConversionOptions): { [k: string]: any }; + public static toObject(message: PublicKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** - * Converts this Uint128 to JSON. + * Converts this PublicKey to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } + +export namespace PublicKey { + + /** KeyType enum. */ + enum KeyType { + ED25519 = 0 + } +} diff --git a/src.ts/providers/json-rpc-provider.ts b/src.ts/providers/json-rpc-provider.ts index be1926ca51..6a4077b35e 100644 --- a/src.ts/providers/json-rpc-provider.ts +++ b/src.ts/providers/json-rpc-provider.ts @@ -32,6 +32,7 @@ export class JsonRpcProvider extends Provider { async sendTransaction(signedTransaction: SignedTransaction): Promise { const bytes = SignedTransaction.encode(signedTransaction).finish(); + console.warn("Bytes: " + new Uint8Array(bytes)); return this.sendJsonRpc('broadcast_tx_commit', [Buffer.from(bytes).toString('base64')]); } diff --git a/src.ts/signer.ts b/src.ts/signer.ts index 141bd2fa98..76639b6c0b 100644 --- a/src.ts/signer.ts +++ b/src.ts/signer.ts @@ -59,6 +59,7 @@ export class InMemorySigner extends Signer { async getPublicKey(accountId?: string, networkId?: string): Promise { const keyPair = await this.keyStore.getKey(networkId, accountId); + console.warn(`network: ${networkId}, account: ${accountId}`); return keyPair.getPublicKey(); } diff --git a/src.ts/transaction.ts b/src.ts/transaction.ts index 8bb629bbf9..a194e426a0 100644 --- a/src.ts/transaction.ts +++ b/src.ts/transaction.ts @@ -3,59 +3,44 @@ import sha256 from 'js-sha256'; import BN from 'bn.js'; -import { Uint128, SendMoneyTransaction, CreateAccountTransaction, - SignedTransaction, DeployContractTransaction, FunctionCallTransaction, - StakeTransaction, SwapKeyTransaction, AddKeyTransaction, - DeleteKeyTransaction, AccessKey, - google} from './protos'; -import { base_decode } from './utils/serialize'; +import { Uint128, Action, AccessKey, PublicKey, SignedTransaction, Transaction, google } from './protos'; +import { base_encode, base_decode } from './utils/serialize'; import { Signature } from './utils/key_pair'; import { Signer } from './signer'; -const TRANSACTION_FIELD_MAP = new Map([ - [CreateAccountTransaction, 'createAccount'], - [DeployContractTransaction, 'deployContract'], - [FunctionCallTransaction, 'functionCall'], - [SendMoneyTransaction, 'sendMoney'], - [StakeTransaction, 'stake'], - [SwapKeyTransaction, 'swapKey'], - [AddKeyTransaction, 'addKey'], - [DeleteKeyTransaction, 'deleteKey'], -]); - -export type AllTransactions = SendMoneyTransaction | CreateAccountTransaction | DeployContractTransaction | FunctionCallTransaction | StakeTransaction | SwapKeyTransaction | AddKeyTransaction | DeleteKeyTransaction; +export type Action = Action; function bigInt(num: BN): Uint128 { const number = new Uint8Array(new BN(num).toArray('le', 16)); return new Uint128({ number }); } -export function bignumHex2Dec(num: string): string { - return new BN(num, 16).toString(10); +function toPublicKey(publicKey: string): PublicKey { + return new PublicKey({ keyType: PublicKey.KeyType.ED25519, data: base_decode(publicKey) }) } -export function createAccount(nonce: number, originator: string, newAccountId: string, publicKey: string, amount: BN): CreateAccountTransaction { - return new CreateAccountTransaction({nonce, originator, newAccountId, publicKey: base_decode(publicKey), amount: bigInt(amount)}); +export function bignumHex2Dec(num: string): string { + return new BN(num, 16).toString(10); } -export function deployContract(nonce: number, contractId: string, wasmByteArray: Uint8Array): DeployContractTransaction { - return new DeployContractTransaction({nonce, contractId, wasmByteArray}); +export function createAccount(): Action { + return new Action({ createAccount: new Action.CreateAccount() }); } -export function functionCall(nonce: number, originator: string, contractId: string, methodName: string, args: Uint8Array, amount: BN): FunctionCallTransaction { - return new FunctionCallTransaction({nonce, originator, contractId, methodName: Buffer.from(methodName), args, amount: bigInt(amount) }); +export function deployContract(code: Uint8Array): Action { + return new Action({ deployContract: new Action.DeployContract({code}) }); } -export function sendMoney(nonce: number, originator: string, receiver: string, amount: BN): SendMoneyTransaction { - return new SendMoneyTransaction({ nonce, originator, receiver, amount: bigInt(amount) }); +export function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action { + return new Action({ functionCall: new Action.FunctionCall({methodName, args, gas, deposit: bigInt(deposit) }) }); } -export function stake(nonce: number, originator: string, amount: BN, publicKey: string): StakeTransaction { - return new StakeTransaction({ nonce, originator, amount: bigInt(amount), publicKey, blsPublicKey: null }); +export function transfer(deposit: BN): Action { + return new Action({ transfer: new Action.Transfer({ deposit: bigInt(deposit) }) }); } -export function swapKey(nonce: number, originator: string, curKey: string, newKey: string): SwapKeyTransaction { - return new SwapKeyTransaction({ nonce, originator, curKey: base_decode(curKey), newKey: base_decode(newKey) }); +export function stake(stake: BN, publicKey: string): Action { + return new Action({ stake: new Action.Stake({ stake: bigInt(stake), publicKey: toPublicKey(publicKey) })}); } export function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey { @@ -67,27 +52,45 @@ export function createAccessKey(contractId?: string, methodName?: string, balanc }); } -export function addKey(nonce: number, originator: string, newKey: string, accessKey: AccessKey): AddKeyTransaction { - return new AddKeyTransaction({ nonce, originator, newKey: base_decode(newKey), accessKey}); +export function addKey(publicKey: string, accessKey: AccessKey): Action { + console.warn(accessKey); + return new Action({ addKey: new Action.AddKey({ publicKey: toPublicKey(publicKey), accessKey}) }); +} + +export function deleteKey(publicKey: string): Action { + return new Action({ deleteKey: new Action.DeleteKey({ publicKey: toPublicKey(publicKey) }) }); +} + +export function deleteAccount(beneficiaryId: string): Action { + return new Action({ deleteAccount: new Action.DeleteAccount({ beneficiaryId }) }); } -export function deleteKey(nonce: number, originator: string, curKey: string): DeleteKeyTransaction { - return new DeleteKeyTransaction({ nonce, originator, curKey: base_decode(curKey) }); +export function transaction(signerId: string, publicKey: string, nonce: number, receiverId: string, actions: Action[]): Transaction { + return new Transaction({ signerId, publicKey: toPublicKey(publicKey), nonce, receiverId, actions }) } -export function signedTransaction(transaction: AllTransactions, signature: Signature): SignedTransaction { - const fieldName = TRANSACTION_FIELD_MAP.get(transaction.constructor); +export function signedTransaction(transaction: Transaction, signature: Signature): SignedTransaction { return new SignedTransaction({ signature: signature.signature, - publicKey: google.protobuf.BytesValue.create({ value: base_decode(signature.publicKey) }), - [fieldName]: transaction, + transaction }); } -export async function signTransaction(signer: Signer, transaction: any, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]> { - const protoClass = transaction.constructor; - const message = protoClass.encode(transaction).finish(); +export async function signTransaction(receiverId: string, nonce: number, actions: Action[], signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]> { + console.warn("WTF?" + await signer.getPublicKey(accountId, networkId)); + const tx = transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); + console.warn(tx.publicKey); + console.warn("XX: " + JSON.stringify(tx)); + const message = Transaction.encode(tx).finish(); + console.warn("11: " + new Uint8Array(message)); + const tx2 = Transaction.decode(message); + console.warn(JSON.stringify(tx2)); + const message2 = Transaction.encode(tx2).finish(); + console.warn("33: " + base_encode(message2)); const hash = new Uint8Array(sha256.sha256.array(message)); + console.warn("22: " + base_encode(hash)); const signature = await signer.signHash(hash, accountId, networkId); - return [hash, signedTransaction(transaction, signature)]; + const signedTx = signedTransaction(tx, signature); + console.warn(JSON.stringify(signedTx)); + return [hash, signedTx]; } diff --git a/test/account.test.js b/test/account.test.js index 211deb6a57..254368ed3b 100644 --- a/test/account.test.js +++ b/test/account.test.js @@ -21,118 +21,118 @@ test('view pre-defined account works and returns correct name', async () => { expect(status.account_id).toEqual(workingAccount.accountId); }); -test('create account and then view account returns the created account', async () => { - const newAccountName = testUtils.generateUniqueString('test'); - const newAccountPublicKey = '9AhWenZ3JddamBoyMqnTbp7yVbRuvqAv3zwfrWgfVRJE'; - await workingAccount.createAccount(newAccountName, newAccountPublicKey, testUtils.INITIAL_BALANCE); - const newAccount = new nearlib.Account(nearjs.connection, newAccountName); - const state = await newAccount.state(); - const expectedState = { nonce: 0, account_id: newAccountName, amount: testUtils.INITIAL_BALANCE.toString(), stake: '0', code_hash: 'GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn', public_keys: state.public_keys }; - expect(state).toMatchObject(expectedState); -}); - -test('send money', async() => { - const sender = await testUtils.createAccount(workingAccount); - const receiver = await testUtils.createAccount(workingAccount); - await sender.sendMoney(receiver.accountId, new BN(10000)); - await receiver.fetchState(); - const state = await receiver.state(); - expect(state.amount).toEqual(testUtils.INITIAL_BALANCE.add(new BN(10000)).toString()); -}); - -describe('errors', () => { - let oldLog; - let logs; - - beforeEach(async () => { - oldLog = console.log; - logs =[]; - console.log = function () { - logs.push(Array.from(arguments).join(' ')); - }; - }); - - afterEach(async () => { - console.log = oldLog; - }); - - test('create existing account', async() => { - await expect(workingAccount.createAccount(workingAccount.accountId, '9AhWenZ3JddamBoyMqnTbp7yVbRuvqAv3zwfrWgfVRJE', 100)).rejects.toThrow(/Transaction .+ failed.+already exists/); - }); -}); - -describe('with deploy contract', () => { - let oldLog; - let logs; - let contractId = testUtils.generateUniqueString('test_contract'); - let contract; - - beforeAll(async () => { - const newPublicKey = await nearjs.connection.signer.createKey(contractId, testUtils.networkId); - const data = [...fs.readFileSync(HELLO_WASM_PATH)]; - await workingAccount.createAndDeployContract(contractId, newPublicKey, data, new BN(100000)); - contract = new nearlib.Contract(workingAccount, contractId, { - viewMethods: ['hello', 'getValue', 'getAllKeys', 'returnHiWithLogs'], - changeMethods: ['setValue', 'generateLogs', 'triggerAssert', 'testSetRemove'] - }); - }); - - beforeEach(async () => { - oldLog = console.log; - logs = []; - console.log = function () { - logs.push(Array.from(arguments).join(' ')); - }; - }); - - afterEach(async () => { - console.log = oldLog; - }); - - test('make function calls via account', async() => { - const result = await workingAccount.viewFunction( - contractId, - 'hello', // this is the function defined in hello.wasm file that we are calling - {name: 'trex'}); - expect(result).toEqual('hello trex'); - - const setCallValue = testUtils.generateUniqueString('setCallPrefix'); - const result2 = await workingAccount.functionCall(contractId, 'setValue', { value: setCallValue }); - expect(nearlib.providers.getTransactionLastResult(result2)).toEqual(setCallValue); - expect(await workingAccount.viewFunction(contractId, 'getValue', {})).toEqual(setCallValue); - }); +// test('create account and then view account returns the created account', async () => { +// const newAccountName = testUtils.generateUniqueString('test'); +// const newAccountPublicKey = '9AhWenZ3JddamBoyMqnTbp7yVbRuvqAv3zwfrWgfVRJE'; +// await workingAccount.createAccount(newAccountName, newAccountPublicKey, testUtils.INITIAL_BALANCE); +// const newAccount = new nearlib.Account(nearjs.connection, newAccountName); +// const state = await newAccount.state(); +// const expectedState = { nonce: 0, account_id: newAccountName, amount: testUtils.INITIAL_BALANCE.toString(), stake: '0', code_hash: 'GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn', public_keys: state.public_keys }; +// expect(state).toMatchObject(expectedState); +// }); + +// test('send money', async() => { +// const sender = await testUtils.createAccount(workingAccount); +// const receiver = await testUtils.createAccount(workingAccount); +// await sender.sendMoney(receiver.accountId, new BN(10000)); +// await receiver.fetchState(); +// const state = await receiver.state(); +// expect(state.amount).toEqual(testUtils.INITIAL_BALANCE.add(new BN(10000)).toString()); +// }); + +// describe('errors', () => { +// let oldLog; +// let logs; + +// beforeEach(async () => { +// oldLog = console.log; +// logs =[]; +// console.log = function () { +// logs.push(Array.from(arguments).join(' ')); +// }; +// }); + +// afterEach(async () => { +// console.log = oldLog; +// }); + +// test('create existing account', async() => { +// await expect(workingAccount.createAccount(workingAccount.accountId, '9AhWenZ3JddamBoyMqnTbp7yVbRuvqAv3zwfrWgfVRJE', 100)).rejects.toThrow(/Transaction .+ failed.+already exists/); +// }); +// }); + +// describe('with deploy contract', () => { +// let oldLog; +// let logs; +// let contractId = testUtils.generateUniqueString('test_contract'); +// let contract; + +// beforeAll(async () => { +// const newPublicKey = await nearjs.connection.signer.createKey(contractId, testUtils.networkId); +// const data = [...fs.readFileSync(HELLO_WASM_PATH)]; +// await workingAccount.createAndDeployContract(contractId, newPublicKey, data, new BN(100000)); +// contract = new nearlib.Contract(workingAccount, contractId, { +// viewMethods: ['hello', 'getValue', 'getAllKeys', 'returnHiWithLogs'], +// changeMethods: ['setValue', 'generateLogs', 'triggerAssert', 'testSetRemove'] +// }); +// }); + +// beforeEach(async () => { +// oldLog = console.log; +// logs = []; +// console.log = function () { +// logs.push(Array.from(arguments).join(' ')); +// }; +// }); + +// afterEach(async () => { +// console.log = oldLog; +// }); + +// test('make function calls via account', async() => { +// const result = await workingAccount.viewFunction( +// contractId, +// 'hello', // this is the function defined in hello.wasm file that we are calling +// {name: 'trex'}); +// expect(result).toEqual('hello trex'); + +// const setCallValue = testUtils.generateUniqueString('setCallPrefix'); +// const result2 = await workingAccount.functionCall(contractId, 'setValue', { value: setCallValue }); +// expect(nearlib.providers.getTransactionLastResult(result2)).toEqual(setCallValue); +// expect(await workingAccount.viewFunction(contractId, 'getValue', {})).toEqual(setCallValue); +// }); - test('make function calls via contract', async() => { - const result = await contract.hello({ name: 'trex' }); - expect(result).toEqual('hello trex'); - - const setCallValue = testUtils.generateUniqueString('setCallPrefix'); - const result2 = await contract.setValue({ value: setCallValue }); - expect(nearlib.providers.getTransactionLastResult(result2)).toEqual(setCallValue); - expect(await contract.getValue()).toEqual(setCallValue); - }); - - test('can get logs from method result', async () => { - await contract.generateLogs(); - expect(logs).toEqual([`[${contractId}]: LOG: log1`, `[${contractId}]: LOG: log2`]); - }); - - test('can get logs from view call', async () => { - let result = await contract.returnHiWithLogs(); - expect(result).toEqual('Hi'); - expect(logs).toEqual([`[${contractId}]: LOG: loooog1`, `[${contractId}]: LOG: loooog2`]); - }); - - test('can get assert message from method result', async () => { - await expect(contract.triggerAssert()).rejects.toThrow(/Transaction .+ failed.+expected to fail.+/); - expect(logs.length).toBe(3); - expect(logs[0]).toEqual(`[${contractId}]: LOG: log before assert`); - expect(logs[1]).toMatch(new RegExp(`^\\[${contractId}\\]: ABORT: "expected to fail" filename: "../out/main.ts" line: \\d+ col: \\d+$`)); - expect(logs[2]).toEqual(`[${contractId}]: Runtime error: wasm async call execution failed with error: Runtime(AssertFailed)`); - }); - - test('test set/remove', async () => { - const result = await contract.testSetRemove({ value: '123' }); - expect(result.status).toBe('Completed'); - }); -}); +// test('make function calls via contract', async() => { +// const result = await contract.hello({ name: 'trex' }); +// expect(result).toEqual('hello trex'); + +// const setCallValue = testUtils.generateUniqueString('setCallPrefix'); +// const result2 = await contract.setValue({ value: setCallValue }); +// expect(nearlib.providers.getTransactionLastResult(result2)).toEqual(setCallValue); +// expect(await contract.getValue()).toEqual(setCallValue); +// }); + +// test('can get logs from method result', async () => { +// await contract.generateLogs(); +// expect(logs).toEqual([`[${contractId}]: LOG: log1`, `[${contractId}]: LOG: log2`]); +// }); + +// test('can get logs from view call', async () => { +// let result = await contract.returnHiWithLogs(); +// expect(result).toEqual('Hi'); +// expect(logs).toEqual([`[${contractId}]: LOG: loooog1`, `[${contractId}]: LOG: loooog2`]); +// }); + +// test('can get assert message from method result', async () => { +// await expect(contract.triggerAssert()).rejects.toThrow(/Transaction .+ failed.+expected to fail.+/); +// expect(logs.length).toBe(3); +// expect(logs[0]).toEqual(`[${contractId}]: LOG: log before assert`); +// expect(logs[1]).toMatch(new RegExp(`^\\[${contractId}\\]: ABORT: "expected to fail" filename: "../out/main.ts" line: \\d+ col: \\d+$`)); +// expect(logs[2]).toEqual(`[${contractId}]: Runtime error: wasm async call execution failed with error: Runtime(AssertFailed)`); +// }); + +// test('test set/remove', async () => { +// const result = await contract.testSetRemove({ value: '123' }); +// expect(result.status).toBe('Completed'); +// }); +// }); diff --git a/test/test-utils.js b/test/test-utils.js index 95bd28d9e9..6603654f91 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -29,6 +29,7 @@ async function createAccount(masterAccount, options = { amount: INITIAL_BALANCE, await masterAccount.fetchState(); const newAccountName = generateUniqueString('test'); const newPublicKey = await masterAccount.connection.signer.createKey(newAccountName, networkId); + console.warn(`account: ${newAccountName}, key: ${newPublicKey}`); await masterAccount.createAccount(newAccountName, newPublicKey, options.amount); return new nearlib.Account(masterAccount.connection, newAccountName); } From e30efb40c9999d99838be19e6fdf34d054f2d275 Mon Sep 17 00:00:00 2001 From: Illia Polosukhin Date: Wed, 14 Aug 2019 16:00:25 -0700 Subject: [PATCH 2/8] Byte serializer / deserializer added --- lib/transaction.d.ts | 41 +++++---- lib/transaction.js | 165 +++++++++++++++++++--------------- lib/utils/serialize.d.ts | 32 +++++++ lib/utils/serialize.js | 153 +++++++++++++++++++++++++++++++ src.ts/transaction.ts | 185 ++++++++++++++++++++++++-------------- src.ts/utils/serialize.ts | 176 ++++++++++++++++++++++++++++++++++++ test/serialize.test.js | 23 +++++ 7 files changed, 619 insertions(+), 156 deletions(-) create mode 100644 test/serialize.test.js diff --git a/lib/transaction.d.ts b/lib/transaction.d.ts index e19619cb2b..b5c5fbd41f 100644 --- a/lib/transaction.d.ts +++ b/lib/transaction.d.ts @@ -1,18 +1,27 @@ -import BN from 'bn.js'; -import { Action, AccessKey, SignedTransaction, Transaction } from './protos'; -import { Signature } from './utils/key_pair'; import { Signer } from './signer'; -export declare type Action = Action; -export declare function bignumHex2Dec(num: string): string; -export declare function createAccount(): Action; -export declare function deployContract(code: Uint8Array): Action; -export declare function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action; -export declare function transfer(deposit: BN): Action; -export declare function stake(stake: BN, publicKey: string): Action; -export declare function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey; -export declare function addKey(publicKey: string, accessKey: AccessKey): Action; -export declare function deleteKey(publicKey: string): Action; -export declare function deleteAccount(beneficiaryId: string): Action; -export declare function transaction(signerId: string, publicKey: string, nonce: number, receiverId: string, actions: Action[]): Transaction; -export declare function signedTransaction(transaction: Transaction, signature: Signature): SignedTransaction; +import { Transaction, PublicKey } from './protos'; +declare enum KeyType { + ED25519 = 0 +} +declare class PublicKey { + keyType: KeyType; + data: Uint8Array; + constructor(publicKey: string); +} +interface Action { +} +declare class Transaction { + signerId: string; + publicKey: PublicKey; + nonce: number; + receiverId: string; + actions: Array; + constructor(signedId: string, publicKey: string, nonce: number, receiverId: string, actions: Array); +} +declare class SignedTransaction { + transaction: Transaction; + signature: Uint8Array; + constructor(transaction: Transaction, signature: Uint8Array); +} export declare function signTransaction(receiverId: string, nonce: number, actions: Action[], signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]>; +export {}; diff --git a/lib/transaction.js b/lib/transaction.js index 752c952ef0..d1598aa441 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -4,89 +4,108 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const js_sha256_1 = __importDefault(require("js-sha256")); -const bn_js_1 = __importDefault(require("bn.js")); -const protos_1 = require("./protos"); +// import { Uint128, Action, AccessKey, PublicKey, SignedTransaction, Transaction, google } from './protos'; const serialize_1 = require("./utils/serialize"); -function bigInt(num) { - const number = new Uint8Array(new bn_js_1.default(num).toArray('le', 16)); - return new protos_1.Uint128({ number }); +// export type Action = Action; +// function bigInt(num: BN): Uint128 { +// const number = new Uint8Array(new BN(num).toArray('le', 16)); +// return new Uint128({ number }); +// } +// function toPublicKey(publicKey: string): PublicKey { +// return new PublicKey({ keyType: PublicKey.KeyType.ED25519, data: base_decode(publicKey) }) +// } +// export function bignumHex2Dec(num: string): string { +// return new BN(num, 16).toString(10); +// } +// export function createAccount(): Action { +// return new Action({ createAccount: new Action.CreateAccount() }); +// } +// export function deployContract(code: Uint8Array): Action { +// return new Action({ deployContract: new Action.DeployContract({code}) }); +// } +// export function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action { +// return new Action({ functionCall: new Action.FunctionCall({methodName, args, gas, deposit: bigInt(deposit) }) }); +// } +// export function transfer(deposit: BN): Action { +// return new Action({ transfer: new Action.Transfer({ deposit: bigInt(deposit) }) }); +// } +// export function stake(stake: BN, publicKey: string): Action { +// return new Action({ stake: new Action.Stake({ stake: bigInt(stake), publicKey: toPublicKey(publicKey) })}); +// } +// export function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey { +// return new AccessKey({ +// contractId: contractId ? new google.protobuf.StringValue({ value: contractId }) : null, +// methodName: methodName ? new google.protobuf.BytesValue({ value: Buffer.from(methodName) }) : null, +// balanceOwner: balanceOwner ? new google.protobuf.StringValue({ value: balanceOwner }) : null, +// amount: bigInt(amount || new BN(0)), +// }); +// } +// export function addKey(publicKey: string, accessKey: AccessKey): Action { +// console.warn(accessKey); +// return new Action({ addKey: new Action.AddKey({ publicKey: toPublicKey(publicKey), accessKey}) }); +// } +// export function deleteKey(publicKey: string): Action { +// return new Action({ deleteKey: new Action.DeleteKey({ publicKey: toPublicKey(publicKey) }) }); +// } +// export function deleteAccount(beneficiaryId: string): Action { +// return new Action({ deleteAccount: new Action.DeleteAccount({ beneficiaryId }) }); +// } +// export function transaction(signerId: string, publicKey: string, nonce: number, receiverId: string, actions: Action[]): Transaction { +// return new Transaction({ signerId, publicKey: toPublicKey(publicKey), nonce, receiverId, actions }) +// } +// export function signedTransaction(transaction: Transaction, signature: Signature): SignedTransaction { +// return new SignedTransaction({ +// signature: signature.signature, +// transaction +// }); +// } +var KeyType; +(function (KeyType) { + KeyType[KeyType["ED25519"] = 0] = "ED25519"; +})(KeyType || (KeyType = {})); +class PublicKey { + constructor(publicKey) { + this.keyType = KeyType.ED25519; + this.data = serialize_1.base_decode(publicKey); + } } -function toPublicKey(publicKey) { - return new protos_1.PublicKey({ keyType: protos_1.PublicKey.KeyType.ED25519, data: serialize_1.base_decode(publicKey) }); +class Transaction { + constructor(signedId, publicKey, nonce, receiverId, actions) { + this.signerId = signedId; + this.publicKey = new PublicKey(publicKey); + this.nonce = nonce; + this.receiverId = receiverId; + this.actions = actions; + } } -function bignumHex2Dec(num) { - return new bn_js_1.default(num, 16).toString(10); +class SignedTransaction { + constructor(transaction, signature) { + this.transaction = transaction; + this.signature = signature; + } } -exports.bignumHex2Dec = bignumHex2Dec; -function createAccount() { - return new protos_1.Action({ createAccount: new protos_1.Action.CreateAccount() }); -} -exports.createAccount = createAccount; -function deployContract(code) { - return new protos_1.Action({ deployContract: new protos_1.Action.DeployContract({ code }) }); -} -exports.deployContract = deployContract; -function functionCall(methodName, args, gas, deposit) { - return new protos_1.Action({ functionCall: new protos_1.Action.FunctionCall({ methodName, args, gas, deposit: bigInt(deposit) }) }); -} -exports.functionCall = functionCall; -function transfer(deposit) { - return new protos_1.Action({ transfer: new protos_1.Action.Transfer({ deposit: bigInt(deposit) }) }); -} -exports.transfer = transfer; -function stake(stake, publicKey) { - return new protos_1.Action({ stake: new protos_1.Action.Stake({ stake: bigInt(stake), publicKey: toPublicKey(publicKey) }) }); -} -exports.stake = stake; -function createAccessKey(contractId, methodName, balanceOwner, amount) { - return new protos_1.AccessKey({ - contractId: contractId ? new protos_1.google.protobuf.StringValue({ value: contractId }) : null, - methodName: methodName ? new protos_1.google.protobuf.BytesValue({ value: Buffer.from(methodName) }) : null, - balanceOwner: balanceOwner ? new protos_1.google.protobuf.StringValue({ value: balanceOwner }) : null, - amount: bigInt(amount || new bn_js_1.default(0)), - }); -} -exports.createAccessKey = createAccessKey; -function addKey(publicKey, accessKey) { - console.warn(accessKey); - return new protos_1.Action({ addKey: new protos_1.Action.AddKey({ publicKey: toPublicKey(publicKey), accessKey }) }); -} -exports.addKey = addKey; -function deleteKey(publicKey) { - return new protos_1.Action({ deleteKey: new protos_1.Action.DeleteKey({ publicKey: toPublicKey(publicKey) }) }); -} -exports.deleteKey = deleteKey; -function deleteAccount(beneficiaryId) { - return new protos_1.Action({ deleteAccount: new protos_1.Action.DeleteAccount({ beneficiaryId }) }); -} -exports.deleteAccount = deleteAccount; -function transaction(signerId, publicKey, nonce, receiverId, actions) { - return new protos_1.Transaction({ signerId, publicKey: toPublicKey(publicKey), nonce, receiverId, actions }); -} -exports.transaction = transaction; -function signedTransaction(transaction, signature) { - return new protos_1.SignedTransaction({ - signature: signature.signature, - transaction - }); -} -exports.signedTransaction = signedTransaction; +// const SCHEMA = { +// 'SignedTransaction': [['transaction', Transaction], ['signature', [32]]], +// 'Transaction': [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]], +// } async function signTransaction(receiverId, nonce, actions, signer, accountId, networkId) { console.warn("WTF?" + await signer.getPublicKey(accountId, networkId)); - const tx = transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); - console.warn(tx.publicKey); - console.warn("XX: " + JSON.stringify(tx)); - const message = protos_1.Transaction.encode(tx).finish(); + // const tx = transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); + const tx = new Transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); + // console.warn(tx.publicKey); + // console.warn("XX: " + JSON.stringify(tx)); + // const message = Transaction.encode(tx).finish(); + const message = tx.encode(); console.warn("11: " + new Uint8Array(message)); - const tx2 = protos_1.Transaction.decode(message); - console.warn(JSON.stringify(tx2)); - const message2 = protos_1.Transaction.encode(tx2).finish(); - console.warn("33: " + serialize_1.base_encode(message2)); + // const tx2 = Transaction.decode(message); + // console.warn(JSON.stringify(tx2)); + // const message2 = Transaction.encode(tx2).finish(); + // console.warn("33: " + base_encode(message2)); const hash = new Uint8Array(js_sha256_1.default.sha256.array(message)); console.warn("22: " + serialize_1.base_encode(hash)); const signature = await signer.signHash(hash, accountId, networkId); - const signedTx = signedTransaction(tx, signature); - console.warn(JSON.stringify(signedTx)); + const signedTx = new SignedTransaction(tx, signature); + // console.warn(JSON.stringify(signedTx)); return [hash, signedTx]; } exports.signTransaction = signTransaction; diff --git a/lib/utils/serialize.d.ts b/lib/utils/serialize.d.ts index 7c0f356196..a5b6ec1642 100644 --- a/lib/utils/serialize.d.ts +++ b/lib/utils/serialize.d.ts @@ -1,2 +1,34 @@ +/// +import BN from 'bn.js'; export declare function base_encode(value: Uint8Array | string): string; export declare function base_decode(value: string): Uint8Array; +export declare class BinaryWriter { + buf: Buffer; + length: number; + constructor(); + resize(): void; + write_u8(value: number): void; + write_u32(value: number): void; + write_u64(value: BN): void; + write_u128(value: BN): void; + private write_buffer; + write_string(str: string): void; + write_fixed_array(array: Uint8Array): void; + write_array(array: Array, fn: any): void; + toArray(): Uint8Array; +} +export declare class BinaryReader { + buf: Buffer; + offset: number; + constructor(buf: Buffer); + read_u8(): number; + read_u32(): number; + read_u64(): BN; + read_u128(): BN; + private read_buffer; + read_string(): string; + read_fixed_array(len: number): Uint8Array; + read_array(fn: any): Array; +} +export declare function serialize(schema: any, obj: any): Uint8Array; +export declare function deserialize(schema: any, classType: any, buffer: Buffer): any; diff --git a/lib/utils/serialize.js b/lib/utils/serialize.js index d31435b140..c263fbc039 100644 --- a/lib/utils/serialize.js +++ b/lib/utils/serialize.js @@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const bs58_1 = __importDefault(require("bs58")); +const bn_js_1 = __importDefault(require("bn.js")); function base_encode(value) { if (typeof (value) === 'string') { value = Buffer.from(value, 'utf8'); @@ -15,3 +16,155 @@ function base_decode(value) { return bs58_1.default.decode(value); } exports.base_decode = base_decode; +const INITIAL_LENGTH = 1024; +/// Binary encoder. +class BinaryWriter { + constructor() { + this.buf = Buffer.alloc(INITIAL_LENGTH); + this.length = 0; + } + resize() { + this.buf = Buffer.concat([this.buf, Buffer.alloc(INITIAL_LENGTH)]); + } + write_u8(value) { + this.buf.writeInt8(value, this.length); + this.length += 1; + } + write_u32(value) { + this.buf.writeUInt32LE(value, this.length); + this.length += 4; + } + write_u64(value) { + this.write_buffer(Buffer.from(new bn_js_1.default(value).toArray('le', 8))); + } + write_u128(value) { + this.write_buffer(Buffer.from(new bn_js_1.default(value).toArray('le', 16))); + } + write_buffer(buffer) { + this.buf = Buffer.concat([this.buf.subarray(0, this.length), buffer, Buffer.alloc(INITIAL_LENGTH)]); + this.length += buffer.length; + } + write_string(str) { + let b = Buffer.from(str, 'utf8'); + this.write_u32(b.length); + this.write_buffer(b); + } + write_fixed_array(array) { + this.write_buffer(Buffer.from(array)); + } + write_array(array, fn) { + this.write_u32(array.length); + for (let i = 0; i < array.length; ++i) { + fn(array[i]); + } + } + toArray() { + return this.buf.subarray(0, this.length); + } +} +exports.BinaryWriter = BinaryWriter; +class BinaryReader { + constructor(buf) { + this.buf = buf; + this.offset = 0; + } + read_u8() { + const value = this.buf.readInt8(this.offset); + this.offset += 1; + return value; + } + read_u32() { + const value = this.buf.readUInt32LE(this.offset); + this.offset += 4; + return value; + } + read_u64() { + let buf = this.read_buffer(8); + buf.reverse(); + return new bn_js_1.default(`${buf.toString('hex')}`, 16); + } + read_u128() { + let buf = this.read_buffer(16); + return new bn_js_1.default(buf); + } + read_buffer(len) { + const result = this.buf.slice(this.offset, this.offset + len); + this.offset += len; + return result; + } + read_string() { + let len = this.read_u32(); + return this.read_buffer(len).toString('utf8'); + } + read_fixed_array(len) { + return new Uint8Array(this.read_buffer(len)); + } + read_array(fn) { + const len = this.read_u32(); + let result = Array(); + for (let i = 0; i < len; ++i) { + result.push(fn()); + } + return result; + } +} +exports.BinaryReader = BinaryReader; +function serializeField(schema, value, fieldType, writer) { + if (typeof fieldType === "string") { + writer[`write_${fieldType}`](value); + } + else if (fieldType instanceof Array) { + if (typeof fieldType[0] === "number") { + writer.write_fixed_array(value); + } + else { + writer.write_array(value, (item) => { serializeField(schema, item, fieldType[0], writer); }); + } + } + else { + serializeStruct(schema, value, writer); + } +} +function serializeStruct(schema, obj, writer) { + const className = obj.constructor.name; + schema[className].map(([fieldName, fieldType]) => { + serializeField(schema, obj[fieldName], fieldType, writer); + }); +} +/// Serialize given object using schema of the form: +/// { class_name -> [ [field_name, field_type], .. ], .. } +function serialize(schema, obj) { + let writer = new BinaryWriter(); + serializeStruct(schema, obj, writer); + return writer.toArray(); +} +exports.serialize = serialize; +function deserializeField(schema, fieldType, reader) { + if (typeof fieldType === "string") { + return reader[`read_${fieldType}`](); + } + else if (fieldType instanceof Array) { + if (typeof fieldType[0] === 'number') { + return reader.read_fixed_array(fieldType[0]); + } + else { + return reader.read_array(() => { return deserializeField(schema, fieldType[0], reader); }); + } + } + else { + return deserializeStruct(schema, fieldType, reader); + } +} +function deserializeStruct(schema, classType, reader) { + console.log(classType.name); + let fields = schema[classType.name].map(([fieldName, fieldType]) => { + return deserializeField(schema, fieldType, reader); + }); + return new classType(...fields); +} +/// Deserializes object from bytes using schema. +function deserialize(schema, classType, buffer) { + let reader = new BinaryReader(buffer); + return deserializeStruct(schema, classType, reader); +} +exports.deserialize = deserialize; diff --git a/src.ts/transaction.ts b/src.ts/transaction.ts index a194e426a0..a8e953e65c 100644 --- a/src.ts/transaction.ts +++ b/src.ts/transaction.ts @@ -3,94 +3,145 @@ import sha256 from 'js-sha256'; import BN from 'bn.js'; -import { Uint128, Action, AccessKey, PublicKey, SignedTransaction, Transaction, google } from './protos'; +// import { Uint128, Action, AccessKey, PublicKey, SignedTransaction, Transaction, google } from './protos'; import { base_encode, base_decode } from './utils/serialize'; import { Signature } from './utils/key_pair'; import { Signer } from './signer'; - -export type Action = Action; - -function bigInt(num: BN): Uint128 { - const number = new Uint8Array(new BN(num).toArray('le', 16)); - return new Uint128({ number }); +import { Transaction, PublicKey } from './protos'; + +// export type Action = Action; + +// function bigInt(num: BN): Uint128 { +// const number = new Uint8Array(new BN(num).toArray('le', 16)); +// return new Uint128({ number }); +// } + +// function toPublicKey(publicKey: string): PublicKey { +// return new PublicKey({ keyType: PublicKey.KeyType.ED25519, data: base_decode(publicKey) }) +// } + +// export function bignumHex2Dec(num: string): string { +// return new BN(num, 16).toString(10); +// } + +// export function createAccount(): Action { +// return new Action({ createAccount: new Action.CreateAccount() }); +// } + +// export function deployContract(code: Uint8Array): Action { +// return new Action({ deployContract: new Action.DeployContract({code}) }); +// } + +// export function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action { +// return new Action({ functionCall: new Action.FunctionCall({methodName, args, gas, deposit: bigInt(deposit) }) }); +// } + +// export function transfer(deposit: BN): Action { +// return new Action({ transfer: new Action.Transfer({ deposit: bigInt(deposit) }) }); +// } + +// export function stake(stake: BN, publicKey: string): Action { +// return new Action({ stake: new Action.Stake({ stake: bigInt(stake), publicKey: toPublicKey(publicKey) })}); +// } + +// export function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey { +// return new AccessKey({ +// contractId: contractId ? new google.protobuf.StringValue({ value: contractId }) : null, +// methodName: methodName ? new google.protobuf.BytesValue({ value: Buffer.from(methodName) }) : null, +// balanceOwner: balanceOwner ? new google.protobuf.StringValue({ value: balanceOwner }) : null, +// amount: bigInt(amount || new BN(0)), +// }); +// } + +// export function addKey(publicKey: string, accessKey: AccessKey): Action { +// console.warn(accessKey); +// return new Action({ addKey: new Action.AddKey({ publicKey: toPublicKey(publicKey), accessKey}) }); +// } + +// export function deleteKey(publicKey: string): Action { +// return new Action({ deleteKey: new Action.DeleteKey({ publicKey: toPublicKey(publicKey) }) }); +// } + +// export function deleteAccount(beneficiaryId: string): Action { +// return new Action({ deleteAccount: new Action.DeleteAccount({ beneficiaryId }) }); +// } + +// export function transaction(signerId: string, publicKey: string, nonce: number, receiverId: string, actions: Action[]): Transaction { +// return new Transaction({ signerId, publicKey: toPublicKey(publicKey), nonce, receiverId, actions }) +// } + +// export function signedTransaction(transaction: Transaction, signature: Signature): SignedTransaction { +// return new SignedTransaction({ +// signature: signature.signature, +// transaction +// }); +// } + +enum KeyType { + ED25519 = 0, } -function toPublicKey(publicKey: string): PublicKey { - return new PublicKey({ keyType: PublicKey.KeyType.ED25519, data: base_decode(publicKey) }) -} +class PublicKey { + keyType: KeyType; + data: Uint8Array; -export function bignumHex2Dec(num: string): string { - return new BN(num, 16).toString(10); + constructor(publicKey: string) { + this.keyType = KeyType.ED25519; + this.data = base_decode(publicKey); + } } -export function createAccount(): Action { - return new Action({ createAccount: new Action.CreateAccount() }); +interface Action { } -export function deployContract(code: Uint8Array): Action { - return new Action({ deployContract: new Action.DeployContract({code}) }); +class Transaction { + signerId: string; + publicKey: PublicKey; + nonce: number; + receiverId: string; + actions: Array; + + constructor(signedId: string, publicKey: string, nonce: number, receiverId: string, actions: Array) { + this.signerId = signedId; + this.publicKey = new PublicKey(publicKey); + this.nonce = nonce; + this.receiverId = receiverId; + this.actions = actions; + } } -export function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action { - return new Action({ functionCall: new Action.FunctionCall({methodName, args, gas, deposit: bigInt(deposit) }) }); -} +class SignedTransaction { + transaction: Transaction; + signature: Uint8Array; -export function transfer(deposit: BN): Action { - return new Action({ transfer: new Action.Transfer({ deposit: bigInt(deposit) }) }); + constructor(transaction: Transaction, signature: Uint8Array) { + this.transaction = transaction; + this.signature = signature; + } } -export function stake(stake: BN, publicKey: string): Action { - return new Action({ stake: new Action.Stake({ stake: bigInt(stake), publicKey: toPublicKey(publicKey) })}); -} - -export function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey { - return new AccessKey({ - contractId: contractId ? new google.protobuf.StringValue({ value: contractId }) : null, - methodName: methodName ? new google.protobuf.BytesValue({ value: Buffer.from(methodName) }) : null, - balanceOwner: balanceOwner ? new google.protobuf.StringValue({ value: balanceOwner }) : null, - amount: bigInt(amount || new BN(0)), - }); -} - -export function addKey(publicKey: string, accessKey: AccessKey): Action { - console.warn(accessKey); - return new Action({ addKey: new Action.AddKey({ publicKey: toPublicKey(publicKey), accessKey}) }); -} - -export function deleteKey(publicKey: string): Action { - return new Action({ deleteKey: new Action.DeleteKey({ publicKey: toPublicKey(publicKey) }) }); -} - -export function deleteAccount(beneficiaryId: string): Action { - return new Action({ deleteAccount: new Action.DeleteAccount({ beneficiaryId }) }); -} - -export function transaction(signerId: string, publicKey: string, nonce: number, receiverId: string, actions: Action[]): Transaction { - return new Transaction({ signerId, publicKey: toPublicKey(publicKey), nonce, receiverId, actions }) -} - -export function signedTransaction(transaction: Transaction, signature: Signature): SignedTransaction { - return new SignedTransaction({ - signature: signature.signature, - transaction - }); -} +// const SCHEMA = { +// 'SignedTransaction': [['transaction', Transaction], ['signature', [32]]], +// 'Transaction': [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]], +// } export async function signTransaction(receiverId: string, nonce: number, actions: Action[], signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]> { console.warn("WTF?" + await signer.getPublicKey(accountId, networkId)); - const tx = transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); - console.warn(tx.publicKey); - console.warn("XX: " + JSON.stringify(tx)); - const message = Transaction.encode(tx).finish(); + // const tx = transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); + const tx = new Transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); + // console.warn(tx.publicKey); + // console.warn("XX: " + JSON.stringify(tx)); + // const message = Transaction.encode(tx).finish(); + const message = tx.encode(); console.warn("11: " + new Uint8Array(message)); - const tx2 = Transaction.decode(message); - console.warn(JSON.stringify(tx2)); - const message2 = Transaction.encode(tx2).finish(); - console.warn("33: " + base_encode(message2)); + // const tx2 = Transaction.decode(message); + // console.warn(JSON.stringify(tx2)); + // const message2 = Transaction.encode(tx2).finish(); + // console.warn("33: " + base_encode(message2)); const hash = new Uint8Array(sha256.sha256.array(message)); console.warn("22: " + base_encode(hash)); const signature = await signer.signHash(hash, accountId, networkId); - const signedTx = signedTransaction(tx, signature); - console.warn(JSON.stringify(signedTx)); + const signedTx = new SignedTransaction(tx, signature); + // console.warn(JSON.stringify(signedTx)); return [hash, signedTx]; } diff --git a/src.ts/utils/serialize.ts b/src.ts/utils/serialize.ts index 78f3827c00..a57e500909 100644 --- a/src.ts/utils/serialize.ts +++ b/src.ts/utils/serialize.ts @@ -1,6 +1,7 @@ 'use strict'; import bs58 from 'bs58'; +import BN from 'bn.js'; export function base_encode(value: Uint8Array | string): string { if (typeof(value) === 'string') { @@ -12,3 +13,178 @@ export function base_encode(value: Uint8Array | string): string { export function base_decode(value: string): Uint8Array { return bs58.decode(value); } + +const INITIAL_LENGTH = 1024; + +/// Binary encoder. +export class BinaryWriter { + buf: Buffer; + length: number; + + public constructor() { + this.buf = Buffer.alloc(INITIAL_LENGTH); + this.length = 0; + } + + resize() { + this.buf = Buffer.concat([this.buf, Buffer.alloc(INITIAL_LENGTH)]); + } + + public write_u8(value: number) { + this.buf.writeInt8(value, this.length); + this.length += 1; + } + + public write_u32(value: number) { + this.buf.writeUInt32LE(value, this.length); + this.length += 4; + } + + public write_u64(value: BN) { + this.write_buffer(Buffer.from(new BN(value).toArray('le', 8))); + } + + public write_u128(value: BN) { + this.write_buffer(Buffer.from(new BN(value).toArray('le', 16))); + } + + private write_buffer(buffer: Buffer) { + this.buf = Buffer.concat([this.buf.subarray(0, this.length), buffer, Buffer.alloc(INITIAL_LENGTH)]) + this.length += buffer.length; + } + + public write_string(str: string) { + let b = Buffer.from(str, 'utf8'); + this.write_u32(b.length); + this.write_buffer(b); + } + + public write_fixed_array(array: Uint8Array) { + this.write_buffer(Buffer.from(array)); + } + + public write_array(array: Array, fn: any) { + this.write_u32(array.length); + for (let i = 0; i < array.length; ++i) { + fn(array[i]); + } + } + + public toArray(): Uint8Array { + return this.buf.subarray(0, this.length); + } +} + +export class BinaryReader { + buf: Buffer; + offset: number; + + public constructor(buf: Buffer) { + this.buf = buf; + this.offset = 0; + } + + read_u8(): number { + const value = this.buf.readInt8(this.offset); + this.offset += 1; + return value; + } + + read_u32(): number { + const value = this.buf.readUInt32LE(this.offset); + this.offset += 4; + return value; + } + + read_u64(): BN { + let buf = this.read_buffer(8); + buf.reverse(); + return new BN(`${buf.toString('hex')}`, 16); + } + + read_u128(): BN { + let buf = this.read_buffer(16); + return new BN(buf); + } + + private read_buffer(len: number): Buffer { + const result = this.buf.slice(this.offset, this.offset + len); + this.offset += len; + return result; + } + + read_string(): string { + let len = this.read_u32(); + return this.read_buffer(len).toString('utf8'); + } + + read_fixed_array(len: number): Uint8Array { + return new Uint8Array(this.read_buffer(len)); + } + + read_array(fn: any): Array { + const len = this.read_u32(); + let result = Array(); + for (let i = 0; i < len; ++i) { + result.push(fn()); + } + return result; + } +} + +function serializeField(schema: any, value: any, fieldType: any, writer: any) { + if (typeof fieldType === "string") { + writer[`write_${fieldType}`](value); + } else if (fieldType instanceof Array) { + if (typeof fieldType[0] === "number") { + writer.write_fixed_array(value); + } else { + writer.write_array(value, (item: any) => { serializeField(schema, item, fieldType[0], writer) }); + } + } else { + serializeStruct(schema, value, writer); + } +} + +function serializeStruct(schema: any, obj: any, writer: any) { + const className = obj.constructor.name; + schema[className].map(([fieldName, fieldType]: [any, any]) => { + serializeField(schema, obj[fieldName], fieldType, writer); + }); +} + +/// Serialize given object using schema of the form: +/// { class_name -> [ [field_name, field_type], .. ], .. } +export function serialize(schema: any, obj: any): Uint8Array { + let writer = new BinaryWriter(); + serializeStruct(schema, obj, writer); + return writer.toArray(); +} + +function deserializeField(schema: any, fieldType: any, reader: any): any { + if (typeof fieldType === "string") { + return reader[`read_${fieldType}`](); + } else if (fieldType instanceof Array) { + if (typeof fieldType[0] === 'number') { + return reader.read_fixed_array(fieldType[0]); + } else { + return reader.read_array(() => { return deserializeField(schema, fieldType[0], reader) }); + } + } else { + return deserializeStruct(schema, fieldType, reader); + } +} + +function deserializeStruct(schema: any, classType: any, reader: any) { + console.log(classType.name); + let fields = schema[classType.name].map(([fieldName, fieldType]: [any, any]) => { + return deserializeField(schema, fieldType, reader); + }); + return new classType(...fields); +} + +/// Deserializes object from bytes using schema. +export function deserialize(schema: any, classType: any, buffer: Buffer): any { + let reader = new BinaryReader(buffer); + return deserializeStruct(schema, classType, reader); +} \ No newline at end of file diff --git a/test/serialize.test.js b/test/serialize.test.js new file mode 100644 index 0000000000..4c6c38c961 --- /dev/null +++ b/test/serialize.test.js @@ -0,0 +1,23 @@ + +const nearlib = require('../lib/index'); +const BN = require('BN.js'); + +class Test { + constructor(x, y, z, q) { + this.x = x; + this.y = y; + this.z = z; + this.q = q; + } +} + +test('serialize object', async () => { + const value = new Test(10, 20, '123', [1, 2, 3]); + const schema = { 'Test': [['x', 'u8'], ['y', 'u64'], ['z', 'string'], ['q', [3]]] }; + let buf = nearlib.utils.serialize.serialize(schema, value); + let new_value = nearlib.utils.serialize.deserialize(schema, Test, buf); + expect(new_value.x).toEqual(10); + expect(new_value.y.toString()).toEqual('20'); + expect(new_value.z).toEqual('123'); + expect(new_value.q).toEqual(new Uint8Array([1, 2, 3])); +}); From 4dbe84cb7bb47399403b44fc87da3e156324d7ee Mon Sep 17 00:00:00 2001 From: Illia Polosukhin Date: Thu, 15 Aug 2019 15:18:25 -0700 Subject: [PATCH 3/8] Remove protobuf. Replace with NBOR --- .gitlab-ci.yml | 1 - lib/account.js | 1 + lib/index.d.ts | 3 +- lib/index.js | 2 + lib/providers/json-rpc-provider.d.ts | 2 +- lib/providers/json-rpc-provider.js | 3 +- lib/providers/provider.d.ts | 2 +- lib/signer.js | 1 - lib/transaction.d.ts | 71 +- lib/transaction.js | 209 +- lib/utils/serialize.js | 43 +- package.json | 6 +- scripts/generate_js_transaction_proto.sh | 16 - src.ts/account.ts | 1 + src.ts/index.ts | 4 +- src.ts/protos.d.ts | 2212 ---------------------- src.ts/providers/json-rpc-provider.ts | 4 +- src.ts/providers/provider.ts | 2 +- src.ts/signer.ts | 1 - src.ts/transaction.ts | 233 +-- src.ts/utils/serialize.ts | 39 +- test/serialize.test.js | 20 +- tsconfig.json | 3 +- 23 files changed, 423 insertions(+), 2456 deletions(-) delete mode 100755 scripts/generate_js_transaction_proto.sh delete mode 100644 src.ts/protos.d.ts diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 17b653a2d5..1b638fb1e4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,6 @@ image: node:10 variables: NODE_ENV: ci - NEAR_PROTOS_DIR: nearcore/core/protos/protos HELLO_WASM_PATH: nearcore/tests/hello.wasm stages: diff --git a/lib/account.js b/lib/account.js index 5a5861bc54..2674b6aa4c 100644 --- a/lib/account.js +++ b/lib/account.js @@ -74,6 +74,7 @@ class Account { throw error; } } + console.log(result); const flatLogs = result.logs.reduce((acc, it) => acc.concat(it.lines), []); this.printLogs(signedTx.transaction.receiverId, flatLogs); if (result.status === provider_1.FinalTransactionStatus.Failed) { diff --git a/lib/index.d.ts b/lib/index.d.ts index 7782bd345f..0ef891e0ea 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,6 +1,7 @@ import * as providers from './providers'; import * as utils from './utils'; import * as keyStores from './key_stores'; +import * as transactions from './transaction'; import { Account } from './account'; import * as accountCreator from './account_creator'; import { Connection } from './connection'; @@ -9,4 +10,4 @@ import { Contract } from './contract'; import { KeyPair } from './utils/key_pair'; import { connect } from './near'; import { WalletAccount } from './wallet-account'; -export { accountCreator, keyStores, providers, utils, Account, Connection, Contract, InMemorySigner, Signer, KeyPair, connect, WalletAccount }; +export { accountCreator, keyStores, providers, utils, transactions, Account, Connection, Contract, InMemorySigner, Signer, KeyPair, connect, WalletAccount }; diff --git a/lib/index.js b/lib/index.js index fd64720fb2..397a958829 100644 --- a/lib/index.js +++ b/lib/index.js @@ -13,6 +13,8 @@ const utils = __importStar(require("./utils")); exports.utils = utils; const keyStores = __importStar(require("./key_stores")); exports.keyStores = keyStores; +const transactions = __importStar(require("./transaction")); +exports.transactions = transactions; const account_1 = require("./account"); exports.Account = account_1.Account; const accountCreator = __importStar(require("./account_creator")); diff --git a/lib/providers/json-rpc-provider.d.ts b/lib/providers/json-rpc-provider.d.ts index e6ad34a09a..cf42d0b764 100644 --- a/lib/providers/json-rpc-provider.d.ts +++ b/lib/providers/json-rpc-provider.d.ts @@ -1,7 +1,7 @@ import { Provider, FinalTransactionResult, NodeStatusResult, BlockResult } from './provider'; import { Network } from '../utils/network'; import { ConnectionInfo } from '../utils/web'; -import { SignedTransaction } from '../protos'; +import { SignedTransaction } from '../transaction'; export declare class JsonRpcProvider extends Provider { readonly connection: ConnectionInfo; constructor(url?: string, network?: Network); diff --git a/lib/providers/json-rpc-provider.js b/lib/providers/json-rpc-provider.js index db0b1eb826..555ed815fa 100644 --- a/lib/providers/json-rpc-provider.js +++ b/lib/providers/json-rpc-provider.js @@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); const provider_1 = require("./provider"); const web_1 = require("../utils/web"); const serialize_1 = require("../utils/serialize"); -const protos_1 = require("../protos"); /// Keep ids unique across all connections. let _nextId = 123; class JsonRpcProvider extends provider_1.Provider { @@ -22,7 +21,7 @@ class JsonRpcProvider extends provider_1.Provider { return this.sendJsonRpc('status', []); } async sendTransaction(signedTransaction) { - const bytes = protos_1.SignedTransaction.encode(signedTransaction).finish(); + const bytes = signedTransaction.encode(); console.warn("Bytes: " + new Uint8Array(bytes)); return this.sendJsonRpc('broadcast_tx_commit', [Buffer.from(bytes).toString('base64')]); } diff --git a/lib/providers/provider.d.ts b/lib/providers/provider.d.ts index 863b78062e..6b1a70d6e9 100644 --- a/lib/providers/provider.d.ts +++ b/lib/providers/provider.d.ts @@ -1,5 +1,5 @@ import { Network } from '../utils/network'; -import { SignedTransaction } from '../protos'; +import { SignedTransaction } from '../transaction'; export interface SyncInfo { latest_block_hash: string; latest_block_height: number; diff --git a/lib/signer.js b/lib/signer.js index 194e206f6d..f2ddc3636a 100644 --- a/lib/signer.js +++ b/lib/signer.js @@ -35,7 +35,6 @@ class InMemorySigner extends Signer { } async getPublicKey(accountId, networkId) { const keyPair = await this.keyStore.getKey(networkId, accountId); - console.warn(`network: ${networkId}, account: ${accountId}`); return keyPair.getPublicKey(); } async signHash(hash, accountId, networkId) { diff --git a/lib/transaction.d.ts b/lib/transaction.d.ts index b5c5fbd41f..5d538496e6 100644 --- a/lib/transaction.d.ts +++ b/lib/transaction.d.ts @@ -1,5 +1,53 @@ +import BN from 'bn.js'; import { Signer } from './signer'; -import { Transaction, PublicKey } from './protos'; +export declare class Assignable { + constructor(properties: any); +} +export declare class AccessKey extends Assignable { + contractId: string; + methodName: Uint8Array; + balanceOwner: string; + amount: BN; +} +export declare function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey; +export declare class IAction extends Assignable { +} +declare class CreateAccount extends IAction { +} +declare class DeployContract extends IAction { + code: Uint8Array; +} +declare class FunctionCall extends IAction { + methodName: string; + args: Uint8Array; + gas: BN; + deposit: BN; +} +declare class Transfer extends IAction { + deposit: BN; +} +declare class Stake extends IAction { + stake: BN; + publicKey: PublicKey; +} +declare class AddKey extends IAction { + publicKey: PublicKey; + accessKey: AccessKey; +} +declare class DeleteKey extends IAction { + publicKey: PublicKey; +} +declare class DeleteAccount extends IAction { + beneficiaryId: string; +} +export declare function createAccount(): Action; +export declare function deployContract(code: Uint8Array): Action; +export declare function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action; +export declare function transfer(deposit: BN): Action; +export declare function stake(stake: BN, publicKey: string): Action; +export declare function addKey(publicKey: string, accessKey: AccessKey): Action; +export declare function deleteKey(publicKey: string): Action; +export declare function deleteAccount(beneficiaryId: string): Action; declare enum KeyType { ED25519 = 0 } @@ -8,20 +56,29 @@ declare class PublicKey { data: Uint8Array; constructor(publicKey: string); } -interface Action { -} -declare class Transaction { +declare class Transaction extends Assignable { signerId: string; publicKey: PublicKey; nonce: number; receiverId: string; actions: Array; - constructor(signedId: string, publicKey: string, nonce: number, receiverId: string, actions: Array); } -declare class SignedTransaction { +export declare class SignedTransaction extends Assignable { transaction: Transaction; signature: Uint8Array; - constructor(transaction: Transaction, signature: Uint8Array); + encode(): Uint8Array; +} +export declare class Action { + action: string; + createAccount: CreateAccount; + deployContract: DeployContract; + functionCall: FunctionCall; + transfer: Transfer; + stake: Stake; + addKey: AddKey; + deleteKey: DeleteKey; + deleteAccount: DeleteAccount; + constructor(properties: any); } export declare function signTransaction(receiverId: string, nonce: number, actions: Action[], signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]>; export {}; diff --git a/lib/transaction.js b/lib/transaction.js index d1598aa441..65d7b28edf 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -4,61 +4,79 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const js_sha256_1 = __importDefault(require("js-sha256")); -// import { Uint128, Action, AccessKey, PublicKey, SignedTransaction, Transaction, google } from './protos'; +const bn_js_1 = __importDefault(require("bn.js")); const serialize_1 = require("./utils/serialize"); -// export type Action = Action; -// function bigInt(num: BN): Uint128 { -// const number = new Uint8Array(new BN(num).toArray('le', 16)); -// return new Uint128({ number }); -// } -// function toPublicKey(publicKey: string): PublicKey { -// return new PublicKey({ keyType: PublicKey.KeyType.ED25519, data: base_decode(publicKey) }) -// } -// export function bignumHex2Dec(num: string): string { -// return new BN(num, 16).toString(10); -// } -// export function createAccount(): Action { -// return new Action({ createAccount: new Action.CreateAccount() }); -// } -// export function deployContract(code: Uint8Array): Action { -// return new Action({ deployContract: new Action.DeployContract({code}) }); -// } -// export function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action { -// return new Action({ functionCall: new Action.FunctionCall({methodName, args, gas, deposit: bigInt(deposit) }) }); -// } -// export function transfer(deposit: BN): Action { -// return new Action({ transfer: new Action.Transfer({ deposit: bigInt(deposit) }) }); -// } -// export function stake(stake: BN, publicKey: string): Action { -// return new Action({ stake: new Action.Stake({ stake: bigInt(stake), publicKey: toPublicKey(publicKey) })}); -// } -// export function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey { -// return new AccessKey({ -// contractId: contractId ? new google.protobuf.StringValue({ value: contractId }) : null, -// methodName: methodName ? new google.protobuf.BytesValue({ value: Buffer.from(methodName) }) : null, -// balanceOwner: balanceOwner ? new google.protobuf.StringValue({ value: balanceOwner }) : null, -// amount: bigInt(amount || new BN(0)), -// }); -// } -// export function addKey(publicKey: string, accessKey: AccessKey): Action { -// console.warn(accessKey); -// return new Action({ addKey: new Action.AddKey({ publicKey: toPublicKey(publicKey), accessKey}) }); -// } -// export function deleteKey(publicKey: string): Action { -// return new Action({ deleteKey: new Action.DeleteKey({ publicKey: toPublicKey(publicKey) }) }); -// } -// export function deleteAccount(beneficiaryId: string): Action { -// return new Action({ deleteAccount: new Action.DeleteAccount({ beneficiaryId }) }); -// } -// export function transaction(signerId: string, publicKey: string, nonce: number, receiverId: string, actions: Action[]): Transaction { -// return new Transaction({ signerId, publicKey: toPublicKey(publicKey), nonce, receiverId, actions }) -// } -// export function signedTransaction(transaction: Transaction, signature: Signature): SignedTransaction { -// return new SignedTransaction({ -// signature: signature.signature, -// transaction -// }); -// } +class Assignable { + constructor(properties) { + Object.keys(properties).map((key) => { + this[key] = properties[key]; + }); + } +} +exports.Assignable = Assignable; +class AccessKey extends Assignable { +} +exports.AccessKey = AccessKey; +function createAccessKey(contractId, methodName, balanceOwner, amount) { + return new AccessKey({ + contractId, + methodName, + balanceOwner, + amount: amount || new bn_js_1.default(0), + }); +} +exports.createAccessKey = createAccessKey; +class IAction extends Assignable { +} +exports.IAction = IAction; +class CreateAccount extends IAction { +} +class DeployContract extends IAction { +} +class FunctionCall extends IAction { +} +class Transfer extends IAction { +} +class Stake extends IAction { +} +class AddKey extends IAction { +} +class DeleteKey extends IAction { +} +class DeleteAccount extends IAction { +} +function createAccount() { + return new Action({ createAccount: new CreateAccount({}) }); +} +exports.createAccount = createAccount; +function deployContract(code) { + return new Action({ deployContract: new DeployContract({ code }) }); +} +exports.deployContract = deployContract; +function functionCall(methodName, args, gas, deposit) { + return new Action({ functionCall: new FunctionCall({ methodName, args, gas, deposit }) }); +} +exports.functionCall = functionCall; +function transfer(deposit) { + return new Action({ transfer: new Transfer({ deposit }) }); +} +exports.transfer = transfer; +function stake(stake, publicKey) { + return new Action({ stake: new Stake({ stake, publicKey: new PublicKey(publicKey) }) }); +} +exports.stake = stake; +function addKey(publicKey, accessKey) { + return new Action({ addKey: new AddKey({ publicKey: new PublicKey(publicKey), accessKey }) }); +} +exports.addKey = addKey; +function deleteKey(publicKey) { + return new Action({ deleteKey: new DeleteKey({ publicKey: new PublicKey(publicKey) }) }); +} +exports.deleteKey = deleteKey; +function deleteAccount(beneficiaryId) { + return new Action({ deleteAccount: new DeleteAccount({ beneficiaryId }) }); +} +exports.deleteAccount = deleteAccount; var KeyType; (function (KeyType) { KeyType[KeyType["ED25519"] = 0] = "ED25519"; @@ -69,43 +87,66 @@ class PublicKey { this.data = serialize_1.base_decode(publicKey); } } -class Transaction { - constructor(signedId, publicKey, nonce, receiverId, actions) { - this.signerId = signedId; - this.publicKey = new PublicKey(publicKey); - this.nonce = nonce; - this.receiverId = receiverId; - this.actions = actions; +class Transaction extends Assignable { +} +class SignedTransaction extends Assignable { + encode() { + return serialize_1.serialize(SCHEMA, this); } } -class SignedTransaction { - constructor(transaction, signature) { - this.transaction = transaction; - this.signature = signature; +exports.SignedTransaction = SignedTransaction; +class Action { + constructor(properties) { + if (Object.keys(properties).length != 1) { + throw new Error("Action can only take single value"); + } + Object.keys(properties).map((key) => { + this[key] = properties[key]; + this.action = key; + }); } } -// const SCHEMA = { -// 'SignedTransaction': [['transaction', Transaction], ['signature', [32]]], -// 'Transaction': [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]], -// } +exports.Action = Action; +const SCHEMA = { + 'SignedTransaction': { kind: 'struct', fields: [['transaction', Transaction], ['signature', [32]]] }, + 'Transaction': { + kind: 'struct', fields: [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]] + }, + 'PublicKey': { + kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]] + }, + 'AccessKey': { kind: 'struct', fields: [ + ['amount', 'u128'], + ['balanceOwner', { kind: 'option', type: 'string' }], + ['contractId', { kind: 'option', type: 'string' }], + ['methodName', { kind: 'option', type: ['u8'] }], + ] }, + 'Action': { kind: 'enum', field: 'action', values: [ + ['createAccount', CreateAccount], + ['deployContract', DeployContract], + ['functionCall', functionCall], + ['transfer', transfer], + ['stake', stake], + ['addKey', addKey], + ['deleteKey', deleteKey], + ['deleteAccount', deleteAccount], + ] }, + 'CreateAccount': { kind: 'struct', fields: [] }, + 'DeployContract': { kind: 'struct', fields: [['code', ['u8']]] }, + 'FunctionCall': { kind: 'struct', fields: [['methodName', 'string'], ['args', ['u8']], ['gas', 'u64'], ['deposit', 'u128']] }, + 'Transfer': { kind: 'struct', fields: [['deposit', 'u128']] }, + 'Stake': { kind: 'struct', fields: [['stake', 'u128'], ['publicKey', PublicKey]] }, + 'AddKey': { kind: 'struct', fields: [['publicKey', PublicKey], ['accessKey', AccessKey]] }, + 'DeleteKey': { kind: 'struct', fields: [['publicKey', PublicKey]] }, + 'DeleteAccount': { kind: 'struct', fields: [['beneficiaryId', 'string']] }, +}; async function signTransaction(receiverId, nonce, actions, signer, accountId, networkId) { - console.warn("WTF?" + await signer.getPublicKey(accountId, networkId)); - // const tx = transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); - const tx = new Transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); - // console.warn(tx.publicKey); - // console.warn("XX: " + JSON.stringify(tx)); - // const message = Transaction.encode(tx).finish(); - const message = tx.encode(); - console.warn("11: " + new Uint8Array(message)); - // const tx2 = Transaction.decode(message); - // console.warn(JSON.stringify(tx2)); - // const message2 = Transaction.encode(tx2).finish(); - // console.warn("33: " + base_encode(message2)); + const publicKey = new PublicKey(await signer.getPublicKey(accountId, networkId)); + const transaction = new Transaction({ signerId: accountId, publicKey, nonce, receiverId, actions }); + const message = serialize_1.serialize(SCHEMA, transaction); const hash = new Uint8Array(js_sha256_1.default.sha256.array(message)); - console.warn("22: " + serialize_1.base_encode(hash)); const signature = await signer.signHash(hash, accountId, networkId); - const signedTx = new SignedTransaction(tx, signature); - // console.warn(JSON.stringify(signedTx)); + const signedTx = new SignedTransaction({ transaction, signature: signature.signature }); return [hash, signedTx]; } exports.signTransaction = signTransaction; diff --git a/lib/utils/serialize.js b/lib/utils/serialize.js index c263fbc039..fb39b56aeb 100644 --- a/lib/utils/serialize.js +++ b/lib/utils/serialize.js @@ -121,15 +121,49 @@ function serializeField(schema, value, fieldType, writer) { writer.write_array(value, (item) => { serializeField(schema, item, fieldType[0], writer); }); } } + else if (fieldType.kind !== undefined) { + switch (fieldType.kind) { + case "option": { + if (value === null) { + writer.write_u8(0); + } + else { + writer.write_u8(1); + serializeField(schema, value, fieldType.type, writer); + } + break; + } + default: throw new Error(`FieldType ${fieldType} unrecognized`); + } + } else { serializeStruct(schema, value, writer); } } function serializeStruct(schema, obj, writer) { const className = obj.constructor.name; - schema[className].map(([fieldName, fieldType]) => { - serializeField(schema, obj[fieldName], fieldType, writer); - }); + if (schema[className] === undefined) { + throw new Error(`Class ${className} is missing in schema`); + } + if (schema[className].kind === 'struct') { + schema[className].fields.map(([fieldName, fieldType]) => { + serializeField(schema, obj[fieldName], fieldType, writer); + }); + } + else if (schema[className].kind === 'enum') { + const name = obj[schema[className].field]; + for (let idx = 0; idx < schema[className].values.length; ++idx) { + let [fieldName, fieldType] = schema[className].values[idx]; + if (fieldName === name) { + writer.write_u8(idx); + serializeField(schema, obj[fieldName], fieldType, writer); + break; + } + } + } + else { + throw new Error(`Unexpected schema kind: ${schema[className].kind} for ${className}`); + } } /// Serialize given object using schema of the form: /// { class_name -> [ [field_name, field_type], .. ], .. } @@ -156,8 +190,7 @@ function deserializeField(schema, fieldType, reader) { } } function deserializeStruct(schema, classType, reader) { - console.log(classType.name); - let fields = schema[classType.name].map(([fieldName, fieldType]) => { + let fields = schema[classType.name].fields.map(([fieldName, fieldType]) => { return deserializeField(schema, fieldType, reader); }); return new classType(...fields); diff --git a/package.json b/package.json index 8b6ceafd35..9c0c236130 100644 --- a/package.json +++ b/package.json @@ -17,14 +17,12 @@ "http-errors": "^1.7.2", "js-sha256": "^0.9.0", "node-fetch": "^2.3.0", - "protobufjs": "^6.8.8", "tslint": "^5.18.0", "tweetnacl": "^1.0.1", "typescript": "^3.5.1" }, "devDependencies": { "@types/bs58": "^4.0.0", - "@types/google-protobuf": "^3.2.7", "@types/http-errors": "^1.6.1", "browserify": "^16.2.3", "documentation": "^9.1.1", @@ -32,7 +30,6 @@ "jest": "^24.1.0", "localstorage-memory": "^1.0.3", "rimraf": "^2.6.3", - "ts-protoc-gen": "^0.10.0", "typedoc": "^0.14.2", "typedoc-plugin-markdown": "^1.2.1", "uglifyify": "^5.0.1" @@ -44,11 +41,10 @@ "keywords": [], "license": "MIT", "scripts": { - "generate-protos": "scripts/generate_js_transaction_proto.sh", "dist": "yarn build && yarn doc && browserify browser-exports.js -i node-fetch -o dist/nearlib.js && browserify browser-exports.js -i node-fetch -g uglifyify -o dist/nearlib.min.js", "compile": "tsc -p ./tsconfig.json", "dev": "yarn compile -- -w", - "build": "yarn generate-protos && yarn compile", + "build": "yarn compile", "pretest": "yarn build", "test": "jest test --runInBand", "lint": "eslint test && tslint -p ./tsconfig.json -t codeFrame", diff --git a/scripts/generate_js_transaction_proto.sh b/scripts/generate_js_transaction_proto.sh deleted file mode 100755 index 2f77c1e0a3..0000000000 --- a/scripts/generate_js_transaction_proto.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -ex - -NEAR_PROTOS_DIR="${NEAR_PROTOS_DIR:-../nearcore/core/protos/protos}" -NEARLIB_DIR="$(npm prefix)" -PROTOC_GEN_TS_PATH="$(yarn bin)/protoc-gen-ts" - -pbjs -t static-module \ - -w commonjs \ - -o "${NEARLIB_DIR}/lib/protos.js" \ - ${NEAR_PROTOS_DIR}/signed_transaction.proto \ - ${NEAR_PROTOS_DIR}/wrappers.proto \ - ${NEAR_PROTOS_DIR}/uint128.proto \ - ${NEAR_PROTOS_DIR}/access_key.proto - -pbts -o "${NEARLIB_DIR}/src.ts/protos.d.ts" "${NEARLIB_DIR}/lib/protos.js" diff --git a/src.ts/account.ts b/src.ts/account.ts index 0ea3fa8d1d..e9b455f57d 100644 --- a/src.ts/account.ts +++ b/src.ts/account.ts @@ -99,6 +99,7 @@ export class Account { throw error; } } + console.log(result); const flatLogs = result.logs.reduce((acc, it) => acc.concat(it.lines), []); this.printLogs(signedTx.transaction.receiverId, flatLogs); diff --git a/src.ts/index.ts b/src.ts/index.ts index a1ddcf4986..7428aa3088 100644 --- a/src.ts/index.ts +++ b/src.ts/index.ts @@ -3,6 +3,7 @@ import * as providers from './providers'; import * as utils from './utils'; import * as keyStores from './key_stores'; +import * as transactions from './transaction'; import { Account } from './account'; import * as accountCreator from './account_creator'; @@ -19,6 +20,7 @@ export { keyStores, providers, utils, + transactions, Account, Connection, @@ -28,6 +30,6 @@ export { KeyPair, connect, - + WalletAccount }; diff --git a/src.ts/protos.d.ts b/src.ts/protos.d.ts deleted file mode 100644 index 24510f75f7..0000000000 --- a/src.ts/protos.d.ts +++ /dev/null @@ -1,2212 +0,0 @@ -import * as $protobuf from "protobufjs"; -/** Properties of an Action. */ -export interface IAction { - - /** Action createAccount */ - createAccount?: (Action.ICreateAccount|null); - - /** Action deployContract */ - deployContract?: (Action.IDeployContract|null); - - /** Action functionCall */ - functionCall?: (Action.IFunctionCall|null); - - /** Action transfer */ - transfer?: (Action.ITransfer|null); - - /** Action stake */ - stake?: (Action.IStake|null); - - /** Action addKey */ - addKey?: (Action.IAddKey|null); - - /** Action deleteKey */ - deleteKey?: (Action.IDeleteKey|null); - - /** Action deleteAccount */ - deleteAccount?: (Action.IDeleteAccount|null); -} - -/** Represents an Action. */ -export class Action implements IAction { - - /** - * Constructs a new Action. - * @param [properties] Properties to set - */ - constructor(properties?: IAction); - - /** Action createAccount. */ - public createAccount?: (Action.ICreateAccount|null); - - /** Action deployContract. */ - public deployContract?: (Action.IDeployContract|null); - - /** Action functionCall. */ - public functionCall?: (Action.IFunctionCall|null); - - /** Action transfer. */ - public transfer?: (Action.ITransfer|null); - - /** Action stake. */ - public stake?: (Action.IStake|null); - - /** Action addKey. */ - public addKey?: (Action.IAddKey|null); - - /** Action deleteKey. */ - public deleteKey?: (Action.IDeleteKey|null); - - /** Action deleteAccount. */ - public deleteAccount?: (Action.IDeleteAccount|null); - - /** Action action. */ - public action?: ("createAccount"|"deployContract"|"functionCall"|"transfer"|"stake"|"addKey"|"deleteKey"|"deleteAccount"); - - /** - * Creates a new Action instance using the specified properties. - * @param [properties] Properties to set - * @returns Action instance - */ - public static create(properties?: IAction): Action; - - /** - * Encodes the specified Action message. Does not implicitly {@link Action.verify|verify} messages. - * @param message Action message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: IAction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified Action message, length delimited. Does not implicitly {@link Action.verify|verify} messages. - * @param message Action message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: IAction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes an Action message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns Action - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action; - - /** - * Decodes an Action message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns Action - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action; - - /** - * Verifies an Action message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates an Action message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns Action - */ - public static fromObject(object: { [k: string]: any }): Action; - - /** - * Creates a plain object from an Action message. Also converts values to other types if specified. - * @param message Action - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this Action to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} - -export namespace Action { - - /** Properties of a CreateAccount. */ - interface ICreateAccount { - } - - /** Represents a CreateAccount. */ - class CreateAccount implements ICreateAccount { - - /** - * Constructs a new CreateAccount. - * @param [properties] Properties to set - */ - constructor(properties?: Action.ICreateAccount); - - /** - * Creates a new CreateAccount instance using the specified properties. - * @param [properties] Properties to set - * @returns CreateAccount instance - */ - public static create(properties?: Action.ICreateAccount): Action.CreateAccount; - - /** - * Encodes the specified CreateAccount message. Does not implicitly {@link Action.CreateAccount.verify|verify} messages. - * @param message CreateAccount message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: Action.ICreateAccount, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified CreateAccount message, length delimited. Does not implicitly {@link Action.CreateAccount.verify|verify} messages. - * @param message CreateAccount message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: Action.ICreateAccount, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a CreateAccount message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns CreateAccount - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.CreateAccount; - - /** - * Decodes a CreateAccount message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns CreateAccount - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.CreateAccount; - - /** - * Verifies a CreateAccount message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a CreateAccount message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns CreateAccount - */ - public static fromObject(object: { [k: string]: any }): Action.CreateAccount; - - /** - * Creates a plain object from a CreateAccount message. Also converts values to other types if specified. - * @param message CreateAccount - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action.CreateAccount, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this CreateAccount to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a DeployContract. */ - interface IDeployContract { - - /** DeployContract code */ - code?: (Uint8Array|null); - } - - /** Represents a DeployContract. */ - class DeployContract implements IDeployContract { - - /** - * Constructs a new DeployContract. - * @param [properties] Properties to set - */ - constructor(properties?: Action.IDeployContract); - - /** DeployContract code. */ - public code: Uint8Array; - - /** - * Creates a new DeployContract instance using the specified properties. - * @param [properties] Properties to set - * @returns DeployContract instance - */ - public static create(properties?: Action.IDeployContract): Action.DeployContract; - - /** - * Encodes the specified DeployContract message. Does not implicitly {@link Action.DeployContract.verify|verify} messages. - * @param message DeployContract message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: Action.IDeployContract, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified DeployContract message, length delimited. Does not implicitly {@link Action.DeployContract.verify|verify} messages. - * @param message DeployContract message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: Action.IDeployContract, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a DeployContract message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns DeployContract - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.DeployContract; - - /** - * Decodes a DeployContract message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns DeployContract - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.DeployContract; - - /** - * Verifies a DeployContract message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a DeployContract message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns DeployContract - */ - public static fromObject(object: { [k: string]: any }): Action.DeployContract; - - /** - * Creates a plain object from a DeployContract message. Also converts values to other types if specified. - * @param message DeployContract - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action.DeployContract, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this DeployContract to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a FunctionCall. */ - interface IFunctionCall { - - /** FunctionCall methodName */ - methodName?: (string|null); - - /** FunctionCall args */ - args?: (Uint8Array|null); - - /** FunctionCall gas */ - gas?: (number|Long|null); - - /** FunctionCall deposit */ - deposit?: (IUint128|null); - } - - /** Represents a FunctionCall. */ - class FunctionCall implements IFunctionCall { - - /** - * Constructs a new FunctionCall. - * @param [properties] Properties to set - */ - constructor(properties?: Action.IFunctionCall); - - /** FunctionCall methodName. */ - public methodName: string; - - /** FunctionCall args. */ - public args: Uint8Array; - - /** FunctionCall gas. */ - public gas: (number|Long); - - /** FunctionCall deposit. */ - public deposit?: (IUint128|null); - - /** - * Creates a new FunctionCall instance using the specified properties. - * @param [properties] Properties to set - * @returns FunctionCall instance - */ - public static create(properties?: Action.IFunctionCall): Action.FunctionCall; - - /** - * Encodes the specified FunctionCall message. Does not implicitly {@link Action.FunctionCall.verify|verify} messages. - * @param message FunctionCall message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: Action.IFunctionCall, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified FunctionCall message, length delimited. Does not implicitly {@link Action.FunctionCall.verify|verify} messages. - * @param message FunctionCall message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: Action.IFunctionCall, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a FunctionCall message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns FunctionCall - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.FunctionCall; - - /** - * Decodes a FunctionCall message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns FunctionCall - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.FunctionCall; - - /** - * Verifies a FunctionCall message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a FunctionCall message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns FunctionCall - */ - public static fromObject(object: { [k: string]: any }): Action.FunctionCall; - - /** - * Creates a plain object from a FunctionCall message. Also converts values to other types if specified. - * @param message FunctionCall - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action.FunctionCall, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this FunctionCall to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a Transfer. */ - interface ITransfer { - - /** Transfer deposit */ - deposit?: (IUint128|null); - } - - /** Represents a Transfer. */ - class Transfer implements ITransfer { - - /** - * Constructs a new Transfer. - * @param [properties] Properties to set - */ - constructor(properties?: Action.ITransfer); - - /** Transfer deposit. */ - public deposit?: (IUint128|null); - - /** - * Creates a new Transfer instance using the specified properties. - * @param [properties] Properties to set - * @returns Transfer instance - */ - public static create(properties?: Action.ITransfer): Action.Transfer; - - /** - * Encodes the specified Transfer message. Does not implicitly {@link Action.Transfer.verify|verify} messages. - * @param message Transfer message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: Action.ITransfer, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified Transfer message, length delimited. Does not implicitly {@link Action.Transfer.verify|verify} messages. - * @param message Transfer message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: Action.ITransfer, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a Transfer message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns Transfer - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.Transfer; - - /** - * Decodes a Transfer message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns Transfer - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.Transfer; - - /** - * Verifies a Transfer message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a Transfer message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns Transfer - */ - public static fromObject(object: { [k: string]: any }): Action.Transfer; - - /** - * Creates a plain object from a Transfer message. Also converts values to other types if specified. - * @param message Transfer - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action.Transfer, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this Transfer to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a Stake. */ - interface IStake { - - /** Stake stake */ - stake?: (IUint128|null); - - /** Stake publicKey */ - publicKey?: (IPublicKey|null); - } - - /** Represents a Stake. */ - class Stake implements IStake { - - /** - * Constructs a new Stake. - * @param [properties] Properties to set - */ - constructor(properties?: Action.IStake); - - /** Stake stake. */ - public stake?: (IUint128|null); - - /** Stake publicKey. */ - public publicKey?: (IPublicKey|null); - - /** - * Creates a new Stake instance using the specified properties. - * @param [properties] Properties to set - * @returns Stake instance - */ - public static create(properties?: Action.IStake): Action.Stake; - - /** - * Encodes the specified Stake message. Does not implicitly {@link Action.Stake.verify|verify} messages. - * @param message Stake message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: Action.IStake, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified Stake message, length delimited. Does not implicitly {@link Action.Stake.verify|verify} messages. - * @param message Stake message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: Action.IStake, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a Stake message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns Stake - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.Stake; - - /** - * Decodes a Stake message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns Stake - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.Stake; - - /** - * Verifies a Stake message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a Stake message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns Stake - */ - public static fromObject(object: { [k: string]: any }): Action.Stake; - - /** - * Creates a plain object from a Stake message. Also converts values to other types if specified. - * @param message Stake - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action.Stake, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this Stake to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of an AddKey. */ - interface IAddKey { - - /** AddKey publicKey */ - publicKey?: (IPublicKey|null); - - /** AddKey accessKey */ - accessKey?: (IAccessKey|null); - } - - /** Represents an AddKey. */ - class AddKey implements IAddKey { - - /** - * Constructs a new AddKey. - * @param [properties] Properties to set - */ - constructor(properties?: Action.IAddKey); - - /** AddKey publicKey. */ - public publicKey?: (IPublicKey|null); - - /** AddKey accessKey. */ - public accessKey?: (IAccessKey|null); - - /** - * Creates a new AddKey instance using the specified properties. - * @param [properties] Properties to set - * @returns AddKey instance - */ - public static create(properties?: Action.IAddKey): Action.AddKey; - - /** - * Encodes the specified AddKey message. Does not implicitly {@link Action.AddKey.verify|verify} messages. - * @param message AddKey message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: Action.IAddKey, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified AddKey message, length delimited. Does not implicitly {@link Action.AddKey.verify|verify} messages. - * @param message AddKey message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: Action.IAddKey, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes an AddKey message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns AddKey - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.AddKey; - - /** - * Decodes an AddKey message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns AddKey - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.AddKey; - - /** - * Verifies an AddKey message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates an AddKey message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns AddKey - */ - public static fromObject(object: { [k: string]: any }): Action.AddKey; - - /** - * Creates a plain object from an AddKey message. Also converts values to other types if specified. - * @param message AddKey - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action.AddKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this AddKey to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a DeleteKey. */ - interface IDeleteKey { - - /** DeleteKey publicKey */ - publicKey?: (IPublicKey|null); - } - - /** Represents a DeleteKey. */ - class DeleteKey implements IDeleteKey { - - /** - * Constructs a new DeleteKey. - * @param [properties] Properties to set - */ - constructor(properties?: Action.IDeleteKey); - - /** DeleteKey publicKey. */ - public publicKey?: (IPublicKey|null); - - /** - * Creates a new DeleteKey instance using the specified properties. - * @param [properties] Properties to set - * @returns DeleteKey instance - */ - public static create(properties?: Action.IDeleteKey): Action.DeleteKey; - - /** - * Encodes the specified DeleteKey message. Does not implicitly {@link Action.DeleteKey.verify|verify} messages. - * @param message DeleteKey message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: Action.IDeleteKey, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified DeleteKey message, length delimited. Does not implicitly {@link Action.DeleteKey.verify|verify} messages. - * @param message DeleteKey message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: Action.IDeleteKey, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a DeleteKey message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns DeleteKey - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.DeleteKey; - - /** - * Decodes a DeleteKey message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns DeleteKey - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.DeleteKey; - - /** - * Verifies a DeleteKey message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a DeleteKey message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns DeleteKey - */ - public static fromObject(object: { [k: string]: any }): Action.DeleteKey; - - /** - * Creates a plain object from a DeleteKey message. Also converts values to other types if specified. - * @param message DeleteKey - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action.DeleteKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this DeleteKey to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a DeleteAccount. */ - interface IDeleteAccount { - - /** DeleteAccount beneficiaryId */ - beneficiaryId?: (string|null); - } - - /** Represents a DeleteAccount. */ - class DeleteAccount implements IDeleteAccount { - - /** - * Constructs a new DeleteAccount. - * @param [properties] Properties to set - */ - constructor(properties?: Action.IDeleteAccount); - - /** DeleteAccount beneficiaryId. */ - public beneficiaryId: string; - - /** - * Creates a new DeleteAccount instance using the specified properties. - * @param [properties] Properties to set - * @returns DeleteAccount instance - */ - public static create(properties?: Action.IDeleteAccount): Action.DeleteAccount; - - /** - * Encodes the specified DeleteAccount message. Does not implicitly {@link Action.DeleteAccount.verify|verify} messages. - * @param message DeleteAccount message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: Action.IDeleteAccount, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified DeleteAccount message, length delimited. Does not implicitly {@link Action.DeleteAccount.verify|verify} messages. - * @param message DeleteAccount message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: Action.IDeleteAccount, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a DeleteAccount message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns DeleteAccount - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Action.DeleteAccount; - - /** - * Decodes a DeleteAccount message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns DeleteAccount - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Action.DeleteAccount; - - /** - * Verifies a DeleteAccount message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a DeleteAccount message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns DeleteAccount - */ - public static fromObject(object: { [k: string]: any }): Action.DeleteAccount; - - /** - * Creates a plain object from a DeleteAccount message. Also converts values to other types if specified. - * @param message DeleteAccount - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Action.DeleteAccount, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this DeleteAccount to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } -} - -/** Properties of a Transaction. */ -export interface ITransaction { - - /** Transaction signerId */ - signerId?: (string|null); - - /** Transaction publicKey */ - publicKey?: (IPublicKey|null); - - /** Transaction nonce */ - nonce?: (number|Long|null); - - /** Transaction receiverId */ - receiverId?: (string|null); - - /** Transaction actions */ - actions?: (IAction[]|null); -} - -/** Represents a Transaction. */ -export class Transaction implements ITransaction { - - /** - * Constructs a new Transaction. - * @param [properties] Properties to set - */ - constructor(properties?: ITransaction); - - /** Transaction signerId. */ - public signerId: string; - - /** Transaction publicKey. */ - public publicKey?: (IPublicKey|null); - - /** Transaction nonce. */ - public nonce: (number|Long); - - /** Transaction receiverId. */ - public receiverId: string; - - /** Transaction actions. */ - public actions: IAction[]; - - /** - * Creates a new Transaction instance using the specified properties. - * @param [properties] Properties to set - * @returns Transaction instance - */ - public static create(properties?: ITransaction): Transaction; - - /** - * Encodes the specified Transaction message. Does not implicitly {@link Transaction.verify|verify} messages. - * @param message Transaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: ITransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified Transaction message, length delimited. Does not implicitly {@link Transaction.verify|verify} messages. - * @param message Transaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: ITransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a Transaction message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns Transaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Transaction; - - /** - * Decodes a Transaction message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns Transaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Transaction; - - /** - * Verifies a Transaction message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a Transaction message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns Transaction - */ - public static fromObject(object: { [k: string]: any }): Transaction; - - /** - * Creates a plain object from a Transaction message. Also converts values to other types if specified. - * @param message Transaction - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Transaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this Transaction to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} - -/** Properties of a SignedTransaction. */ -export interface ISignedTransaction { - - /** SignedTransaction signature */ - signature?: (Uint8Array|null); - - /** SignedTransaction transaction */ - transaction?: (ITransaction|null); -} - -/** Represents a SignedTransaction. */ -export class SignedTransaction implements ISignedTransaction { - - /** - * Constructs a new SignedTransaction. - * @param [properties] Properties to set - */ - constructor(properties?: ISignedTransaction); - - /** SignedTransaction signature. */ - public signature: Uint8Array; - - /** SignedTransaction transaction. */ - public transaction?: (ITransaction|null); - - /** - * Creates a new SignedTransaction instance using the specified properties. - * @param [properties] Properties to set - * @returns SignedTransaction instance - */ - public static create(properties?: ISignedTransaction): SignedTransaction; - - /** - * Encodes the specified SignedTransaction message. Does not implicitly {@link SignedTransaction.verify|verify} messages. - * @param message SignedTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: ISignedTransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified SignedTransaction message, length delimited. Does not implicitly {@link SignedTransaction.verify|verify} messages. - * @param message SignedTransaction message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: ISignedTransaction, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a SignedTransaction message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns SignedTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): SignedTransaction; - - /** - * Decodes a SignedTransaction message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns SignedTransaction - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): SignedTransaction; - - /** - * Verifies a SignedTransaction message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a SignedTransaction message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns SignedTransaction - */ - public static fromObject(object: { [k: string]: any }): SignedTransaction; - - /** - * Creates a plain object from a SignedTransaction message. Also converts values to other types if specified. - * @param message SignedTransaction - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: SignedTransaction, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this SignedTransaction to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} - -/** Properties of an AccessKey. */ -export interface IAccessKey { - - /** AccessKey amount */ - amount?: (IUint128|null); - - /** AccessKey balanceOwner */ - balanceOwner?: (google.protobuf.IStringValue|null); - - /** AccessKey contractId */ - contractId?: (google.protobuf.IStringValue|null); - - /** AccessKey methodName */ - methodName?: (google.protobuf.IBytesValue|null); -} - -/** Represents an AccessKey. */ -export class AccessKey implements IAccessKey { - - /** - * Constructs a new AccessKey. - * @param [properties] Properties to set - */ - constructor(properties?: IAccessKey); - - /** AccessKey amount. */ - public amount?: (IUint128|null); - - /** AccessKey balanceOwner. */ - public balanceOwner?: (google.protobuf.IStringValue|null); - - /** AccessKey contractId. */ - public contractId?: (google.protobuf.IStringValue|null); - - /** AccessKey methodName. */ - public methodName?: (google.protobuf.IBytesValue|null); - - /** - * Creates a new AccessKey instance using the specified properties. - * @param [properties] Properties to set - * @returns AccessKey instance - */ - public static create(properties?: IAccessKey): AccessKey; - - /** - * Encodes the specified AccessKey message. Does not implicitly {@link AccessKey.verify|verify} messages. - * @param message AccessKey message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: IAccessKey, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified AccessKey message, length delimited. Does not implicitly {@link AccessKey.verify|verify} messages. - * @param message AccessKey message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: IAccessKey, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes an AccessKey message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns AccessKey - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): AccessKey; - - /** - * Decodes an AccessKey message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns AccessKey - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): AccessKey; - - /** - * Verifies an AccessKey message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates an AccessKey message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns AccessKey - */ - public static fromObject(object: { [k: string]: any }): AccessKey; - - /** - * Creates a plain object from an AccessKey message. Also converts values to other types if specified. - * @param message AccessKey - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: AccessKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this AccessKey to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} - -/** Namespace google. */ -export namespace google { - - /** Namespace protobuf. */ - namespace protobuf { - - /** Properties of a DoubleValue. */ - interface IDoubleValue { - - /** DoubleValue value */ - value?: (number|null); - } - - /** Represents a DoubleValue. */ - class DoubleValue implements IDoubleValue { - - /** - * Constructs a new DoubleValue. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IDoubleValue); - - /** DoubleValue value. */ - public value: number; - - /** - * Creates a new DoubleValue instance using the specified properties. - * @param [properties] Properties to set - * @returns DoubleValue instance - */ - public static create(properties?: google.protobuf.IDoubleValue): google.protobuf.DoubleValue; - - /** - * Encodes the specified DoubleValue message. Does not implicitly {@link google.protobuf.DoubleValue.verify|verify} messages. - * @param message DoubleValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IDoubleValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified DoubleValue message, length delimited. Does not implicitly {@link google.protobuf.DoubleValue.verify|verify} messages. - * @param message DoubleValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IDoubleValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a DoubleValue message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns DoubleValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.DoubleValue; - - /** - * Decodes a DoubleValue message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns DoubleValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.DoubleValue; - - /** - * Verifies a DoubleValue message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a DoubleValue message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns DoubleValue - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.DoubleValue; - - /** - * Creates a plain object from a DoubleValue message. Also converts values to other types if specified. - * @param message DoubleValue - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.DoubleValue, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this DoubleValue to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a FloatValue. */ - interface IFloatValue { - - /** FloatValue value */ - value?: (number|null); - } - - /** Represents a FloatValue. */ - class FloatValue implements IFloatValue { - - /** - * Constructs a new FloatValue. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IFloatValue); - - /** FloatValue value. */ - public value: number; - - /** - * Creates a new FloatValue instance using the specified properties. - * @param [properties] Properties to set - * @returns FloatValue instance - */ - public static create(properties?: google.protobuf.IFloatValue): google.protobuf.FloatValue; - - /** - * Encodes the specified FloatValue message. Does not implicitly {@link google.protobuf.FloatValue.verify|verify} messages. - * @param message FloatValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IFloatValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified FloatValue message, length delimited. Does not implicitly {@link google.protobuf.FloatValue.verify|verify} messages. - * @param message FloatValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IFloatValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a FloatValue message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns FloatValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FloatValue; - - /** - * Decodes a FloatValue message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns FloatValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.FloatValue; - - /** - * Verifies a FloatValue message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a FloatValue message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns FloatValue - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.FloatValue; - - /** - * Creates a plain object from a FloatValue message. Also converts values to other types if specified. - * @param message FloatValue - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.FloatValue, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this FloatValue to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of an Int64Value. */ - interface IInt64Value { - - /** Int64Value value */ - value?: (number|Long|null); - } - - /** Represents an Int64Value. */ - class Int64Value implements IInt64Value { - - /** - * Constructs a new Int64Value. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IInt64Value); - - /** Int64Value value. */ - public value: (number|Long); - - /** - * Creates a new Int64Value instance using the specified properties. - * @param [properties] Properties to set - * @returns Int64Value instance - */ - public static create(properties?: google.protobuf.IInt64Value): google.protobuf.Int64Value; - - /** - * Encodes the specified Int64Value message. Does not implicitly {@link google.protobuf.Int64Value.verify|verify} messages. - * @param message Int64Value message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IInt64Value, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified Int64Value message, length delimited. Does not implicitly {@link google.protobuf.Int64Value.verify|verify} messages. - * @param message Int64Value message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IInt64Value, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes an Int64Value message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns Int64Value - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.Int64Value; - - /** - * Decodes an Int64Value message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns Int64Value - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.Int64Value; - - /** - * Verifies an Int64Value message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates an Int64Value message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns Int64Value - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.Int64Value; - - /** - * Creates a plain object from an Int64Value message. Also converts values to other types if specified. - * @param message Int64Value - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.Int64Value, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this Int64Value to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a UInt64Value. */ - interface IUInt64Value { - - /** UInt64Value value */ - value?: (number|Long|null); - } - - /** Represents a UInt64Value. */ - class UInt64Value implements IUInt64Value { - - /** - * Constructs a new UInt64Value. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IUInt64Value); - - /** UInt64Value value. */ - public value: (number|Long); - - /** - * Creates a new UInt64Value instance using the specified properties. - * @param [properties] Properties to set - * @returns UInt64Value instance - */ - public static create(properties?: google.protobuf.IUInt64Value): google.protobuf.UInt64Value; - - /** - * Encodes the specified UInt64Value message. Does not implicitly {@link google.protobuf.UInt64Value.verify|verify} messages. - * @param message UInt64Value message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IUInt64Value, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified UInt64Value message, length delimited. Does not implicitly {@link google.protobuf.UInt64Value.verify|verify} messages. - * @param message UInt64Value message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IUInt64Value, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a UInt64Value message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns UInt64Value - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.UInt64Value; - - /** - * Decodes a UInt64Value message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns UInt64Value - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.UInt64Value; - - /** - * Verifies a UInt64Value message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a UInt64Value message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns UInt64Value - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.UInt64Value; - - /** - * Creates a plain object from a UInt64Value message. Also converts values to other types if specified. - * @param message UInt64Value - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.UInt64Value, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this UInt64Value to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of an Int32Value. */ - interface IInt32Value { - - /** Int32Value value */ - value?: (number|null); - } - - /** Represents an Int32Value. */ - class Int32Value implements IInt32Value { - - /** - * Constructs a new Int32Value. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IInt32Value); - - /** Int32Value value. */ - public value: number; - - /** - * Creates a new Int32Value instance using the specified properties. - * @param [properties] Properties to set - * @returns Int32Value instance - */ - public static create(properties?: google.protobuf.IInt32Value): google.protobuf.Int32Value; - - /** - * Encodes the specified Int32Value message. Does not implicitly {@link google.protobuf.Int32Value.verify|verify} messages. - * @param message Int32Value message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IInt32Value, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified Int32Value message, length delimited. Does not implicitly {@link google.protobuf.Int32Value.verify|verify} messages. - * @param message Int32Value message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IInt32Value, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes an Int32Value message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns Int32Value - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.Int32Value; - - /** - * Decodes an Int32Value message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns Int32Value - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.Int32Value; - - /** - * Verifies an Int32Value message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates an Int32Value message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns Int32Value - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.Int32Value; - - /** - * Creates a plain object from an Int32Value message. Also converts values to other types if specified. - * @param message Int32Value - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.Int32Value, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this Int32Value to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a UInt32Value. */ - interface IUInt32Value { - - /** UInt32Value value */ - value?: (number|null); - } - - /** Represents a UInt32Value. */ - class UInt32Value implements IUInt32Value { - - /** - * Constructs a new UInt32Value. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IUInt32Value); - - /** UInt32Value value. */ - public value: number; - - /** - * Creates a new UInt32Value instance using the specified properties. - * @param [properties] Properties to set - * @returns UInt32Value instance - */ - public static create(properties?: google.protobuf.IUInt32Value): google.protobuf.UInt32Value; - - /** - * Encodes the specified UInt32Value message. Does not implicitly {@link google.protobuf.UInt32Value.verify|verify} messages. - * @param message UInt32Value message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IUInt32Value, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified UInt32Value message, length delimited. Does not implicitly {@link google.protobuf.UInt32Value.verify|verify} messages. - * @param message UInt32Value message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IUInt32Value, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a UInt32Value message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns UInt32Value - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.UInt32Value; - - /** - * Decodes a UInt32Value message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns UInt32Value - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.UInt32Value; - - /** - * Verifies a UInt32Value message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a UInt32Value message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns UInt32Value - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.UInt32Value; - - /** - * Creates a plain object from a UInt32Value message. Also converts values to other types if specified. - * @param message UInt32Value - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.UInt32Value, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this UInt32Value to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a BoolValue. */ - interface IBoolValue { - - /** BoolValue value */ - value?: (boolean|null); - } - - /** Represents a BoolValue. */ - class BoolValue implements IBoolValue { - - /** - * Constructs a new BoolValue. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IBoolValue); - - /** BoolValue value. */ - public value: boolean; - - /** - * Creates a new BoolValue instance using the specified properties. - * @param [properties] Properties to set - * @returns BoolValue instance - */ - public static create(properties?: google.protobuf.IBoolValue): google.protobuf.BoolValue; - - /** - * Encodes the specified BoolValue message. Does not implicitly {@link google.protobuf.BoolValue.verify|verify} messages. - * @param message BoolValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IBoolValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified BoolValue message, length delimited. Does not implicitly {@link google.protobuf.BoolValue.verify|verify} messages. - * @param message BoolValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IBoolValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a BoolValue message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns BoolValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.BoolValue; - - /** - * Decodes a BoolValue message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns BoolValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.BoolValue; - - /** - * Verifies a BoolValue message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a BoolValue message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns BoolValue - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.BoolValue; - - /** - * Creates a plain object from a BoolValue message. Also converts values to other types if specified. - * @param message BoolValue - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.BoolValue, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this BoolValue to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a StringValue. */ - interface IStringValue { - - /** StringValue value */ - value?: (string|null); - } - - /** Represents a StringValue. */ - class StringValue implements IStringValue { - - /** - * Constructs a new StringValue. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IStringValue); - - /** StringValue value. */ - public value: string; - - /** - * Creates a new StringValue instance using the specified properties. - * @param [properties] Properties to set - * @returns StringValue instance - */ - public static create(properties?: google.protobuf.IStringValue): google.protobuf.StringValue; - - /** - * Encodes the specified StringValue message. Does not implicitly {@link google.protobuf.StringValue.verify|verify} messages. - * @param message StringValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IStringValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified StringValue message, length delimited. Does not implicitly {@link google.protobuf.StringValue.verify|verify} messages. - * @param message StringValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IStringValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a StringValue message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns StringValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.StringValue; - - /** - * Decodes a StringValue message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns StringValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.StringValue; - - /** - * Verifies a StringValue message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a StringValue message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns StringValue - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.StringValue; - - /** - * Creates a plain object from a StringValue message. Also converts values to other types if specified. - * @param message StringValue - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.StringValue, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this StringValue to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - - /** Properties of a BytesValue. */ - interface IBytesValue { - - /** BytesValue value */ - value?: (Uint8Array|null); - } - - /** Represents a BytesValue. */ - class BytesValue implements IBytesValue { - - /** - * Constructs a new BytesValue. - * @param [properties] Properties to set - */ - constructor(properties?: google.protobuf.IBytesValue); - - /** BytesValue value. */ - public value: Uint8Array; - - /** - * Creates a new BytesValue instance using the specified properties. - * @param [properties] Properties to set - * @returns BytesValue instance - */ - public static create(properties?: google.protobuf.IBytesValue): google.protobuf.BytesValue; - - /** - * Encodes the specified BytesValue message. Does not implicitly {@link google.protobuf.BytesValue.verify|verify} messages. - * @param message BytesValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: google.protobuf.IBytesValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified BytesValue message, length delimited. Does not implicitly {@link google.protobuf.BytesValue.verify|verify} messages. - * @param message BytesValue message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: google.protobuf.IBytesValue, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a BytesValue message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns BytesValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.BytesValue; - - /** - * Decodes a BytesValue message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns BytesValue - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.BytesValue; - - /** - * Verifies a BytesValue message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a BytesValue message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns BytesValue - */ - public static fromObject(object: { [k: string]: any }): google.protobuf.BytesValue; - - /** - * Creates a plain object from a BytesValue message. Also converts values to other types if specified. - * @param message BytesValue - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: google.protobuf.BytesValue, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this BytesValue to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; - } - } -} - -/** Properties of an Uint128. */ -export interface IUint128 { - - /** Uint128 number */ - number?: (Uint8Array|null); -} - -/** Provides container for unsigned 128 bit integers. */ -export class Uint128 implements IUint128 { - - /** - * Constructs a new Uint128. - * @param [properties] Properties to set - */ - constructor(properties?: IUint128); - - /** Uint128 number. */ - public number: Uint8Array; - - /** - * Creates a new Uint128 instance using the specified properties. - * @param [properties] Properties to set - * @returns Uint128 instance - */ - public static create(properties?: IUint128): Uint128; - - /** - * Encodes the specified Uint128 message. Does not implicitly {@link Uint128.verify|verify} messages. - * @param message Uint128 message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: IUint128, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified Uint128 message, length delimited. Does not implicitly {@link Uint128.verify|verify} messages. - * @param message Uint128 message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: IUint128, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes an Uint128 message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns Uint128 - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Uint128; - - /** - * Decodes an Uint128 message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns Uint128 - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Uint128; - - /** - * Verifies an Uint128 message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates an Uint128 message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns Uint128 - */ - public static fromObject(object: { [k: string]: any }): Uint128; - - /** - * Creates a plain object from an Uint128 message. Also converts values to other types if specified. - * @param message Uint128 - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: Uint128, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this Uint128 to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} - -/** Properties of a PublicKey. */ -export interface IPublicKey { - - /** PublicKey keyType */ - keyType?: (PublicKey.KeyType|null); - - /** PublicKey data */ - data?: (Uint8Array|null); -} - -/** Represents a PublicKey. */ -export class PublicKey implements IPublicKey { - - /** - * Constructs a new PublicKey. - * @param [properties] Properties to set - */ - constructor(properties?: IPublicKey); - - /** PublicKey keyType. */ - public keyType: PublicKey.KeyType; - - /** PublicKey data. */ - public data: Uint8Array; - - /** - * Creates a new PublicKey instance using the specified properties. - * @param [properties] Properties to set - * @returns PublicKey instance - */ - public static create(properties?: IPublicKey): PublicKey; - - /** - * Encodes the specified PublicKey message. Does not implicitly {@link PublicKey.verify|verify} messages. - * @param message PublicKey message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encode(message: IPublicKey, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Encodes the specified PublicKey message, length delimited. Does not implicitly {@link PublicKey.verify|verify} messages. - * @param message PublicKey message or plain object to encode - * @param [writer] Writer to encode to - * @returns Writer - */ - public static encodeDelimited(message: IPublicKey, writer?: $protobuf.Writer): $protobuf.Writer; - - /** - * Decodes a PublicKey message from the specified reader or buffer. - * @param reader Reader or buffer to decode from - * @param [length] Message length if known beforehand - * @returns PublicKey - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): PublicKey; - - /** - * Decodes a PublicKey message from the specified reader or buffer, length delimited. - * @param reader Reader or buffer to decode from - * @returns PublicKey - * @throws {Error} If the payload is not a reader or valid buffer - * @throws {$protobuf.util.ProtocolError} If required fields are missing - */ - public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): PublicKey; - - /** - * Verifies a PublicKey message. - * @param message Plain object to verify - * @returns `null` if valid, otherwise the reason why it is not - */ - public static verify(message: { [k: string]: any }): (string|null); - - /** - * Creates a PublicKey message from a plain object. Also converts values to their respective internal types. - * @param object Plain object - * @returns PublicKey - */ - public static fromObject(object: { [k: string]: any }): PublicKey; - - /** - * Creates a plain object from a PublicKey message. Also converts values to other types if specified. - * @param message PublicKey - * @param [options] Conversion options - * @returns Plain object - */ - public static toObject(message: PublicKey, options?: $protobuf.IConversionOptions): { [k: string]: any }; - - /** - * Converts this PublicKey to JSON. - * @returns JSON object - */ - public toJSON(): { [k: string]: any }; -} - -export namespace PublicKey { - - /** KeyType enum. */ - enum KeyType { - ED25519 = 0 - } -} diff --git a/src.ts/providers/json-rpc-provider.ts b/src.ts/providers/json-rpc-provider.ts index 6a4077b35e..b4e30182f2 100644 --- a/src.ts/providers/json-rpc-provider.ts +++ b/src.ts/providers/json-rpc-provider.ts @@ -4,7 +4,7 @@ import { Provider, FinalTransactionResult, NodeStatusResult, BlockResult } from import { Network } from '../utils/network'; import { ConnectionInfo, fetchJson } from '../utils/web'; import { base_encode } from '../utils/serialize'; -import { SignedTransaction } from '../protos'; +import { SignedTransaction } from '../transaction'; /// Keep ids unique across all connections. let _nextId = 123; @@ -31,7 +31,7 @@ export class JsonRpcProvider extends Provider { } async sendTransaction(signedTransaction: SignedTransaction): Promise { - const bytes = SignedTransaction.encode(signedTransaction).finish(); + const bytes = signedTransaction.encode(); console.warn("Bytes: " + new Uint8Array(bytes)); return this.sendJsonRpc('broadcast_tx_commit', [Buffer.from(bytes).toString('base64')]); } diff --git a/src.ts/providers/provider.ts b/src.ts/providers/provider.ts index da57e575b6..db33288cd4 100644 --- a/src.ts/providers/provider.ts +++ b/src.ts/providers/provider.ts @@ -1,7 +1,7 @@ 'use strict'; import { Network } from '../utils/network'; -import { SignedTransaction } from '../protos'; +import { SignedTransaction } from '../transaction'; export interface SyncInfo { latest_block_hash: string; diff --git a/src.ts/signer.ts b/src.ts/signer.ts index 76639b6c0b..141bd2fa98 100644 --- a/src.ts/signer.ts +++ b/src.ts/signer.ts @@ -59,7 +59,6 @@ export class InMemorySigner extends Signer { async getPublicKey(accountId?: string, networkId?: string): Promise { const keyPair = await this.keyStore.getKey(networkId, accountId); - console.warn(`network: ${networkId}, account: ${accountId}`); return keyPair.getPublicKey(); } diff --git a/src.ts/transaction.ts b/src.ts/transaction.ts index a8e953e65c..0da741d182 100644 --- a/src.ts/transaction.ts +++ b/src.ts/transaction.ts @@ -3,79 +3,72 @@ import sha256 from 'js-sha256'; import BN from 'bn.js'; -// import { Uint128, Action, AccessKey, PublicKey, SignedTransaction, Transaction, google } from './protos'; -import { base_encode, base_decode } from './utils/serialize'; -import { Signature } from './utils/key_pair'; +import { base_decode, serialize } from './utils/serialize'; import { Signer } from './signer'; -import { Transaction, PublicKey } from './protos'; - -// export type Action = Action; - -// function bigInt(num: BN): Uint128 { -// const number = new Uint8Array(new BN(num).toArray('le', 16)); -// return new Uint128({ number }); -// } - -// function toPublicKey(publicKey: string): PublicKey { -// return new PublicKey({ keyType: PublicKey.KeyType.ED25519, data: base_decode(publicKey) }) -// } - -// export function bignumHex2Dec(num: string): string { -// return new BN(num, 16).toString(10); -// } - -// export function createAccount(): Action { -// return new Action({ createAccount: new Action.CreateAccount() }); -// } - -// export function deployContract(code: Uint8Array): Action { -// return new Action({ deployContract: new Action.DeployContract({code}) }); -// } - -// export function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action { -// return new Action({ functionCall: new Action.FunctionCall({methodName, args, gas, deposit: bigInt(deposit) }) }); -// } - -// export function transfer(deposit: BN): Action { -// return new Action({ transfer: new Action.Transfer({ deposit: bigInt(deposit) }) }); -// } - -// export function stake(stake: BN, publicKey: string): Action { -// return new Action({ stake: new Action.Stake({ stake: bigInt(stake), publicKey: toPublicKey(publicKey) })}); -// } - -// export function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey { -// return new AccessKey({ -// contractId: contractId ? new google.protobuf.StringValue({ value: contractId }) : null, -// methodName: methodName ? new google.protobuf.BytesValue({ value: Buffer.from(methodName) }) : null, -// balanceOwner: balanceOwner ? new google.protobuf.StringValue({ value: balanceOwner }) : null, -// amount: bigInt(amount || new BN(0)), -// }); -// } - -// export function addKey(publicKey: string, accessKey: AccessKey): Action { -// console.warn(accessKey); -// return new Action({ addKey: new Action.AddKey({ publicKey: toPublicKey(publicKey), accessKey}) }); -// } - -// export function deleteKey(publicKey: string): Action { -// return new Action({ deleteKey: new Action.DeleteKey({ publicKey: toPublicKey(publicKey) }) }); -// } - -// export function deleteAccount(beneficiaryId: string): Action { -// return new Action({ deleteAccount: new Action.DeleteAccount({ beneficiaryId }) }); -// } - -// export function transaction(signerId: string, publicKey: string, nonce: number, receiverId: string, actions: Action[]): Transaction { -// return new Transaction({ signerId, publicKey: toPublicKey(publicKey), nonce, receiverId, actions }) -// } - -// export function signedTransaction(transaction: Transaction, signature: Signature): SignedTransaction { -// return new SignedTransaction({ -// signature: signature.signature, -// transaction -// }); -// } + +export class Assignable { + constructor(properties: any) { + Object.keys(properties).map((key: any) => { + (this as any)[key] = properties[key]; + }); + } +} + +export class AccessKey extends Assignable { + contractId: string; methodName: Uint8Array; balanceOwner: string; amount: BN +} + +export function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey { + return new AccessKey({ + contractId, + methodName, + balanceOwner, + amount: amount || new BN(0), + }); +} + +export class IAction extends Assignable {} + +class CreateAccount extends IAction {} +class DeployContract extends IAction { code: Uint8Array } +class FunctionCall extends IAction { methodName: string; args: Uint8Array; gas: BN; deposit: BN } +class Transfer extends IAction { deposit: BN } +class Stake extends IAction { stake: BN; publicKey: PublicKey } +class AddKey extends IAction { publicKey: PublicKey; accessKey: AccessKey } +class DeleteKey extends IAction { publicKey: PublicKey } +class DeleteAccount extends IAction { beneficiaryId: string } + +export function createAccount(): Action { + return new Action({createAccount: new CreateAccount({}) }); +} + +export function deployContract(code: Uint8Array): Action { + return new Action({ deployContract: new DeployContract({code}) }); +} + +export function functionCall(methodName: string, args: Uint8Array, gas: number, deposit: BN): Action { + return new Action({functionCall: new FunctionCall({methodName, args, gas, deposit }) }); +} + +export function transfer(deposit: BN): Action { + return new Action({transfer: new Transfer({ deposit }) }); +} + +export function stake(stake: BN, publicKey: string): Action { + return new Action({stake: new Stake({ stake, publicKey: new PublicKey(publicKey) }) }); +} + +export function addKey(publicKey: string, accessKey: AccessKey): Action { + return new Action({addKey: new AddKey({ publicKey: new PublicKey(publicKey), accessKey}) }); +} + +export function deleteKey(publicKey: string): Action { + return new Action({deleteKey: new DeleteKey({ publicKey: new PublicKey(publicKey) }) }); +} + +export function deleteAccount(beneficiaryId: string): Action { + return new Action({deleteAccount: new DeleteAccount({ beneficiaryId }) }); +} enum KeyType { ED25519 = 0, @@ -91,57 +84,83 @@ class PublicKey { } } -interface Action { -} - -class Transaction { +class Transaction extends Assignable { signerId: string; publicKey: PublicKey; nonce: number; receiverId: string; actions: Array; - - constructor(signedId: string, publicKey: string, nonce: number, receiverId: string, actions: Array) { - this.signerId = signedId; - this.publicKey = new PublicKey(publicKey); - this.nonce = nonce; - this.receiverId = receiverId; - this.actions = actions; - } } -class SignedTransaction { +export class SignedTransaction extends Assignable { transaction: Transaction; signature: Uint8Array; - constructor(transaction: Transaction, signature: Uint8Array) { - this.transaction = transaction; - this.signature = signature; + encode(): Uint8Array { + return serialize(SCHEMA, this); } } -// const SCHEMA = { -// 'SignedTransaction': [['transaction', Transaction], ['signature', [32]]], -// 'Transaction': [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]], -// } +export class Action { + action: string; + createAccount: CreateAccount; + deployContract: DeployContract; + functionCall: FunctionCall; + transfer: Transfer; + stake: Stake; + addKey: AddKey; + deleteKey: DeleteKey; + deleteAccount: DeleteAccount; + + constructor(properties: any) { + if (Object.keys(properties).length != 1) { + throw new Error("Action can only take single value"); + } + Object.keys(properties).map((key: string) => { + (this as any)[key] = properties[key]; + this.action = key; + }); + } +} + +const SCHEMA = { + 'SignedTransaction': {kind: 'struct', fields: [['transaction', Transaction], ['signature', [32]]]}, + 'Transaction': { + kind: 'struct', fields: [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]] }, + 'PublicKey': { + kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]] }, + 'AccessKey': { kind: 'struct', fields: [ + ['amount', 'u128'], + ['balanceOwner', { kind: 'option', type: 'string' }], + ['contractId', {kind: 'option', type: 'string'}], + ['methodName', {kind: 'option', type: ['u8']}], + ]}, + 'Action': {kind: 'enum', field: 'action', values: [ + ['createAccount', CreateAccount], + ['deployContract', DeployContract], + ['functionCall', functionCall], + ['transfer', transfer], + ['stake', stake], + ['addKey', addKey], + ['deleteKey', deleteKey], + ['deleteAccount', deleteAccount], + ]}, + 'CreateAccount': { kind: 'struct', fields: [] }, + 'DeployContract': { kind: 'struct', fields: [['code', ['u8']]] }, + 'FunctionCall': { kind: 'struct', fields: [['methodName', 'string'], ['args', ['u8']], ['gas', 'u64'], ['deposit', 'u128']] }, + 'Transfer': { kind: 'struct', fields: [['deposit', 'u128']] }, + 'Stake': { kind: 'struct', fields: [['stake', 'u128'], ['publicKey', PublicKey]] }, + 'AddKey': { kind: 'struct', fields: [['publicKey', PublicKey], ['accessKey', AccessKey]] }, + 'DeleteKey': { kind: 'struct', fields: [['publicKey', PublicKey]] }, + 'DeleteAccount': { kind: 'struct', fields: [['beneficiaryId', 'string']] }, +} export async function signTransaction(receiverId: string, nonce: number, actions: Action[], signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]> { - console.warn("WTF?" + await signer.getPublicKey(accountId, networkId)); - // const tx = transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); - const tx = new Transaction(accountId, await signer.getPublicKey(accountId, networkId), nonce, receiverId, actions); - // console.warn(tx.publicKey); - // console.warn("XX: " + JSON.stringify(tx)); - // const message = Transaction.encode(tx).finish(); - const message = tx.encode(); - console.warn("11: " + new Uint8Array(message)); - // const tx2 = Transaction.decode(message); - // console.warn(JSON.stringify(tx2)); - // const message2 = Transaction.encode(tx2).finish(); - // console.warn("33: " + base_encode(message2)); + const publicKey = new PublicKey(await signer.getPublicKey(accountId, networkId)); + const transaction = new Transaction({ signerId: accountId, publicKey, nonce, receiverId, actions }); + const message = serialize(SCHEMA, transaction); const hash = new Uint8Array(sha256.sha256.array(message)); - console.warn("22: " + base_encode(hash)); const signature = await signer.signHash(hash, accountId, networkId); - const signedTx = new SignedTransaction(tx, signature); - // console.warn(JSON.stringify(signedTx)); + const signedTx = new SignedTransaction({transaction, signature: signature.signature }); return [hash, signedTx]; } diff --git a/src.ts/utils/serialize.ts b/src.ts/utils/serialize.ts index a57e500909..2bd6fd3635 100644 --- a/src.ts/utils/serialize.ts +++ b/src.ts/utils/serialize.ts @@ -141,6 +141,19 @@ function serializeField(schema: any, value: any, fieldType: any, writer: any) { } else { writer.write_array(value, (item: any) => { serializeField(schema, item, fieldType[0], writer) }); } + } else if (fieldType.kind !== undefined) { + switch (fieldType.kind) { + case "option": { + if (value === null) { + writer.write_u8(0); + } else { + writer.write_u8(1); + serializeField(schema, value, fieldType.type, writer); + } + break; + } + default: throw new Error(`FieldType ${fieldType} unrecognized`) + } } else { serializeStruct(schema, value, writer); } @@ -148,9 +161,26 @@ function serializeField(schema: any, value: any, fieldType: any, writer: any) { function serializeStruct(schema: any, obj: any, writer: any) { const className = obj.constructor.name; - schema[className].map(([fieldName, fieldType]: [any, any]) => { - serializeField(schema, obj[fieldName], fieldType, writer); - }); + if (schema[className] === undefined) { + throw new Error(`Class ${className} is missing in schema`) + } + if (schema[className].kind === 'struct') { + schema[className].fields.map(([fieldName, fieldType]: [any, any]) => { + serializeField(schema, obj[fieldName], fieldType, writer); + }); + } else if (schema[className].kind === 'enum') { + const name = obj[schema[className].field]; + for (let idx = 0; idx < schema[className].values.length; ++idx) { + let [fieldName, fieldType]: [any, any] = schema[className].values[idx]; + if (fieldName === name) { + writer.write_u8(idx); + serializeField(schema, obj[fieldName], fieldType, writer); + break; + } + } + } else { + throw new Error(`Unexpected schema kind: ${schema[className].kind} for ${className}`); + } } /// Serialize given object using schema of the form: @@ -176,8 +206,7 @@ function deserializeField(schema: any, fieldType: any, reader: any): any { } function deserializeStruct(schema: any, classType: any, reader: any) { - console.log(classType.name); - let fields = schema[classType.name].map(([fieldName, fieldType]: [any, any]) => { + let fields = schema[classType.name].fields.map(([fieldName, fieldType]: [any, any]) => { return deserializeField(schema, fieldType, reader); }); return new classType(...fields); diff --git a/test/serialize.test.js b/test/serialize.test.js index 4c6c38c961..1cc9fdd36f 100644 --- a/test/serialize.test.js +++ b/test/serialize.test.js @@ -13,7 +13,7 @@ class Test { test('serialize object', async () => { const value = new Test(10, 20, '123', [1, 2, 3]); - const schema = { 'Test': [['x', 'u8'], ['y', 'u64'], ['z', 'string'], ['q', [3]]] }; + const schema = { 'Test': {kind: 'struct', fields: [['x', 'u8'], ['y', 'u64'], ['z', 'string'], ['q', [3]]] } }; let buf = nearlib.utils.serialize.serialize(schema, value); let new_value = nearlib.utils.serialize.deserialize(schema, Test, buf); expect(new_value.x).toEqual(10); @@ -21,3 +21,21 @@ test('serialize object', async () => { expect(new_value.z).toEqual('123'); expect(new_value.q).toEqual(new Uint8Array([1, 2, 3])); }); + +test('serialize tx', async() => { + const keyStore = new nearlib.keyStores.InMemoryKeyStore(); + await keyStore.setKey("test", "test.near", nearlib.utils.KeyPair.fromString('ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw')); + const publicKey = (await keyStore.getKey("test", "test.near")).publicKey; + const actions = [ + nearlib.transactions.createAccount(), + nearlib.transactions.deployContract(new Uint8Array([1, 2, 3])), + nearlib.transactions.functionCall("qqq", new Uint8Array([1, 2, 3]), 1000, 1000000), + nearlib.transactions.transfer(123), + nearlib.transactions.stake(1000000, publicKey), + nearlib.transactions.addKey(publicKey, nearlib.transactions.createAccessKey("321", null, "123", 1)), + nearlib.transactions.deleteKey(publicKey), + nearlib.transactions.deleteAccount("123") + ]; + let [hash, signedTx] = await nearlib.transactions.signTransaction("123", 1, actions, new nearlib.InMemorySigner(keyStore), "test.near", "test"); + expect(nearlib.utils.serialize.base_encode(hash)).toEqual("6jaty3HYh35hQUj2PSN4rhVoZXx5EZ1xUBhBgXjko8fa"); +}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index b752f2721a..70129643d1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,12 +16,11 @@ "pretty": false, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, + "noImplicitAny": false, "noImplicitReturns": true, "noUnusedLocals": true }, "files": [ "./src.ts/index.ts", - "./src.ts/protos.d.ts" ] } From ab71399c3048975b4d4d282f3259b800d340c082 Mon Sep 17 00:00:00 2001 From: Illia Polosukhin Date: Thu, 15 Aug 2019 16:22:56 -0700 Subject: [PATCH 4/8] Fixing bugs after switch to NBOR --- lib/account.d.ts | 2 +- lib/account.js | 15 +- lib/providers/json-rpc-provider.js | 1 - lib/utils/serialize.d.ts | 2 +- lib/utils/serialize.js | 17 +- src.ts/account.ts | 17 +- src.ts/providers/json-rpc-provider.ts | 1 - src.ts/utils/serialize.ts | 17 +- test/account.test.js | 229 +++++++++++++------------- test/serialize.test.js | 4 +- 10 files changed, 155 insertions(+), 150 deletions(-) diff --git a/lib/account.d.ts b/lib/account.d.ts index 580ead93fb..a4b1d3c76d 100644 --- a/lib/account.d.ts +++ b/lib/account.d.ts @@ -5,7 +5,7 @@ export interface AccountState { account_id: string; nonce: number; amount: string; - stake: string; + staked: string; public_keys: Uint8Array[]; code_hash: string; } diff --git a/lib/account.js b/lib/account.js index 2674b6aa4c..5244a32f1c 100644 --- a/lib/account.js +++ b/lib/account.js @@ -10,7 +10,7 @@ const serialize_1 = require("./utils/serialize"); // Default amount of tokens to be send with the function calls. Used to pay for the fees // incurred while running the contract execution. The unused amount will be refunded back to // the originator. -const DEFAULT_FUNC_CALL_AMOUNT = new bn_js_1.default(1000000000); +const DEFAULT_FUNC_CALL_AMOUNT = 1000000; // Default number of retries before giving up on a transactioin. const TX_STATUS_RETRY_NUMBER = 10; // Default wait until next retry in millis. @@ -32,8 +32,6 @@ class Account { async fetchState() { const state = await this.connection.provider.query(`account/${this.accountId}`, ''); this._state = state; - this._state.amount = state.amount; - this._state.stake = state.stake; } async state() { await this.ready; @@ -60,7 +58,6 @@ class Account { } async signAndSendTransaction(receiverId, actions) { await this.ready; - console.warn(`receiverId: ${receiverId}, actions: ${actions}, signer: ${this.connection.signer}`); const [txHash, signedTx] = await transaction_1.signTransaction(receiverId, ++this._state.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); let result; try { @@ -74,14 +71,12 @@ class Account { throw error; } } - console.log(result); - const flatLogs = result.logs.reduce((acc, it) => acc.concat(it.lines), []); + const flatLogs = result.transactions.reduce((acc, it) => acc.concat(it.result.logs), []); this.printLogs(signedTx.transaction.receiverId, flatLogs); if (result.status === provider_1.FinalTransactionStatus.Failed) { - if (result.logs) { - console.warn(flatLogs); + if (flatLogs) { const errorMessage = flatLogs.find(it => it.startsWith('ABORT:')) || flatLogs.find(it => it.startsWith('Runtime error:')) || ''; - throw new Error(`Transaction ${result.logs[0].hash} failed. ${errorMessage}`); + throw new Error(`Transaction ${result.transactions[0].hash} failed. ${errorMessage}`); } } // TODO: if Tx is Unknown or Started. @@ -109,7 +104,7 @@ class Account { if (!args) { args = {}; } - return this.signAndSendTransaction(contractId, [transaction_1.functionCall(methodName, Buffer.from(JSON.stringify(args)), gas, amount || DEFAULT_FUNC_CALL_AMOUNT)]); + return this.signAndSendTransaction(contractId, [transaction_1.functionCall(methodName, Buffer.from(JSON.stringify(args)), gas || DEFAULT_FUNC_CALL_AMOUNT, amount)]); } async addKey(publicKey, contractId, methodName, balanceOwner, amount) { const accessKey = transaction_1.createAccessKey(contractId ? contractId : null, methodName, balanceOwner, amount); diff --git a/lib/providers/json-rpc-provider.js b/lib/providers/json-rpc-provider.js index 555ed815fa..3177c77062 100644 --- a/lib/providers/json-rpc-provider.js +++ b/lib/providers/json-rpc-provider.js @@ -22,7 +22,6 @@ class JsonRpcProvider extends provider_1.Provider { } async sendTransaction(signedTransaction) { const bytes = signedTransaction.encode(); - console.warn("Bytes: " + new Uint8Array(bytes)); return this.sendJsonRpc('broadcast_tx_commit', [Buffer.from(bytes).toString('base64')]); } async txStatus(txHash) { diff --git a/lib/utils/serialize.d.ts b/lib/utils/serialize.d.ts index a5b6ec1642..0abc4bd503 100644 --- a/lib/utils/serialize.d.ts +++ b/lib/utils/serialize.d.ts @@ -6,7 +6,7 @@ export declare class BinaryWriter { buf: Buffer; length: number; constructor(); - resize(): void; + maybe_resize(): void; write_u8(value: number): void; write_u32(value: number): void; write_u64(value: BN): void; diff --git a/lib/utils/serialize.js b/lib/utils/serialize.js index fb39b56aeb..923010680c 100644 --- a/lib/utils/serialize.js +++ b/lib/utils/serialize.js @@ -23,21 +23,27 @@ class BinaryWriter { this.buf = Buffer.alloc(INITIAL_LENGTH); this.length = 0; } - resize() { - this.buf = Buffer.concat([this.buf, Buffer.alloc(INITIAL_LENGTH)]); + maybe_resize() { + if (this.buf.length < 16 + this.length) { + this.buf = Buffer.concat([this.buf, Buffer.alloc(INITIAL_LENGTH)]); + } } write_u8(value) { - this.buf.writeInt8(value, this.length); + this.maybe_resize(); + this.buf.writeUInt8(value, this.length); this.length += 1; } write_u32(value) { + this.maybe_resize(); this.buf.writeUInt32LE(value, this.length); this.length += 4; } write_u64(value) { + this.maybe_resize(); this.write_buffer(Buffer.from(new bn_js_1.default(value).toArray('le', 8))); } write_u128(value) { + this.maybe_resize(); this.write_buffer(Buffer.from(new bn_js_1.default(value).toArray('le', 16))); } write_buffer(buffer) { @@ -45,6 +51,7 @@ class BinaryWriter { this.length += buffer.length; } write_string(str) { + this.maybe_resize(); let b = Buffer.from(str, 'utf8'); this.write_u32(b.length); this.write_buffer(b); @@ -53,8 +60,10 @@ class BinaryWriter { this.write_buffer(Buffer.from(array)); } write_array(array, fn) { + this.maybe_resize(); this.write_u32(array.length); for (let i = 0; i < array.length; ++i) { + this.maybe_resize(); fn(array[i]); } } @@ -69,7 +78,7 @@ class BinaryReader { this.offset = 0; } read_u8() { - const value = this.buf.readInt8(this.offset); + const value = this.buf.readUInt8(this.offset); this.offset += 1; return value; } diff --git a/src.ts/account.ts b/src.ts/account.ts index e9b455f57d..10e89c5d83 100644 --- a/src.ts/account.ts +++ b/src.ts/account.ts @@ -10,7 +10,7 @@ import { base_encode } from './utils/serialize'; // Default amount of tokens to be send with the function calls. Used to pay for the fees // incurred while running the contract execution. The unused amount will be refunded back to // the originator. -const DEFAULT_FUNC_CALL_AMOUNT = new BN(1000000000); +const DEFAULT_FUNC_CALL_AMOUNT = 1000000; // Default number of retries before giving up on a transactioin. const TX_STATUS_RETRY_NUMBER = 10; @@ -30,7 +30,7 @@ export interface AccountState { account_id: string; nonce: number; amount: string; - stake: string; + staked: string; public_keys: Uint8Array[]; code_hash: string; } @@ -53,8 +53,6 @@ export class Account { async fetchState(): Promise { const state = await this.connection.provider.query(`account/${this.accountId}`, ''); this._state = state; - this._state.amount = state.amount; - this._state.stake = state.stake; } async state(): Promise { @@ -85,7 +83,6 @@ export class Account { private async signAndSendTransaction(receiverId: string, actions: Array): Promise { await this.ready; - console.warn(`receiverId: ${receiverId}, actions: ${actions}, signer: ${this.connection.signer}`); const [txHash, signedTx] = await signTransaction( receiverId, ++this._state.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); @@ -99,16 +96,14 @@ export class Account { throw error; } } - console.log(result); - const flatLogs = result.logs.reduce((acc, it) => acc.concat(it.lines), []); + const flatLogs = result.transactions.reduce((acc, it) => acc.concat(it.result.logs), []); this.printLogs(signedTx.transaction.receiverId, flatLogs); if (result.status === FinalTransactionStatus.Failed) { - if (result.logs) { - console.warn(flatLogs); + if (flatLogs) { const errorMessage = flatLogs.find(it => it.startsWith('ABORT:')) || flatLogs.find(it => it.startsWith('Runtime error:')) || ''; - throw new Error(`Transaction ${result.logs[0].hash} failed. ${errorMessage}`); + throw new Error(`Transaction ${result.transactions[0].hash} failed. ${errorMessage}`); } } // TODO: if Tx is Unknown or Started. @@ -141,7 +136,7 @@ export class Account { if (!args) { args = {}; } - return this.signAndSendTransaction(contractId, [functionCall(methodName, Buffer.from(JSON.stringify(args)), gas, amount || DEFAULT_FUNC_CALL_AMOUNT)]); + return this.signAndSendTransaction(contractId, [functionCall(methodName, Buffer.from(JSON.stringify(args)), gas || DEFAULT_FUNC_CALL_AMOUNT, amount)]); } async addKey(publicKey: string, contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): Promise { diff --git a/src.ts/providers/json-rpc-provider.ts b/src.ts/providers/json-rpc-provider.ts index b4e30182f2..ed98d24f0f 100644 --- a/src.ts/providers/json-rpc-provider.ts +++ b/src.ts/providers/json-rpc-provider.ts @@ -32,7 +32,6 @@ export class JsonRpcProvider extends Provider { async sendTransaction(signedTransaction: SignedTransaction): Promise { const bytes = signedTransaction.encode(); - console.warn("Bytes: " + new Uint8Array(bytes)); return this.sendJsonRpc('broadcast_tx_commit', [Buffer.from(bytes).toString('base64')]); } diff --git a/src.ts/utils/serialize.ts b/src.ts/utils/serialize.ts index 2bd6fd3635..70d6d1d5f0 100644 --- a/src.ts/utils/serialize.ts +++ b/src.ts/utils/serialize.ts @@ -26,25 +26,31 @@ export class BinaryWriter { this.length = 0; } - resize() { - this.buf = Buffer.concat([this.buf, Buffer.alloc(INITIAL_LENGTH)]); + maybe_resize() { + if (this.buf.length < 16 + this.length) { + this.buf = Buffer.concat([this.buf, Buffer.alloc(INITIAL_LENGTH)]); + } } public write_u8(value: number) { - this.buf.writeInt8(value, this.length); + this.maybe_resize(); + this.buf.writeUInt8(value, this.length); this.length += 1; } public write_u32(value: number) { + this.maybe_resize(); this.buf.writeUInt32LE(value, this.length); this.length += 4; } public write_u64(value: BN) { + this.maybe_resize(); this.write_buffer(Buffer.from(new BN(value).toArray('le', 8))); } public write_u128(value: BN) { + this.maybe_resize(); this.write_buffer(Buffer.from(new BN(value).toArray('le', 16))); } @@ -54,6 +60,7 @@ export class BinaryWriter { } public write_string(str: string) { + this.maybe_resize(); let b = Buffer.from(str, 'utf8'); this.write_u32(b.length); this.write_buffer(b); @@ -64,8 +71,10 @@ export class BinaryWriter { } public write_array(array: Array, fn: any) { + this.maybe_resize(); this.write_u32(array.length); for (let i = 0; i < array.length; ++i) { + this.maybe_resize(); fn(array[i]); } } @@ -85,7 +94,7 @@ export class BinaryReader { } read_u8(): number { - const value = this.buf.readInt8(this.offset); + const value = this.buf.readUInt8(this.offset); this.offset += 1; return value; } diff --git a/test/account.test.js b/test/account.test.js index 254368ed3b..5195a3813b 100644 --- a/test/account.test.js +++ b/test/account.test.js @@ -18,121 +18,120 @@ beforeAll(async () => { test('view pre-defined account works and returns correct name', async () => { let status = await workingAccount.state(); - expect(status.account_id).toEqual(workingAccount.accountId); + expect(status.code_hash).toEqual("11111111111111111111111111111111"); }); -// test('create account and then view account returns the created account', async () => { -// const newAccountName = testUtils.generateUniqueString('test'); -// const newAccountPublicKey = '9AhWenZ3JddamBoyMqnTbp7yVbRuvqAv3zwfrWgfVRJE'; -// await workingAccount.createAccount(newAccountName, newAccountPublicKey, testUtils.INITIAL_BALANCE); -// const newAccount = new nearlib.Account(nearjs.connection, newAccountName); -// const state = await newAccount.state(); -// const expectedState = { nonce: 0, account_id: newAccountName, amount: testUtils.INITIAL_BALANCE.toString(), stake: '0', code_hash: 'GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn', public_keys: state.public_keys }; -// expect(state).toMatchObject(expectedState); -// }); - -// test('send money', async() => { -// const sender = await testUtils.createAccount(workingAccount); -// const receiver = await testUtils.createAccount(workingAccount); -// await sender.sendMoney(receiver.accountId, new BN(10000)); -// await receiver.fetchState(); -// const state = await receiver.state(); -// expect(state.amount).toEqual(testUtils.INITIAL_BALANCE.add(new BN(10000)).toString()); -// }); - -// describe('errors', () => { -// let oldLog; -// let logs; - -// beforeEach(async () => { -// oldLog = console.log; -// logs =[]; -// console.log = function () { -// logs.push(Array.from(arguments).join(' ')); -// }; -// }); - -// afterEach(async () => { -// console.log = oldLog; -// }); - -// test('create existing account', async() => { -// await expect(workingAccount.createAccount(workingAccount.accountId, '9AhWenZ3JddamBoyMqnTbp7yVbRuvqAv3zwfrWgfVRJE', 100)).rejects.toThrow(/Transaction .+ failed.+already exists/); -// }); -// }); - -// describe('with deploy contract', () => { -// let oldLog; -// let logs; -// let contractId = testUtils.generateUniqueString('test_contract'); -// let contract; - -// beforeAll(async () => { -// const newPublicKey = await nearjs.connection.signer.createKey(contractId, testUtils.networkId); -// const data = [...fs.readFileSync(HELLO_WASM_PATH)]; -// await workingAccount.createAndDeployContract(contractId, newPublicKey, data, new BN(100000)); -// contract = new nearlib.Contract(workingAccount, contractId, { -// viewMethods: ['hello', 'getValue', 'getAllKeys', 'returnHiWithLogs'], -// changeMethods: ['setValue', 'generateLogs', 'triggerAssert', 'testSetRemove'] -// }); -// }); - -// beforeEach(async () => { -// oldLog = console.log; -// logs = []; -// console.log = function () { -// logs.push(Array.from(arguments).join(' ')); -// }; -// }); - -// afterEach(async () => { -// console.log = oldLog; -// }); - -// test('make function calls via account', async() => { -// const result = await workingAccount.viewFunction( -// contractId, -// 'hello', // this is the function defined in hello.wasm file that we are calling -// {name: 'trex'}); -// expect(result).toEqual('hello trex'); - -// const setCallValue = testUtils.generateUniqueString('setCallPrefix'); -// const result2 = await workingAccount.functionCall(contractId, 'setValue', { value: setCallValue }); -// expect(nearlib.providers.getTransactionLastResult(result2)).toEqual(setCallValue); -// expect(await workingAccount.viewFunction(contractId, 'getValue', {})).toEqual(setCallValue); -// }); +test('create account and then view account returns the created account', async () => { + const newAccountName = testUtils.generateUniqueString('test'); + const newAccountPublicKey = '9AhWenZ3JddamBoyMqnTbp7yVbRuvqAv3zwfrWgfVRJE'; + await workingAccount.createAccount(newAccountName, newAccountPublicKey, testUtils.INITIAL_BALANCE); + const newAccount = new nearlib.Account(nearjs.connection, newAccountName); + const state = await newAccount.state(); + expect(state.amount).toEqual(testUtils.INITIAL_BALANCE.toString()); +}); + +test('send money', async() => { + const sender = await testUtils.createAccount(workingAccount); + const receiver = await testUtils.createAccount(workingAccount); + await sender.sendMoney(receiver.accountId, new BN(10000)); + await receiver.fetchState(); + const state = await receiver.state(); + expect(state.amount).toEqual(testUtils.INITIAL_BALANCE.add(new BN(10000)).toString()); +}); + +describe('errors', () => { + let oldLog; + let logs; + + beforeEach(async () => { + oldLog = console.log; + logs =[]; + console.log = function () { + logs.push(Array.from(arguments).join(' ')); + }; + }); + + afterEach(async () => { + console.log = oldLog; + }); + + test('create existing account', async() => { + await expect(workingAccount.createAccount(workingAccount.accountId, '9AhWenZ3JddamBoyMqnTbp7yVbRuvqAv3zwfrWgfVRJE', 100)).rejects.toThrow(/Transaction .+ failed.+already exists/); + }); +}); + +describe('with deploy contract', () => { + let oldLog; + let logs; + let contractId = testUtils.generateUniqueString('test_contract'); + let contract; + + beforeAll(async () => { + const newPublicKey = await nearjs.connection.signer.createKey(contractId, testUtils.networkId); + const data = [...fs.readFileSync(HELLO_WASM_PATH)]; + await workingAccount.createAndDeployContract(contractId, newPublicKey, data, new BN(100000)); + contract = new nearlib.Contract(workingAccount, contractId, { + viewMethods: ['hello', 'getValue', 'getAllKeys', 'returnHiWithLogs'], + changeMethods: ['setValue', 'generateLogs', 'triggerAssert', 'testSetRemove'] + }); + }); + + beforeEach(async () => { + oldLog = console.log; + logs = []; + console.log = function () { + logs.push(Array.from(arguments).join(' ')); + }; + }); + + afterEach(async () => { + console.log = oldLog; + }); + + test('make function calls via account', async() => { + const result = await workingAccount.viewFunction( + contractId, + 'hello', // this is the function defined in hello.wasm file that we are calling + {name: 'trex'}); + expect(result).toEqual('hello trex'); + + const setCallValue = testUtils.generateUniqueString('setCallPrefix'); + const result2 = await workingAccount.functionCall(contractId, 'setValue', { value: setCallValue }); + expect(nearlib.providers.getTransactionLastResult(result2)).toEqual(setCallValue); + expect(await workingAccount.viewFunction(contractId, 'getValue', {})).toEqual(setCallValue); + }); -// test('make function calls via contract', async() => { -// const result = await contract.hello({ name: 'trex' }); -// expect(result).toEqual('hello trex'); - -// const setCallValue = testUtils.generateUniqueString('setCallPrefix'); -// const result2 = await contract.setValue({ value: setCallValue }); -// expect(nearlib.providers.getTransactionLastResult(result2)).toEqual(setCallValue); -// expect(await contract.getValue()).toEqual(setCallValue); -// }); - -// test('can get logs from method result', async () => { -// await contract.generateLogs(); -// expect(logs).toEqual([`[${contractId}]: LOG: log1`, `[${contractId}]: LOG: log2`]); -// }); - -// test('can get logs from view call', async () => { -// let result = await contract.returnHiWithLogs(); -// expect(result).toEqual('Hi'); -// expect(logs).toEqual([`[${contractId}]: LOG: loooog1`, `[${contractId}]: LOG: loooog2`]); -// }); - -// test('can get assert message from method result', async () => { -// await expect(contract.triggerAssert()).rejects.toThrow(/Transaction .+ failed.+expected to fail.+/); -// expect(logs.length).toBe(3); -// expect(logs[0]).toEqual(`[${contractId}]: LOG: log before assert`); -// expect(logs[1]).toMatch(new RegExp(`^\\[${contractId}\\]: ABORT: "expected to fail" filename: "../out/main.ts" line: \\d+ col: \\d+$`)); -// expect(logs[2]).toEqual(`[${contractId}]: Runtime error: wasm async call execution failed with error: Runtime(AssertFailed)`); -// }); - -// test('test set/remove', async () => { -// const result = await contract.testSetRemove({ value: '123' }); -// expect(result.status).toBe('Completed'); -// }); -// }); + test('make function calls via contract', async() => { + const result = await contract.hello({ name: 'trex' }); + expect(result).toEqual('hello trex'); + + const setCallValue = testUtils.generateUniqueString('setCallPrefix'); + const result2 = await contract.setValue({ value: setCallValue }); + expect(nearlib.providers.getTransactionLastResult(result2)).toEqual(setCallValue); + expect(await contract.getValue()).toEqual(setCallValue); + }); + + test('can get logs from method result', async () => { + await contract.generateLogs(); + expect(logs).toEqual([`[${contractId}]: LOG: log1`, `[${contractId}]: LOG: log2`]); + }); + + test('can get logs from view call', async () => { + let result = await contract.returnHiWithLogs(); + expect(result).toEqual('Hi'); + expect(logs).toEqual([`[${contractId}]: LOG: loooog1`, `[${contractId}]: LOG: loooog2`]); + }); + + test('can get assert message from method result', async () => { + await expect(contract.triggerAssert()).rejects.toThrow(/Transaction .+ failed.+expected to fail.+/); + expect(logs.length).toBe(3); + expect(logs[0]).toEqual(`[${contractId}]: LOG: log before assert`); + expect(logs[1]).toMatch(new RegExp(`^\\[${contractId}\\]: ABORT: "expected to fail" filename: "../out/main.ts" line: \\d+ col: \\d+$`)); + expect(logs[2]).toEqual(`[${contractId}]: Runtime error: wasm async call execution failed with error: Runtime(AssertFailed)`); + }); + + test('test set/remove', async () => { + const result = await contract.testSetRemove({ value: '123' }); + expect(result.status).toBe('Completed'); + }); +}); diff --git a/test/serialize.test.js b/test/serialize.test.js index 1cc9fdd36f..10cfcd8901 100644 --- a/test/serialize.test.js +++ b/test/serialize.test.js @@ -12,11 +12,11 @@ class Test { } test('serialize object', async () => { - const value = new Test(10, 20, '123', [1, 2, 3]); + const value = new Test(255, 20, '123', [1, 2, 3]); const schema = { 'Test': {kind: 'struct', fields: [['x', 'u8'], ['y', 'u64'], ['z', 'string'], ['q', [3]]] } }; let buf = nearlib.utils.serialize.serialize(schema, value); let new_value = nearlib.utils.serialize.deserialize(schema, Test, buf); - expect(new_value.x).toEqual(10); + expect(new_value.x).toEqual(255); expect(new_value.y.toString()).toEqual('20'); expect(new_value.z).toEqual('123'); expect(new_value.q).toEqual(new Uint8Array([1, 2, 3])); From d7047f1f08534f570048110107f900bfe80fca1a Mon Sep 17 00:00:00 2001 From: Illia Polosukhin Date: Thu, 15 Aug 2019 18:16:14 -0700 Subject: [PATCH 5/8] NEP 5 changes --- lib/account.d.ts | 3 +- lib/account.js | 30 +++++++++++----- lib/transaction.d.ts | 30 +++++++++++----- lib/transaction.js | 68 ++++++++++++++++++++++-------------- src.ts/account.ts | 29 +++++++++++----- src.ts/transaction.ts | 78 +++++++++++++++++++++++++++--------------- test/serialize.test.js | 14 ++++---- 7 files changed, 164 insertions(+), 88 deletions(-) diff --git a/lib/account.d.ts b/lib/account.d.ts index a4b1d3c76d..2a9e81a99c 100644 --- a/lib/account.d.ts +++ b/lib/account.d.ts @@ -3,16 +3,15 @@ import { FinalTransactionResult } from './providers/provider'; import { Connection } from './connection'; export interface AccountState { account_id: string; - nonce: number; amount: string; staked: string; - public_keys: Uint8Array[]; code_hash: string; } export declare class Account { readonly connection: Connection; readonly accountId: string; private _state; + private _access_key; private _ready; protected readonly ready: Promise; constructor(connection: Connection, accountId: string); diff --git a/lib/account.js b/lib/account.js index 5244a32f1c..5e02501e89 100644 --- a/lib/account.js +++ b/lib/account.js @@ -1,9 +1,5 @@ 'use strict'; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -const bn_js_1 = __importDefault(require("bn.js")); const transaction_1 = require("./transaction"); const provider_1 = require("./providers/provider"); const serialize_1 = require("./utils/serialize"); @@ -30,8 +26,14 @@ class Account { this.accountId = accountId; } async fetchState() { - const state = await this.connection.provider.query(`account/${this.accountId}`, ''); - this._state = state; + this._state = await this.connection.provider.query(`account/${this.accountId}`, ''); + try { + const publicKey = await this.connection.signer.getPublicKey(this.accountId, this.connection.networkId); + this._access_key = await this.connection.provider.query(`access_key/${this.accountId}/${publicKey}`, ''); + } + catch { + this._access_key = null; + } } async state() { await this.ready; @@ -58,7 +60,10 @@ class Account { } async signAndSendTransaction(receiverId, actions) { await this.ready; - const [txHash, signedTx] = await transaction_1.signTransaction(receiverId, ++this._state.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); + if (this._access_key === null) { + throw new Error(`Can not sign transactions, initialize account with available public key in Signer.`); + } + const [txHash, signedTx] = await transaction_1.signTransaction(receiverId, ++this._access_key.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); let result; try { result = await this.connection.provider.sendTransaction(signedTx); @@ -94,7 +99,7 @@ class Account { return this.signAndSendTransaction(receiverId, [transaction_1.transfer(amount)]); } async createAccount(newAccountId, publicKey, amount) { - const accessKey = transaction_1.createAccessKey(null, "", newAccountId, new bn_js_1.default(0)); + const accessKey = transaction_1.fullAccessKey(); return this.signAndSendTransaction(newAccountId, [transaction_1.createAccount(), transaction_1.transfer(amount), transaction_1.addKey(publicKey, accessKey)]); } async deployContract(data) { @@ -106,8 +111,15 @@ class Account { } return this.signAndSendTransaction(contractId, [transaction_1.functionCall(methodName, Buffer.from(JSON.stringify(args)), gas || DEFAULT_FUNC_CALL_AMOUNT, amount)]); } + // TODO: expand this API to support more options. async addKey(publicKey, contractId, methodName, balanceOwner, amount) { - const accessKey = transaction_1.createAccessKey(contractId ? contractId : null, methodName, balanceOwner, amount); + let accessKey; + if (contractId === null) { + accessKey = transaction_1.fullAccessKey(); + } + else { + accessKey = transaction_1.functionCallAccessKey(contractId, methodName === null ? [] : [methodName], amount); + } return this.signAndSendTransaction(this.accountId, [transaction_1.addKey(publicKey, accessKey)]); } async deleteKey(publicKey) { diff --git a/lib/transaction.d.ts b/lib/transaction.d.ts index 5d538496e6..692c8b8cf2 100644 --- a/lib/transaction.d.ts +++ b/lib/transaction.d.ts @@ -1,15 +1,29 @@ import BN from 'bn.js'; import { Signer } from './signer'; -export declare class Assignable { +declare class Enum { + enum: string; constructor(properties: any); } +declare class Assignable { + constructor(properties: any); +} +export declare class FunctionCallPermission extends Assignable { + allowance?: BN; + receiverId: string; + methodNames: String[]; +} +export declare class FullAccessPermission extends Assignable { +} +export declare class AccessKeyPermission extends Enum { + functionCall: FunctionCallPermission; + fullAccess: FullAccessPermission; +} export declare class AccessKey extends Assignable { - contractId: string; - methodName: Uint8Array; - balanceOwner: string; - amount: BN; + nonce: number; + permission: AccessKeyPermission; } -export declare function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey; +export declare function fullAccessKey(): AccessKey; +export declare function functionCallAccessKey(receiverId: string, methodNames: String[], allowance?: BN): AccessKey; export declare class IAction extends Assignable { } declare class CreateAccount extends IAction { @@ -68,8 +82,7 @@ export declare class SignedTransaction extends Assignable { signature: Uint8Array; encode(): Uint8Array; } -export declare class Action { - action: string; +export declare class Action extends Enum { createAccount: CreateAccount; deployContract: DeployContract; functionCall: FunctionCall; @@ -78,7 +91,6 @@ export declare class Action { addKey: AddKey; deleteKey: DeleteKey; deleteAccount: DeleteAccount; - constructor(properties: any); } export declare function signTransaction(receiverId: string, nonce: number, actions: Action[], signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]>; export {}; diff --git a/lib/transaction.js b/lib/transaction.js index 65d7b28edf..8633930630 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -4,8 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const js_sha256_1 = __importDefault(require("js-sha256")); -const bn_js_1 = __importDefault(require("bn.js")); const serialize_1 = require("./utils/serialize"); +class Enum { + constructor(properties) { + if (Object.keys(properties).length != 1) { + throw new Error("Enum can only take single value"); + } + Object.keys(properties).map((key) => { + this[key] = properties[key]; + this.enum = key; + }); + } +} class Assignable { constructor(properties) { Object.keys(properties).map((key) => { @@ -13,19 +23,26 @@ class Assignable { }); } } -exports.Assignable = Assignable; +class FunctionCallPermission extends Assignable { +} +exports.FunctionCallPermission = FunctionCallPermission; +class FullAccessPermission extends Assignable { +} +exports.FullAccessPermission = FullAccessPermission; +class AccessKeyPermission extends Enum { +} +exports.AccessKeyPermission = AccessKeyPermission; class AccessKey extends Assignable { } exports.AccessKey = AccessKey; -function createAccessKey(contractId, methodName, balanceOwner, amount) { - return new AccessKey({ - contractId, - methodName, - balanceOwner, - amount: amount || new bn_js_1.default(0), - }); -} -exports.createAccessKey = createAccessKey; +function fullAccessKey() { + return new AccessKey({ nonce: 0, permission: new AccessKeyPermission({ fullAccess: new FullAccessPermission({}) }) }); +} +exports.fullAccessKey = fullAccessKey; +function functionCallAccessKey(receiverId, methodNames, allowance) { + return new AccessKey({ nonce: 0, permission: new AccessKeyPermission({ functionCall: new FunctionCallPermission({ receiverId, allowance, methodNames }) }) }); +} +exports.functionCallAccessKey = functionCallAccessKey; class IAction extends Assignable { } exports.IAction = IAction; @@ -95,16 +112,7 @@ class SignedTransaction extends Assignable { } } exports.SignedTransaction = SignedTransaction; -class Action { - constructor(properties) { - if (Object.keys(properties).length != 1) { - throw new Error("Action can only take single value"); - } - Object.keys(properties).map((key) => { - this[key] = properties[key]; - this.action = key; - }); - } +class Action extends Enum { } exports.Action = Action; const SCHEMA = { @@ -116,12 +124,20 @@ const SCHEMA = { kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]] }, 'AccessKey': { kind: 'struct', fields: [ - ['amount', 'u128'], - ['balanceOwner', { kind: 'option', type: 'string' }], - ['contractId', { kind: 'option', type: 'string' }], - ['methodName', { kind: 'option', type: ['u8'] }], + ['nonce', 'u64'], + ['permission', AccessKeyPermission], + ] }, + 'AccessKeyPermission': { kind: 'enum', field: 'enum', values: [ + ['functionCall', FunctionCallPermission], + ['fullAccess', FullAccessPermission], + ] }, + 'FunctionCallPermission': { kind: 'struct', fields: [ + ['allowance', { kind: 'option', type: 'u128' }], + ['receiverId', 'string'], + ['methodNames', ['string']], ] }, - 'Action': { kind: 'enum', field: 'action', values: [ + 'FullAccessPermission': { kind: 'struct', fields: [] }, + 'Action': { kind: 'enum', field: 'enum', values: [ ['createAccount', CreateAccount], ['deployContract', DeployContract], ['functionCall', functionCall], diff --git a/src.ts/account.ts b/src.ts/account.ts index 10e89c5d83..4ae8645eea 100644 --- a/src.ts/account.ts +++ b/src.ts/account.ts @@ -2,7 +2,7 @@ import BN from 'bn.js'; import { Action, transfer, createAccount, signTransaction, deployContract, - addKey, functionCall, createAccessKey, deleteKey, stake } from './transaction'; + addKey, functionCall, fullAccessKey, functionCallAccessKey, deleteKey, stake, AccessKey } from './transaction'; import { FinalTransactionResult, FinalTransactionStatus } from './providers/provider'; import { Connection } from './connection'; import { base_encode } from './utils/serialize'; @@ -28,10 +28,8 @@ function sleep(millis: number): Promise { export interface AccountState { account_id: string; - nonce: number; amount: string; staked: string; - public_keys: Uint8Array[]; code_hash: string; } @@ -39,6 +37,7 @@ export class Account { readonly connection: Connection; readonly accountId: string; private _state: AccountState; + private _access_key: AccessKey; private _ready: Promise; protected get ready(): Promise { @@ -51,8 +50,13 @@ export class Account { } async fetchState(): Promise { - const state = await this.connection.provider.query(`account/${this.accountId}`, ''); - this._state = state; + this._state = await this.connection.provider.query(`account/${this.accountId}`, ''); + try { + const publicKey = await this.connection.signer.getPublicKey(this.accountId, this.connection.networkId); + this._access_key = await this.connection.provider.query(`access_key/${this.accountId}/${publicKey}`, ''); + } catch { + this._access_key = null; + } } async state(): Promise { @@ -83,8 +87,11 @@ export class Account { private async signAndSendTransaction(receiverId: string, actions: Array): Promise { await this.ready; + if (this._access_key === null) { + throw new Error(`Can not sign transactions, initialize account with available public key in Signer.`); + } const [txHash, signedTx] = await signTransaction( - receiverId, ++this._state.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); + receiverId, ++this._access_key.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); let result; try { @@ -124,7 +131,7 @@ export class Account { } async createAccount(newAccountId: string, publicKey: string, amount: BN): Promise { - const accessKey = createAccessKey(null, "", newAccountId, new BN(0)); + const accessKey = fullAccessKey(); return this.signAndSendTransaction(newAccountId, [createAccount(), transfer(amount), addKey(publicKey, accessKey)]); } @@ -139,8 +146,14 @@ export class Account { return this.signAndSendTransaction(contractId, [functionCall(methodName, Buffer.from(JSON.stringify(args)), gas || DEFAULT_FUNC_CALL_AMOUNT, amount)]); } + // TODO: expand this API to support more options. async addKey(publicKey: string, contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): Promise { - const accessKey = createAccessKey(contractId ? contractId : null, methodName, balanceOwner, amount); + let accessKey; + if (contractId === null) { + accessKey = fullAccessKey(); + } else { + accessKey = functionCallAccessKey(contractId, methodName === null ? [] : [methodName], amount); + } return this.signAndSendTransaction(this.accountId, [addKey(publicKey, accessKey)]); } diff --git a/src.ts/transaction.ts b/src.ts/transaction.ts index 0da741d182..0e16ceac8b 100644 --- a/src.ts/transaction.ts +++ b/src.ts/transaction.ts @@ -6,7 +6,21 @@ import BN from 'bn.js'; import { base_decode, serialize } from './utils/serialize'; import { Signer } from './signer'; -export class Assignable { +class Enum { + enum: string; + + constructor(properties: any) { + if (Object.keys(properties).length != 1) { + throw new Error("Enum can only take single value"); + } + Object.keys(properties).map((key: string) => { + (this as any)[key] = properties[key]; + this.enum = key; + }); + } +} + +class Assignable { constructor(properties: any) { Object.keys(properties).map((key: any) => { (this as any)[key] = properties[key]; @@ -14,17 +28,30 @@ export class Assignable { } } -export class AccessKey extends Assignable { - contractId: string; methodName: Uint8Array; balanceOwner: string; amount: BN +export class FunctionCallPermission extends Assignable { + allowance?: BN; + receiverId: string; + methodNames: String[]; } -export function createAccessKey(contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): AccessKey { - return new AccessKey({ - contractId, - methodName, - balanceOwner, - amount: amount || new BN(0), - }); +export class FullAccessPermission extends Assignable {} + +export class AccessKeyPermission extends Enum { + functionCall: FunctionCallPermission; + fullAccess: FullAccessPermission; +} + +export class AccessKey extends Assignable { + nonce: number; + permission: AccessKeyPermission; +} + +export function fullAccessKey(): AccessKey { + return new AccessKey({ nonce: 0, permission: new AccessKeyPermission({fullAccess: new FullAccessPermission({})}) }); +} + +export function functionCallAccessKey(receiverId: string, methodNames: String[], allowance?: BN): AccessKey { + return new AccessKey({ nonce: 0, permission: new AccessKeyPermission({functionCall: new FunctionCallPermission({receiverId, allowance, methodNames})})}); } export class IAction extends Assignable {} @@ -101,8 +128,7 @@ export class SignedTransaction extends Assignable { } } -export class Action { - action: string; +export class Action extends Enum { createAccount: CreateAccount; deployContract: DeployContract; functionCall: FunctionCall; @@ -111,16 +137,6 @@ export class Action { addKey: AddKey; deleteKey: DeleteKey; deleteAccount: DeleteAccount; - - constructor(properties: any) { - if (Object.keys(properties).length != 1) { - throw new Error("Action can only take single value"); - } - Object.keys(properties).map((key: string) => { - (this as any)[key] = properties[key]; - this.action = key; - }); - } } const SCHEMA = { @@ -130,12 +146,20 @@ const SCHEMA = { 'PublicKey': { kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]] }, 'AccessKey': { kind: 'struct', fields: [ - ['amount', 'u128'], - ['balanceOwner', { kind: 'option', type: 'string' }], - ['contractId', {kind: 'option', type: 'string'}], - ['methodName', {kind: 'option', type: ['u8']}], + ['nonce', 'u64'], + ['permission', AccessKeyPermission], + ]}, + 'AccessKeyPermission': {kind: 'enum', field: 'enum', values: [ + ['functionCall', FunctionCallPermission], + ['fullAccess', FullAccessPermission], + ]}, + 'FunctionCallPermission': {kind: 'struct', fields: [ + ['allowance', {kind: 'option', type: 'u128'}], + ['receiverId', 'string'], + ['methodNames', ['string']], ]}, - 'Action': {kind: 'enum', field: 'action', values: [ + 'FullAccessPermission': {kind: 'struct', fields: []}, + 'Action': {kind: 'enum', field: 'enum', values: [ ['createAccount', CreateAccount], ['deployContract', DeployContract], ['functionCall', functionCall], diff --git a/test/serialize.test.js b/test/serialize.test.js index 10cfcd8901..a4d37c9ffa 100644 --- a/test/serialize.test.js +++ b/test/serialize.test.js @@ -24,18 +24,18 @@ test('serialize object', async () => { test('serialize tx', async() => { const keyStore = new nearlib.keyStores.InMemoryKeyStore(); - await keyStore.setKey("test", "test.near", nearlib.utils.KeyPair.fromString('ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw')); - const publicKey = (await keyStore.getKey("test", "test.near")).publicKey; + await keyStore.setKey('test', 'test.near', nearlib.utils.KeyPair.fromString('ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw')); + const publicKey = (await keyStore.getKey('test', 'test.near')).publicKey; const actions = [ nearlib.transactions.createAccount(), nearlib.transactions.deployContract(new Uint8Array([1, 2, 3])), - nearlib.transactions.functionCall("qqq", new Uint8Array([1, 2, 3]), 1000, 1000000), + nearlib.transactions.functionCall('qqq', new Uint8Array([1, 2, 3]), 1000, 1000000), nearlib.transactions.transfer(123), nearlib.transactions.stake(1000000, publicKey), - nearlib.transactions.addKey(publicKey, nearlib.transactions.createAccessKey("321", null, "123", 1)), + nearlib.transactions.addKey(publicKey, nearlib.transactions.functionCallAccessKey('zzz', ['www'], null)), nearlib.transactions.deleteKey(publicKey), - nearlib.transactions.deleteAccount("123") + nearlib.transactions.deleteAccount('123') ]; - let [hash, signedTx] = await nearlib.transactions.signTransaction("123", 1, actions, new nearlib.InMemorySigner(keyStore), "test.near", "test"); - expect(nearlib.utils.serialize.base_encode(hash)).toEqual("6jaty3HYh35hQUj2PSN4rhVoZXx5EZ1xUBhBgXjko8fa"); + let [hash, signedTx] = await nearlib.transactions.signTransaction('123', 1, actions, new nearlib.InMemorySigner(keyStore), 'test.near', 'test'); + expect(nearlib.utils.serialize.base_encode(hash)).toEqual('244ZQ9cgj3CQ6bWBdytfrJMuMQ1jdXLFGnr4HhvtCTnM'); }); \ No newline at end of file From 2ce08d31658a2c66c648fc723f12d2836b1aeeee Mon Sep 17 00:00:00 2001 From: Illia Polosukhin Date: Fri, 16 Aug 2019 16:35:21 -0700 Subject: [PATCH 6/8] Fixing access keys & few other small issues --- lib/account.d.ts | 3 +- lib/account.js | 30 ++++++--- lib/transaction.d.ts | 7 ++- lib/transaction.js | 11 +++- package.json | 2 +- src.ts/account.ts | 31 +++++++--- src.ts/transaction.ts | 17 +++++- test/account.access_key.test.js | 21 ++++--- test/providers.test.js | 2 +- test/test-utils.js | 1 - yarn.lock | 104 -------------------------------- 11 files changed, 85 insertions(+), 144 deletions(-) diff --git a/lib/account.d.ts b/lib/account.d.ts index 2a9e81a99c..9641504bc8 100644 --- a/lib/account.d.ts +++ b/lib/account.d.ts @@ -25,9 +25,10 @@ export declare class Account { createAccount(newAccountId: string, publicKey: string, amount: BN): Promise; deployContract(data: Uint8Array): Promise; functionCall(contractId: string, methodName: string, args: any, gas: number, amount?: BN): Promise; - addKey(publicKey: string, contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): Promise; + addKey(publicKey: string, contractId?: string, methodName?: string, amount?: BN): Promise; deleteKey(publicKey: string): Promise; stake(publicKey: string, amount: BN): Promise; viewFunction(contractId: string, methodName: string, args: any): Promise; + getAccessKeys(): Promise; getAccountDetails(): Promise; } diff --git a/lib/account.js b/lib/account.js index 5e02501e89..a3482fbf60 100644 --- a/lib/account.js +++ b/lib/account.js @@ -112,13 +112,13 @@ class Account { return this.signAndSendTransaction(contractId, [transaction_1.functionCall(methodName, Buffer.from(JSON.stringify(args)), gas || DEFAULT_FUNC_CALL_AMOUNT, amount)]); } // TODO: expand this API to support more options. - async addKey(publicKey, contractId, methodName, balanceOwner, amount) { + async addKey(publicKey, contractId, methodName, amount) { let accessKey; - if (contractId === null) { + if (contractId === null || contractId === undefined) { accessKey = transaction_1.fullAccessKey(); } else { - accessKey = transaction_1.functionCallAccessKey(contractId, methodName === null ? [] : [methodName], amount); + accessKey = transaction_1.functionCallAccessKey(contractId, !methodName ? [] : [methodName], amount); } return this.signAndSendTransaction(this.accountId, [transaction_1.addKey(publicKey, accessKey)]); } @@ -135,15 +135,25 @@ class Account { } return JSON.parse(Buffer.from(result.result).toString()); } - async getAccountDetails() { + /// Returns array of {access_key: AccessKey, public_key: PublicKey} items. + async getAccessKeys() { const response = await this.connection.provider.query(`access_key/${this.accountId}`, ''); + return response; + } + async getAccountDetails() { + // TODO: update the response value to return all the different keys, not just app keys. + // Also if we need this function, or getAccessKeys is good enough. + const accessKeys = await this.getAccessKeys(); const result = { authorizedApps: [], transactions: [] }; - Object.keys(response).forEach((key) => { - result.authorizedApps.push({ - contractId: response[key][1].contract_id, - amount: response[key][1].amount, - publicKey: serialize_1.base_encode(response[key][0]), - }); + accessKeys.map((item) => { + if (item.access_key.permission.FunctionCall !== undefined) { + const perm = item.access_key.permission.FunctionCall; + result.authorizedApps.push({ + contractId: perm.receiver_id, + amount: perm.allowance, + publicKey: item.public_key.data, + }); + } }); return result; } diff --git a/lib/transaction.d.ts b/lib/transaction.d.ts index 692c8b8cf2..086ffaaa2f 100644 --- a/lib/transaction.d.ts +++ b/lib/transaction.d.ts @@ -70,6 +70,11 @@ declare class PublicKey { data: Uint8Array; constructor(publicKey: string); } +declare class Signature { + keyType: KeyType; + data: Uint8Array; + constructor(signature: Uint8Array); +} declare class Transaction extends Assignable { signerId: string; publicKey: PublicKey; @@ -79,7 +84,7 @@ declare class Transaction extends Assignable { } export declare class SignedTransaction extends Assignable { transaction: Transaction; - signature: Uint8Array; + signature: Signature; encode(): Uint8Array; } export declare class Action extends Enum { diff --git a/lib/transaction.js b/lib/transaction.js index 8633930630..364e8fae52 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -104,6 +104,12 @@ class PublicKey { this.data = serialize_1.base_decode(publicKey); } } +class Signature { + constructor(signature) { + this.keyType = KeyType.ED25519; + this.data = signature; + } +} class Transaction extends Assignable { } class SignedTransaction extends Assignable { @@ -116,7 +122,8 @@ class Action extends Enum { } exports.Action = Action; const SCHEMA = { - 'SignedTransaction': { kind: 'struct', fields: [['transaction', Transaction], ['signature', [32]]] }, + 'Signature': { kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]] }, + 'SignedTransaction': { kind: 'struct', fields: [['transaction', Transaction], ['signature', Signature]] }, 'Transaction': { kind: 'struct', fields: [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]] }, @@ -162,7 +169,7 @@ async function signTransaction(receiverId, nonce, actions, signer, accountId, ne const message = serialize_1.serialize(SCHEMA, transaction); const hash = new Uint8Array(js_sha256_1.default.sha256.array(message)); const signature = await signer.signHash(hash, accountId, networkId); - const signedTx = new SignedTransaction({ transaction, signature: signature.signature }); + const signedTx = new SignedTransaction({ transaction, signature: new Signature(signature.signature) }); return [hash, signedTx]; } exports.signTransaction = signTransaction; diff --git a/package.json b/package.json index 1095c2022a..bfb73960c0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "scripts": { "dist": "yarn build && yarn doc && browserify browser-exports.js -i node-fetch -o dist/nearlib.js && browserify browser-exports.js -i node-fetch -g uglifyify -o dist/nearlib.min.js", "compile": "tsc -p ./tsconfig.json", - "dev": "yarn compile -- -w", + "dev": "yarn compile -w", "build": "yarn compile", "pretest": "yarn build", "test": "jest test --runInBand", diff --git a/src.ts/account.ts b/src.ts/account.ts index 4ae8645eea..29bab81b47 100644 --- a/src.ts/account.ts +++ b/src.ts/account.ts @@ -147,12 +147,12 @@ export class Account { } // TODO: expand this API to support more options. - async addKey(publicKey: string, contractId?: string, methodName?: string, balanceOwner?: string, amount?: BN): Promise { + async addKey(publicKey: string, contractId?: string, methodName?: string, amount?: BN): Promise { let accessKey; - if (contractId === null) { + if (contractId === null || contractId === undefined) { accessKey = fullAccessKey(); } else { - accessKey = functionCallAccessKey(contractId, methodName === null ? [] : [methodName], amount); + accessKey = functionCallAccessKey(contractId, !methodName ? [] : [methodName], amount); } return this.signAndSendTransaction(this.accountId, [addKey(publicKey, accessKey)]); } @@ -173,15 +173,26 @@ export class Account { return JSON.parse(Buffer.from(result.result).toString()); } - async getAccountDetails(): Promise { + /// Returns array of {access_key: AccessKey, public_key: PublicKey} items. + async getAccessKeys(): Promise { const response = await this.connection.provider.query(`access_key/${this.accountId}`, ''); + return response; + } + + async getAccountDetails(): Promise { + // TODO: update the response value to return all the different keys, not just app keys. + // Also if we need this function, or getAccessKeys is good enough. + const accessKeys = await this.getAccessKeys(); const result: any = { authorizedApps: [], transactions: [] }; - Object.keys(response).forEach((key) => { - result.authorizedApps.push({ - contractId: response[key][1].contract_id, - amount: response[key][1].amount, - publicKey: base_encode(response[key][0]), - }); + accessKeys.map((item) => { + if (item.access_key.permission.FunctionCall !== undefined) { + const perm = item.access_key.permission.FunctionCall; + result.authorizedApps.push({ + contractId: perm.receiver_id, + amount: perm.allowance, + publicKey: item.public_key.data, + }); + } }); return result; } diff --git a/src.ts/transaction.ts b/src.ts/transaction.ts index 0e16ceac8b..283234c0ec 100644 --- a/src.ts/transaction.ts +++ b/src.ts/transaction.ts @@ -111,6 +111,16 @@ class PublicKey { } } +class Signature { + keyType: KeyType; + data: Uint8Array; + + constructor(signature: Uint8Array) { + this.keyType = KeyType.ED25519; + this.data = signature; + } +} + class Transaction extends Assignable { signerId: string; publicKey: PublicKey; @@ -121,7 +131,7 @@ class Transaction extends Assignable { export class SignedTransaction extends Assignable { transaction: Transaction; - signature: Uint8Array; + signature: Signature; encode(): Uint8Array { return serialize(SCHEMA, this); @@ -140,7 +150,8 @@ export class Action extends Enum { } const SCHEMA = { - 'SignedTransaction': {kind: 'struct', fields: [['transaction', Transaction], ['signature', [32]]]}, + 'Signature': {kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]]}, + 'SignedTransaction': {kind: 'struct', fields: [['transaction', Transaction], ['signature', Signature]]}, 'Transaction': { kind: 'struct', fields: [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]] }, 'PublicKey': { @@ -185,6 +196,6 @@ export async function signTransaction(receiverId: string, nonce: number, actions const message = serialize(SCHEMA, transaction); const hash = new Uint8Array(sha256.sha256.array(message)); const signature = await signer.signHash(hash, accountId, networkId); - const signedTx = new SignedTransaction({transaction, signature: signature.signature }); + const signedTx = new SignedTransaction({transaction, signature: new Signature(signature.signature) }); return [hash, signedTx]; } diff --git a/test/account.access_key.test.js b/test/account.access_key.test.js index 895a5373ea..d29254c4fb 100644 --- a/test/account.access_key.test.js +++ b/test/account.access_key.test.js @@ -24,7 +24,7 @@ beforeEach(async () => { test('make function call using access key', async() => { const keyPair = nearlib.utils.KeyPair.fromRandom('ed25519'); - await workingAccount.addKey(keyPair.getPublicKey(), contractId, '', '', 400000); + await workingAccount.addKey(keyPair.getPublicKey(), contractId, '', 1000000); // Override in the key store the workingAccount key to the given access key. await nearjs.connection.signer.keyStore.setKey(testUtils.networkId, workingAccount.accountId, keyPair); @@ -35,20 +35,21 @@ test('make function call using access key', async() => { test('remove access key no longer works', async() => { const keyPair = nearlib.utils.KeyPair.fromRandom('ed25519'); - await workingAccount.addKey(keyPair.getPublicKey(), contractId, '', '', 400000); - await workingAccount.deleteKey(keyPair.getPublicKey()); + let publicKey = keyPair.getPublicKey(); + await workingAccount.addKey(publicKey, contractId, '', 400000); + await workingAccount.deleteKey(publicKey); // Override in the key store the workingAccount key to the given access key. await nearjs.connection.signer.keyStore.setKey(testUtils.networkId, workingAccount.accountId, keyPair); - await expect(contract.setValue({ value: 'test' })).rejects.toThrow(/\[-32000\] Server error: Transaction is not signed with a public key of the originator .+/); + await expect(contract.setValue({ value: 'test' })).rejects.toThrow(new RegExp(`\\[-32000\\] Server error: Signer "${workingAccount.accountId}" doesn't have access key with the given public_key \`${publicKey}\``)); }); test('view account details after adding access keys', async() => { const keyPair = nearlib.utils.KeyPair.fromRandom('ed25519'); - await workingAccount.addKey(keyPair.getPublicKey(), contractId, '', '', 1000000000); + await workingAccount.addKey(keyPair.getPublicKey(), contractId, '', 1000000000); const contract2 = await testUtils.deployContract(workingAccount, 'test_contract2_' + Date.now()); const keyPair2 = nearlib.utils.KeyPair.fromRandom('ed25519'); - await workingAccount.addKey(keyPair2.getPublicKey(), contract2.contractId, '', '', 2000000000); + await workingAccount.addKey(keyPair2.getPublicKey(), contract2.contractId, '', 2000000000); const details = await workingAccount.getAccountDetails(); const expectedResult = { @@ -69,10 +70,10 @@ test('view account details after adding access keys', async() => { test('loading account after adding a full key', async() => { const keyPair = nearlib.utils.KeyPair.fromRandom('ed25519'); - await workingAccount.addKey(keyPair.getPublicKey(), '', '', '', 1000000000); + await workingAccount.addKey(keyPair.getPublicKey()); - await workingAccount.fetchState(); + let accessKeys = await workingAccount.getAccessKeys(); - expect(workingAccount._state.public_keys.length).toBe(2); - expect(workingAccount._state.public_keys.includes(keyPair.getPublicKey())).toBe(true); + expect(accessKeys.length).toBe(2); + expect(accessKeys.map((item) => item.public_key.data).includes(keyPair.getPublicKey())).toBe(true); }); diff --git a/test/providers.test.js b/test/providers.test.js index c2aeaa8149..8e11bed323 100644 --- a/test/providers.test.js +++ b/test/providers.test.js @@ -19,7 +19,7 @@ test('json rpc query account', async () => { const config = Object.assign(require('./config')(process.env.NODE_ENV || 'test')); const provider = new nearlib.providers.JsonRpcProvider(config.nodeUrl); let response = await provider.query('account/test.near', ''); - expect(response.account_id).toEqual('test.near'); + expect(response.code_hash).toEqual('11111111111111111111111111111111'); }); test('final tx result', async() => { diff --git a/test/test-utils.js b/test/test-utils.js index 6603654f91..95bd28d9e9 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -29,7 +29,6 @@ async function createAccount(masterAccount, options = { amount: INITIAL_BALANCE, await masterAccount.fetchState(); const newAccountName = generateUniqueString('test'); const newPublicKey = await masterAccount.connection.signer.createKey(newAccountName, networkId); - console.warn(`account: ${newAccountName}, key: ${newPublicKey}`); await masterAccount.createAccount(newAccountName, newPublicKey, options.amount); return new nearlib.Account(masterAccount.connection, newAccountName); } diff --git a/yarn.lock b/yarn.lock index b2e37c00c4..f74ca8c1b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1079,59 +1079,6 @@ "@types/istanbul-reports" "^1.1.1" "@types/yargs" "^12.0.9" -"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf" - integrity sha1-m4sMxmPWaafY9vXQiToU00jzD78= - -"@protobufjs/base64@^1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@protobufjs/base64/-/base64-1.1.2.tgz#4c85730e59b9a1f1f349047dbf24296034bb2735" - integrity sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg== - -"@protobufjs/codegen@^2.0.4": - version "2.0.4" - resolved "https://registry.yarnpkg.com/@protobufjs/codegen/-/codegen-2.0.4.tgz#7ef37f0d010fb028ad1ad59722e506d9262815cb" - integrity sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg== - -"@protobufjs/eventemitter@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz#355cbc98bafad5978f9ed095f397621f1d066b70" - integrity sha1-NVy8mLr61ZePntCV85diHx0Ga3A= - -"@protobufjs/fetch@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@protobufjs/fetch/-/fetch-1.1.0.tgz#ba99fb598614af65700c1619ff06d454b0d84c45" - integrity sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU= - dependencies: - "@protobufjs/aspromise" "^1.1.1" - "@protobufjs/inquire" "^1.1.0" - -"@protobufjs/float@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@protobufjs/float/-/float-1.0.2.tgz#5e9e1abdcb73fc0a7cb8b291df78c8cbd97b87d1" - integrity sha1-Xp4avctz/Ap8uLKR33jIy9l7h9E= - -"@protobufjs/inquire@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@protobufjs/inquire/-/inquire-1.1.0.tgz#ff200e3e7cf2429e2dcafc1140828e8cc638f089" - integrity sha1-/yAOPnzyQp4tyvwRQIKOjMY48Ik= - -"@protobufjs/path@^1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@protobufjs/path/-/path-1.1.2.tgz#6cc2b20c5c9ad6ad0dccfd21ca7673d8d7fbf68d" - integrity sha1-bMKyDFya1q0NzP0hynZz2Nf79o0= - -"@protobufjs/pool@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@protobufjs/pool/-/pool-1.1.0.tgz#09fd15f2d6d3abfa9b65bc366506d6ad7846ff54" - integrity sha1-Cf0V8tbTq/qbZbw2ZQbWrXhG/1Q= - -"@protobufjs/utf8@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570" - integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA= - "@types/babel__core@^7.1.0": version "7.1.2" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.2.tgz#608c74f55928033fce18b99b213c16be4b3d114f" @@ -1207,11 +1154,6 @@ "@types/minimatch" "*" "@types/node" "*" -"@types/google-protobuf@^3.2.7": - version "3.2.7" - resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.2.7.tgz#9576ed5dd62cdb1c9f952522028a03b7cb2b69b5" - integrity sha512-Pb9wl5qDEwfnJeeu6Zpn5Y+waLrKETStqLZXHMGCTbkNuBBudPy4qOGN6veamyeoUBwTm2knOVeP/FlHHhhmzA== - "@types/handlebars@^4.0.38": version "4.1.0" resolved "https://registry.yarnpkg.com/@types/handlebars/-/handlebars-4.1.0.tgz#3fcce9bf88f85fe73dc932240ab3fb682c624850" @@ -1254,11 +1196,6 @@ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.134.tgz#9032b440122db3a2a56200e91191996161dde5b9" integrity sha512-2/O0khFUCFeDlbi7sZ7ZFRCcT812fAeOLm7Ev4KbwASkZ575TDrDcY7YyaoHdTOzKcNbfiwLYZqPmoC4wadrsw== -"@types/long@^4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.0.tgz#719551d2352d301ac8b81db732acb6bdc28dbdef" - integrity sha512-1w52Nyx4Gq47uuu0EVcsHBxZFJgurQ+rTKS3qMHxR1GY2T8c2AJYd6vZoZ9q1rupaDjU0yT+Jc2XTyXkjeMA+Q== - "@types/marked@^0.4.0": version "0.4.2" resolved "https://registry.yarnpkg.com/@types/marked/-/marked-0.4.2.tgz#64a89e53ea37f61cc0f3ee1732c555c2dbf6452f" @@ -1274,11 +1211,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.8.tgz#551466be11b2adc3f3d47156758f610bd9f6b1d8" integrity sha512-b8bbUOTwzIY3V5vDTY1fIJ+ePKDUBqt2hC2woVGotdQQhG/2Sh62HOKHrT7ab+VerXAcPyAiTEipPu/FsreUtg== -"@types/node@^10.1.0": - version "10.14.9" - resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.9.tgz#2e8d678039d27943ce53a1913386133227fd9066" - integrity sha512-NelG/dSahlXYtSoVPErrp06tYFrvzj8XLWmKA+X8x0W//4MqbUyZu++giUG/v0bjAT6/Qxa8IjodrfdACyb0Fg== - "@types/shelljs@^0.8.0": version "0.8.5" resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.5.tgz#1e507b2f6d1f893269bd3e851ec24419ef9beeea" @@ -3217,11 +3149,6 @@ globals@^11.1.0, globals@^11.7.0: resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== -google-protobuf@^3.6.1: - version "3.8.0" - resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.8.0.tgz#4fd2ee3a97751cb543dc5de85ffd264aff9f4980" - integrity sha512-tx39PTc//HaIT7K/baUF/8JYLGDozEi1e4xwPP1qSx3InP78cNpbSJpxiDsDMwj77qNOndVBDXnn7oi9zKxZew== - graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6: version "4.1.15" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00" @@ -4508,11 +4435,6 @@ lodash@^4.17.10, lodash@^4.17.11: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== -long@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" - integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== - longest-streak@^2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/longest-streak/-/longest-streak-2.0.3.tgz#3de7a3f47ee18e9074ded8575b5c091f5d0a4105" @@ -5457,25 +5379,6 @@ property-information@^4.0.0: dependencies: xtend "^4.0.1" -protobufjs@^6.8.8: - version "6.8.8" - resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.8.8.tgz#c8b4f1282fd7a90e6f5b109ed11c84af82908e7c" - integrity sha512-AAmHtD5pXgZfi7GMpllpO3q1Xw1OYldr+dMUlAnffGTAhqkg72WdmSY71uKBF/JuyiKs8psYbtKrhi0ASCD8qw== - dependencies: - "@protobufjs/aspromise" "^1.1.2" - "@protobufjs/base64" "^1.1.2" - "@protobufjs/codegen" "^2.0.4" - "@protobufjs/eventemitter" "^1.1.0" - "@protobufjs/fetch" "^1.1.0" - "@protobufjs/float" "^1.0.2" - "@protobufjs/inquire" "^1.1.0" - "@protobufjs/path" "^1.1.2" - "@protobufjs/pool" "^1.1.0" - "@protobufjs/utf8" "^1.1.0" - "@types/long" "^4.0.0" - "@types/node" "^10.1.0" - long "^4.0.0" - protocols@^1.1.0, protocols@^1.4.0: version "1.4.7" resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.7.tgz#95f788a4f0e979b291ffefcf5636ad113d037d32" @@ -6739,13 +6642,6 @@ trough@^1.0.0: resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.4.tgz#3b52b1f13924f460c3fbfd0df69b587dbcbc762e" integrity sha512-tdzBRDGWcI1OpPVmChbdSKhvSVurznZ8X36AYURAcl+0o2ldlCY2XPzyXNNxwJwwyIU+rIglTCG4kxtNKBQH7Q== -ts-protoc-gen@^0.10.0: - version "0.10.0" - resolved "https://registry.yarnpkg.com/ts-protoc-gen/-/ts-protoc-gen-0.10.0.tgz#f708d99be59ad0be6bdce6f4fe893ec41757d2c9" - integrity sha512-EEbgDWNHK3CvcNhmib94I4HMO23qLddjLRdXW8EUE11VJxbi3n5J0l2DiX/L1pijOaPTkbEoRK+zQinKgKGqsw== - dependencies: - google-protobuf "^3.6.1" - tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: version "1.10.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" From a4ce8a1aa63e5cb1170b918210e23885198c50bb Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Mon, 19 Aug 2019 14:15:04 -0700 Subject: [PATCH 7/8] Lint fixes --- src.ts/account.ts | 12 ++++---- src.ts/index.ts | 2 +- src.ts/transaction.ts | 62 +++++++++++++++++++-------------------- src.ts/utils/serialize.ts | 46 ++++++++++++++--------------- test/account.test.js | 2 +- test/serialize.test.js | 3 +- 6 files changed, 63 insertions(+), 64 deletions(-) diff --git a/src.ts/account.ts b/src.ts/account.ts index 29bab81b47..b14e88fa32 100644 --- a/src.ts/account.ts +++ b/src.ts/account.ts @@ -37,7 +37,7 @@ export class Account { readonly connection: Connection; readonly accountId: string; private _state: AccountState; - private _access_key: AccessKey; + private _accessKey: AccessKey; private _ready: Promise; protected get ready(): Promise { @@ -53,9 +53,9 @@ export class Account { this._state = await this.connection.provider.query(`account/${this.accountId}`, ''); try { const publicKey = await this.connection.signer.getPublicKey(this.accountId, this.connection.networkId); - this._access_key = await this.connection.provider.query(`access_key/${this.accountId}/${publicKey}`, ''); + this._accessKey = await this.connection.provider.query(`access_key/${this.accountId}/${publicKey}`, ''); } catch { - this._access_key = null; + this._accessKey = null; } } @@ -85,13 +85,13 @@ export class Account { throw new Error(`Exceeded ${TX_STATUS_RETRY_NUMBER} status check attempts for transaction ${base_encode(txHash)}.`); } - private async signAndSendTransaction(receiverId: string, actions: Array): Promise { + private async signAndSendTransaction(receiverId: string, actions: Action[]): Promise { await this.ready; - if (this._access_key === null) { + if (this._accessKey === null) { throw new Error(`Can not sign transactions, initialize account with available public key in Signer.`); } const [txHash, signedTx] = await signTransaction( - receiverId, ++this._access_key.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); + receiverId, ++this._accessKey.nonce, actions, this.connection.signer, this.accountId, this.connection.networkId); let result; try { diff --git a/src.ts/index.ts b/src.ts/index.ts index 7428aa3088..3379115c12 100644 --- a/src.ts/index.ts +++ b/src.ts/index.ts @@ -30,6 +30,6 @@ export { KeyPair, connect, - + WalletAccount }; diff --git a/src.ts/transaction.ts b/src.ts/transaction.ts index 283234c0ec..e805353ade 100644 --- a/src.ts/transaction.ts +++ b/src.ts/transaction.ts @@ -10,8 +10,8 @@ class Enum { enum: string; constructor(properties: any) { - if (Object.keys(properties).length != 1) { - throw new Error("Enum can only take single value"); + if (Object.keys(properties).length !== 1) { + throw new Error('Enum can only take single value'); } Object.keys(properties).map((key: string) => { (this as any)[key] = properties[key]; @@ -57,13 +57,13 @@ export function functionCallAccessKey(receiverId: string, methodNames: String[], export class IAction extends Assignable {} class CreateAccount extends IAction {} -class DeployContract extends IAction { code: Uint8Array } -class FunctionCall extends IAction { methodName: string; args: Uint8Array; gas: BN; deposit: BN } -class Transfer extends IAction { deposit: BN } -class Stake extends IAction { stake: BN; publicKey: PublicKey } -class AddKey extends IAction { publicKey: PublicKey; accessKey: AccessKey } -class DeleteKey extends IAction { publicKey: PublicKey } -class DeleteAccount extends IAction { beneficiaryId: string } +class DeployContract extends IAction { code: Uint8Array; } +class FunctionCall extends IAction { methodName: string; args: Uint8Array; gas: BN; deposit: BN; } +class Transfer extends IAction { deposit: BN; } +class Stake extends IAction { stake: BN; publicKey: PublicKey; } +class AddKey extends IAction { publicKey: PublicKey; accessKey: AccessKey; } +class DeleteKey extends IAction { publicKey: PublicKey; } +class DeleteAccount extends IAction { beneficiaryId: string; } export function createAccount(): Action { return new Action({createAccount: new CreateAccount({}) }); @@ -126,7 +126,7 @@ class Transaction extends Assignable { publicKey: PublicKey; nonce: number; receiverId: string; - actions: Array; + actions: Action[]; } export class SignedTransaction extends Assignable { @@ -150,28 +150,28 @@ export class Action extends Enum { } const SCHEMA = { - 'Signature': {kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]]}, - 'SignedTransaction': {kind: 'struct', fields: [['transaction', Transaction], ['signature', Signature]]}, - 'Transaction': { + Signature: {kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]]}, + SignedTransaction: {kind: 'struct', fields: [['transaction', Transaction], ['signature', Signature]]}, + Transaction: { kind: 'struct', fields: [['signerId', 'string'], ['publicKey', PublicKey], ['nonce', 'u64'], ['receiverId', 'string'], ['actions', [Action]]] }, - 'PublicKey': { + PublicKey: { kind: 'struct', fields: [['keyType', 'u8'], ['data', [32]]] }, - 'AccessKey': { kind: 'struct', fields: [ + AccessKey: { kind: 'struct', fields: [ ['nonce', 'u64'], ['permission', AccessKeyPermission], ]}, - 'AccessKeyPermission': {kind: 'enum', field: 'enum', values: [ + AccessKeyPermission: {kind: 'enum', field: 'enum', values: [ ['functionCall', FunctionCallPermission], ['fullAccess', FullAccessPermission], ]}, - 'FunctionCallPermission': {kind: 'struct', fields: [ - ['allowance', {kind: 'option', type: 'u128'}], - ['receiverId', 'string'], + FunctionCallPermission: {kind: 'struct', fields: [ + ['allowance', {kind: 'option', type: 'u128'}], + ['receiverId', 'string'], ['methodNames', ['string']], ]}, - 'FullAccessPermission': {kind: 'struct', fields: []}, - 'Action': {kind: 'enum', field: 'enum', values: [ - ['createAccount', CreateAccount], + FullAccessPermission: {kind: 'struct', fields: []}, + Action: {kind: 'enum', field: 'enum', values: [ + ['createAccount', CreateAccount], ['deployContract', DeployContract], ['functionCall', functionCall], ['transfer', transfer], @@ -180,15 +180,15 @@ const SCHEMA = { ['deleteKey', deleteKey], ['deleteAccount', deleteAccount], ]}, - 'CreateAccount': { kind: 'struct', fields: [] }, - 'DeployContract': { kind: 'struct', fields: [['code', ['u8']]] }, - 'FunctionCall': { kind: 'struct', fields: [['methodName', 'string'], ['args', ['u8']], ['gas', 'u64'], ['deposit', 'u128']] }, - 'Transfer': { kind: 'struct', fields: [['deposit', 'u128']] }, - 'Stake': { kind: 'struct', fields: [['stake', 'u128'], ['publicKey', PublicKey]] }, - 'AddKey': { kind: 'struct', fields: [['publicKey', PublicKey], ['accessKey', AccessKey]] }, - 'DeleteKey': { kind: 'struct', fields: [['publicKey', PublicKey]] }, - 'DeleteAccount': { kind: 'struct', fields: [['beneficiaryId', 'string']] }, -} + CreateAccount: { kind: 'struct', fields: [] }, + DeployContract: { kind: 'struct', fields: [['code', ['u8']]] }, + FunctionCall: { kind: 'struct', fields: [['methodName', 'string'], ['args', ['u8']], ['gas', 'u64'], ['deposit', 'u128']] }, + Transfer: { kind: 'struct', fields: [['deposit', 'u128']] }, + Stake: { kind: 'struct', fields: [['stake', 'u128'], ['publicKey', PublicKey]] }, + AddKey: { kind: 'struct', fields: [['publicKey', PublicKey], ['accessKey', AccessKey]] }, + DeleteKey: { kind: 'struct', fields: [['publicKey', PublicKey]] }, + DeleteAccount: { kind: 'struct', fields: [['beneficiaryId', 'string']] }, +}; export async function signTransaction(receiverId: string, nonce: number, actions: Action[], signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]> { const publicKey = new PublicKey(await signer.getPublicKey(accountId, networkId)); diff --git a/src.ts/utils/serialize.ts b/src.ts/utils/serialize.ts index 70d6d1d5f0..b41570a1a8 100644 --- a/src.ts/utils/serialize.ts +++ b/src.ts/utils/serialize.ts @@ -55,13 +55,13 @@ export class BinaryWriter { } private write_buffer(buffer: Buffer) { - this.buf = Buffer.concat([this.buf.subarray(0, this.length), buffer, Buffer.alloc(INITIAL_LENGTH)]) + this.buf = Buffer.concat([this.buf.subarray(0, this.length), buffer, Buffer.alloc(INITIAL_LENGTH)]); this.length += buffer.length; } public write_string(str: string) { this.maybe_resize(); - let b = Buffer.from(str, 'utf8'); + const b = Buffer.from(str, 'utf8'); this.write_u32(b.length); this.write_buffer(b); } @@ -70,12 +70,12 @@ export class BinaryWriter { this.write_buffer(Buffer.from(array)); } - public write_array(array: Array, fn: any) { + public write_array(array: any[], fn: any) { this.maybe_resize(); this.write_u32(array.length); - for (let i = 0; i < array.length; ++i) { + for (const elem of array) { this.maybe_resize(); - fn(array[i]); + fn(elem); } } @@ -106,13 +106,13 @@ export class BinaryReader { } read_u64(): BN { - let buf = this.read_buffer(8); + const buf = this.read_buffer(8); buf.reverse(); return new BN(`${buf.toString('hex')}`, 16); } read_u128(): BN { - let buf = this.read_buffer(16); + const buf = this.read_buffer(16); return new BN(buf); } @@ -123,7 +123,7 @@ export class BinaryReader { } read_string(): string { - let len = this.read_u32(); + const len = this.read_u32(); return this.read_buffer(len).toString('utf8'); } @@ -131,9 +131,9 @@ export class BinaryReader { return new Uint8Array(this.read_buffer(len)); } - read_array(fn: any): Array { + read_array(fn: any): any[] { const len = this.read_u32(); - let result = Array(); + const result = Array(); for (let i = 0; i < len; ++i) { result.push(fn()); } @@ -142,17 +142,17 @@ export class BinaryReader { } function serializeField(schema: any, value: any, fieldType: any, writer: any) { - if (typeof fieldType === "string") { + if (typeof fieldType === 'string') { writer[`write_${fieldType}`](value); } else if (fieldType instanceof Array) { - if (typeof fieldType[0] === "number") { + if (typeof fieldType[0] === 'number') { writer.write_fixed_array(value); } else { - writer.write_array(value, (item: any) => { serializeField(schema, item, fieldType[0], writer) }); + writer.write_array(value, (item: any) => { serializeField(schema, item, fieldType[0], writer); }); } } else if (fieldType.kind !== undefined) { switch (fieldType.kind) { - case "option": { + case 'option': { if (value === null) { writer.write_u8(0); } else { @@ -161,7 +161,7 @@ function serializeField(schema: any, value: any, fieldType: any, writer: any) { } break; } - default: throw new Error(`FieldType ${fieldType} unrecognized`) + default: throw new Error(`FieldType ${fieldType} unrecognized`); } } else { serializeStruct(schema, value, writer); @@ -171,7 +171,7 @@ function serializeField(schema: any, value: any, fieldType: any, writer: any) { function serializeStruct(schema: any, obj: any, writer: any) { const className = obj.constructor.name; if (schema[className] === undefined) { - throw new Error(`Class ${className} is missing in schema`) + throw new Error(`Class ${className} is missing in schema`); } if (schema[className].kind === 'struct') { schema[className].fields.map(([fieldName, fieldType]: [any, any]) => { @@ -180,7 +180,7 @@ function serializeStruct(schema: any, obj: any, writer: any) { } else if (schema[className].kind === 'enum') { const name = obj[schema[className].field]; for (let idx = 0; idx < schema[className].values.length; ++idx) { - let [fieldName, fieldType]: [any, any] = schema[className].values[idx]; + const [fieldName, fieldType]: [any, any] = schema[className].values[idx]; if (fieldName === name) { writer.write_u8(idx); serializeField(schema, obj[fieldName], fieldType, writer); @@ -195,19 +195,19 @@ function serializeStruct(schema: any, obj: any, writer: any) { /// Serialize given object using schema of the form: /// { class_name -> [ [field_name, field_type], .. ], .. } export function serialize(schema: any, obj: any): Uint8Array { - let writer = new BinaryWriter(); + const writer = new BinaryWriter(); serializeStruct(schema, obj, writer); return writer.toArray(); } function deserializeField(schema: any, fieldType: any, reader: any): any { - if (typeof fieldType === "string") { + if (typeof fieldType === 'string') { return reader[`read_${fieldType}`](); } else if (fieldType instanceof Array) { if (typeof fieldType[0] === 'number') { return reader.read_fixed_array(fieldType[0]); } else { - return reader.read_array(() => { return deserializeField(schema, fieldType[0], reader) }); + return reader.read_array(() => deserializeField(schema, fieldType[0], reader)); } } else { return deserializeStruct(schema, fieldType, reader); @@ -215,7 +215,7 @@ function deserializeField(schema: any, fieldType: any, reader: any): any { } function deserializeStruct(schema: any, classType: any, reader: any) { - let fields = schema[classType.name].fields.map(([fieldName, fieldType]: [any, any]) => { + const fields = schema[classType.name].fields.map(([fieldName, fieldType]: [any, any]) => { return deserializeField(schema, fieldType, reader); }); return new classType(...fields); @@ -223,6 +223,6 @@ function deserializeStruct(schema: any, classType: any, reader: any) { /// Deserializes object from bytes using schema. export function deserialize(schema: any, classType: any, buffer: Buffer): any { - let reader = new BinaryReader(buffer); + const reader = new BinaryReader(buffer); return deserializeStruct(schema, classType, reader); -} \ No newline at end of file +} diff --git a/test/account.test.js b/test/account.test.js index 1acadf8ca6..40d696da2c 100644 --- a/test/account.test.js +++ b/test/account.test.js @@ -18,7 +18,7 @@ beforeAll(async () => { test('view pre-defined account works and returns correct name', async () => { let status = await workingAccount.state(); - expect(status.code_hash).toEqual("11111111111111111111111111111111"); + expect(status.code_hash).toEqual('11111111111111111111111111111111'); }); test('create account and then view account returns the created account', async () => { diff --git a/test/serialize.test.js b/test/serialize.test.js index a4d37c9ffa..275b9d8679 100644 --- a/test/serialize.test.js +++ b/test/serialize.test.js @@ -1,6 +1,5 @@ const nearlib = require('../lib/index'); -const BN = require('BN.js'); class Test { constructor(x, y, z, q) { @@ -36,6 +35,6 @@ test('serialize tx', async() => { nearlib.transactions.deleteKey(publicKey), nearlib.transactions.deleteAccount('123') ]; - let [hash, signedTx] = await nearlib.transactions.signTransaction('123', 1, actions, new nearlib.InMemorySigner(keyStore), 'test.near', 'test'); + let [hash] = await nearlib.transactions.signTransaction('123', 1, actions, new nearlib.InMemorySigner(keyStore), 'test.near', 'test'); expect(nearlib.utils.serialize.base_encode(hash)).toEqual('244ZQ9cgj3CQ6bWBdytfrJMuMQ1jdXLFGnr4HhvtCTnM'); }); \ No newline at end of file From 80c6a56da69d4d5cc97a00b0af65afd195d10457 Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 20 Aug 2019 22:48:26 -0700 Subject: [PATCH 8/8] Remove unused protos-utils module --- protos-utils.js | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 protos-utils.js diff --git a/protos-utils.js b/protos-utils.js deleted file mode 100644 index 044ddd8ab6..0000000000 --- a/protos-utils.js +++ /dev/null @@ -1,14 +0,0 @@ -const protos = require('./protos'); - -const TRANSACTION_FIELD_MAP = new Map([ - [protos.CreateAccountTransaction, 'createAccount'], - [protos.DeployContractTransaction, 'deployContract'], - [protos.FunctionCallTransaction, 'functionCall'], - [protos.SendMoneyTransaction, 'sendMoney'], - [protos.StakeTransaction, 'stake'], - [protos.SwapKeyTransaction, 'swapKey'], - [protos.AddKeyTransaction, 'addKey'], - [protos.DeleteKeyTransaction, 'deleteKey'], -]); - -module.exports.getTransactionFieldName = (transactionProto) => TRANSACTION_FIELD_MAP.get(transactionProto.constructor);