@dojima-wallet/connection
Version:
Initialise and connection for layer 1&2 blockchain
1,451 lines (1,366 loc) • 475 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*/
"use strict";
var $protobuf = require("protobufjs/minimal");
// Common aliases
var $Reader = $protobuf.Reader,
$Writer = $protobuf.Writer,
$util = $protobuf.util;
// Exported root namespace
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
$root.common = (function () {
/**
* Namespace common.
* @exports common
* @namespace
*/
var common = {};
common.Asset = (function () {
/**
* Properties of an Asset.
* @memberof common
* @interface IAsset
* @property {string|null} [chain] Asset chain
* @property {string|null} [symbol] Asset symbol
* @property {string|null} [ticker] Asset ticker
* @property {boolean|null} [synth] Asset synth
*/
/**
* Constructs a new Asset.
* @memberof common
* @classdesc Represents an Asset.
* @implements IAsset
* @constructor
* @param {common.IAsset=} [properties] Properties to set
*/
function Asset(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]];
}
/**
* Asset chain.
* @member {string} chain
* @memberof common.Asset
* @instance
*/
Asset.prototype.chain = "";
/**
* Asset symbol.
* @member {string} symbol
* @memberof common.Asset
* @instance
*/
Asset.prototype.symbol = "";
/**
* Asset ticker.
* @member {string} ticker
* @memberof common.Asset
* @instance
*/
Asset.prototype.ticker = "";
/**
* Asset synth.
* @member {boolean} synth
* @memberof common.Asset
* @instance
*/
Asset.prototype.synth = false;
/**
* Creates a new Asset instance using the specified properties.
* @function create
* @memberof common.Asset
* @static
* @param {common.IAsset=} [properties] Properties to set
* @returns {common.Asset} Asset instance
*/
Asset.create = function create(properties) {
return new Asset(properties);
};
/**
* Encodes the specified Asset message. Does not implicitly {@link common.Asset.verify|verify} messages.
* @function encode
* @memberof common.Asset
* @static
* @param {common.IAsset} message Asset message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Asset.encode = function encode(message, writer) {
if (!writer) writer = $Writer.create();
if (message.chain != null && Object.hasOwnProperty.call(message, "chain"))
writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.chain);
if (
message.symbol != null &&
Object.hasOwnProperty.call(message, "symbol")
)
writer.uint32(/* id 2, wireType 2 =*/ 18).string(message.symbol);
if (
message.ticker != null &&
Object.hasOwnProperty.call(message, "ticker")
)
writer.uint32(/* id 3, wireType 2 =*/ 26).string(message.ticker);
if (message.synth != null && Object.hasOwnProperty.call(message, "synth"))
writer.uint32(/* id 4, wireType 0 =*/ 32).bool(message.synth);
return writer;
};
/**
* Encodes the specified Asset message, length delimited. Does not implicitly {@link common.Asset.verify|verify} messages.
* @function encodeDelimited
* @memberof common.Asset
* @static
* @param {common.IAsset} message Asset message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Asset.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes an Asset message from the specified reader or buffer.
* @function decode
* @memberof common.Asset
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.Asset} Asset
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Asset.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.common.Asset();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
message.chain = reader.string();
break;
}
case 2: {
message.symbol = reader.string();
break;
}
case 3: {
message.ticker = reader.string();
break;
}
case 4: {
message.synth = reader.bool();
break;
}
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes an Asset message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.Asset
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.Asset} Asset
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Asset.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies an Asset message.
* @function verify
* @memberof common.Asset
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Asset.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.chain != null && message.hasOwnProperty("chain"))
if (!$util.isString(message.chain)) return "chain: string expected";
if (message.symbol != null && message.hasOwnProperty("symbol"))
if (!$util.isString(message.symbol)) return "symbol: string expected";
if (message.ticker != null && message.hasOwnProperty("ticker"))
if (!$util.isString(message.ticker)) return "ticker: string expected";
if (message.synth != null && message.hasOwnProperty("synth"))
if (typeof message.synth !== "boolean")
return "synth: boolean expected";
return null;
};
/**
* Creates an Asset message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.Asset
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.Asset} Asset
*/
Asset.fromObject = function fromObject(object) {
if (object instanceof $root.common.Asset) return object;
var message = new $root.common.Asset();
if (object.chain != null) message.chain = String(object.chain);
if (object.symbol != null) message.symbol = String(object.symbol);
if (object.ticker != null) message.ticker = String(object.ticker);
if (object.synth != null) message.synth = Boolean(object.synth);
return message;
};
/**
* Creates a plain object from an Asset message. Also converts values to other types if specified.
* @function toObject
* @memberof common.Asset
* @static
* @param {common.Asset} message Asset
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Asset.toObject = function toObject(message, options) {
if (!options) options = {};
var object = {};
if (options.defaults) {
object.chain = "";
object.symbol = "";
object.ticker = "";
object.synth = false;
}
if (message.chain != null && message.hasOwnProperty("chain"))
object.chain = message.chain;
if (message.symbol != null && message.hasOwnProperty("symbol"))
object.symbol = message.symbol;
if (message.ticker != null && message.hasOwnProperty("ticker"))
object.ticker = message.ticker;
if (message.synth != null && message.hasOwnProperty("synth"))
object.synth = message.synth;
return object;
};
/**
* Converts this Asset to JSON.
* @function toJSON
* @memberof common.Asset
* @instance
* @returns {Object.<string,*>} JSON object
*/
Asset.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
/**
* Gets the default type url for Asset
* @function getTypeUrl
* @memberof common.Asset
* @static
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns {string} The default type url
*/
Asset.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
if (typeUrlPrefix === undefined) {
typeUrlPrefix = "type.googleapis.com";
}
return typeUrlPrefix + "/common.Asset";
};
return Asset;
})();
common.Coin = (function () {
/**
* Properties of a Coin.
* @memberof common
* @interface ICoin
* @property {common.IAsset|null} [asset] Coin asset
* @property {string|null} [amount] Coin amount
* @property {number|Long|null} [decimals] Coin decimals
*/
/**
* Constructs a new Coin.
* @memberof common
* @classdesc Represents a Coin.
* @implements ICoin
* @constructor
* @param {common.ICoin=} [properties] Properties to set
*/
function Coin(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]];
}
/**
* Coin asset.
* @member {common.IAsset|null|undefined} asset
* @memberof common.Coin
* @instance
*/
Coin.prototype.asset = null;
/**
* Coin amount.
* @member {string} amount
* @memberof common.Coin
* @instance
*/
Coin.prototype.amount = "";
/**
* Coin decimals.
* @member {number|Long} decimals
* @memberof common.Coin
* @instance
*/
Coin.prototype.decimals = $util.Long ? $util.Long.fromBits(0, 0, false) : 0;
/**
* Creates a new Coin instance using the specified properties.
* @function create
* @memberof common.Coin
* @static
* @param {common.ICoin=} [properties] Properties to set
* @returns {common.Coin} Coin instance
*/
Coin.create = function create(properties) {
return new Coin(properties);
};
/**
* Encodes the specified Coin message. Does not implicitly {@link common.Coin.verify|verify} messages.
* @function encode
* @memberof common.Coin
* @static
* @param {common.ICoin} message Coin message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Coin.encode = function encode(message, writer) {
if (!writer) writer = $Writer.create();
if (message.asset != null && Object.hasOwnProperty.call(message, "asset"))
$root.common.Asset.encode(
message.asset,
writer.uint32(/* id 1, wireType 2 =*/ 10).fork()
).ldelim();
if (
message.amount != null &&
Object.hasOwnProperty.call(message, "amount")
)
writer.uint32(/* id 2, wireType 2 =*/ 18).string(message.amount);
if (
message.decimals != null &&
Object.hasOwnProperty.call(message, "decimals")
)
writer.uint32(/* id 3, wireType 0 =*/ 24).int64(message.decimals);
return writer;
};
/**
* Encodes the specified Coin message, length delimited. Does not implicitly {@link common.Coin.verify|verify} messages.
* @function encodeDelimited
* @memberof common.Coin
* @static
* @param {common.ICoin} message Coin message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Coin.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a Coin message from the specified reader or buffer.
* @function decode
* @memberof common.Coin
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.Coin} Coin
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Coin.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.common.Coin();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
message.asset = $root.common.Asset.decode(reader, reader.uint32());
break;
}
case 2: {
message.amount = reader.string();
break;
}
case 3: {
message.decimals = reader.int64();
break;
}
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a Coin message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.Coin
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.Coin} Coin
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Coin.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a Coin message.
* @function verify
* @memberof common.Coin
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Coin.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.asset != null && message.hasOwnProperty("asset")) {
var error = $root.common.Asset.verify(message.asset);
if (error) return "asset." + error;
}
if (message.amount != null && message.hasOwnProperty("amount"))
if (!$util.isString(message.amount)) return "amount: string expected";
if (message.decimals != null && message.hasOwnProperty("decimals"))
if (
!$util.isInteger(message.decimals) &&
!(
message.decimals &&
$util.isInteger(message.decimals.low) &&
$util.isInteger(message.decimals.high)
)
)
return "decimals: integer|Long expected";
return null;
};
/**
* Creates a Coin message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.Coin
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.Coin} Coin
*/
Coin.fromObject = function fromObject(object) {
if (object instanceof $root.common.Coin) return object;
var message = new $root.common.Coin();
if (object.asset != null) {
if (typeof object.asset !== "object")
throw TypeError(".common.Coin.asset: object expected");
message.asset = $root.common.Asset.fromObject(object.asset);
}
if (object.amount != null) message.amount = String(object.amount);
if (object.decimals != null)
if ($util.Long)
(message.decimals = $util.Long.fromValue(
object.decimals
)).unsigned = false;
else if (typeof object.decimals === "string")
message.decimals = parseInt(object.decimals, 10);
else if (typeof object.decimals === "number")
message.decimals = object.decimals;
else if (typeof object.decimals === "object")
message.decimals = new $util.LongBits(
object.decimals.low >>> 0,
object.decimals.high >>> 0
).toNumber();
return message;
};
/**
* Creates a plain object from a Coin message. Also converts values to other types if specified.
* @function toObject
* @memberof common.Coin
* @static
* @param {common.Coin} message Coin
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Coin.toObject = function toObject(message, options) {
if (!options) options = {};
var object = {};
if (options.defaults) {
object.asset = null;
object.amount = "";
if ($util.Long) {
var long = new $util.Long(0, 0, false);
object.decimals =
options.longs === String
? long.toString()
: options.longs === Number
? long.toNumber()
: long;
} else object.decimals = options.longs === String ? "0" : 0;
}
if (message.asset != null && message.hasOwnProperty("asset"))
object.asset = $root.common.Asset.toObject(message.asset, options);
if (message.amount != null && message.hasOwnProperty("amount"))
object.amount = message.amount;
if (message.decimals != null && message.hasOwnProperty("decimals"))
if (typeof message.decimals === "number")
object.decimals =
options.longs === String
? String(message.decimals)
: message.decimals;
else
object.decimals =
options.longs === String
? $util.Long.prototype.toString.call(message.decimals)
: options.longs === Number
? new $util.LongBits(
message.decimals.low >>> 0,
message.decimals.high >>> 0
).toNumber()
: message.decimals;
return object;
};
/**
* Converts this Coin to JSON.
* @function toJSON
* @memberof common.Coin
* @instance
* @returns {Object.<string,*>} JSON object
*/
Coin.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
/**
* Gets the default type url for Coin
* @function getTypeUrl
* @memberof common.Coin
* @static
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns {string} The default type url
*/
Coin.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
if (typeUrlPrefix === undefined) {
typeUrlPrefix = "type.googleapis.com";
}
return typeUrlPrefix + "/common.Coin";
};
return Coin;
})();
common.PubKeySet = (function () {
/**
* Properties of a PubKeySet.
* @memberof common
* @interface IPubKeySet
* @property {string|null} [secp256k1] PubKeySet secp256k1
* @property {string|null} [ed25519] PubKeySet ed25519
*/
/**
* Constructs a new PubKeySet.
* @memberof common
* @classdesc Represents a PubKeySet.
* @implements IPubKeySet
* @constructor
* @param {common.IPubKeySet=} [properties] Properties to set
*/
function PubKeySet(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]];
}
/**
* PubKeySet secp256k1.
* @member {string} secp256k1
* @memberof common.PubKeySet
* @instance
*/
PubKeySet.prototype.secp256k1 = "";
/**
* PubKeySet ed25519.
* @member {string} ed25519
* @memberof common.PubKeySet
* @instance
*/
PubKeySet.prototype.ed25519 = "";
/**
* Creates a new PubKeySet instance using the specified properties.
* @function create
* @memberof common.PubKeySet
* @static
* @param {common.IPubKeySet=} [properties] Properties to set
* @returns {common.PubKeySet} PubKeySet instance
*/
PubKeySet.create = function create(properties) {
return new PubKeySet(properties);
};
/**
* Encodes the specified PubKeySet message. Does not implicitly {@link common.PubKeySet.verify|verify} messages.
* @function encode
* @memberof common.PubKeySet
* @static
* @param {common.IPubKeySet} message PubKeySet message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
PubKeySet.encode = function encode(message, writer) {
if (!writer) writer = $Writer.create();
if (
message.secp256k1 != null &&
Object.hasOwnProperty.call(message, "secp256k1")
)
writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.secp256k1);
if (
message.ed25519 != null &&
Object.hasOwnProperty.call(message, "ed25519")
)
writer.uint32(/* id 2, wireType 2 =*/ 18).string(message.ed25519);
return writer;
};
/**
* Encodes the specified PubKeySet message, length delimited. Does not implicitly {@link common.PubKeySet.verify|verify} messages.
* @function encodeDelimited
* @memberof common.PubKeySet
* @static
* @param {common.IPubKeySet} message PubKeySet message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
PubKeySet.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a PubKeySet message from the specified reader or buffer.
* @function decode
* @memberof common.PubKeySet
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.PubKeySet} PubKeySet
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
PubKeySet.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.common.PubKeySet();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
message.secp256k1 = reader.string();
break;
}
case 2: {
message.ed25519 = reader.string();
break;
}
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a PubKeySet message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.PubKeySet
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.PubKeySet} PubKeySet
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
PubKeySet.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a PubKeySet message.
* @function verify
* @memberof common.PubKeySet
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
PubKeySet.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.secp256k1 != null && message.hasOwnProperty("secp256k1"))
if (!$util.isString(message.secp256k1))
return "secp256k1: string expected";
if (message.ed25519 != null && message.hasOwnProperty("ed25519"))
if (!$util.isString(message.ed25519)) return "ed25519: string expected";
return null;
};
/**
* Creates a PubKeySet message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.PubKeySet
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.PubKeySet} PubKeySet
*/
PubKeySet.fromObject = function fromObject(object) {
if (object instanceof $root.common.PubKeySet) return object;
var message = new $root.common.PubKeySet();
if (object.secp256k1 != null)
message.secp256k1 = String(object.secp256k1);
if (object.ed25519 != null) message.ed25519 = String(object.ed25519);
return message;
};
/**
* Creates a plain object from a PubKeySet message. Also converts values to other types if specified.
* @function toObject
* @memberof common.PubKeySet
* @static
* @param {common.PubKeySet} message PubKeySet
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
PubKeySet.toObject = function toObject(message, options) {
if (!options) options = {};
var object = {};
if (options.defaults) {
object.secp256k1 = "";
object.ed25519 = "";
}
if (message.secp256k1 != null && message.hasOwnProperty("secp256k1"))
object.secp256k1 = message.secp256k1;
if (message.ed25519 != null && message.hasOwnProperty("ed25519"))
object.ed25519 = message.ed25519;
return object;
};
/**
* Converts this PubKeySet to JSON.
* @function toJSON
* @memberof common.PubKeySet
* @instance
* @returns {Object.<string,*>} JSON object
*/
PubKeySet.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
/**
* Gets the default type url for PubKeySet
* @function getTypeUrl
* @memberof common.PubKeySet
* @static
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns {string} The default type url
*/
PubKeySet.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
if (typeUrlPrefix === undefined) {
typeUrlPrefix = "type.googleapis.com";
}
return typeUrlPrefix + "/common.PubKeySet";
};
return PubKeySet;
})();
common.Tx = (function () {
/**
* Properties of a Tx.
* @memberof common
* @interface ITx
* @property {string|null} [id] Tx id
* @property {string|null} [chain] Tx chain
* @property {string|null} [fromAddress] Tx fromAddress
* @property {string|null} [toAddress] Tx toAddress
* @property {Array.<common.ICoin>|null} [coins] Tx coins
* @property {Array.<common.ICoin>|null} [gas] Tx gas
* @property {string|null} [memo] Tx memo
* @property {Uint8Array|null} [payload] Tx payload
* @property {boolean|null} [isXcMsg] Tx isXcMsg
*/
/**
* Constructs a new Tx.
* @memberof common
* @classdesc Represents a Tx.
* @implements ITx
* @constructor
* @param {common.ITx=} [properties] Properties to set
*/
function Tx(properties) {
this.coins = [];
this.gas = [];
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]];
}
/**
* Tx id.
* @member {string} id
* @memberof common.Tx
* @instance
*/
Tx.prototype.id = "";
/**
* Tx chain.
* @member {string} chain
* @memberof common.Tx
* @instance
*/
Tx.prototype.chain = "";
/**
* Tx fromAddress.
* @member {string} fromAddress
* @memberof common.Tx
* @instance
*/
Tx.prototype.fromAddress = "";
/**
* Tx toAddress.
* @member {string} toAddress
* @memberof common.Tx
* @instance
*/
Tx.prototype.toAddress = "";
/**
* Tx coins.
* @member {Array.<common.ICoin>} coins
* @memberof common.Tx
* @instance
*/
Tx.prototype.coins = $util.emptyArray;
/**
* Tx gas.
* @member {Array.<common.ICoin>} gas
* @memberof common.Tx
* @instance
*/
Tx.prototype.gas = $util.emptyArray;
/**
* Tx memo.
* @member {string} memo
* @memberof common.Tx
* @instance
*/
Tx.prototype.memo = "";
/**
* Tx payload.
* @member {Uint8Array} payload
* @memberof common.Tx
* @instance
*/
Tx.prototype.payload = $util.newBuffer([]);
/**
* Tx isXcMsg.
* @member {boolean} isXcMsg
* @memberof common.Tx
* @instance
*/
Tx.prototype.isXcMsg = false;
/**
* Creates a new Tx instance using the specified properties.
* @function create
* @memberof common.Tx
* @static
* @param {common.ITx=} [properties] Properties to set
* @returns {common.Tx} Tx instance
*/
Tx.create = function create(properties) {
return new Tx(properties);
};
/**
* Encodes the specified Tx message. Does not implicitly {@link common.Tx.verify|verify} messages.
* @function encode
* @memberof common.Tx
* @static
* @param {common.ITx} message Tx message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Tx.encode = function encode(message, writer) {
if (!writer) writer = $Writer.create();
if (message.id != null && Object.hasOwnProperty.call(message, "id"))
writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.id);
if (message.chain != null && Object.hasOwnProperty.call(message, "chain"))
writer.uint32(/* id 2, wireType 2 =*/ 18).string(message.chain);
if (
message.fromAddress != null &&
Object.hasOwnProperty.call(message, "fromAddress")
)
writer.uint32(/* id 3, wireType 2 =*/ 26).string(message.fromAddress);
if (
message.toAddress != null &&
Object.hasOwnProperty.call(message, "toAddress")
)
writer.uint32(/* id 4, wireType 2 =*/ 34).string(message.toAddress);
if (message.coins != null && message.coins.length)
for (var i = 0; i < message.coins.length; ++i)
$root.common.Coin.encode(
message.coins[i],
writer.uint32(/* id 5, wireType 2 =*/ 42).fork()
).ldelim();
if (message.gas != null && message.gas.length)
for (var i = 0; i < message.gas.length; ++i)
$root.common.Coin.encode(
message.gas[i],
writer.uint32(/* id 6, wireType 2 =*/ 50).fork()
).ldelim();
if (message.memo != null && Object.hasOwnProperty.call(message, "memo"))
writer.uint32(/* id 7, wireType 2 =*/ 58).string(message.memo);
if (
message.payload != null &&
Object.hasOwnProperty.call(message, "payload")
)
writer.uint32(/* id 8, wireType 2 =*/ 66).bytes(message.payload);
if (
message.isXcMsg != null &&
Object.hasOwnProperty.call(message, "isXcMsg")
)
writer.uint32(/* id 9, wireType 0 =*/ 72).bool(message.isXcMsg);
return writer;
};
/**
* Encodes the specified Tx message, length delimited. Does not implicitly {@link common.Tx.verify|verify} messages.
* @function encodeDelimited
* @memberof common.Tx
* @static
* @param {common.ITx} message Tx message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Tx.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a Tx message from the specified reader or buffer.
* @function decode
* @memberof common.Tx
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.Tx} Tx
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Tx.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.common.Tx();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
message.id = reader.string();
break;
}
case 2: {
message.chain = reader.string();
break;
}
case 3: {
message.fromAddress = reader.string();
break;
}
case 4: {
message.toAddress = reader.string();
break;
}
case 5: {
if (!(message.coins && message.coins.length)) message.coins = [];
message.coins.push(
$root.common.Coin.decode(reader, reader.uint32())
);
break;
}
case 6: {
if (!(message.gas && message.gas.length)) message.gas = [];
message.gas.push($root.common.Coin.decode(reader, reader.uint32()));
break;
}
case 7: {
message.memo = reader.string();
break;
}
case 8: {
message.payload = reader.bytes();
break;
}
case 9: {
message.isXcMsg = reader.bool();
break;
}
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a Tx message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.Tx
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.Tx} Tx
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Tx.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a Tx message.
* @function verify
* @memberof common.Tx
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Tx.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.id != null && message.hasOwnProperty("id"))
if (!$util.isString(message.id)) return "id: string expected";
if (message.chain != null && message.hasOwnProperty("chain"))
if (!$util.isString(message.chain)) return "chain: string expected";
if (message.fromAddress != null && message.hasOwnProperty("fromAddress"))
if (!$util.isString(message.fromAddress))
return "fromAddress: string expected";
if (message.toAddress != null && message.hasOwnProperty("toAddress"))
if (!$util.isString(message.toAddress))
return "toAddress: string expected";
if (message.coins != null && message.hasOwnProperty("coins")) {
if (!Array.isArray(message.coins)) return "coins: array expected";
for (var i = 0; i < message.coins.length; ++i) {
var error = $root.common.Coin.verify(message.coins[i]);
if (error) return "coins." + error;
}
}
if (message.gas != null && message.hasOwnProperty("gas")) {
if (!Array.isArray(message.gas)) return "gas: array expected";
for (var i = 0; i < message.gas.length; ++i) {
var error = $root.common.Coin.verify(message.gas[i]);
if (error) return "gas." + error;
}
}
if (message.memo != null && message.hasOwnProperty("memo"))
if (!$util.isString(message.memo)) return "memo: string expected";
if (message.payload != null && message.hasOwnProperty("payload"))
if (
!(
(message.payload && typeof message.payload.length === "number") ||
$util.isString(message.payload)
)
)
return "payload: buffer expected";
if (message.isXcMsg != null && message.hasOwnProperty("isXcMsg"))
if (typeof message.isXcMsg !== "boolean")
return "isXcMsg: boolean expected";
return null;
};
/**
* Creates a Tx message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.Tx
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.Tx} Tx
*/
Tx.fromObject = function fromObject(object) {
if (object instanceof $root.common.Tx) return object;
var message = new $root.common.Tx();
if (object.id != null) message.id = String(object.id);
if (object.chain != null) message.chain = String(object.chain);
if (object.fromAddress != null)
message.fromAddress = String(object.fromAddress);
if (object.toAddress != null)
message.toAddress = String(object.toAddress);
if (object.coins) {
if (!Array.isArray(object.coins))
throw TypeError(".common.Tx.coins: array expected");
message.coins = [];
for (var i = 0; i < object.coins.length; ++i) {
if (typeof object.coins[i] !== "object")
throw TypeError(".common.Tx.coins: object expected");
message.coins[i] = $root.common.Coin.fromObject(object.coins[i]);
}
}
if (object.gas) {
if (!Array.isArray(object.gas))
throw TypeError(".common.Tx.gas: array expected");
message.gas = [];
for (var i = 0; i < object.gas.length; ++i) {
if (typeof object.gas[i] !== "object")
throw TypeError(".common.Tx.gas: object expected");
message.gas[i] = $root.common.Coin.fromObject(object.gas[i]);
}
}
if (object.memo != null) message.memo = String(object.memo);
if (object.payload != null)
if (typeof object.payload === "string")
$util.base64.decode(
object.payload,
(message.payload = $util.newBuffer(
$util.base64.length(object.payload)
)),
0
);
else if (object.payload.length >= 0) message.payload = object.payload;
if (object.isXcMsg != null) message.isXcMsg = Boolean(object.isXcMsg);
return message;
};
/**
* Creates a plain object from a Tx message. Also converts values to other types if specified.
* @function toObject
* @memberof common.Tx
* @static
* @param {common.Tx} message Tx
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
Tx.toObject = function toObject(message, options) {
if (!options) options = {};
var object = {};
if (options.arrays || options.defaults) {
object.coins = [];
object.gas = [];
}
if (options.defaults) {
object.id = "";
object.chain = "";
object.fromAddress = "";
object.toAddress = "";
object.memo = "";
if (options.bytes === String) object.payload = "";
else {
object.payload = [];
if (options.bytes !== Array)
object.payload = $util.newBuffer(object.payload);
}
object.isXcMsg = false;
}
if (message.id != null && message.hasOwnProperty("id"))
object.id = message.id;
if (message.chain != null && message.hasOwnProperty("chain"))
object.chain = message.chain;
if (message.fromAddress != null && message.hasOwnProperty("fromAddress"))
object.fromAddress = message.fromAddress;
if (message.toAddress != null && message.hasOwnProperty("toAddress"))
object.toAddress = message.toAddress;
if (message.coins && message.coins.length) {
object.coins = [];
for (var j = 0; j < message.coins.length; ++j)
object.coins[j] = $root.common.Coin.toObject(
message.coins[j],
options
);
}
if (message.gas && message.gas.length) {
object.gas = [];
for (var j = 0; j < message.gas.length; ++j)
object.gas[j] = $root.common.Coin.toObject(message.gas[j], options);
}
if (message.memo != null && message.hasOwnProperty("memo"))
object.memo = message.memo;
if (message.payload != null && message.hasOwnProperty("payload"))
object.payload =
options.bytes === String
? $util.base64.encode(message.payload, 0, message.payload.length)
: options.bytes === Array
? Array.prototype.slice.call(message.payload)
: message.payload;
if (message.isXcMsg != null && message.hasOwnProperty("isXcMsg"))
object.isXcMsg = message.isXcMsg;
return object;
};
/**
* Converts this Tx to JSON.
* @function toJSON
* @memberof common.Tx
* @instance
* @returns {Object.<string,*>} JSON object
*/
Tx.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
/**
* Gets the default type url for Tx
* @function getTypeUrl
* @memberof common.Tx
* @static
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns {string} The default type url
*/
Tx.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
if (typeUrlPrefix === undefined) {
typeUrlPrefix = "type.googleapis.com";
}
return typeUrlPrefix + "/common.Tx";
};
return Tx;
})();
common.Fee = (function () {
/**
* Properties of a Fee.
* @memberof common
* @interface IFee
* @property {Array.<common.ICoin>|null} [coins] Fee coins
* @property {string|null} [poolDeduct] Fee poolDeduct
*/
/**
* Constructs a new Fee.
* @memberof common
* @classdesc Represents a Fee.
* @implements IFee
* @constructor
* @param {common.IFee=} [properties] Properties to set
*/
function Fee(properties) {
this.coins = [];
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]];
}
/**
* Fee coins.
* @member {Array.<common.ICoin>} coins
* @memberof common.Fee
* @instance
*/
Fee.prototype.coins = $util.emptyArray;
/**
* Fee poolDeduct.
* @member {string} poolDeduct
* @memberof common.Fee
* @instance
*/
Fee.prototype.poolDeduct = "";
/**
* Creates a new Fee instance using the specified properties.
* @function create
* @memberof common.Fee
* @static
* @param {common.IFee=} [properties] Properties to set
* @returns {common.Fee} Fee instance
*/
Fee.create = function create(properties) {
return new Fee(properties);
};
/**
* Encodes the specified Fee message. Does not implicitly {@link common.Fee.verify|verify} messages.
* @function encode
* @memberof common.Fee
* @static
* @param {common.IFee} message Fee message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Fee.encode = function encode(message, writer) {
if (!writer) writer = $Writer.create();
if (message.coins != null && message.coins.length)
for (var i = 0; i < message.coins.length; ++i)
$root.common.Coin.encode(
message.coins[i],
writer.uint32(/* id 1, wireType 2 =*/ 10).fork()
).ldelim();
if (
message.poolDeduct != null &&
Object.hasOwnProperty.call(message, "poolDeduct")
)
writer.uint32(/* id 2, wireType 2 =*/ 18).string(message.poolDeduct);
return writer;
};
/**
* Encodes the specified Fee message, length delimited. Does not implicitly {@link common.Fee.verify|verify} messages.
* @function encodeDelimited
* @memberof common.Fee
* @static
* @param {common.IFee} message Fee message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Fee.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a Fee message from the specified reader or buffer.
* @function decode
* @memberof common.Fee
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {common.Fee} Fee
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Fee.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.common.Fee();
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (!(message.coins && message.coins.length)) message.coins = [];
message.coins.push(
$root.common.Coin.decode(reader, reader.uint32())
);
break;
}
case 2: {
message.poolDeduct = reader.string();
break;
}
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a Fee message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof common.Fee
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {common.Fee} Fee
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
Fee.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a Fee message.
* @function verify
* @memberof common.Fee
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Fee.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.coins != null && message.hasOwnProperty("coins")) {
if (!Array.isArray(message.coins)) return "coins: array expected";
for (var i = 0; i < message.coins.length; ++i) {
var error = $root.common.Coin.verify(message.coins[i]);
if (error) return "coins." + error;
}
}
if (message.poolDeduct != null && message.hasOwnProperty("poolDeduct"))
if (!$util.isString(message.poolDeduct))
return "poolDeduct: string expected";
return null;
};
/**
* Creates a Fee message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof common.Fee
* @static
* @param {Object.<string,*>} object Plain object
* @returns {common.Fee} Fee
*/
Fee.fromObject = function fromObject(object) {
if (object instanceof $root.common.Fee) return object;
var message = new $root.common.Fee();
if (object.coins) {
if (!Array.isArray(object.coins))
throw TypeError(".common.Fee.coins: array expected");
message.coins = [];
for (var i = 0; i < object.coins.length; ++i) {
if (typeof object.coins[i] !== "object")
throw TypeError(".common.Fee.