exonum-client-cis
Version:
Light Client for Exonum CIS Blockchain
1,039 lines (960 loc) • 714 kB
JavaScript
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
(function(global, factory) { /* global define, require, module */
/* AMD */ if (typeof define === 'function' && define.amd)
define(["protobufjs/minimal"], factory);
/* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports)
module.exports = factory(require("protobufjs/minimal"));
})(this, function($protobuf) {
"use strict";
// Common aliases
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
// Exported root namespace
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
$root.exonum = (function() {
/**
* Namespace exonum.
* @exports exonum
* @namespace
*/
var exonum = {};
exonum.crypto = (function() {
/**
* Namespace crypto.
* @memberof exonum
* @namespace
*/
var crypto = {};
crypto.Hash = (function() {
/**
* Properties of a Hash.
* @memberof exonum.crypto
* @interface IHash
* @property {Uint8Array|null} [data] Hash data
*/
/**
* Constructs a new Hash.
* @memberof exonum.crypto
* @classdesc Represents a Hash.
* @implements IHash
* @constructor
* @param {exonum.crypto.IHash=} [properties] Properties to set
*/
function Hash(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]];
}
/**
* Hash data.
* @member {Uint8Array} data
* @memberof exonum.crypto.Hash
* @instance
*/
Hash.prototype.data = $util.newBuffer([]);
/**
* Creates a new Hash instance using the specified properties.
* @function create
* @memberof exonum.crypto.Hash
* @static
* @param {exonum.crypto.IHash=} [properties] Properties to set
* @returns {exonum.crypto.Hash} Hash instance
*/
Hash.create = function create(properties) {
return new Hash(properties);
};
/**
* Encodes the specified Hash message. Does not implicitly {@link exonum.crypto.Hash.verify|verify} messages.
* @function encode
* @memberof exonum.crypto.Hash
* @static
* @param {exonum.crypto.IHash} message Hash message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Hash.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.data != null && message.hasOwnProperty("data"))
writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.data);
return writer;
};
/**
* Encodes the specified Hash message, length delimited. Does not implicitly {@link exonum.crypto.Hash.verify|verify} messages.
* @function encodeDelimited
* @memberof exonum.crypto.Hash
* @static
* @param {exonum.crypto.IHash} message Hash message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Hash.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a Hash message from the specified reader or buffer.
* @function decode
* @memberof exonum.crypto.Hash
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {exonum.crypto.Hash} Hash
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Hash.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.exonum.crypto.Hash();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.data = reader.bytes();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a Hash message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof exonum.crypto.Hash
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {exonum.crypto.Hash} Hash
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Hash.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a Hash message.
* @function verify
* @memberof exonum.crypto.Hash
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Hash.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
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 a Hash message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof exonum.crypto.Hash
* @static
* @param {Object.<string,*>} object Plain object
* @returns {exonum.crypto.Hash} Hash
*/
Hash.fromObject = function fromObject(object) {
if (object instanceof $root.exonum.crypto.Hash)
return object;
var message = new $root.exonum.crypto.Hash();
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 a Hash message. Also converts values to other types if specified.
* @function toObject
* @memberof exonum.crypto.Hash
* @static
* @param {exonum.crypto.Hash} message Hash
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Hash.toObject = function toObject(message, options) {
if (!options)
options = {};
var object = {};
if (options.defaults)
if (options.bytes === String)
object.data = "";
else {
object.data = [];
if (options.bytes !== Array)
object.data = $util.newBuffer(object.data);
}
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 Hash to JSON.
* @function toJSON
* @memberof exonum.crypto.Hash
* @instance
* @returns {Object.<string,*>} JSON object
*/
Hash.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
return Hash;
})();
crypto.PublicKey = (function() {
/**
* Properties of a PublicKey.
* @memberof exonum.crypto
* @interface IPublicKey
* @property {Uint8Array|null} [data] PublicKey data
*/
/**
* Constructs a new PublicKey.
* @memberof exonum.crypto
* @classdesc Represents a PublicKey.
* @implements IPublicKey
* @constructor
* @param {exonum.crypto.IPublicKey=} [properties] Properties to set
*/
function PublicKey(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]];
}
/**
* PublicKey data.
* @member {Uint8Array} data
* @memberof exonum.crypto.PublicKey
* @instance
*/
PublicKey.prototype.data = $util.newBuffer([]);
/**
* Creates a new PublicKey instance using the specified properties.
* @function create
* @memberof exonum.crypto.PublicKey
* @static
* @param {exonum.crypto.IPublicKey=} [properties] Properties to set
* @returns {exonum.crypto.PublicKey} PublicKey instance
*/
PublicKey.create = function create(properties) {
return new PublicKey(properties);
};
/**
* Encodes the specified PublicKey message. Does not implicitly {@link exonum.crypto.PublicKey.verify|verify} messages.
* @function encode
* @memberof exonum.crypto.PublicKey
* @static
* @param {exonum.crypto.IPublicKey} message PublicKey message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
PublicKey.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.data != null && message.hasOwnProperty("data"))
writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.data);
return writer;
};
/**
* Encodes the specified PublicKey message, length delimited. Does not implicitly {@link exonum.crypto.PublicKey.verify|verify} messages.
* @function encodeDelimited
* @memberof exonum.crypto.PublicKey
* @static
* @param {exonum.crypto.IPublicKey} message PublicKey message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
PublicKey.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a PublicKey message from the specified reader or buffer.
* @function decode
* @memberof exonum.crypto.PublicKey
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {exonum.crypto.PublicKey} PublicKey
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
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.exonum.crypto.PublicKey();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.data = reader.bytes();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a PublicKey message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof exonum.crypto.PublicKey
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {exonum.crypto.PublicKey} PublicKey
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
PublicKey.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a PublicKey message.
* @function verify
* @memberof exonum.crypto.PublicKey
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
PublicKey.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
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 a PublicKey message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof exonum.crypto.PublicKey
* @static
* @param {Object.<string,*>} object Plain object
* @returns {exonum.crypto.PublicKey} PublicKey
*/
PublicKey.fromObject = function fromObject(object) {
if (object instanceof $root.exonum.crypto.PublicKey)
return object;
var message = new $root.exonum.crypto.PublicKey();
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 a PublicKey message. Also converts values to other types if specified.
* @function toObject
* @memberof exonum.crypto.PublicKey
* @static
* @param {exonum.crypto.PublicKey} message PublicKey
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
PublicKey.toObject = function toObject(message, options) {
if (!options)
options = {};
var object = {};
if (options.defaults)
if (options.bytes === String)
object.data = "";
else {
object.data = [];
if (options.bytes !== Array)
object.data = $util.newBuffer(object.data);
}
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 PublicKey to JSON.
* @function toJSON
* @memberof exonum.crypto.PublicKey
* @instance
* @returns {Object.<string,*>} JSON object
*/
PublicKey.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
return PublicKey;
})();
crypto.Signature = (function() {
/**
* Properties of a Signature.
* @memberof exonum.crypto
* @interface ISignature
* @property {Uint8Array|null} [data] Signature data
*/
/**
* Constructs a new Signature.
* @memberof exonum.crypto
* @classdesc Represents a Signature.
* @implements ISignature
* @constructor
* @param {exonum.crypto.ISignature=} [properties] Properties to set
*/
function Signature(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]];
}
/**
* Signature data.
* @member {Uint8Array} data
* @memberof exonum.crypto.Signature
* @instance
*/
Signature.prototype.data = $util.newBuffer([]);
/**
* Creates a new Signature instance using the specified properties.
* @function create
* @memberof exonum.crypto.Signature
* @static
* @param {exonum.crypto.ISignature=} [properties] Properties to set
* @returns {exonum.crypto.Signature} Signature instance
*/
Signature.create = function create(properties) {
return new Signature(properties);
};
/**
* Encodes the specified Signature message. Does not implicitly {@link exonum.crypto.Signature.verify|verify} messages.
* @function encode
* @memberof exonum.crypto.Signature
* @static
* @param {exonum.crypto.ISignature} message Signature message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Signature.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.data != null && message.hasOwnProperty("data"))
writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.data);
return writer;
};
/**
* Encodes the specified Signature message, length delimited. Does not implicitly {@link exonum.crypto.Signature.verify|verify} messages.
* @function encodeDelimited
* @memberof exonum.crypto.Signature
* @static
* @param {exonum.crypto.ISignature} message Signature message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Signature.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a Signature message from the specified reader or buffer.
* @function decode
* @memberof exonum.crypto.Signature
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {exonum.crypto.Signature} Signature
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Signature.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.exonum.crypto.Signature();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.data = reader.bytes();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a Signature message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof exonum.crypto.Signature
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {exonum.crypto.Signature} Signature
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Signature.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a Signature message.
* @function verify
* @memberof exonum.crypto.Signature
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Signature.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
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 a Signature message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof exonum.crypto.Signature
* @static
* @param {Object.<string,*>} object Plain object
* @returns {exonum.crypto.Signature} Signature
*/
Signature.fromObject = function fromObject(object) {
if (object instanceof $root.exonum.crypto.Signature)
return object;
var message = new $root.exonum.crypto.Signature();
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 a Signature message. Also converts values to other types if specified.
* @function toObject
* @memberof exonum.crypto.Signature
* @static
* @param {exonum.crypto.Signature} message Signature
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Signature.toObject = function toObject(message, options) {
if (!options)
options = {};
var object = {};
if (options.defaults)
if (options.bytes === String)
object.data = "";
else {
object.data = [];
if (options.bytes !== Array)
object.data = $util.newBuffer(object.data);
}
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 Signature to JSON.
* @function toJSON
* @memberof exonum.crypto.Signature
* @instance
* @returns {Object.<string,*>} JSON object
*/
Signature.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
return Signature;
})();
return crypto;
})();
exonum.Block = (function() {
/**
* Properties of a Block.
* @memberof exonum
* @interface IBlock
* @property {number|Long|null} [chain_id] Block chain_id
* @property {number|null} [proposer_id] Block proposer_id
* @property {number|Long|null} [height] Block height
* @property {number|null} [tx_count] Block tx_count
* @property {exonum.crypto.IHash|null} [prev_hash] Block prev_hash
* @property {exonum.crypto.IHash|null} [tx_hash] Block tx_hash
* @property {exonum.crypto.IHash|null} [state_hash] Block state_hash
*/
/**
* Constructs a new Block.
* @memberof exonum
* @classdesc Represents a Block.
* @implements IBlock
* @constructor
* @param {exonum.IBlock=} [properties] Properties to set
*/
function Block(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]];
}
/**
* Block chain_id.
* @member {number|Long} chain_id
* @memberof exonum.Block
* @instance
*/
Block.prototype.chain_id = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
/**
* Block proposer_id.
* @member {number} proposer_id
* @memberof exonum.Block
* @instance
*/
Block.prototype.proposer_id = 0;
/**
* Block height.
* @member {number|Long} height
* @memberof exonum.Block
* @instance
*/
Block.prototype.height = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
/**
* Block tx_count.
* @member {number} tx_count
* @memberof exonum.Block
* @instance
*/
Block.prototype.tx_count = 0;
/**
* Block prev_hash.
* @member {exonum.crypto.IHash|null|undefined} prev_hash
* @memberof exonum.Block
* @instance
*/
Block.prototype.prev_hash = null;
/**
* Block tx_hash.
* @member {exonum.crypto.IHash|null|undefined} tx_hash
* @memberof exonum.Block
* @instance
*/
Block.prototype.tx_hash = null;
/**
* Block state_hash.
* @member {exonum.crypto.IHash|null|undefined} state_hash
* @memberof exonum.Block
* @instance
*/
Block.prototype.state_hash = null;
/**
* Creates a new Block instance using the specified properties.
* @function create
* @memberof exonum.Block
* @static
* @param {exonum.IBlock=} [properties] Properties to set
* @returns {exonum.Block} Block instance
*/
Block.create = function create(properties) {
return new Block(properties);
};
/**
* Encodes the specified Block message. Does not implicitly {@link exonum.Block.verify|verify} messages.
* @function encode
* @memberof exonum.Block
* @static
* @param {exonum.IBlock} message Block message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Block.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.proposer_id != null && message.hasOwnProperty("proposer_id"))
writer.uint32(/* id 1, wireType 0 =*/8).uint32(message.proposer_id);
if (message.height != null && message.hasOwnProperty("height"))
writer.uint32(/* id 2, wireType 0 =*/16).uint64(message.height);
if (message.tx_count != null && message.hasOwnProperty("tx_count"))
writer.uint32(/* id 3, wireType 0 =*/24).uint32(message.tx_count);
if (message.prev_hash != null && message.hasOwnProperty("prev_hash"))
$root.exonum.crypto.Hash.encode(message.prev_hash, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim();
if (message.tx_hash != null && message.hasOwnProperty("tx_hash"))
$root.exonum.crypto.Hash.encode(message.tx_hash, writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim();
if (message.state_hash != null && message.hasOwnProperty("state_hash"))
$root.exonum.crypto.Hash.encode(message.state_hash, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim();
if (message.chain_id != null && message.hasOwnProperty("chain_id"))
writer.uint32(/* id 7, wireType 0 =*/56).uint64(message.chain_id);
return writer;
};
/**
* Encodes the specified Block message, length delimited. Does not implicitly {@link exonum.Block.verify|verify} messages.
* @function encodeDelimited
* @memberof exonum.Block
* @static
* @param {exonum.IBlock} message Block message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Block.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a Block message from the specified reader or buffer.
* @function decode
* @memberof exonum.Block
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {exonum.Block} Block
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Block.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.exonum.Block();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 7:
message.chain_id = reader.uint64();
break;
case 1:
message.proposer_id = reader.uint32();
break;
case 2:
message.height = reader.uint64();
break;
case 3:
message.tx_count = reader.uint32();
break;
case 4:
message.prev_hash = $root.exonum.crypto.Hash.decode(reader, reader.uint32());
break;
case 5:
message.tx_hash = $root.exonum.crypto.Hash.decode(reader, reader.uint32());
break;
case 6:
message.state_hash = $root.exonum.crypto.Hash.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a Block message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof exonum.Block
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {exonum.Block} Block
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Block.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a Block message.
* @function verify
* @memberof exonum.Block
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Block.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.chain_id != null && message.hasOwnProperty("chain_id"))
if (!$util.isInteger(message.chain_id) && !(message.chain_id && $util.isInteger(message.chain_id.low) && $util.isInteger(message.chain_id.high)))
return "chain_id: integer|Long expected";
if (message.proposer_id != null && message.hasOwnProperty("proposer_id"))
if (!$util.isInteger(message.proposer_id))
return "proposer_id: integer expected";
if (message.height != null && message.hasOwnProperty("height"))
if (!$util.isInteger(message.height) && !(message.height && $util.isInteger(message.height.low) && $util.isInteger(message.height.high)))
return "height: integer|Long expected";
if (message.tx_count != null && message.hasOwnProperty("tx_count"))
if (!$util.isInteger(message.tx_count))
return "tx_count: integer expected";
if (message.prev_hash != null && message.hasOwnProperty("prev_hash")) {
var error = $root.exonum.crypto.Hash.verify(message.prev_hash);
if (error)
return "prev_hash." + error;
}
if (message.tx_hash != null && message.hasOwnProperty("tx_hash")) {
var error = $root.exonum.crypto.Hash.verify(message.tx_hash);
if (error)
return "tx_hash." + error;
}
if (message.state_hash != null && message.hasOwnProperty("state_hash")) {
var error = $root.exonum.crypto.Hash.verify(message.state_hash);
if (error)
return "state_hash." + error;
}
return null;
};
/**
* Creates a Block message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof exonum.Block
* @static
* @param {Object.<string,*>} object Plain object
* @returns {exonum.Block} Block
*/
Block.fromObject = function fromObject(object) {
if (object instanceof $root.exonum.Block)
return object;
var message = new $root.exonum.Block();
if (object.chain_id != null)
if ($util.Long)
(message.chain_id = $util.Long.fromValue(object.chain_id)).unsigned = true;
else if (typeof object.chain_id === "string")
message.chain_id = parseInt(object.chain_id, 10);
else if (typeof object.chain_id === "number")
message.chain_id = object.chain_id;
else if (typeof object.chain_id === "object")
message.chain_id = new $util.LongBits(object.chain_id.low >>> 0, object.chain_id.high >>> 0).toNumber(true);
if (object.proposer_id != null)
message.proposer_id = object.proposer_id >>> 0;
if (object.height != null)
if ($util.Long)
(message.height = $util.Long.fromValue(object.height)).unsigned = true;
else if (typeof object.height === "string")
message.height = parseInt(object.height, 10);
else if (typeof object.height === "number")
message.height = object.height;
else if (typeof object.height === "object")
message.height = new $util.LongBits(object.height.low >>> 0, object.height.high >>> 0).toNumber(true);
if (object.tx_count != null)
message.tx_count = object.tx_count >>> 0;
if (object.prev_hash != null) {
if (typeof object.prev_hash !== "object")
throw TypeError(".exonum.Block.prev_hash: object expected");
message.prev_hash = $root.exonum.crypto.Hash.fromObject(object.prev_hash);
}
if (object.tx_hash != null) {
if (typeof object.tx_hash !== "object")
throw TypeError(".exonum.Block.tx_hash: object expected");
message.tx_hash = $root.exonum.crypto.Hash.fromObject(object.tx_hash);
}
if (object.state_hash != null) {
if (typeof object.state_hash !== "object")
throw TypeError(".exonum.Block.state_hash: object expected");
message.state_hash = $root.exonum.crypto.Hash.fromObject(object.state_hash);
}
return message;
};
/**
* Creates a plain object from a Block message. Also converts values to other types if specified.
* @function toObject
* @memberof exonum.Block
* @static
* @param {exonum.Block} message Block
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Block.toObject = function toObject(message, options) {
if (!options)
options = {};
var object = {};
if (options.defaults) {
object.proposer_id = 0;
if ($util.Long) {
var long = new $util.Long(0, 0, true);
object.height = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
} else
object.height = options.longs === String ? "0" : 0;
object.tx_count = 0;
object.prev_hash = null;
object.tx_hash = null;
object.state_hash = null;
if ($util.Long) {
var long = new $util.Long(0, 0, true);
object.chain_id = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
} else
object.chain_id = options.longs === String ? "0" : 0;
}
if (message.proposer_id != null && message.hasOwnProperty("proposer_id"))
object.proposer_id = message.proposer_id;
if (message.height != null && message.hasOwnProperty("height"))
if (typeof message.height === "number")
object.height = options.longs === String ? String(message.height) : message.height;
else
object.height = options.longs === String ? $util.Long.prototype.toString.call(message.height) : options.longs === Number ? new $util.LongBits(message.height.low >>> 0, message.height.high >>> 0).toNumber(true) : message.height;
if (message.tx_count != null && message.hasOwnProperty("tx_count"))
object.tx_count = message.tx_count;
if (message.prev_hash != null && message.hasOwnProperty("prev_hash"))
object.prev_hash = $root.exonum.crypto.Hash.toObject(message.prev_hash, options);
if (message.tx_hash != null && message.hasOwnProperty("tx_hash"))
object.tx_hash = $root.exonum.crypto.Hash.toObject(message.tx_hash, options);
if (message.state_hash != null && message.hasOwnProperty("state_hash"))
object.state_hash = $root.exonum.crypto.Hash.toObject(message.state_hash, options);
if (message.chain_id != null && message.hasOwnProperty("chain_id"))
if (typeof message.chain_id === "number")
object.chain_id = options.longs === String ? String(message.chain_id) : message.chain_id;
else
object.chain_id = options.longs === String ? $util.Long.prototype.toString.call(message.chain_id) : options.longs === Number ? new $util.LongBits(message.chain_id.low >>> 0, message.chain_id.high >>> 0).toNumber(true) : message.chain_id;
return object;
};
/**
* Converts this Block to JSON.
* @function toJSON
* @memberof exonum.Block
* @instance
* @returns {Object.<string,*>} JSON object
*/
Block.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
return Block;
})();
exonum.TxLocation = (function() {
/**
* Properties of a TxLocation.
* @memberof exonum
* @interface ITxLocation
* @property {number|Long|null} [block_height] TxLocation block_height
* @property {number|Long|null} [position_in_block] TxLocation position_in_block
*/
/**
* Constructs a new TxLocation.
* @memberof exonum
* @classdesc Represents a TxLocation.
* @implements ITxLocation
* @constructor
* @param {exonum.ITxLocation=} [properties] Properties to set
*/
function TxLocation(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]];
}
/**
* TxLocation block_height.
* @member {number|Long} block_height
* @memberof exonum.TxLocation
* @instance
*/
TxLocation.prototype.block_height = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
/**
* TxLocation position_in_block.
* @member {number|Long} position_in_block
* @memberof exonum.TxLocation
* @instance
*/
TxLocation.prototype.position_in_block = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
/**
* Creates a new TxLocation instance using the specified properties.
* @function create
* @memberof exonum.TxLocation
* @static
* @param {exonum.ITxLocation=} [properties] Properties to set
* @returns {exonum.TxLocation} TxLocation instance