diff --git a/dist/generated/qrcode_data_pb.js b/dist/generated/qrcode_data_pb.js index 381181455cd978bc7d6626f095f86807d9c2cf14..ec425f7ca7b9225db5461cc16560dfe25467572d 100644 --- a/dist/generated/qrcode_data_pb.js +++ b/dist/generated/qrcode_data_pb.js @@ -760,9 +760,10 @@ $root.vereign = (function () { * Properties of an IpfsContentData_V1. * @memberof vereign.protobuf.qrcode_data * @interface IIpfsContentData_V1 - * @property {string|null} [cid] IpfsContentData_V1 cid - * @property {string|null} [key] IpfsContentData_V1 key * @property {string|null} [head] IpfsContentData_V1 head + * @property {string|null} [key] IpfsContentData_V1 key + * @property {string|null} [cid] IpfsContentData_V1 cid + * @property {string|null} [ipnsKeyId] IpfsContentData_V1 ipnsKeyId */ /** * Constructs a new IpfsContentData_V1. @@ -779,12 +780,12 @@ $root.vereign = (function () { this[keys[i]] = properties[keys[i]]; } /** - * IpfsContentData_V1 cid. - * @member {string} cid + * IpfsContentData_V1 head. + * @member {string} head * @memberof vereign.protobuf.qrcode_data.IpfsContentData_V1 * @instance */ - IpfsContentData_V1.prototype.cid = ""; + IpfsContentData_V1.prototype.head = ""; /** * IpfsContentData_V1 key. * @member {string} key @@ -793,12 +794,19 @@ $root.vereign = (function () { */ IpfsContentData_V1.prototype.key = ""; /** - * IpfsContentData_V1 head. - * @member {string} head + * IpfsContentData_V1 cid. + * @member {string} cid * @memberof vereign.protobuf.qrcode_data.IpfsContentData_V1 * @instance */ - IpfsContentData_V1.prototype.head = ""; + IpfsContentData_V1.prototype.cid = ""; + /** + * IpfsContentData_V1 ipnsKeyId. + * @member {string} ipnsKeyId + * @memberof vereign.protobuf.qrcode_data.IpfsContentData_V1 + * @instance + */ + IpfsContentData_V1.prototype.ipnsKeyId = ""; /** * Creates a new IpfsContentData_V1 instance using the specified properties. * @function create @@ -822,12 +830,14 @@ $root.vereign = (function () { IpfsContentData_V1.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.cid != null && Object.hasOwnProperty.call(message, "cid")) - writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.cid); + if (message.head != null && Object.hasOwnProperty.call(message, "head")) + writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.head); if (message.key != null && Object.hasOwnProperty.call(message, "key")) writer.uint32(/* id 2, wireType 2 =*/ 18).string(message.key); - if (message.head != null && Object.hasOwnProperty.call(message, "head")) - writer.uint32(/* id 3, wireType 2 =*/ 26).string(message.head); + if (message.cid != null && Object.hasOwnProperty.call(message, "cid")) + writer.uint32(/* id 3, wireType 2 =*/ 26).string(message.cid); + if (message.ipnsKeyId != null && Object.hasOwnProperty.call(message, "ipnsKeyId")) + writer.uint32(/* id 4, wireType 2 =*/ 34).string(message.ipnsKeyId); return writer; }; /** @@ -861,13 +871,16 @@ $root.vereign = (function () { var tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.cid = reader.string(); + message.head = reader.string(); break; case 2: message.key = reader.string(); break; case 3: - message.head = reader.string(); + message.cid = reader.string(); + break; + case 4: + message.ipnsKeyId = reader.string(); break; default: reader.skipType(tag & 7); @@ -902,15 +915,18 @@ $root.vereign = (function () { IpfsContentData_V1.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; - if (message.cid != null && message.hasOwnProperty("cid")) - if (!$util.isString(message.cid)) - return "cid: string expected"; - if (message.key != null && message.hasOwnProperty("key")) - if (!$util.isString(message.key)) - return "key: string expected"; if (message.head != null && message.hasOwnProperty("head")) if (!$util.isString(message.head)) return "head: string expected"; + if (message.key != null && message.hasOwnProperty("key")) + if (!$util.isString(message.key)) + return "key: string expected"; + if (message.cid != null && message.hasOwnProperty("cid")) + if (!$util.isString(message.cid)) + return "cid: string expected"; + if (message.ipnsKeyId != null && message.hasOwnProperty("ipnsKeyId")) + if (!$util.isString(message.ipnsKeyId)) + return "ipnsKeyId: string expected"; return null; }; /** @@ -925,12 +941,14 @@ $root.vereign = (function () { if (object instanceof $root.vereign.protobuf.qrcode_data.IpfsContentData_V1) return object; var message = new $root.vereign.protobuf.qrcode_data.IpfsContentData_V1(); - if (object.cid != null) - message.cid = String(object.cid); - if (object.key != null) - message.key = String(object.key); if (object.head != null) message.head = String(object.head); + if (object.key != null) + message.key = String(object.key); + if (object.cid != null) + message.cid = String(object.cid); + if (object.ipnsKeyId != null) + message.ipnsKeyId = String(object.ipnsKeyId); return message; }; /** @@ -947,16 +965,19 @@ $root.vereign = (function () { options = {}; var object = {}; if (options.defaults) { - object.cid = ""; - object.key = ""; object.head = ""; + object.key = ""; + object.cid = ""; + object.ipnsKeyId = ""; } - if (message.cid != null && message.hasOwnProperty("cid")) - object.cid = message.cid; - if (message.key != null && message.hasOwnProperty("key")) - object.key = message.key; if (message.head != null && message.hasOwnProperty("head")) object.head = message.head; + if (message.key != null && message.hasOwnProperty("key")) + object.key = message.key; + if (message.cid != null && message.hasOwnProperty("cid")) + object.cid = message.cid; + if (message.ipnsKeyId != null && message.hasOwnProperty("ipnsKeyId")) + object.ipnsKeyId = message.ipnsKeyId; return object; }; /** diff --git a/dist/services/AeternityService/AeternityService.d.ts b/dist/services/AeternityService/AeternityService.d.ts index 25dfedce056d947df3f3b81bb53a4868e3182da8..d4ba4a5f13da8d1b17e7c1dbad06f8e0f247defd 100644 --- a/dist/services/AeternityService/AeternityService.d.ts +++ b/dist/services/AeternityService/AeternityService.d.ts @@ -1,13 +1,15 @@ import { TxData, DecodedCallData } from "../../types"; import { Request } from "../../utils/requestAdapter"; +import { AeternityAPIBlockData } from "./types"; declare class AeternityService { readonly _nodeUrls: any[]; readonly _compilerUrls: any[]; readonly _contractBytecode: string; + readonly _blockHeightStep: number; requestWrapper: Request; readonly requestNode: Request; readonly requestCompiler: Request; - constructor(nodeUrls: string[] | string, compilerUrls: string[] | string, contractBytecode: string); + constructor(nodeUrls: string[] | string, compilerUrls: string[] | string, contractBytecode: string, blockHeightStep?: number); /** * Function provides retry mechanism if node from the array is failing to respond * @param apiUrls @@ -26,5 +28,6 @@ declare class AeternityService { hash: string; }>; getBlockchainHeight(): Promise<number>; + getBlockHeightRange(startingBlock: number): Promise<Array<AeternityAPIBlockData>>; } export default AeternityService; diff --git a/dist/services/AeternityService/AeternityService.js b/dist/services/AeternityService/AeternityService.js index 898caa877020eef43542b7ed29773b9180d9ccd3..c10616122863cd87e2ad7a25e549ed69d0427d71 100644 --- a/dist/services/AeternityService/AeternityService.js +++ b/dist/services/AeternityService/AeternityService.js @@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const requestAdapter_1 = __importDefault(require("../../utils/requestAdapter")); class AeternityService { - constructor(nodeUrls, compilerUrls, contractBytecode) { + constructor(nodeUrls, compilerUrls, contractBytecode, blockHeightStep) { this._nodeUrls = []; this._compilerUrls = []; this._contractBytecode = ""; @@ -65,6 +65,8 @@ class AeternityService { if (!contractBytecode) { throw new Error("Aeternity contract bytecode not defined"); } + //Default value for block height step is 2, based on tests + this._blockHeightStep = typeof blockHeightStep === "number" ? blockHeightStep : 2; this._nodeUrls = typeof nodeUrls === "string" ? [nodeUrls] : nodeUrls; this._compilerUrls = typeof compilerUrls === "string" ? [compilerUrls] : compilerUrls; @@ -139,5 +141,13 @@ class AeternityService { return data.height; }); } + getBlockHeightRange(startingBlock) { + return __awaiter(this, void 0, void 0, function* () { + const endBlockHeight = startingBlock + this._blockHeightStep; + const { data } = yield this.requestNode({ url: `/mdw/v2/blocks?scope=gen${startingBlock}-${endBlockHeight}` }) + .then(({ data }) => data); + return data; + }); + } } exports.default = AeternityService; diff --git a/dist/services/AeternityService/types.d.ts b/dist/services/AeternityService/types.d.ts index 5774a08efbc4925818b96cb6b04e5e0e78f83698..4e618642ed4b961cd1a1aeb1f077cc9ba85bf5af 100644 --- a/dist/services/AeternityService/types.d.ts +++ b/dist/services/AeternityService/types.d.ts @@ -1,15 +1,50 @@ export interface AeternityAPITxData { + "block_hash": string; + "block_height": number; + "hash": string; + "signatures": Array<string>; + "tx": { + "abi_version": number; + "amount": number; + "call_data": string; + "caller_id": string; + "contract_id": string; + "fee": number; + "gas": number; + "gas_price": number; + "nonce": number; + "type": string; + "version": number; + }; +} +export interface AeternityAPIMicroBLock { hash: string; - block_height: number; - block_hash: string; - tx: { - call_data: string; + height: number; + pof_hash: string; + prev_hash: string; + prev_key_hash: string; + signature: string; + state_hash: string; + time: number; + transactions: { + [key: string]: AeternityAPITxData; }; } export interface AeternityAPIBlockData { + beneficiary: string; + hash: string; height: number; + info: string; + microBlock: Array<AeternityAPIMicroBLock>; + miner: string; + nonce: number; + pow: Array<number>; + prev_hash: string; + prev_key_hash: string; + state_hash: string; + target: number; time: number; - hash: string; + version: number; } export interface AeternityAPICurrentHeight { height: number; @@ -30,3 +65,6 @@ export interface AeternityAPIContractData { } ]; } +export interface AeternityAPIBlockRange { + data: Array<AeternityAPIBlockData>; +} diff --git a/src/services/AeternityService/AeternityService.ts b/src/services/AeternityService/AeternityService.ts index d9fae929170ff253544bd5647bcdf275b39a7e52..2d9ef1aad269779e68be4da1824331ed04f53e0c 100644 --- a/src/services/AeternityService/AeternityService.ts +++ b/src/services/AeternityService/AeternityService.ts @@ -5,12 +5,14 @@ import { AeternityAPICurrentHeight, AeternityAPIContractData, AeternityAPITxData, + AeternityAPIBlockRange, } from "./types"; class AeternityService { readonly _nodeUrls = []; readonly _compilerUrls = []; readonly _contractBytecode: string = ""; + readonly _blockHeightStep: number; public requestWrapper: Request = defaultRequest; @@ -20,7 +22,8 @@ class AeternityService { constructor( nodeUrls: string[] | string, compilerUrls: string[] | string, - contractBytecode: string + contractBytecode: string, + blockHeightStep?: number ) { if (!nodeUrls?.length) { throw new Error("Invalid node URLs"); @@ -34,6 +37,9 @@ class AeternityService { throw new Error("Aeternity contract bytecode not defined"); } + //Default value for block height step is 2, based on tests + this._blockHeightStep = + typeof blockHeightStep === "number" ? blockHeightStep : 2; this._nodeUrls = typeof nodeUrls === "string" ? [nodeUrls] : nodeUrls; this._compilerUrls = typeof compilerUrls === "string" ? [compilerUrls] : compilerUrls; @@ -152,6 +158,17 @@ class AeternityService { })) as Response<AeternityAPICurrentHeight>; return data.height; } + + async getBlockHeightRange( + startingBlock: number + ): Promise<Array<AeternityAPIBlockData>> { + const endBlockHeight = startingBlock + this._blockHeightStep; + const { data } = await this.requestNode({ + url: `/mdw/v2/blocks?scope=gen${startingBlock}-${endBlockHeight}`, + }).then(({ data }: Response<AeternityAPIBlockRange>) => data); + + return data; + } } export default AeternityService; diff --git a/src/services/AeternityService/types.ts b/src/services/AeternityService/types.ts index c95b4ed45fa8ea39c459a12c8842005ae53ced40..21b69414448ab91f5b4125da36e9183c218215e8 100644 --- a/src/services/AeternityService/types.ts +++ b/src/services/AeternityService/types.ts @@ -1,16 +1,50 @@ export interface AeternityAPITxData { - hash: string; - block_height: number; block_hash: string; + block_height: number; + hash: string; + signatures: Array<string>; tx: { + abi_version: number; + amount: number; call_data: string; + caller_id: string; + contract_id: string; + fee: number; + gas: number; + gas_price: number; + nonce: number; + type: string; + version: number; }; } -export interface AeternityAPIBlockData { +export interface AeternityAPIMicroBLock { + hash: string; height: number; + pof_hash: string; + prev_hash: string; + prev_key_hash: string; + signature: string; + state_hash: string; time: number; + transactions: { [key: string]: AeternityAPITxData }; +} + +export interface AeternityAPIBlockData { + beneficiary: string; hash: string; + height: number; + info: string; + microBlock: Array<AeternityAPIMicroBLock>; + miner: string; + nonce: number; + pow: Array<number>; + prev_hash: string; + prev_key_hash: string; + state_hash: string; + target: number; + time: number; + version: number; } export interface AeternityAPICurrentHeight { @@ -29,3 +63,7 @@ export interface AeternityAPIContractData { } ]; } + +export interface AeternityAPIBlockRange { + data: Array<AeternityAPIBlockData>; +}