diff --git a/packages/cactus-plugin-ledger-connector-iroha2/package.json b/packages/cactus-plugin-ledger-connector-iroha2/package.json index a44b484f71..acf5a9a0c9 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/package.json +++ b/packages/cactus-plugin-ledger-connector-iroha2/package.json @@ -49,14 +49,16 @@ "@hyperledger/cactus-common": "2.0.0-alpha.1", "@hyperledger/cactus-core": "2.0.0-alpha.1", "@hyperledger/cactus-core-api": "2.0.0-alpha.1", - "@iroha2/client": "3.0.0", + "@iroha2/client": "4.0.0", "@iroha2/crypto-core": "0.1.1", "@iroha2/crypto-target-node": "0.4.0", - "@iroha2/data-model": "3.0.0", + "@iroha2/data-model": "4.0.0", + "express": "4.17.1", "fast-safe-stringify": "2.1.1", "hada": "0.0.8", "rxjs": "7.8.1", "sanitize-html": "2.7.0", + "socket.io": "4.4.1", "socket.io-client": "4.5.4", "undici": "5.19.1" }, diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/client.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/client.ts index baacebbfaa..ac2855441a 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/client.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/client.ts @@ -7,11 +7,10 @@ import { Signer, Torii, setCrypto, - CreateToriiProps, makeTransactionPayload, executableIntoSignedTransaction, computeTransactionHash, - makeSignedTransaction, + makeVersionedSignedTransaction, } from "@iroha2/client"; import { AssetDefinitionId, @@ -44,7 +43,6 @@ import { TransferBox, TransactionPayload, AccountId, - VersionedTransaction, RejectionReason, FilterBox, PipelineEventFilter, @@ -52,13 +50,10 @@ import { PipelineEntityKind, OptionPipelineStatusKind, OptionHash, + VersionedSignedTransaction, } from "@iroha2/data-model"; import { Key, KeyPair } from "@iroha2/crypto-core"; -// This module can't be imported unless we use `nodenext` moduleResolution -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { adapter: irohaWSAdapter } = require("@iroha2/client/web-socket/node"); - import { Checks, Logger, @@ -67,7 +62,6 @@ import { } from "@hyperledger/cactus-common"; import { bytesToHex, hexToBytes } from "hada"; -import { fetch as undiciFetch } from "undici"; import { CactusIrohaV2QueryClient } from "./query"; import { @@ -79,7 +73,9 @@ import { import { TransactResponseV1, TransactionStatusV1, + Iroha2BaseConfigTorii, } from "../generated/openapi/typescript-axios"; +import { IrohaV2PrerequisitesProvider } from "./prerequisites-provider"; setCrypto(crypto); @@ -149,11 +145,7 @@ export type TransactionPayloadParameters = Exclude< export class CactusIrohaV2Client { private readonly log: Logger; private readonly transactions: Array = []; - - /** - * Iroha Torii client used to send transactions to the ledger. - */ - public readonly irohaToriiClient: Torii; + private readonly prerequisitesProvider: IrohaV2PrerequisitesProvider; /** * Iroha signer used to sign transaction with user private key and account. @@ -166,21 +158,13 @@ export class CactusIrohaV2Client { public readonly query: CactusIrohaV2QueryClient; constructor( - public readonly toriiOptions: Omit, + public readonly toriiOptions: Iroha2BaseConfigTorii, public readonly accountId: AccountId, private readonly keyPair?: KeyPair, private readonly logLevel: LogLevelDesc = "info", ) { - Checks.truthy(toriiOptions.apiURL, "toriiOptions apiURL"); - Checks.truthy(toriiOptions.telemetryURL, "toriiOptions telemetryURL"); Checks.truthy(accountId, "signerOptions accountId"); - this.irohaToriiClient = new Torii({ - ...toriiOptions, - ws: irohaWSAdapter, - fetch: undiciFetch as any, - }); - const label = this.constructor.name; this.log = LoggerProvider.getOrCreate({ level: this.logLevel, label }); this.log.debug(`${label} created`); @@ -190,8 +174,12 @@ export class CactusIrohaV2Client { this.irohaSigner = new Signer(accountId, keyPair); } + this.prerequisitesProvider = new IrohaV2PrerequisitesProvider( + toriiOptions.apiURL, + ); + this.query = new CactusIrohaV2QueryClient( - this.irohaToriiClient, + this.prerequisitesProvider, this.irohaSigner ?? this.accountId, this.log, ); @@ -717,19 +705,22 @@ export class CactusIrohaV2Client { const txHashHex = bytesToHex([...txHash]); this.log.debug("waitForTransactionStatus() - hash:", txHashHex); - const monitor = await this.irohaToriiClient.listenForEvents({ - filter: FilterBox( - "Pipeline", - PipelineEventFilter({ - entity_kind: OptionPipelineEntityKind( - "Some", - PipelineEntityKind("Transaction"), - ), - status_kind: OptionPipelineStatusKind("None"), - hash: OptionHash("Some", txHash), - }), - ), - }); + const monitor = await Torii.listenForEvents( + this.prerequisitesProvider.getApiWebSocketProperties(), + { + filter: FilterBox( + "Pipeline", + PipelineEventFilter({ + entity_kind: OptionPipelineEntityKind( + "Some", + PipelineEntityKind("Transaction"), + ), + status_kind: OptionPipelineStatusKind("None"), + hash: OptionHash("Some", txHash), + }), + ), + }, + ); this.log.debug("waitForTransactionStatus() - monitoring started."); const txStatusPromise = new Promise( @@ -821,8 +812,14 @@ export class CactusIrohaV2Client { statusPromise = this.waitForTransactionStatus(hash); } - const signedTx = makeSignedTransaction(txPayload, this.irohaSigner); - await this.irohaToriiClient.submit(signedTx); + const signedTx = makeVersionedSignedTransaction( + txPayload, + this.irohaSigner, + ); + await Torii.submit( + this.prerequisitesProvider.getApiHttpProperties(), + signedTx, + ); this.clear(); if (statusPromise) { @@ -838,28 +835,34 @@ export class CactusIrohaV2Client { /** * Send signed transaction payload to the ledger. * - * @param signedPayload Encoded or plain `VersionedTransaction` + * @param signedPayload Encoded or plain `VersionedSignedTransaction` * @param waitForCommit If `true` - block and return the final transaction status. Otherwise - return immediately. * * @returns `TransactResponseV1` */ public async sendSignedPayload( - signedPayload: VersionedTransaction | ArrayBufferView, + signedPayload: VersionedSignedTransaction | ArrayBufferView, waitForCommit = false, ): Promise { Checks.truthy(signedPayload, "sendSigned arg signedPayload"); if (ArrayBuffer.isView(signedPayload)) { - signedPayload = VersionedTransaction.fromBuffer(signedPayload); + signedPayload = VersionedSignedTransaction.fromBuffer(signedPayload); } const hash = computeTransactionHash(signedPayload.as("V1").payload); if (waitForCommit) { const statusPromise = this.waitForTransactionStatus(hash); - await this.irohaToriiClient.submit(signedPayload); + await Torii.submit( + this.prerequisitesProvider.getApiHttpProperties(), + signedPayload, + ); return await statusPromise; } else { - await this.irohaToriiClient.submit(signedPayload); + await Torii.submit( + this.prerequisitesProvider.getApiHttpProperties(), + signedPayload, + ); return { hash: bytesToHex([...hash]), status: TransactionStatusV1.Submitted, diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/prerequisites-provider.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/prerequisites-provider.ts new file mode 100644 index 0000000000..58094f42c7 --- /dev/null +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/prerequisites-provider.ts @@ -0,0 +1,67 @@ +/** + * Provider for IrohaV2 ToriiRequirements needed by Iroha2 SDK. + */ + +import { + IsomorphicWebSocketAdapter, + ToriiRequirementsForApiWebSocket, + ToriiRequirementsForApiHttp, +} from "@iroha2/client"; + +// This module can't be imported unless we use `nodenext` moduleResolution +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { adapter: irohaWSAdapter } = require("@iroha2/client/web-socket/node"); +import { fetch as undiciFetch } from "undici"; + +/** + * Helper class that returns ToriiRequirements for different Iroha2 commands. + * Can be created with missing parameters, if they are required for requested requirement + * an exception will be thrown. + */ +export class IrohaV2PrerequisitesProvider { + /** + * IrohaV2 isomorphic ws adapter + */ + public webSocketAdapter: IsomorphicWebSocketAdapter = irohaWSAdapter; + + /** + * IrohaV2 isomorphic fetch adapter + */ + public fetchAdapter = (undiciFetch as any) as typeof fetch; + + constructor(public apiURL?: string, public telemetryURL?: string) {} + + /** + * Get requirements for executing API calls on web socket protocol. + * @returns `ToriiRequirementsForApiWebSocket` + */ + getApiWebSocketProperties(): ToriiRequirementsForApiWebSocket { + if (!this.apiURL || !this.webSocketAdapter) { + throw new Error( + "Missing required arguments: apiURL and iroha ws adapter", + ); + } + + return { + apiURL: this.apiURL, + ws: this.webSocketAdapter, + }; + } + + /** + * Get requirements for executing API calls on HTTP protocol. + * @returns `ToriiRequirementsForApiHttp` + */ + getApiHttpProperties(): ToriiRequirementsForApiHttp { + if (!this.apiURL || !this.fetchAdapter) { + throw new Error( + "Missing required arguments: apiURL and iroha fetch adapter", + ); + } + + return { + apiURL: this.apiURL, + fetch: this.fetchAdapter, + }; + } +} diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/query.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/query.ts index 970680ad39..83c156aa82 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/query.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/cactus-iroha-sdk-wrapper/query.ts @@ -8,7 +8,7 @@ import { Signer, ToriiQueryResult, makeQueryPayload, - makeSignedQuery, + makeVersionedSignedQuery, } from "@iroha2/client"; import { DomainId, @@ -42,6 +42,7 @@ import { createAssetDefinitionId, createAssetId, } from "./data-factories"; +import { IrohaV2PrerequisitesProvider } from "./prerequisites-provider"; /** * Action context for specific query. @@ -81,13 +82,13 @@ interface QueryContext< */ export class CactusIrohaV2QueryClient { constructor( - public readonly irohaToriiClient: Torii, + private readonly prerequisitesProvider: IrohaV2PrerequisitesProvider, public readonly irohaSigner: Signer | AccountId, private readonly log: Logger, ) { Checks.truthy( - irohaToriiClient, - "CactusIrohaV2QueryClient irohaToriiClient", + prerequisitesProvider, + "CactusIrohaV2QueryClient prerequisitesProvider", ); Checks.truthy(irohaSigner, "CactusIrohaV2QueryClient irohaSigner"); Checks.truthy(log, "CactusIrohaV2QueryClient log"); @@ -152,9 +153,15 @@ export class CactusIrohaV2QueryClient { accountId: this.signerAccountId, query: args.getQueryBox(...params), }); - const signedQuery = makeSignedQuery(queryPayload, this.irohaSigner); + const signedQuery = makeVersionedSignedQuery( + queryPayload, + this.irohaSigner, + ); - const result = await this.irohaToriiClient.request(signedQuery); + const result = await Torii.request( + this.prerequisitesProvider.getApiHttpProperties(), + signedQuery, + ); return args.parseQueryResponse(result); }; @@ -177,7 +184,10 @@ export class CactusIrohaV2QueryClient { signedPayload = VersionedSignedQueryRequest.fromBuffer(signedPayload); } - const result = await this.irohaToriiClient.request(signedPayload); + const result = await Torii.request( + this.prerequisitesProvider.getApiHttpProperties(), + signedPayload, + ); return args.parseQueryResponse(result); }; @@ -484,7 +494,9 @@ export class CactusIrohaV2QueryClient { result, "findAllTransactions", ); - const transactions = vectorResult.map((i) => i.as("TransactionValue")); + const transactions = vectorResult.map( + (i) => i.as("TransactionQueryResult").tx_value, + ); this.log.debug("findAllTransactions:", transactions); return transactions; diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/iroha-sign-utils.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/iroha-sign-utils.ts index 3f99533e27..502d654141 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/iroha-sign-utils.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/iroha-sign-utils.ts @@ -6,12 +6,16 @@ * Remember to free key objects supplied to the signing methods. */ -import { Signer, makeSignedTransaction, makeSignedQuery } from "@iroha2/client"; +import { + Signer, + makeVersionedSignedTransaction, + makeVersionedSignedQuery, +} from "@iroha2/client"; import { QueryPayload, TransactionPayload, VersionedSignedQueryRequest, - VersionedTransaction, + VersionedSignedTransaction, } from "@iroha2/data-model"; import { generateIrohaV2KeyPair } from "./cactus-iroha-sdk-wrapper/client"; @@ -59,8 +63,8 @@ export function signIrohaV2Transaction( ): Uint8Array { const unsignedTx = TransactionPayload.fromBuffer(serializedTx); const signer = getSigner(accountName, domainName, keyPair); - const signedTx = makeSignedTransaction(unsignedTx, signer); - return VersionedTransaction.toBuffer(signedTx); + const signedTx = makeVersionedSignedTransaction(unsignedTx, signer); + return VersionedSignedTransaction.toBuffer(signedTx); } /** @@ -81,6 +85,6 @@ export function signIrohaV2Query( ): Uint8Array { const unsignedQueryReq = QueryPayload.fromBuffer(serializedQuery); const signer = getSigner(accountName, domainName, keyPair); - const queryReq = makeSignedQuery(unsignedQueryReq, signer); + const queryReq = makeVersionedSignedQuery(unsignedQueryReq, signer); return VersionedSignedQueryRequest.toBuffer(queryReq); } diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/plugin-ledger-connector-iroha2.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/plugin-ledger-connector-iroha2.ts index 2efdb923d0..0c1f84a31c 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/plugin-ledger-connector-iroha2.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/plugin-ledger-connector-iroha2.ts @@ -171,17 +171,24 @@ export class PluginLedgerConnectorIroha2 socket: SocketIoSocket, ): SocketIoSocket { this.log.debug("Register WatchBlocks.Subscribe handler."); + socket.on( WatchBlocksV1.Subscribe, async (options: WatchBlocksOptionsV1) => { - // Get client - const cactusIrohaClient = await this.createClient(options.baseConfig); + const apiURL = options.baseConfig?.torii.apiURL; + if (!apiURL) { + socket.emit(WatchBlocksV1.Error, { + message: "WatchBlocksV1.Subscribe error", + error: "WatchBlocksV1.Subscribe requires apiURL torii parameter", + }); + return socket; + } // Start monitoring const monitor = new Iroha2WatchBlocksEndpointV1({ socket, logLevel: this.options.logLevel, - torii: cactusIrohaClient.irohaToriiClient, + apiURL, }); this.runningWatchBlocksMonitors.add(monitor); await monitor.subscribe(options); @@ -191,7 +198,6 @@ export class PluginLedgerConnectorIroha2 ); socket.on("disconnect", async () => { - cactusIrohaClient.clear(); this.runningWatchBlocksMonitors.delete(monitor); this.log.debug( "Running monitors count:", @@ -357,11 +363,10 @@ export class PluginLedgerConnectorIroha2 mergedConfig.accountId.domainId, ); - // TODO - confirm which args are optional and remove type casts accordingly return new CactusIrohaV2Client( { - apiURL: mergedConfig.torii.apiURL as string, - telemetryURL: mergedConfig.torii.telemetryURL as string, + apiURL: mergedConfig.torii.apiURL, + telemetryURL: mergedConfig.torii.telemetryURL, }, accountId, keyPair, diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/watch-blocks-v1-endpoint.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/watch-blocks-v1-endpoint.ts index 474a3efc6b..47515bb810 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/watch-blocks-v1-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/main/typescript/web-services/watch-blocks-v1-endpoint.ts @@ -24,6 +24,7 @@ import { Torii as ToriiClient } from "@iroha2/client"; import safeStringify from "fast-safe-stringify"; import { VersionedCommittedBlock } from "@iroha2/data-model"; +import { IrohaV2PrerequisitesProvider } from "../cactus-iroha-sdk-wrapper/prerequisites-provider"; /** * Iroha2WatchBlocksEndpointV1 configuration. @@ -31,7 +32,7 @@ import { VersionedCommittedBlock } from "@iroha2/data-model"; export interface IIroha2WatchBlocksEndpointV1Configuration { logLevel?: LogLevelDesc; socket: SocketIoSocket; - torii: ToriiClient; + apiURL: string; } /** @@ -41,10 +42,10 @@ export interface IIroha2WatchBlocksEndpointV1Configuration { export class Iroha2WatchBlocksEndpointV1 { public readonly className = "Iroha2WatchBlocksEndpointV1"; private readonly log: Logger; - private readonly torii: ToriiClient; private readonly socket: SocketIoSocket< Record void> >; + private readonly prerequisitesProvider: IrohaV2PrerequisitesProvider; constructor( public readonly config: IIroha2WatchBlocksEndpointV1Configuration, @@ -52,11 +53,12 @@ export class Iroha2WatchBlocksEndpointV1 { const fnTag = `${this.className}#constructor()`; Checks.truthy(config, `${fnTag} arg options`); Checks.truthy(config.socket, `${fnTag} arg options.socket`); - Checks.truthy(config.torii, `${fnTag} arg options.client`); + Checks.truthy(config.apiURL, `${fnTag} arg options.apiURL`); this.socket = config.socket; - this.torii = config.torii; - + this.prerequisitesProvider = new IrohaV2PrerequisitesProvider( + config.apiURL, + ); const level = this.config.logLevel || "info"; this.log = LoggerProvider.getOrCreate({ level, label: this.className }); } @@ -67,7 +69,7 @@ export class Iroha2WatchBlocksEndpointV1 { * @param options Block monitoring options. */ public async subscribe(options: WatchBlocksOptionsV1): Promise { - const { torii, socket, log } = this; + const { socket, log } = this; const clientId = socket.id; log.info( `${WatchBlocksV1.Subscribe} => clientId: ${clientId}, startBlock: ${options.startBlock}`, @@ -76,9 +78,12 @@ export class Iroha2WatchBlocksEndpointV1 { try { const height = options.startBlock ?? "0"; const blockType = options.type ?? BlockTypeV1.Raw; - const blockMonitor = await torii.listenForBlocksStream({ - height: BigInt(height), - }); + const blockMonitor = await ToriiClient.listenForBlocksStream( + this.prerequisitesProvider.getApiWebSocketProperties(), + { + height: BigInt(height), + }, + ); // Handle events blockMonitor.ee.on("open", (openEvent) => { diff --git a/packages/cactus-plugin-ledger-connector-iroha2/src/test/typescript/test-helpers/iroha2-env-setup.ts b/packages/cactus-plugin-ledger-connector-iroha2/src/test/typescript/test-helpers/iroha2-env-setup.ts index 50db9104ce..02a38b8793 100644 --- a/packages/cactus-plugin-ledger-connector-iroha2/src/test/typescript/test-helpers/iroha2-env-setup.ts +++ b/packages/cactus-plugin-ledger-connector-iroha2/src/test/typescript/test-helpers/iroha2-env-setup.ts @@ -4,7 +4,7 @@ // Ledger settings const containerImageName = "ghcr.io/hyperledger/cactus-iroha2-all-in-one"; -const containerImageVersion = "2022-12-22-6c715bdb"; +const containerImageVersion = "2023-07-29-f2bc772ee"; const useRunningLedger = false; // Log settings @@ -162,6 +162,8 @@ export class IrohaV2TestEnv { useRunningLedger, emitContainerLogs: true, logLevel: testLogLevel, + // Uncomment to test against the latest LTS image (pinned, older version of LTS is used by default) + // envVars: ["IROHA_IMAGE_TAG=lts"], }); this.log.debug("IrohaV2 image:", this.ledger.fullContainerImageName); expect(this.ledger).toBeTruthy(); @@ -203,14 +205,18 @@ export class IrohaV2TestEnv { logLevel: sutLogLevel, }); + const [accountName, accountDomain] = this.clientConfig.ACCOUNT_ID.split( + "@", + ); + this._defaultBaseConfig = { torii: { apiURL: this.clientConfig.TORII_API_URL, telemetryURL: this.clientConfig.TORII_TELEMETRY_URL, }, accountId: { - name: this.clientConfig.ACCOUNT_ID.name, - domainId: this.clientConfig.ACCOUNT_ID.domain_id.name, + name: accountName, + domainId: accountDomain, }, signingCredential: this.keychainCredentials, }; @@ -252,7 +258,7 @@ export class IrohaV2TestEnv { this.log.info("FINISHING THE TESTS"); if (this.ledger) { - this.log.info("Stop the fabric ledger..."); + this.log.info("Stop the iroha2 ledger..."); await this.ledger.stop(); await this.ledger.destroy(); } @@ -265,7 +271,7 @@ export class IrohaV2TestEnv { } if (this.connectorServer) { - this.log.info("Stop the fabric connector..."); + this.log.info("Stop the iroha2 connector..."); await new Promise((resolve) => this.connectorServer?.close(() => resolve()), ); diff --git a/packages/cactus-test-tooling/src/main/typescript/iroha/iroha2-test-ledger.ts b/packages/cactus-test-tooling/src/main/typescript/iroha/iroha2-test-ledger.ts index 723c13bf77..0a3b11c840 100644 --- a/packages/cactus-test-tooling/src/main/typescript/iroha/iroha2-test-ledger.ts +++ b/packages/cactus-test-tooling/src/main/typescript/iroha/iroha2-test-ledger.ts @@ -34,7 +34,7 @@ export interface IIroha2TestLedgerOptions { */ export const IROHA2_TEST_LEDGER_DEFAULT_OPTIONS = Object.freeze({ containerImageName: "ghcr.io/hyperledger/cactus-iroha2-all-in-one", - containerImageVersion: "2022-10-18-06770b6c", + containerImageVersion: "2023-07-29-f2bc772ee", logLevel: "info" as LogLevelDesc, emitContainerLogs: true, envVars: [], @@ -46,24 +46,25 @@ export const IROHA2_TEST_LEDGER_DEFAULT_OPTIONS = Object.freeze({ * Contains all the necessary data needed to connect to the Iroha ledger. */ export type Iroha2ClientConfig = { - TORII_API_URL: string; - TORII_TELEMETRY_URL: string; - ACCOUNT_ID: { - name: string; - domain_id: { - name: string; - }; + PUBLIC_KEY: string; + PRIVATE_KEY: { + digest_function: string; + payload: string; }; + ACCOUNT_ID: string; BASIC_AUTH: { web_login: string; password: string; }; - PUBLIC_KEY: string; - PRIVATE_KEY: { - digest_function: string; - payload: string; + TORII_API_URL: string; + TORII_TELEMETRY_URL: string; + TRANSACTION_TIME_TO_LIVE_MS: number; + TRANSACTION_STATUS_TIMEOUT_MS: number; + TRANSACTION_LIMITS: { + max_instruction_number: number; + max_wasm_size_bytes: number; }; - LOGGER_CONFIGURATION: Record; + ADD_TRANSACTION_NONCE: boolean; }; /** diff --git a/packages/cactus-test-tooling/src/test/typescript/integration/iroha/iroha2-test-ledger/iroha2-test-ledger.test.ts b/packages/cactus-test-tooling/src/test/typescript/integration/iroha/iroha2-test-ledger/iroha2-test-ledger.test.ts index 87eae536ee..5554f86030 100644 --- a/packages/cactus-test-tooling/src/test/typescript/integration/iroha/iroha2-test-ledger/iroha2-test-ledger.test.ts +++ b/packages/cactus-test-tooling/src/test/typescript/integration/iroha/iroha2-test-ledger/iroha2-test-ledger.test.ts @@ -8,7 +8,7 @@ // Ledger settings const containerImageName = "ghcr.io/hyperledger/cactus-iroha2-all-in-one"; -const containerImageVersion = "2022-10-18-06770b6c"; +const containerImageVersion = "2023-07-29-f2bc772ee"; const useRunningLedger = false; // Log settings @@ -66,7 +66,7 @@ describe("Iroha V2 Test Ledger checks", () => { log.info("FINISHING THE TESTS"); if (ledger) { - log.info("Stop the fabric ledger..."); + log.info("Stop the iroha2 ledger..."); await ledger.stop(); await ledger.destroy(); } @@ -152,39 +152,19 @@ describe("Iroha V2 Test Ledger checks", () => { test("getClientConfig returns correct data", async () => { const config = await ledger.getClientConfig(); log.info("Received client config:", JSON.stringify(config)); - expect(config).toBeTruthy(); - - expect(config.TORII_API_URL).toBeTruthy(); - expect(config.TORII_TELEMETRY_URL).toBeTruthy(); - - expect(config.ACCOUNT_ID).toBeTruthy(); - expect(config.ACCOUNT_ID.name).toBeTruthy(); - expect(config.ACCOUNT_ID.domain_id).toBeTruthy(); - expect(config.ACCOUNT_ID.domain_id.name).toBeTruthy(); - - expect(config.BASIC_AUTH).toBeTruthy(); - expect(config.BASIC_AUTH.web_login).toBeTruthy(); - expect(config.BASIC_AUTH.password).toBeTruthy(); - expect(config.PUBLIC_KEY).toBeTruthy(); - - expect(config.PRIVATE_KEY).toBeTruthy(); expect(config.PRIVATE_KEY.digest_function).toBeTruthy(); expect(config.PRIVATE_KEY.payload).toBeTruthy(); - - expect(config.LOGGER_CONFIGURATION).toBeTruthy(); - }); - - /** - * Check response of `runIrohaClientCli()` - * - * @todo this is flaky for some reason - fix - */ - test.skip("runIrohaClientCli returns asset data", async () => { - const assets = await ledger.runIrohaClientCli(["asset", "list", "all"]); - log.info("Received assets response:", assets); - expect(assets).toBeTruthy(); - expect(assets).toContain("definition_id"); + expect(config.ACCOUNT_ID).toBeTruthy(); + expect(config.BASIC_AUTH.web_login).toBeTruthy(); + expect(config.BASIC_AUTH.password).toBeTruthy(); + expect(config.TORII_API_URL).toBeTruthy(); + expect(config.TORII_TELEMETRY_URL).toBeTruthy(); + expect(config.TRANSACTION_TIME_TO_LIVE_MS).toBeDefined(); + expect(config.TRANSACTION_STATUS_TIMEOUT_MS).toBeDefined(); + expect(config.TRANSACTION_LIMITS.max_instruction_number).toBeDefined(); + expect(config.TRANSACTION_LIMITS.max_wasm_size_bytes).toBeDefined(); + expect(config.ADD_TRANSACTION_NONCE).toBeDefined(); }); }); diff --git a/tools/docker/iroha2-all-in-one/Dockerfile b/tools/docker/iroha2-all-in-one/Dockerfile index 3b872a7d02..f303a29271 100644 --- a/tools/docker/iroha2-all-in-one/Dockerfile +++ b/tools/docker/iroha2-all-in-one/Dockerfile @@ -1,27 +1,41 @@ -FROM docker:24.0.2-dind +################################ +# Build +################################ + +FROM alpine:3.18.2 as builder + +# LTS image pulled at 28.07.2023 +ENV IROHA_IMAGE_DIGEST="sha256:57d8d2c8dd5ead90200f365be6809b995ecfad14a77796b9f6de1e32d0da62a3" + +RUN apk update && apk add --no-cache skopeo + +WORKDIR "/build" + +# Freeze images +RUN skopeo copy docker://hyperledger/iroha2@${IROHA_IMAGE_DIGEST} docker-archive:iroha2.tar:hyperledger/iroha2:local +RUN tar -zcf iroha2.tar.gz iroha2.tar + +################################ +# Runtime +################################ + +FROM docker:24.0.5-dind ENV APP_ROOT="/app" -ENV FREEZE_TMP_DIR="/opt/docker-freeze" -ENV IROHA_VERSION="dev-nightly-75da907f66d5270f407a50e06bc76cec41d3d409" -ENV IROHA_CLI_VERSION="dev-nightly-75da907f66d5270f407a50e06bc76cec41d3d409" +ENV FREEZE_TMP_DIR="/media/docker/" +ENV IROHA_IMAGE_TAG="local" # Install docker-compose RUN apk update \ && apk add --no-cache \ - # docker-compose dependencies - py-pip \ - python3-dev \ - libffi-dev \ - openssl-dev \ - # Other dependencies - supervisor \ - jq \ - curl \ - bash \ - && pip install wheel \ - && pip install docker-compose - -# Copy iroha_client_cli proxy script + docker-cli \ + docker-cli-compose \ + supervisor \ + jq \ + curl \ + bash + +# Copy iroha_client_cli COPY ./iroha_client_cli.sh /bin/iroha_client_cli RUN chmod +x /bin/iroha_client_cli @@ -30,9 +44,8 @@ COPY ./healthcheck.sh /bin/healthcheck RUN chmod +x /bin/healthcheck HEALTHCHECK --interval=5s --timeout=10s --start-period=45s --retries=60 CMD /bin/healthcheck -# Freeze docker images -COPY ./freeze-images.sh /usr/bin/freeze-images.sh -RUN bash /usr/bin/freeze-images.sh +# Copy frozen image +COPY --from=builder /build/iroha2.tar.gz ${FREEZE_TMP_DIR} WORKDIR ${APP_ROOT} diff --git a/tools/docker/iroha2-all-in-one/README.md b/tools/docker/iroha2-all-in-one/README.md index 5e7ad1218f..aa5cb6262f 100644 --- a/tools/docker/iroha2-all-in-one/README.md +++ b/tools/docker/iroha2-all-in-one/README.md @@ -46,7 +46,3 @@ docker exec -ti iroha2_aio_testnet iroha_client_cli domain list all ## Test Setup - Use typescript [Iroha2TestLedger helper class](../../../packages/cactus-test-tooling/src/main/typescript/iroha/iroha2-test-ledger.ts) to start this ledger and use it from inside of automatic test. - -## Possible improvements -- Use specific iroha docker image tag when they are available. -- Freeze images like it's done in fabric-all-in-one, to speed up the startup (although it's pretty fast already). diff --git a/tools/docker/iroha2-all-in-one/freeze-images.sh b/tools/docker/iroha2-all-in-one/freeze-images.sh deleted file mode 100755 index b78181bd56..0000000000 --- a/tools/docker/iroha2-all-in-one/freeze-images.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -set -e - -FREEZE_SCRIPT_NAME="download-frozen-image-v2.sh" -FREEZE_SCRIPT_PATH="/usr/bin/${FREEZE_SCRIPT_NAME}" - -echo "Download freeze script..." -curl -sSL https://raw.githubusercontent.com/moby/moby/dedf8528a51c6db40686ed6676e9486d1ed5f9c0/contrib/download-frozen-image-v2.sh > "${FREEZE_SCRIPT_PATH}" -chmod +x "${FREEZE_SCRIPT_PATH}" - -# Get default iroha image -img_name="hyperledger/iroha2:${IROHA_VERSION}" -img_path="${FREEZE_TMP_DIR}/iroha2_${IROHA_VERSION}" -echo "Freeze image '${img_name}' in '${img_path}" -mkdir -p "${img_path}" -bash "${FREEZE_SCRIPT_PATH}" "${img_path}" "${img_name}" - -echo "Image freeze done." diff --git a/tools/docker/iroha2-all-in-one/iroha_client_cli.sh b/tools/docker/iroha2-all-in-one/iroha_client_cli.sh old mode 100755 new mode 100644 index 888f497f8e..32b93643bd --- a/tools/docker/iroha2-all-in-one/iroha_client_cli.sh +++ b/tools/docker/iroha2-all-in-one/iroha_client_cli.sh @@ -6,5 +6,5 @@ docker run \ -v"${APP_ROOT}/configs/client_cli/config.json":"/config.json" \ --network="host" \ -ti \ - "hyperledger/iroha2:client-cli-${IROHA_CLI_VERSION}" \ - ./iroha_client_cli "$@" + "hyperledger/iroha2:${IROHA_IMAGE_TAG}" \ + iroha_client_cli "$@" diff --git a/tools/docker/iroha2-all-in-one/run-iroha-ledger.sh b/tools/docker/iroha2-all-in-one/run-iroha-ledger.sh index 61fc4ed932..3dfee8864b 100755 --- a/tools/docker/iroha2-all-in-one/run-iroha-ledger.sh +++ b/tools/docker/iroha2-all-in-one/run-iroha-ledger.sh @@ -1,18 +1,21 @@ #!/bin/bash +# Wait for docker while ! docker ps &> /dev/null do echo "Wait for dockerd to start..." sleep 3 done -# Get list of images from docker-compose -for img in `ls ${FREEZE_TMP_DIR}` +# Load frozen images + +for img in `find "${FREEZE_TMP_DIR}" -name "*.tar.gz"` do echo "Load frozen image '${img}'" - tar -cC "${FREEZE_TMP_DIR}/${img}" . | docker load + tar -zxf "${img}" -O | docker load done echo "Frozen images loaded" +# Run docker compose -f "${APP_ROOT}/docker-compose.yml" up diff --git a/tools/docker/iroha2-all-in-one/src/configs/client_cli/config.json b/tools/docker/iroha2-all-in-one/src/configs/client_cli/config.json index f4a289f078..426f229af3 100644 --- a/tools/docker/iroha2-all-in-one/src/configs/client_cli/config.json +++ b/tools/docker/iroha2-all-in-one/src/configs/client_cli/config.json @@ -1,20 +1,21 @@ { - "TORII_API_URL": "http://127.0.0.1:8080", - "TORII_TELEMETRY_URL": "http://127.0.0.1:8180", - "ACCOUNT_ID": { - "name": "alice", - "domain_id": { - "name": "wonderland" - } + "PUBLIC_KEY": "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0", + "PRIVATE_KEY": { + "digest_function": "ed25519", + "payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" }, + "ACCOUNT_ID": "alice@wonderland", "BASIC_AUTH": { "web_login": "mad_hatter", "password": "ilovetea" }, - "PUBLIC_KEY": "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0", - "PRIVATE_KEY": { - "digest_function": "ed25519", - "payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" + "TORII_API_URL": "http://127.0.0.1:8080", + "TORII_TELEMETRY_URL": "http://127.0.0.1:8180", + "TRANSACTION_TIME_TO_LIVE_MS": 100000, + "TRANSACTION_STATUS_TIMEOUT_MS": 15000, + "TRANSACTION_LIMITS": { + "max_instruction_number": 4096, + "max_wasm_size_bytes": 4194304 }, - "LOGGER_CONFIGURATION": {} + "ADD_TRANSACTION_NONCE": false } diff --git a/tools/docker/iroha2-all-in-one/src/configs/peer/config.json b/tools/docker/iroha2-all-in-one/src/configs/peer/config.json index 8f5ee24946..e1763c4d80 100644 --- a/tools/docker/iroha2-all-in-one/src/configs/peer/config.json +++ b/tools/docker/iroha2-all-in-one/src/configs/peer/config.json @@ -1,46 +1,95 @@ { - "TORII": { - "P2P_ADDR": "127.0.0.1:1337", - "API_URL": "127.0.0.1:8080" + "PUBLIC_KEY": null, + "PRIVATE_KEY": null, + "DISABLE_PANIC_TERMINAL_COLORS": false, + "KURA": { + "INIT_MODE": "strict", + "BLOCK_STORE_PATH": "./storage", + "BLOCKS_PER_STORAGE_FILE": 1000, + "ACTOR_CHANNEL_CAPACITY": 100, + "DEBUG_OUTPUT_NEW_BLOCKS": false }, "SUMERAGI": { - "TRUSTED_PEERS": [ - { - "address": "127.0.0.1:1337", - "public_key": "ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b" - }, - { - "address": "127.0.0.1:1338", - "public_key": "ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1" - }, - { - "address": "127.0.0.1:1339", - "public_key": "ed0120faca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020" - }, - { - "address": "127.0.0.1:1340", - "public_key": "ed01208e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f" - } - ] + "KEY_PAIR": null, + "PEER_ID": null, + "BLOCK_TIME_MS": 1000, + "TRUSTED_PEERS": null, + "COMMIT_TIME_LIMIT_MS": 2000, + "TX_RECEIPT_TIME_LIMIT_MS": 500, + "TRANSACTION_LIMITS": { + "max_instruction_number": 4096, + "max_wasm_size_bytes": 4194304 + }, + "ACTOR_CHANNEL_CAPACITY": 100, + "GOSSIP_BATCH_SIZE": 500, + "GOSSIP_PERIOD_MS": 1000 }, - "KURA": { - "INIT_MODE": "strict", - "BLOCK_STORE_PATH": "./blocks" + "TORII": { + "P2P_ADDR": null, + "API_URL": null, + "TELEMETRY_URL": null, + "MAX_TRANSACTION_SIZE": 32768, + "MAX_CONTENT_LEN": 16384000 }, "BLOCK_SYNC": { "GOSSIP_PERIOD_MS": 10000, - "BATCH_SIZE": 4 + "BLOCK_BATCH_SIZE": 4, + "ACTOR_CHANNEL_CAPACITY": 100 + }, + "QUEUE": { + "MAXIMUM_TRANSACTIONS_IN_BLOCK": 8192, + "MAXIMUM_TRANSACTIONS_IN_QUEUE": 65536, + "TRANSACTION_TIME_TO_LIVE_MS": 86400000, + "FUTURE_THRESHOLD_MS": 1000 }, - "PUBLIC_KEY": "ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b", - "PRIVATE_KEY": { - "digest_function": "ed25519", - "payload": "282ed9f3cf92811c3818dbc4ae594ed59dc1a2f78e4241e31924e101d6b1fb831c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b" + "LOGGER": { + "MAX_LOG_LEVEL": "INFO", + "TELEMETRY_CAPACITY": 1000, + "COMPACT_MODE": false, + "LOG_FILE_PATH": null, + "TERMINAL_COLORS": true }, "GENESIS": { - "ACCOUNT_PUBLIC_KEY": "ed01204cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf", - "ACCOUNT_PRIVATE_KEY": { - "digest_function": "ed25519", - "payload": "d748e18ce60cb30dea3e73c9019b7af45a8d465e3d71bcc9a5ef99a008205e534cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf" + "ACCOUNT_PUBLIC_KEY": null, + "ACCOUNT_PRIVATE_KEY": null, + "WAIT_FOR_PEERS_RETRY_COUNT_LIMIT": 100, + "WAIT_FOR_PEERS_RETRY_PERIOD_MS": 500, + "GENESIS_SUBMISSION_DELAY_MS": 1000 + }, + "WSV": { + "ASSET_METADATA_LIMITS": { + "max_len": 1048576, + "max_entry_byte_size": 4096 + }, + "ASSET_DEFINITION_METADATA_LIMITS": { + "max_len": 1048576, + "max_entry_byte_size": 4096 + }, + "ACCOUNT_METADATA_LIMITS": { + "max_len": 1048576, + "max_entry_byte_size": 4096 + }, + "DOMAIN_METADATA_LIMITS": { + "max_len": 1048576, + "max_entry_byte_size": 4096 + }, + "IDENT_LENGTH_LIMITS": { + "min": 1, + "max": 128 + }, + "WASM_RUNTIME_CONFIG": { + "FUEL_LIMIT": 1000000, + "MAX_MEMORY": 524288000 } + }, + "NETWORK": { + "ACTOR_CHANNEL_CAPACITY": 100 + }, + "TELEMETRY": { + "NAME": null, + "URL": null, + "MIN_RETRY_PERIOD": 1, + "MAX_RETRY_DELAY_EXPONENT": 4, + "FILE": null } } diff --git a/tools/docker/iroha2-all-in-one/src/configs/peer/genesis.json b/tools/docker/iroha2-all-in-one/src/configs/peer/genesis.json index 8a78005a5e..94e4254be4 100644 --- a/tools/docker/iroha2-all-in-one/src/configs/peer/genesis.json +++ b/tools/docker/iroha2-all-in-one/src/configs/peer/genesis.json @@ -4,15 +4,13 @@ "isi": [ { "Register": { - "object": { - "Raw": { - "Identifiable": { - "NewDomain": { - "id": { - "name": "wonderland" - }, - "logo": null, - "metadata": {} + "Identifiable": { + "NewDomain": { + "id": "wonderland", + "logo": null, + "metadata": { + "key": { + "String": "value" } } } @@ -21,20 +19,15 @@ }, { "Register": { - "object": { - "Raw": { - "Identifiable": { - "NewAccount": { - "id": { - "name": "alice", - "domain_id": { - "name": "wonderland" - } - }, - "signatories": [ - "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" - ], - "metadata": {} + "Identifiable": { + "NewAccount": { + "id": "alice@wonderland", + "signatories": [ + "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" + ], + "metadata": { + "key": { + "String": "value" } } } @@ -43,49 +36,308 @@ }, { "Register": { - "object": { - "Raw": { - "Identifiable": { - "NewAssetDefinition": { - "id": { - "name": "rose", - "domain_id": { - "name": "wonderland" - } - }, - "value_type": "Quantity", - "mintable": "Infinitely", - "metadata": {} + "Identifiable": { + "NewAccount": { + "id": "bob@wonderland", + "signatories": [ + "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" + ], + "metadata": { + "key": { + "String": "value" } } } } } }, + { + "Register": { + "Identifiable": { + "NewAssetDefinition": { + "id": "rose#wonderland", + "value_type": "Quantity", + "mintable": "Infinitely", + "metadata": {} + } + } + } + }, + { + "Register": { + "Identifiable": { + "NewDomain": { + "id": "garden_of_live_flowers", + "logo": null, + "metadata": {} + } + } + } + }, + { + "Register": { + "Identifiable": { + "NewAccount": { + "id": "carpenter@garden_of_live_flowers", + "signatories": [ + "ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" + ], + "metadata": {} + } + } + } + }, + { + "Register": { + "Identifiable": { + "NewAssetDefinition": { + "id": "cabbage#garden_of_live_flowers", + "value_type": "Quantity", + "mintable": "Infinitely", + "metadata": {} + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_unregister_asset_with_definition", + "params": { + "asset_definition_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_burn_asset_with_definition", + "params": { + "asset_definition_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_burn_user_assets", + "params": { + "asset_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_set_key_value_in_user_assets", + "params": { + "asset_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_remove_key_value_in_user_assets", + "params": { + "asset_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_set_key_value_in_user_metadata", + "params": { + "account_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_remove_key_value_in_user_metadata", + "params": { + "account_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_set_key_value_in_asset_definition", + "params": { + "asset_definition_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_remove_key_value_in_asset_definition", + "params": { + "asset_definition_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_mint_user_asset_definitions", + "params": { + "asset_definition_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_transfer_user_assets", + "params": { + "asset_id": "Id" + } + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "can_transfer_only_fixed_number_of_times_per_period", + "params": { + "count": "U32", + "period": "U128" + } + } + } + } + }, { "Mint": { "object": { - "Raw": { - "U32": 13 + "U32": 13 + }, + "destination_id": { + "Id": { + "AssetId": "rose##alice@wonderland" } + } + } + }, + { + "Mint": { + "object": { + "U32": 44 }, "destination_id": { - "Raw": { - "Id": { - "AssetId": { - "definition_id": { - "name": "rose", - "domain_id": { - "name": "wonderland" + "Id": { + "AssetId": "cabbage#garden_of_live_flowers#alice@wonderland" + } + } + } + }, + { + "Register": { + "Identifiable": { + "PermissionTokenDefinition": { + "id": "allowed_to_do_stuff", + "params": {} + } + } + } + }, + { + "Register": { + "Identifiable": { + "NewRole": { + "inner": { + "id": "USER_METADATA_ACCESS", + "permissions": [ + { + "definition_id": "can_remove_key_value_in_user_metadata", + "params": { + "account_id": { + "Id": { + "AccountId": "alice@wonderland" + } + } } }, - "account_id": { - "name": "alice", - "domain_id": { - "name": "wonderland" + { + "definition_id": "can_set_key_value_in_user_metadata", + "params": { + "account_id": { + "Id": { + "AccountId": "alice@wonderland" + } + } } } - } + ] + } + } + } + } + }, + { + "Grant": { + "object": { + "PermissionToken": { + "definition_id": "allowed_to_do_stuff", + "params": {} + } + }, + "destination_id": { + "Id": { + "AccountId": "alice@wonderland" + } + } + } + }, + { + "Register": { + "Identifiable": { + "NewRole": { + "inner": { + "id": "staff_that_does_stuff_in_genesis", + "permissions": [ + { + "definition_id": "allowed_to_do_stuff", + "params": {} + } + ] } } } diff --git a/tools/docker/iroha2-all-in-one/src/configs/prometheus.yml b/tools/docker/iroha2-all-in-one/src/configs/prometheus.yml new file mode 100644 index 0000000000..811a010109 --- /dev/null +++ b/tools/docker/iroha2-all-in-one/src/configs/prometheus.yml @@ -0,0 +1,12 @@ +global: + scrape_interval: 15s + evaluation_interval: 15s + +rule_files: + # - "first.rules" + # - "second.rules" + +scrape_configs: + - job_name: prometheus + static_configs: + - targets: ['localhost:8180'] diff --git a/tools/docker/iroha2-all-in-one/src/docker-compose.yml b/tools/docker/iroha2-all-in-one/src/docker-compose.yml index 0b37e4f4be..5e1968675b 100644 --- a/tools/docker/iroha2-all-in-one/src/docker-compose.yml +++ b/tools/docker/iroha2-all-in-one/src/docker-compose.yml @@ -1,9 +1,7 @@ -# Based on upstream https://github.com/hyperledger/iroha/blob/iroha2/docker-compose.yml - -version: "3.7" +version: "3.8" services: iroha0: - image: hyperledger/iroha2:${IROHA_VERSION} + image: hyperledger/iroha2:${IROHA_IMAGE_TAG} environment: TORII_P2P_ADDR: iroha0:1337 TORII_API_URL: iroha0:8080 @@ -11,6 +9,8 @@ services: IROHA_PUBLIC_KEY: "ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "282ed9f3cf92811c3818dbc4ae594ed59dc1a2f78e4241e31924e101d6b1fb831c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b"}' SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b"}, {"address":"iroha1:1338", "public_key": "ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1"}, {"address": "iroha2:1339", "public_key": "ed0120faca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020"}, {"address": "iroha3:1340", "public_key": "ed01208e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f"}]' + IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203f4e3e98571b55514edc5ccf7e53ca7509d89b2868e62921180a6f57c2f4e255' + IROHA_GENESIS_ACCOUNT_PRIVATE_KEY: '{ "digest_function": "ed25519", "payload": "038ae16b219da35aa036335ed0a43c28a2cc737150112c78a7b8034b9d99c9023f4e3e98571b55514edc5ccf7e53ca7509d89b2868e62921180a6f57c2f4e255" }' ports: - "1337:1337" - "8080:8080" @@ -18,10 +18,10 @@ services: volumes: - './configs/peer:/config' init: true - command: ./iroha --submit-genesis + command: iroha --submit-genesis iroha1: - image: hyperledger/iroha2:${IROHA_VERSION} + image: hyperledger/iroha2:${IROHA_IMAGE_TAG} environment: TORII_P2P_ADDR: iroha1:1338 TORII_API_URL: iroha1:8081 @@ -29,6 +29,7 @@ services: IROHA_PUBLIC_KEY: "ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "3bac34cda9e3763fa069c1198312d1ec73b53023b8180c822ac355435edc4a24cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1"}' SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b"}, {"address":"iroha1:1338", "public_key": "ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1"}, {"address": "iroha2:1339", "public_key": "ed0120faca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020"}, {"address": "iroha3:1340", "public_key": "ed01208e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f"}]' + IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203f4e3e98571b55514edc5ccf7e53ca7509d89b2868e62921180a6f57c2f4e255' ports: - "1338:1338" - "8081:8081" @@ -38,7 +39,7 @@ services: init: true iroha2: - image: hyperledger/iroha2:${IROHA_VERSION} + image: hyperledger/iroha2:${IROHA_IMAGE_TAG} environment: TORII_P2P_ADDR: iroha2:1339 TORII_API_URL: iroha2:8082 @@ -46,6 +47,7 @@ services: IROHA_PUBLIC_KEY: "ed0120faca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "1261a436d36779223d7d6cf20e8b644510e488e6a50bafd77a7485264d27197dfaca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020"}' SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b"}, {"address":"iroha1:1338", "public_key": "ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1"}, {"address": "iroha2:1339", "public_key": "ed0120faca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020"}, {"address": "iroha3:1340", "public_key": "ed01208e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f"}]' + IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203f4e3e98571b55514edc5ccf7e53ca7509d89b2868e62921180a6f57c2f4e255' ports: - "1339:1339" - "8082:8082" @@ -55,7 +57,7 @@ services: init: true iroha3: - image: hyperledger/iroha2:${IROHA_VERSION} + image: hyperledger/iroha2:${IROHA_IMAGE_TAG} environment: TORII_P2P_ADDR: iroha3:1340 TORII_API_URL: iroha3:8083 @@ -63,6 +65,7 @@ services: IROHA_PUBLIC_KEY: "ed01208e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "a70dab95c7482eb9f159111b65947e482108cfe67df877bd8d3b9441a781c7c98e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f"}' SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201c61faf8fe94e253b93114240394f79a607b7fa55f9e5a41ebec74b88055768b"}, {"address":"iroha1:1338", "public_key": "ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1"}, {"address": "iroha2:1339", "public_key": "ed0120faca9e8aa83225cb4d16d67f27dd4f93fc30ffa11adc1f5c88fd5495ecc91020"}, {"address": "iroha3:1340", "public_key": "ed01208e351a70b6a603ed285d666b8d689b680865913ba03ce29fb7d13a166c4e7f1f"}]' + IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203f4e3e98571b55514edc5ccf7e53ca7509d89b2868e62921180a6f57c2f4e255' ports: - "1340:1340" - "8083:8083" diff --git a/yarn.lock b/yarn.lock index 1b3d41c81e..90f0cd1de4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7175,10 +7175,10 @@ __metadata: "@hyperledger/cactus-core-api": 2.0.0-alpha.1 "@hyperledger/cactus-plugin-keychain-memory": 2.0.0-alpha.1 "@hyperledger/cactus-test-tooling": 2.0.0-alpha.1 - "@iroha2/client": 3.0.0 + "@iroha2/client": 4.0.0 "@iroha2/crypto-core": 0.1.1 "@iroha2/crypto-target-node": 0.4.0 - "@iroha2/data-model": 3.0.0 + "@iroha2/data-model": 4.0.0 "@types/express": 4.17.8 "@types/sanitize-html": 2.6.2 body-parser: 1.19.0 @@ -7920,18 +7920,18 @@ __metadata: languageName: node linkType: hard -"@iroha2/client@npm:3.0.0": - version: 3.0.0 - resolution: "@iroha2/client@npm:3.0.0" +"@iroha2/client@npm:4.0.0": + version: 4.0.0 + resolution: "@iroha2/client@npm:4.0.0" dependencies: "@iroha2/crypto-core": ^0.1.1 - "@iroha2/data-model": 3.0.0 + "@iroha2/data-model": 4.0.0 "@types/ws": ^8.2.2 debug: ^4.3.4 emittery: ^0.10.1 json-bigint: ^1.0.0 ws: ^8.4.0 - checksum: 22db8b73fa0ea547b1e371a864ae90ed1df5b0584882cd6b7e5f43645fa90635439453ffe878404d9541ceeef63a7e34992117c85f88d6cfa26a3033df4f9a0a + checksum: a49699ffa102fc6db72b7ccaa0d2633bfe535c057618d4ac62d6cb013fa402a95e336054f1d478f45e625d25049565f7bb60b6317960f9093e5537eab9e9ddfa languageName: node linkType: hard @@ -7951,13 +7951,13 @@ __metadata: languageName: node linkType: hard -"@iroha2/data-model@npm:3.0.0": - version: 3.0.0 - resolution: "@iroha2/data-model@npm:3.0.0" +"@iroha2/data-model@npm:4.0.0": + version: 4.0.0 + resolution: "@iroha2/data-model@npm:4.0.0" dependencies: "@iroha2/i64-fixnum": ^0.4.2 "@scale-codec/definition-runtime": ^2.2.2 - checksum: fbcf133978f682f7f415c57dd1832d1800d7e926cf93813ff8c9c9a5bd521bf551d5c2e292b037d3102c15b0d36d8d4c4f421df48ae424fc09f4e42bcb72e6cf + checksum: 37a0eb7e265e4abd86d320f4ae295e50b7d5c01ca2cbbf807bc89b25e3f0d1de620eb954ca4f093b162afad0ebfd64bb56bce1a66bd5e55a8e03b0fb53efd6c4 languageName: node linkType: hard