diff --git a/trackAndTrace/README.md b/trackAndTrace/README.md index 32c7e5e8..6a6b2a13 100644 --- a/trackAndTrace/README.md +++ b/trackAndTrace/README.md @@ -1,5 +1,11 @@ # Track and Trace Project +## Hosted front end + +[Hosted front end link](https://trackntrace.testnet.concordium.com/) + +## Overview + This project contains a complete implementation of a track and trace solution with [CIS-3](https://proposals.concordium.software/CIS/cis-3.html) compliant sponsored transactions. It has five primary components. @@ -20,13 +26,20 @@ However, the easiest option is to use [docker-compose](https://docs.docker.com/c For this to work, you should do the following: 1. Deploy and initialize your version of the Track and Trace smart contract. -2. [Export your account keys from the Browser Wallet](https://developer.concordium.software/en/mainnet/net/guides/export-key.html) and note the location you save the keys. +2. [Export your account keys from the Browser Wallet](https://developer.concordium.software/en/mainnet/net/guides/export-key.html) and generate a `./private-keys` folder to save the key file into it. 3. Set the following environment variables: - Set the `TRACK_AND_TRACE_CONTRACT_ADDRESS` variable to the contract address of your contract instance. - Set the `TRACK_AND_TRACE_PRIVATE_KEY_FILE` variable to the path of your keys from step 2. - (Optional) Set the `TRACK_AND_TRACE_NETWORK` variable to the correct net (testnet/mainnet). Defaults to testnet. - (Optional) Set the `TRACK_AND_TRACE_NODE` to the gRPC endpoint of the node you want to use. Make sure it runs on the right net, i.e., testnet or mainnet. Defaults to `https://grpc.testnet.concordium.com:20000`. 4. Run `docker-compose up` to build and start all the services. + +e.g. + +```bash +TRACK_AND_TRACE_CONTRACT_ADDRESS="<8527,0>" TRACK_AND_TRACE_PRIVATE_KEY_FILE="./private-keys/4SizPU2ipqQQza9Xa6fUkQBCDjyd1vTNUNDGbBeiRGpaJQc6qX.export" docker-compose up +``` + 5. Access the frontend at `http://localhost:8080` - The sponsored transaction service runs on port `8000` by default, and the postgres database runs on `5432`. Both are configurable in the `./docker-compose.yml` file. diff --git a/trackAndTrace/frontend/CHANGELOG.md b/trackAndTrace/frontend/CHANGELOG.md index 032c58eb..0d59f746 100644 --- a/trackAndTrace/frontend/CHANGELOG.md +++ b/trackAndTrace/frontend/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased changes +## 1.1.0 + +- Add transition edges management by admin to front end. + ## 1.0.2 - Fix `Writable` error via polyfill in `walletConnect` dependency. diff --git a/trackAndTrace/frontend/README.md b/trackAndTrace/frontend/README.md index d3af015b..63adfb04 100644 --- a/trackAndTrace/frontend/README.md +++ b/trackAndTrace/frontend/README.md @@ -34,6 +34,12 @@ To start a development environment make sure to first generate the smart contrac yarn dev ``` +e.g. + +```bash +TRACK_AND_TRACE_CONTRACT_ADDRESS="<8527,0>" yarn dev +``` + This will launch a development server with hot module replacement enabled. _Please note that calls to the backend server do not work in the development setup._ diff --git a/trackAndTrace/frontend/generated/module.ts b/trackAndTrace/frontend/generated/module.ts index 3869afbc..c59d6e19 100644 --- a/trackAndTrace/frontend/generated/module.ts +++ b/trackAndTrace/frontend/generated/module.ts @@ -1,9 +1,9 @@ // @ts-nocheck import * as SDK from "@concordium/web-sdk"; /** The reference of the smart contract module supported by the provided client. */ -export const moduleReference: SDK.ModuleReference.Type = /*#__PURE__*/ SDK.ModuleReference.fromHexString('2826a0cf9516115386fd2c8587ab2a179fdc9b40203143044de13fdacf02733e'); +export const moduleReference: SDK.ModuleReference.Type = /*#__PURE__*/ SDK.ModuleReference.fromHexString('2c484449e32d435dcaa3921b7c04b395b3b4b8b25b1ccdc3d3002322dd04edcb'); -/** Client for an on-chain smart contract module with module reference '2826a0cf9516115386fd2c8587ab2a179fdc9b40203143044de13fdacf02733e', can be used for instantiating new smart contract instances. */ +/** Client for an on-chain smart contract module with module reference '2c484449e32d435dcaa3921b7c04b395b3b4b8b25b1ccdc3d3002322dd04edcb', can be used for instantiating new smart contract instances. */ class ModuleModule { /** Having a private field prevents similar structured objects to be considered the same type (similar to nominal typing). */ private __nominal = true; @@ -16,7 +16,7 @@ class ModuleModule { } } -/** Client for an on-chain smart contract module with module reference '2826a0cf9516115386fd2c8587ab2a179fdc9b40203143044de13fdacf02733e', can be used for instantiating new smart contract instances. */ +/** Client for an on-chain smart contract module with module reference '2c484449e32d435dcaa3921b7c04b395b3b4b8b25b1ccdc3d3002322dd04edcb', can be used for instantiating new smart contract instances. */ export type Type = ModuleModule; /** @@ -45,7 +45,7 @@ export function createUnchecked(grpcClient: SDK.ConcordiumGRPCClient): ModuleMod /** * Construct a ModuleModule client for interacting with a smart contract module on chain. * This function ensures the smart contract module is deployed on chain. - * @param {ModuleModule} moduleClient - The client of the on-chain smart contract module with referecence '2826a0cf9516115386fd2c8587ab2a179fdc9b40203143044de13fdacf02733e'. + * @param {ModuleModule} moduleClient - The client of the on-chain smart contract module with referecence '2c484449e32d435dcaa3921b7c04b395b3b4b8b25b1ccdc3d3002322dd04edcb'. * @throws If failing to communicate with the concordium node or if the module reference is not present on chain. * @returns {ModuleModule} A module client ensured to be deployed on chain. */ @@ -55,7 +55,7 @@ export function checkOnChain(moduleClient: ModuleModule): Promise { /** * Get the module source of the deployed smart contract module. - * @param {ModuleModule} moduleClient - The client of the on-chain smart contract module with referecence '2826a0cf9516115386fd2c8587ab2a179fdc9b40203143044de13fdacf02733e'. + * @param {ModuleModule} moduleClient - The client of the on-chain smart contract module with referecence '2c484449e32d435dcaa3921b7c04b395b3b4b8b25b1ccdc3d3002322dd04edcb'. * @throws {SDK.RpcError} If failing to communicate with the concordium node or module not found. * @returns {SDK.VersionedModuleSource} Module source of the deployed smart contract module. */ @@ -159,7 +159,7 @@ export function createTrackAndTraceParameterWebWallet(parameter: TrackAndTracePa /** * Send transaction for instantiating a new 'track_and_trace' smart contract instance. - * @param {ModuleModule} moduleClient - The client of the on-chain smart contract module with referecence '2826a0cf9516115386fd2c8587ab2a179fdc9b40203143044de13fdacf02733e'. + * @param {ModuleModule} moduleClient - The client of the on-chain smart contract module with referecence '2c484449e32d435dcaa3921b7c04b395b3b4b8b25b1ccdc3d3002322dd04edcb'. * @param {SDK.ContractTransactionMetadata} transactionMetadata - Metadata related to constructing a transaction for a smart contract module. * @param {TrackAndTraceParameter} parameter - Parameter to provide as part of the transaction for the instantiation of a new smart contract contract. * @param {SDK.AccountSigner} signer - The signer of the update contract transaction. diff --git a/trackAndTrace/frontend/generated/module_track_and_trace.ts b/trackAndTrace/frontend/generated/module_track_and_trace.ts index b3d393d7..3f8a4972 100644 --- a/trackAndTrace/frontend/generated/module_track_and_trace.ts +++ b/trackAndTrace/frontend/generated/module_track_and_trace.ts @@ -1,7 +1,7 @@ // @ts-nocheck import * as SDK from "@concordium/web-sdk"; /** The reference of the smart contract module supported by the provided client. */ -export const moduleReference: SDK.ModuleReference.Type = /*#__PURE__*/ SDK.ModuleReference.fromHexString('2826a0cf9516115386fd2c8587ab2a179fdc9b40203143044de13fdacf02733e'); +export const moduleReference: SDK.ModuleReference.Type = /*#__PURE__*/ SDK.ModuleReference.fromHexString('2c484449e32d435dcaa3921b7c04b395b3b4b8b25b1ccdc3d3002322dd04edcb'); /** Name of the smart contract supported by this client. */ export const contractName: SDK.ContractName.Type = /*#__PURE__*/ SDK.ContractName.fromStringUnchecked('track_and_trace'); @@ -86,10 +86,10 @@ export type Event = { type: 'ItemCreated', content: { }, } } | { type: 'GrantRole', content: { address: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }, - role: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}, + role: { type: 'Admin'}, } } | { type: 'RevokeRole', content: { address: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }, - role: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}, + role: { type: 'Admin'}, } } | { type: 'Nonce', content: { account: SDK.AccountAddress.Type, nonce: number | bigint, @@ -115,14 +115,14 @@ export function parseEvent(event: SDK.ContractEvent.Type): Event { }, }] } | {'GrantRole' : [{ address: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }, - role: {'Admin' : [] } | {'Producer' : [] } | {'Transporter' : [] } | {'Seller' : [] }, + role: {'Admin' : [] }, }] } | {'RevokeRole' : [{ address: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }, - role: {'Admin' : [] } | {'Producer' : [] } | {'Transporter' : [] } | {'Seller' : [] }, + role: {'Admin' : [] }, }] } | {'Nonce' : [{ account: SDK.AccountAddress.SchemaValue, nonce: bigint, - }] }>SDK.ContractEvent.parseWithSchemaTypeBase64(event, 'HwUAAAAACwAAAEl0ZW1DcmVhdGVkAQEAAAAUAAIAAAAHAAAAaXRlbV9pZAUMAAAAbWV0YWRhdGFfdXJsFQIAAAAEAAAATm9uZQIEAAAAU29tZQEBAAAAFAACAAAAAwAAAHVybBYBBAAAAGhhc2gVAgAAAAQAAABOb25lAgQAAABTb21lAQEAAAAeIAAAAAERAAAASXRlbVN0YXR1c0NoYW5nZWQBAQAAABQAAwAAAAcAAABpdGVtX2lkBQoAAABuZXdfc3RhdHVzFQQAAAAIAAAAUHJvZHVjZWQCCQAAAEluVHJhbnNpdAIHAAAASW5TdG9yZQIEAAAAU29sZAIPAAAAYWRkaXRpb25hbF9kYXRhFAABAAAABQAAAGJ5dGVzEAICAgkAAABHcmFudFJvbGUBAQAAABQAAgAAAAcAAABhZGRyZXNzFQIAAAAHAAAAQWNjb3VudAEBAAAACwgAAABDb250cmFjdAEBAAAADAQAAAByb2xlFQQAAAAFAAAAQWRtaW4CCAAAAFByb2R1Y2VyAgsAAABUcmFuc3BvcnRlcgIGAAAAU2VsbGVyAgMKAAAAUmV2b2tlUm9sZQEBAAAAFAACAAAABwAAAGFkZHJlc3MVAgAAAAcAAABBY2NvdW50AQEAAAALCAAAAENvbnRyYWN0AQEAAAAMBAAAAHJvbGUVBAAAAAUAAABBZG1pbgIIAAAAUHJvZHVjZXICCwAAAFRyYW5zcG9ydGVyAgYAAABTZWxsZXIC+gUAAABOb25jZQEBAAAAFAACAAAABwAAAGFjY291bnQLBQAAAG5vbmNlBQ=='); + }] }>SDK.ContractEvent.parseWithSchemaTypeBase64(event, 'HwUAAAAACwAAAEl0ZW1DcmVhdGVkAQEAAAAUAAIAAAAHAAAAaXRlbV9pZAUMAAAAbWV0YWRhdGFfdXJsFQIAAAAEAAAATm9uZQIEAAAAU29tZQEBAAAAFAACAAAAAwAAAHVybBYBBAAAAGhhc2gVAgAAAAQAAABOb25lAgQAAABTb21lAQEAAAAeIAAAAAERAAAASXRlbVN0YXR1c0NoYW5nZWQBAQAAABQAAwAAAAcAAABpdGVtX2lkBQoAAABuZXdfc3RhdHVzFQQAAAAIAAAAUHJvZHVjZWQCCQAAAEluVHJhbnNpdAIHAAAASW5TdG9yZQIEAAAAU29sZAIPAAAAYWRkaXRpb25hbF9kYXRhFAABAAAABQAAAGJ5dGVzEAICAgkAAABHcmFudFJvbGUBAQAAABQAAgAAAAcAAABhZGRyZXNzFQIAAAAHAAAAQWNjb3VudAEBAAAACwgAAABDb250cmFjdAEBAAAADAQAAAByb2xlFQEAAAAFAAAAQWRtaW4CAwoAAABSZXZva2VSb2xlAQEAAAAUAAIAAAAHAAAAYWRkcmVzcxUCAAAABwAAAEFjY291bnQBAQAAAAsIAAAAQ29udHJhY3QBAQAAAAwEAAAAcm9sZRUBAAAABQAAAEFkbWluAvoFAAAATm9uY2UBAQAAABQAAgAAAAcAAABhY2NvdW50CwUAAABub25jZQU='); let match11: { type: 'ItemCreated', content: { item_id: number | bigint, metadata_url: { type: 'None'} | { type: 'Some', content: { @@ -137,10 +137,10 @@ export function parseEvent(event: SDK.ContractEvent.Type): Event { }, } } | { type: 'GrantRole', content: { address: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }, - role: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}, + role: { type: 'Admin'}, } } | { type: 'RevokeRole', content: { address: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }, - role: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}, + role: { type: 'Admin'}, } } | { type: 'Nonce', content: { account: SDK.AccountAddress.Type, nonce: number | bigint, @@ -258,99 +258,75 @@ export function parseEvent(event: SDK.ContractEvent.Type): Event { throw new Error("Unexpected enum variant"); } const field46 = variant39[0].role; - let match47: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}; + let match47: { type: 'Admin'}; if ('Admin' in field46) { match47 = { type: 'Admin', }; - } else if ('Producer' in field46) { - match47 = { - type: 'Producer', - }; - } else if ('Transporter' in field46) { - match47 = { - type: 'Transporter', - }; - } else if ('Seller' in field46) { - match47 = { - type: 'Seller', - }; } else { throw new Error("Unexpected enum variant"); } - const named52 = { + const named49 = { address: match41, role: match47, }; match11 = { type: 'GrantRole', - content: named52, + content: named49, }; } else if ('RevokeRole' in schemaJson) { - const variant53 = schemaJson.RevokeRole; - const field54 = variant53[0].address; - let match55: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }; - if ('Account' in field54) { - const variant56 = field54.Account; - const accountAddress57 = SDK.AccountAddress.fromSchemaValue(variant56[0]); - match55 = { + const variant50 = schemaJson.RevokeRole; + const field51 = variant50[0].address; + let match52: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }; + if ('Account' in field51) { + const variant53 = field51.Account; + const accountAddress54 = SDK.AccountAddress.fromSchemaValue(variant53[0]); + match52 = { type: 'Account', - content: accountAddress57, + content: accountAddress54, }; - } else if ('Contract' in field54) { - const variant58 = field54.Contract; - const contractAddress59 = SDK.ContractAddress.fromSchemaValue(variant58[0]); - match55 = { + } else if ('Contract' in field51) { + const variant55 = field51.Contract; + const contractAddress56 = SDK.ContractAddress.fromSchemaValue(variant55[0]); + match52 = { type: 'Contract', - content: contractAddress59, + content: contractAddress56, }; } else { throw new Error("Unexpected enum variant"); } - const field60 = variant53[0].role; - let match61: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}; - if ('Admin' in field60) { - match61 = { + const field57 = variant50[0].role; + let match58: { type: 'Admin'}; + if ('Admin' in field57) { + match58 = { type: 'Admin', }; - } else if ('Producer' in field60) { - match61 = { - type: 'Producer', - }; - } else if ('Transporter' in field60) { - match61 = { - type: 'Transporter', - }; - } else if ('Seller' in field60) { - match61 = { - type: 'Seller', - }; } else { throw new Error("Unexpected enum variant"); } - const named66 = { - address: match55, - role: match61, + const named60 = { + address: match52, + role: match58, }; match11 = { type: 'RevokeRole', - content: named66, + content: named60, }; } else if ('Nonce' in schemaJson) { - const variant67 = schemaJson.Nonce; - const field68 = variant67[0].account; - const accountAddress69 = SDK.AccountAddress.fromSchemaValue(field68); - const field70 = variant67[0].nonce; - const named71 = { - account: accountAddress69, - nonce: field70, + const variant61 = schemaJson.Nonce; + const field62 = variant61[0].account; + const accountAddress63 = SDK.AccountAddress.fromSchemaValue(field62); + const field64 = variant61[0].nonce; + const named65 = { + account: accountAddress63, + nonce: field64, }; match11 = { type: 'Nonce', - content: named71, + content: named65, }; } else { @@ -433,19 +409,19 @@ export type GetRolesParameter = { type: 'Account', content: SDK.AccountAddress.T * @returns {GetRolesParameterSchemaJson} The smart contract parameter JSON. */ function createGetRolesParameterSchemaJson(parameter: GetRolesParameter): GetRolesParameterSchemaJson { - let match72: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }; + let match66: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }; switch (parameter.type) { case 'Account': - const accountAddress73 = SDK.AccountAddress.toSchemaValue(parameter.content); - match72 = { Account: [accountAddress73], }; + const accountAddress67 = SDK.AccountAddress.toSchemaValue(parameter.content); + match66 = { Account: [accountAddress67], }; break; case 'Contract': - const contractAddress74 = SDK.ContractAddress.toSchemaValue(parameter.content); - match72 = { Contract: [contractAddress74], }; + const contractAddress68 = SDK.ContractAddress.toSchemaValue(parameter.content); + match66 = { Contract: [contractAddress68], }; break; } - return match72; + return match66; } /** @@ -511,7 +487,7 @@ export function dryRunGetRoles(contractClient: TrackAndTraceContract, parameter: } /** Return value for dry-running update transaction for 'getRoles' entrypoint of the 'track_and_trace' contract. */ -export type ReturnValueGetRoles = Array<{ type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}>; +export type ReturnValueGetRoles = Array<{ type: 'Admin'}>; /** * Get and parse the return value from dry-running update transaction for 'getRoles' entrypoint of the 'track_and_trace' contract. @@ -528,34 +504,22 @@ export function parseReturnValueGetRoles(invokeResult: SDK.InvokeContractResult) throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = >SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'EAIVBAAAAAUAAABBZG1pbgIIAAAAUHJvZHVjZXICCwAAAFRyYW5zcG9ydGVyAgYAAABTZWxsZXIC'); - const list75 = schemaJson.map((item76) => { - let match77: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}; - if ('Admin' in item76) { - match77 = { + const schemaJson = >SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'EAIVAQAAAAUAAABBZG1pbgI='); + const list69 = schemaJson.map((item70) => { + let match71: { type: 'Admin'}; + if ('Admin' in item70) { + match71 = { type: 'Admin', }; - } else if ('Producer' in item76) { - match77 = { - type: 'Producer', - }; - } else if ('Transporter' in item76) { - match77 = { - type: 'Transporter', - }; - } else if ('Seller' in item76) { - match77 = { - type: 'Seller', - }; } else { throw new Error("Unexpected enum variant"); } - return match77; + return match71; }); - return list75; + return list69; } /** Base64 encoding of the parameter schema type for update transactions to 'getItemState' entrypoint of the 'track_and_trace' contract. */ const base64GetItemStateParameterSchema = 'BQ=='; @@ -570,8 +534,8 @@ export type GetItemStateParameter = number | bigint; * @returns {GetItemStateParameterSchemaJson} The smart contract parameter JSON. */ function createGetItemStateParameterSchemaJson(parameter: GetItemStateParameter): GetItemStateParameterSchemaJson { - const number82 = BigInt(parameter); - return number82; + const number73 = BigInt(parameter); + return number73; } /** @@ -667,22 +631,22 @@ export function parseReturnValueGetItemState(invokeResult: SDK.InvokeContractRes hash: {'None' : [] } | {'Some' : [string] }, }] }, }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FAACAAAABgAAAHN0YXR1cxUEAAAACAAAAFByb2R1Y2VkAgkAAABJblRyYW5zaXQCBwAAAEluU3RvcmUCBAAAAFNvbGQCDAAAAG1ldGFkYXRhX3VybBUCAAAABAAAAE5vbmUCBAAAAFNvbWUBAQAAABQAAgAAAAMAAAB1cmwWAQQAAABoYXNoFQIAAAAEAAAATm9uZQIEAAAAU29tZQEBAAAAHiAAAAA='); - const field83 = schemaJson.status; - let match84: { type: 'Produced'} | { type: 'InTransit'} | { type: 'InStore'} | { type: 'Sold'}; - if ('Produced' in field83) { - match84 = { + const field74 = schemaJson.status; + let match75: { type: 'Produced'} | { type: 'InTransit'} | { type: 'InStore'} | { type: 'Sold'}; + if ('Produced' in field74) { + match75 = { type: 'Produced', }; - } else if ('InTransit' in field83) { - match84 = { + } else if ('InTransit' in field74) { + match75 = { type: 'InTransit', }; - } else if ('InStore' in field83) { - match84 = { + } else if ('InStore' in field74) { + match75 = { type: 'InStore', }; - } else if ('Sold' in field83) { - match84 = { + } else if ('Sold' in field74) { + match75 = { type: 'Sold', }; } @@ -691,41 +655,41 @@ export function parseReturnValueGetItemState(invokeResult: SDK.InvokeContractRes throw new Error("Unexpected enum variant"); } - const field89 = schemaJson.metadata_url; - let match90: { type: 'None'} | { type: 'Some', content: { + const field80 = schemaJson.metadata_url; + let match81: { type: 'None'} | { type: 'Some', content: { url: string, hash: { type: 'None'} | { type: 'Some', content: SDK.HexString }, } }; - if ('None' in field89) { - match90 = { + if ('None' in field80) { + match81 = { type: 'None', }; - } else if ('Some' in field89) { - const variant92 = field89.Some; - const field93 = variant92[0].url; - const field94 = variant92[0].hash; - let match95: { type: 'None'} | { type: 'Some', content: SDK.HexString }; - if ('None' in field94) { - match95 = { + } else if ('Some' in field80) { + const variant83 = field80.Some; + const field84 = variant83[0].url; + const field85 = variant83[0].hash; + let match86: { type: 'None'} | { type: 'Some', content: SDK.HexString }; + if ('None' in field85) { + match86 = { type: 'None', }; - } else if ('Some' in field94) { - const variant97 = field94.Some; - match95 = { + } else if ('Some' in field85) { + const variant88 = field85.Some; + match86 = { type: 'Some', - content: variant97[0], + content: variant88[0], }; } else { throw new Error("Unexpected enum variant"); } - const named98 = { - url: field93, - hash: match95, + const named89 = { + url: field84, + hash: match86, }; - match90 = { + match81 = { type: 'Some', - content: named98, + content: named89, }; } @@ -733,11 +697,11 @@ export function parseReturnValueGetItemState(invokeResult: SDK.InvokeContractRes throw new Error("Unexpected enum variant"); } - const named99 = { - status: match84, - metadata_url: match90, + const named90 = { + status: match75, + metadata_url: match81, }; - return named99; + return named90; } /** Base64 encoding of the parameter schema type for update transactions to 'createItem' entrypoint of the 'track_and_trace' contract. */ const base64CreateItemParameterSchema = 'FQIAAAAEAAAATm9uZQIEAAAAU29tZQEBAAAAFAACAAAAAwAAAHVybBYBBAAAAGhhc2gVAgAAAAQAAABOb25lAgQAAABTb21lAQEAAAAeIAAAAA=='; @@ -758,36 +722,36 @@ export type CreateItemParameter = { type: 'None'} | { type: 'Some', content: { * @returns {CreateItemParameterSchemaJson} The smart contract parameter JSON. */ function createCreateItemParameterSchemaJson(parameter: CreateItemParameter): CreateItemParameterSchemaJson { - let match100: {'None' : [] } | {'Some' : [{ + let match91: {'None' : [] } | {'Some' : [{ url: string, hash: {'None' : [] } | {'Some' : [string] }, }] }; switch (parameter.type) { case 'None': - match100 = { None: [], }; + match91 = { None: [], }; break; case 'Some': - const field102 = parameter.content.url; - const field103 = parameter.content.hash; - let match104: {'None' : [] } | {'Some' : [string] }; - switch (field103.type) { + const field93 = parameter.content.url; + const field94 = parameter.content.hash; + let match95: {'None' : [] } | {'Some' : [string] }; + switch (field94.type) { case 'None': - match104 = { None: [], }; + match95 = { None: [], }; break; case 'Some': - match104 = { Some: [field103.content], }; + match95 = { Some: [field94.content], }; break; } - const named101 = { - url: field102, - hash: match104, + const named92 = { + url: field93, + hash: match95, }; - match100 = { Some: [named101], }; + match91 = { Some: [named92], }; break; } - return match100; + return match91; } /** @@ -853,7 +817,7 @@ export function dryRunCreateItem(contractClient: TrackAndTraceContract, paramete } /** Error message for dry-running update transaction for 'createItem' entrypoint of the 'track_and_trace' contract. */ -export type ErrorMessageCreateItem = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; +export type ErrorMessageCreateItem = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; /** * Get and parse the error message from dry-running update transaction for 'createItem' entrypoint of the 'track_and_trace' contract. @@ -870,75 +834,79 @@ export function parseErrorMessageCreateItem(invokeResult: SDK.InvokeContractResu throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FQ8AAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQC'); - let match105: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match96: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; if ('ParseParams' in schemaJson) { - match105 = { + match96 = { type: 'ParseParams', }; } else if ('LogFull' in schemaJson) { - match105 = { + match96 = { type: 'LogFull', }; } else if ('LogMalformed' in schemaJson) { - match105 = { + match96 = { type: 'LogMalformed', }; } else if ('Unauthorized' in schemaJson) { - match105 = { + match96 = { type: 'Unauthorized', }; } else if ('ItemAlreadyExists' in schemaJson) { - match105 = { + match96 = { type: 'ItemAlreadyExists', }; } else if ('ItemDoesNotExist' in schemaJson) { - match105 = { + match96 = { type: 'ItemDoesNotExist', }; } else if ('FinalState' in schemaJson) { - match105 = { + match96 = { type: 'FinalState', }; } else if ('NoContract' in schemaJson) { - match105 = { + match96 = { type: 'NoContract', }; } else if ('MissingAccount' in schemaJson) { - match105 = { + match96 = { type: 'MissingAccount', }; } else if ('MalformedData' in schemaJson) { - match105 = { + match96 = { type: 'MalformedData', }; } else if ('WrongSignature' in schemaJson) { - match105 = { + match96 = { type: 'WrongSignature', }; } else if ('NonceMismatch' in schemaJson) { - match105 = { + match96 = { type: 'NonceMismatch', }; } else if ('WrongContract' in schemaJson) { - match105 = { + match96 = { type: 'WrongContract', }; } else if ('WrongEntryPoint' in schemaJson) { - match105 = { + match96 = { type: 'WrongEntryPoint', }; } else if ('Expired' in schemaJson) { - match105 = { + match96 = { type: 'Expired', }; + } else if ('UnSuccessful' in schemaJson) { + match96 = { + type: 'UnSuccessful', + }; } else { throw new Error("Unexpected enum variant"); } - return match105 + return match96 } /** Base64 encoding of the parameter schema type for update transactions to 'changeItemStatus' entrypoint of the 'track_and_trace' contract. */ const base64ChangeItemStatusParameterSchema = 'FAADAAAABwAAAGl0ZW1faWQFCgAAAG5ld19zdGF0dXMVBAAAAAgAAABQcm9kdWNlZAIJAAAASW5UcmFuc2l0AgcAAABJblN0b3JlAgQAAABTb2xkAg8AAABhZGRpdGlvbmFsX2RhdGEUAAEAAAAFAAAAYnl0ZXMQAgI='; @@ -965,36 +933,36 @@ export type ChangeItemStatusParameter = { * @returns {ChangeItemStatusParameterSchemaJson} The smart contract parameter JSON. */ function createChangeItemStatusParameterSchemaJson(parameter: ChangeItemStatusParameter): ChangeItemStatusParameterSchemaJson { - const field122 = parameter.item_id; - const number123 = BigInt(field122); - const field124 = parameter.new_status; - let match125: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }; - switch (field124.type) { + const field114 = parameter.item_id; + const number115 = BigInt(field114); + const field116 = parameter.new_status; + let match117: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }; + switch (field116.type) { case 'Produced': - match125 = { Produced: [], }; + match117 = { Produced: [], }; break; case 'InTransit': - match125 = { InTransit: [], }; + match117 = { InTransit: [], }; break; case 'InStore': - match125 = { InStore: [], }; + match117 = { InStore: [], }; break; case 'Sold': - match125 = { Sold: [], }; + match117 = { Sold: [], }; break; } - const field126 = parameter.additional_data; - const field128 = field126.bytes; - const named127 = { - bytes: field128, + const field118 = parameter.additional_data; + const field120 = field118.bytes; + const named119 = { + bytes: field120, }; - const named121 = { - item_id: number123, - new_status: match125, - additional_data: named127, + const named113 = { + item_id: number115, + new_status: match117, + additional_data: named119, }; - return named121; + return named113; } /** @@ -1060,7 +1028,7 @@ export function dryRunChangeItemStatus(contractClient: TrackAndTraceContract, pa } /** Error message for dry-running update transaction for 'changeItemStatus' entrypoint of the 'track_and_trace' contract. */ -export type ErrorMessageChangeItemStatus = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; +export type ErrorMessageChangeItemStatus = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; /** * Get and parse the error message from dry-running update transaction for 'changeItemStatus' entrypoint of the 'track_and_trace' contract. @@ -1077,87 +1045,324 @@ export function parseErrorMessageChangeItemStatus(invokeResult: SDK.InvokeContra throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FQ8AAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQC'); - let match131: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match123: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; + if ('ParseParams' in schemaJson) { + match123 = { + type: 'ParseParams', + }; + } else if ('LogFull' in schemaJson) { + match123 = { + type: 'LogFull', + }; + } else if ('LogMalformed' in schemaJson) { + match123 = { + type: 'LogMalformed', + }; + } else if ('Unauthorized' in schemaJson) { + match123 = { + type: 'Unauthorized', + }; + } else if ('ItemAlreadyExists' in schemaJson) { + match123 = { + type: 'ItemAlreadyExists', + }; + } else if ('ItemDoesNotExist' in schemaJson) { + match123 = { + type: 'ItemDoesNotExist', + }; + } else if ('FinalState' in schemaJson) { + match123 = { + type: 'FinalState', + }; + } else if ('NoContract' in schemaJson) { + match123 = { + type: 'NoContract', + }; + } else if ('MissingAccount' in schemaJson) { + match123 = { + type: 'MissingAccount', + }; + } else if ('MalformedData' in schemaJson) { + match123 = { + type: 'MalformedData', + }; + } else if ('WrongSignature' in schemaJson) { + match123 = { + type: 'WrongSignature', + }; + } else if ('NonceMismatch' in schemaJson) { + match123 = { + type: 'NonceMismatch', + }; + } else if ('WrongContract' in schemaJson) { + match123 = { + type: 'WrongContract', + }; + } else if ('WrongEntryPoint' in schemaJson) { + match123 = { + type: 'WrongEntryPoint', + }; + } else if ('Expired' in schemaJson) { + match123 = { + type: 'Expired', + }; + } else if ('UnSuccessful' in schemaJson) { + match123 = { + type: 'UnSuccessful', + }; + } + + else { + throw new Error("Unexpected enum variant"); + } + + return match123 +} +/** Base64 encoding of the parameter schema type for update transactions to 'updateStateMachine' entrypoint of the 'track_and_trace' contract. */ +const base64UpdateStateMachineParameterSchema = 'FAAEAAAABwAAAGFkZHJlc3MLCwAAAGZyb21fc3RhdHVzFQQAAAAIAAAAUHJvZHVjZWQCCQAAAEluVHJhbnNpdAIHAAAASW5TdG9yZQIEAAAAU29sZAIJAAAAdG9fc3RhdHVzFQQAAAAIAAAAUHJvZHVjZWQCCQAAAEluVHJhbnNpdAIHAAAASW5TdG9yZQIEAAAAU29sZAIGAAAAdXBkYXRlFQIAAAAGAAAAUmVtb3ZlAgMAAABBZGQC'; +/** Parameter JSON type needed by the schema for update transaction for 'updateStateMachine' entrypoint of the 'track_and_trace' contract. */ +type UpdateStateMachineParameterSchemaJson = { + address: SDK.AccountAddress.SchemaValue, + from_status: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }, + to_status: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }, + update: {'Remove' : [] } | {'Add' : [] }, + }; +/** Parameter type for update transaction for 'updateStateMachine' entrypoint of the 'track_and_trace' contract. */ +export type UpdateStateMachineParameter = { + address: SDK.AccountAddress.Type, + from_status: { type: 'Produced'} | { type: 'InTransit'} | { type: 'InStore'} | { type: 'Sold'}, + to_status: { type: 'Produced'} | { type: 'InTransit'} | { type: 'InStore'} | { type: 'Sold'}, + update: { type: 'Remove'} | { type: 'Add'}, + }; + +/** + * Construct schema JSON representation used in update transaction for 'updateStateMachine' entrypoint of the 'track_and_trace' contract. + * @param {UpdateStateMachineParameter} parameter The structured parameter to construct from. + * @returns {UpdateStateMachineParameterSchemaJson} The smart contract parameter JSON. + */ +function createUpdateStateMachineParameterSchemaJson(parameter: UpdateStateMachineParameter): UpdateStateMachineParameterSchemaJson { + const field141 = parameter.address; + const accountAddress142 = SDK.AccountAddress.toSchemaValue(field141); + const field143 = parameter.from_status; + let match144: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }; + switch (field143.type) { + case 'Produced': + match144 = { Produced: [], }; + break; + case 'InTransit': + match144 = { InTransit: [], }; + break; + case 'InStore': + match144 = { InStore: [], }; + break; + case 'Sold': + match144 = { Sold: [], }; + break; + } + + const field145 = parameter.to_status; + let match146: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }; + switch (field145.type) { + case 'Produced': + match146 = { Produced: [], }; + break; + case 'InTransit': + match146 = { InTransit: [], }; + break; + case 'InStore': + match146 = { InStore: [], }; + break; + case 'Sold': + match146 = { Sold: [], }; + break; + } + + const field147 = parameter.update; + let match148: {'Remove' : [] } | {'Add' : [] }; + switch (field147.type) { + case 'Remove': + match148 = { Remove: [], }; + break; + case 'Add': + match148 = { Add: [], }; + break; + } + + const named140 = { + address: accountAddress142, + from_status: match144, + to_status: match146, + update: match148, + }; + return named140; +} + +/** + * Construct Parameter type used in update transaction for 'updateStateMachine' entrypoint of the 'track_and_trace' contract. + * @param {UpdateStateMachineParameter} parameter The structured parameter to construct from. + * @returns {SDK.Parameter.Type} The smart contract parameter. + */ +export function createUpdateStateMachineParameter(parameter: UpdateStateMachineParameter): SDK.Parameter.Type { + return SDK.Parameter.fromBase64SchemaType(base64UpdateStateMachineParameterSchema, createUpdateStateMachineParameterSchemaJson(parameter)); +} + +/** + * Construct WebWallet parameter type used in update transaction for 'updateStateMachine' entrypoint of the 'track_and_trace' contract. + * @param {UpdateStateMachineParameter} parameter The structured parameter to construct from. + * @returns The smart contract parameter support by the WebWallet. + */ +export function createUpdateStateMachineParameterWebWallet(parameter: UpdateStateMachineParameter) { + return { + parameters: createUpdateStateMachineParameterSchemaJson(parameter), + schema: { + type: 'TypeSchema' as const, + value: SDK.toBuffer(base64UpdateStateMachineParameterSchema, 'base64') + }, + } +} + +/** + * Send an update-contract transaction to the 'updateStateMachine' entrypoint of the 'track_and_trace' contract. + * @param {TrackAndTraceContract} contractClient The client for a 'track_and_trace' smart contract instance on chain. + * @param {SDK.ContractTransactionMetadata} transactionMetadata - Metadata related to constructing a transaction for a smart contract. + * @param {UpdateStateMachineParameter} parameter - Parameter to provide the smart contract entrypoint as part of the transaction. + * @param {SDK.AccountSigner} signer - The signer of the update contract transaction. + * @throws If the entrypoint is not successfully invoked. + * @returns {SDK.TransactionHash.Type} Hash of the transaction. + */ +export function sendUpdateStateMachine(contractClient: TrackAndTraceContract, transactionMetadata: SDK.ContractTransactionMetadata, parameter: UpdateStateMachineParameter, signer: SDK.AccountSigner): Promise { + return contractClient.genericContract.createAndSendUpdateTransaction( + SDK.EntrypointName.fromStringUnchecked('updateStateMachine'), + SDK.Parameter.toBuffer, + transactionMetadata, + createUpdateStateMachineParameter(parameter), + signer + ); +} + +/** + * Dry-run an update-contract transaction to the 'updateStateMachine' entrypoint of the 'track_and_trace' contract. + * @param {TrackAndTraceContract} contractClient The client for a 'track_and_trace' smart contract instance on chain. + * @param {SDK.ContractAddress.Type | SDK.AccountAddress.Type} invokeMetadata - The address of the account or contract which is invoking this transaction. + * @param {UpdateStateMachineParameter} parameter - Parameter to provide the smart contract entrypoint as part of the transaction. + * @param {SDK.BlockHash.Type} [blockHash] - Optional block hash allowing for dry-running the transaction at the end of a specific block. + * @throws {SDK.RpcError} If failing to communicate with the concordium node or if any of the checks fails. + * @returns {SDK.InvokeContractResult} The result of invoking the smart contract instance. + */ +export function dryRunUpdateStateMachine(contractClient: TrackAndTraceContract, parameter: UpdateStateMachineParameter, invokeMetadata: SDK.ContractInvokeMetadata = {}, blockHash?: SDK.BlockHash.Type): Promise { + return contractClient.genericContract.dryRun.invokeMethod( + SDK.EntrypointName.fromStringUnchecked('updateStateMachine'), + invokeMetadata, + SDK.Parameter.toBuffer, + createUpdateStateMachineParameter(parameter), + blockHash + ); +} + +/** Error message for dry-running update transaction for 'updateStateMachine' entrypoint of the 'track_and_trace' contract. */ +export type ErrorMessageUpdateStateMachine = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; + +/** + * Get and parse the error message from dry-running update transaction for 'updateStateMachine' entrypoint of the 'track_and_trace' contract. + * Returns undefined if the result is not a failure. + * @param {SDK.InvokeContractResult} invokeResult The result from dry-running the transaction. + * @returns {ErrorMessageUpdateStateMachine | undefined} The structured error message or undefined if result was not a failure or failed for other reason than contract rejectedReceive. + */ +export function parseErrorMessageUpdateStateMachine(invokeResult: SDK.InvokeContractResult): ErrorMessageUpdateStateMachine | undefined { + if (invokeResult.tag !== 'failure' || invokeResult.reason.tag !== 'RejectedReceive') { + return undefined; + } + + if (invokeResult.returnValue === undefined) { + throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); + } + + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match149: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; if ('ParseParams' in schemaJson) { - match131 = { + match149 = { type: 'ParseParams', }; } else if ('LogFull' in schemaJson) { - match131 = { + match149 = { type: 'LogFull', }; } else if ('LogMalformed' in schemaJson) { - match131 = { + match149 = { type: 'LogMalformed', }; } else if ('Unauthorized' in schemaJson) { - match131 = { + match149 = { type: 'Unauthorized', }; } else if ('ItemAlreadyExists' in schemaJson) { - match131 = { + match149 = { type: 'ItemAlreadyExists', }; } else if ('ItemDoesNotExist' in schemaJson) { - match131 = { + match149 = { type: 'ItemDoesNotExist', }; } else if ('FinalState' in schemaJson) { - match131 = { + match149 = { type: 'FinalState', }; } else if ('NoContract' in schemaJson) { - match131 = { + match149 = { type: 'NoContract', }; } else if ('MissingAccount' in schemaJson) { - match131 = { + match149 = { type: 'MissingAccount', }; } else if ('MalformedData' in schemaJson) { - match131 = { + match149 = { type: 'MalformedData', }; } else if ('WrongSignature' in schemaJson) { - match131 = { + match149 = { type: 'WrongSignature', }; } else if ('NonceMismatch' in schemaJson) { - match131 = { + match149 = { type: 'NonceMismatch', }; } else if ('WrongContract' in schemaJson) { - match131 = { + match149 = { type: 'WrongContract', }; } else if ('WrongEntryPoint' in schemaJson) { - match131 = { + match149 = { type: 'WrongEntryPoint', }; } else if ('Expired' in schemaJson) { - match131 = { + match149 = { type: 'Expired', }; + } else if ('UnSuccessful' in schemaJson) { + match149 = { + type: 'UnSuccessful', + }; } else { throw new Error("Unexpected enum variant"); } - return match131 + return match149 } /** Base64 encoding of the parameter schema type for update transactions to 'grantRole' entrypoint of the 'track_and_trace' contract. */ -const base64GrantRoleParameterSchema = 'FAACAAAABwAAAGFkZHJlc3MVAgAAAAcAAABBY2NvdW50AQEAAAALCAAAAENvbnRyYWN0AQEAAAAMBAAAAHJvbGUVBAAAAAUAAABBZG1pbgIIAAAAUHJvZHVjZXICCwAAAFRyYW5zcG9ydGVyAgYAAABTZWxsZXIC'; +const base64GrantRoleParameterSchema = 'FAACAAAABwAAAGFkZHJlc3MVAgAAAAcAAABBY2NvdW50AQEAAAALCAAAAENvbnRyYWN0AQEAAAAMBAAAAHJvbGUVAQAAAAUAAABBZG1pbgI='; /** Parameter JSON type needed by the schema for update transaction for 'grantRole' entrypoint of the 'track_and_trace' contract. */ type GrantRoleParameterSchemaJson = { address: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }, - role: {'Admin' : [] } | {'Producer' : [] } | {'Transporter' : [] } | {'Seller' : [] }, + role: {'Admin' : [] }, }; /** Parameter type for update transaction for 'grantRole' entrypoint of the 'track_and_trace' contract. */ export type GrantRoleParameter = { address: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }, - role: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}, + role: { type: 'Admin'}, }; /** @@ -1166,41 +1371,32 @@ export type GrantRoleParameter = { * @returns {GrantRoleParameterSchemaJson} The smart contract parameter JSON. */ function createGrantRoleParameterSchemaJson(parameter: GrantRoleParameter): GrantRoleParameterSchemaJson { - const field148 = parameter.address; - let match149: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }; - switch (field148.type) { + const field167 = parameter.address; + let match168: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }; + switch (field167.type) { case 'Account': - const accountAddress150 = SDK.AccountAddress.toSchemaValue(field148.content); - match149 = { Account: [accountAddress150], }; + const accountAddress169 = SDK.AccountAddress.toSchemaValue(field167.content); + match168 = { Account: [accountAddress169], }; break; case 'Contract': - const contractAddress151 = SDK.ContractAddress.toSchemaValue(field148.content); - match149 = { Contract: [contractAddress151], }; + const contractAddress170 = SDK.ContractAddress.toSchemaValue(field167.content); + match168 = { Contract: [contractAddress170], }; break; } - const field152 = parameter.role; - let match153: {'Admin' : [] } | {'Producer' : [] } | {'Transporter' : [] } | {'Seller' : [] }; - switch (field152.type) { + const field171 = parameter.role; + let match172: {'Admin' : [] }; + switch (field171.type) { case 'Admin': - match153 = { Admin: [], }; - break; - case 'Producer': - match153 = { Producer: [], }; - break; - case 'Transporter': - match153 = { Transporter: [], }; - break; - case 'Seller': - match153 = { Seller: [], }; + match172 = { Admin: [], }; break; } - const named147 = { - address: match149, - role: match153, + const named166 = { + address: match168, + role: match172, }; - return named147; + return named166; } /** @@ -1266,7 +1462,7 @@ export function dryRunGrantRole(contractClient: TrackAndTraceContract, parameter } /** Error message for dry-running update transaction for 'grantRole' entrypoint of the 'track_and_trace' contract. */ -export type ErrorMessageGrantRole = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; +export type ErrorMessageGrantRole = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; /** * Get and parse the error message from dry-running update transaction for 'grantRole' entrypoint of the 'track_and_trace' contract. @@ -1283,87 +1479,91 @@ export function parseErrorMessageGrantRole(invokeResult: SDK.InvokeContractResul throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FQ8AAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQC'); - let match154: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match173: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; if ('ParseParams' in schemaJson) { - match154 = { + match173 = { type: 'ParseParams', }; } else if ('LogFull' in schemaJson) { - match154 = { + match173 = { type: 'LogFull', }; } else if ('LogMalformed' in schemaJson) { - match154 = { + match173 = { type: 'LogMalformed', }; } else if ('Unauthorized' in schemaJson) { - match154 = { + match173 = { type: 'Unauthorized', }; } else if ('ItemAlreadyExists' in schemaJson) { - match154 = { + match173 = { type: 'ItemAlreadyExists', }; } else if ('ItemDoesNotExist' in schemaJson) { - match154 = { + match173 = { type: 'ItemDoesNotExist', }; } else if ('FinalState' in schemaJson) { - match154 = { + match173 = { type: 'FinalState', }; } else if ('NoContract' in schemaJson) { - match154 = { + match173 = { type: 'NoContract', }; } else if ('MissingAccount' in schemaJson) { - match154 = { + match173 = { type: 'MissingAccount', }; } else if ('MalformedData' in schemaJson) { - match154 = { + match173 = { type: 'MalformedData', }; } else if ('WrongSignature' in schemaJson) { - match154 = { + match173 = { type: 'WrongSignature', }; } else if ('NonceMismatch' in schemaJson) { - match154 = { + match173 = { type: 'NonceMismatch', }; } else if ('WrongContract' in schemaJson) { - match154 = { + match173 = { type: 'WrongContract', }; } else if ('WrongEntryPoint' in schemaJson) { - match154 = { + match173 = { type: 'WrongEntryPoint', }; } else if ('Expired' in schemaJson) { - match154 = { + match173 = { type: 'Expired', }; + } else if ('UnSuccessful' in schemaJson) { + match173 = { + type: 'UnSuccessful', + }; } else { throw new Error("Unexpected enum variant"); } - return match154 + return match173 } /** Base64 encoding of the parameter schema type for update transactions to 'revokeRole' entrypoint of the 'track_and_trace' contract. */ -const base64RevokeRoleParameterSchema = 'FAACAAAABwAAAGFkZHJlc3MVAgAAAAcAAABBY2NvdW50AQEAAAALCAAAAENvbnRyYWN0AQEAAAAMBAAAAHJvbGUVBAAAAAUAAABBZG1pbgIIAAAAUHJvZHVjZXICCwAAAFRyYW5zcG9ydGVyAgYAAABTZWxsZXIC'; +const base64RevokeRoleParameterSchema = 'FAACAAAABwAAAGFkZHJlc3MVAgAAAAcAAABBY2NvdW50AQEAAAALCAAAAENvbnRyYWN0AQEAAAAMBAAAAHJvbGUVAQAAAAUAAABBZG1pbgI='; /** Parameter JSON type needed by the schema for update transaction for 'revokeRole' entrypoint of the 'track_and_trace' contract. */ type RevokeRoleParameterSchemaJson = { address: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }, - role: {'Admin' : [] } | {'Producer' : [] } | {'Transporter' : [] } | {'Seller' : [] }, + role: {'Admin' : [] }, }; /** Parameter type for update transaction for 'revokeRole' entrypoint of the 'track_and_trace' contract. */ export type RevokeRoleParameter = { address: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }, - role: { type: 'Admin'} | { type: 'Producer'} | { type: 'Transporter'} | { type: 'Seller'}, + role: { type: 'Admin'}, }; /** @@ -1372,41 +1572,32 @@ export type RevokeRoleParameter = { * @returns {RevokeRoleParameterSchemaJson} The smart contract parameter JSON. */ function createRevokeRoleParameterSchemaJson(parameter: RevokeRoleParameter): RevokeRoleParameterSchemaJson { - const field171 = parameter.address; - let match172: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }; - switch (field171.type) { + const field191 = parameter.address; + let match192: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }; + switch (field191.type) { case 'Account': - const accountAddress173 = SDK.AccountAddress.toSchemaValue(field171.content); - match172 = { Account: [accountAddress173], }; + const accountAddress193 = SDK.AccountAddress.toSchemaValue(field191.content); + match192 = { Account: [accountAddress193], }; break; case 'Contract': - const contractAddress174 = SDK.ContractAddress.toSchemaValue(field171.content); - match172 = { Contract: [contractAddress174], }; + const contractAddress194 = SDK.ContractAddress.toSchemaValue(field191.content); + match192 = { Contract: [contractAddress194], }; break; } - const field175 = parameter.role; - let match176: {'Admin' : [] } | {'Producer' : [] } | {'Transporter' : [] } | {'Seller' : [] }; - switch (field175.type) { + const field195 = parameter.role; + let match196: {'Admin' : [] }; + switch (field195.type) { case 'Admin': - match176 = { Admin: [], }; - break; - case 'Producer': - match176 = { Producer: [], }; - break; - case 'Transporter': - match176 = { Transporter: [], }; - break; - case 'Seller': - match176 = { Seller: [], }; + match196 = { Admin: [], }; break; } - const named170 = { - address: match172, - role: match176, + const named190 = { + address: match192, + role: match196, }; - return named170; + return named190; } /** @@ -1472,7 +1663,7 @@ export function dryRunRevokeRole(contractClient: TrackAndTraceContract, paramete } /** Error message for dry-running update transaction for 'revokeRole' entrypoint of the 'track_and_trace' contract. */ -export type ErrorMessageRevokeRole = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; +export type ErrorMessageRevokeRole = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; /** * Get and parse the error message from dry-running update transaction for 'revokeRole' entrypoint of the 'track_and_trace' contract. @@ -1489,75 +1680,79 @@ export function parseErrorMessageRevokeRole(invokeResult: SDK.InvokeContractResu throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FQ8AAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQC'); - let match177: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match197: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; if ('ParseParams' in schemaJson) { - match177 = { + match197 = { type: 'ParseParams', }; } else if ('LogFull' in schemaJson) { - match177 = { + match197 = { type: 'LogFull', }; } else if ('LogMalformed' in schemaJson) { - match177 = { + match197 = { type: 'LogMalformed', }; } else if ('Unauthorized' in schemaJson) { - match177 = { + match197 = { type: 'Unauthorized', }; } else if ('ItemAlreadyExists' in schemaJson) { - match177 = { + match197 = { type: 'ItemAlreadyExists', }; } else if ('ItemDoesNotExist' in schemaJson) { - match177 = { + match197 = { type: 'ItemDoesNotExist', }; } else if ('FinalState' in schemaJson) { - match177 = { + match197 = { type: 'FinalState', }; } else if ('NoContract' in schemaJson) { - match177 = { + match197 = { type: 'NoContract', }; } else if ('MissingAccount' in schemaJson) { - match177 = { + match197 = { type: 'MissingAccount', }; } else if ('MalformedData' in schemaJson) { - match177 = { + match197 = { type: 'MalformedData', }; } else if ('WrongSignature' in schemaJson) { - match177 = { + match197 = { type: 'WrongSignature', }; } else if ('NonceMismatch' in schemaJson) { - match177 = { + match197 = { type: 'NonceMismatch', }; } else if ('WrongContract' in schemaJson) { - match177 = { + match197 = { type: 'WrongContract', }; } else if ('WrongEntryPoint' in schemaJson) { - match177 = { + match197 = { type: 'WrongEntryPoint', }; } else if ('Expired' in schemaJson) { - match177 = { + match197 = { type: 'Expired', }; + } else if ('UnSuccessful' in schemaJson) { + match197 = { + type: 'UnSuccessful', + }; } else { throw new Error("Unexpected enum variant"); } - return match177 + return match197 } /** Base64 encoding of the parameter schema type for update transactions to 'permit' entrypoint of the 'track_and_trace' contract. */ const base64PermitParameterSchema = 'FAADAAAACQAAAHNpZ25hdHVyZRIAAhIAAhUBAAAABwAAAEVkMjU1MTkBAQAAAB5AAAAABgAAAHNpZ25lcgsHAAAAbWVzc2FnZRQABQAAABAAAABjb250cmFjdF9hZGRyZXNzDAUAAABub25jZQUJAAAAdGltZXN0YW1wDQsAAABlbnRyeV9wb2ludBYBBwAAAHBheWxvYWQQAQI='; @@ -1592,44 +1787,44 @@ export type PermitParameter = { * @returns {PermitParameterSchemaJson} The smart contract parameter JSON. */ function createPermitParameterSchemaJson(parameter: PermitParameter): PermitParameterSchemaJson { - const field194 = parameter.signature; - const map195: [number, [number, {'Ed25519' : [string] }][]][] = [...field194.entries()].map(([key196, value197]) => { - const map198: [number, {'Ed25519' : [string] }][] = [...value197.entries()].map(([key199, value200]) => { - let match201: {'Ed25519' : [string] }; - switch (value200.type) { + const field215 = parameter.signature; + const map216: [number, [number, {'Ed25519' : [string] }][]][] = [...field215.entries()].map(([key217, value218]) => { + const map219: [number, {'Ed25519' : [string] }][] = [...value218.entries()].map(([key220, value221]) => { + let match222: {'Ed25519' : [string] }; + switch (value221.type) { case 'Ed25519': - match201 = { Ed25519: [value200.content], }; + match222 = { Ed25519: [value221.content], }; break; } - return [key199, match201]; + return [key220, match222]; }); - return [key196, map198]; + return [key217, map219]; }); - const field202 = parameter.signer; - const accountAddress203 = SDK.AccountAddress.toSchemaValue(field202); - const field204 = parameter.message; - const field206 = field204.contract_address; - const contractAddress207 = SDK.ContractAddress.toSchemaValue(field206); - const field208 = field204.nonce; - const number209 = BigInt(field208); - const field210 = field204.timestamp; - const timestamp211 = SDK.Timestamp.toSchemaValue(field210); - const field212 = field204.entry_point; - const field213 = field204.payload; - const named205 = { - contract_address: contractAddress207, - nonce: number209, - timestamp: timestamp211, - entry_point: field212, - payload: field213, + const field223 = parameter.signer; + const accountAddress224 = SDK.AccountAddress.toSchemaValue(field223); + const field225 = parameter.message; + const field227 = field225.contract_address; + const contractAddress228 = SDK.ContractAddress.toSchemaValue(field227); + const field229 = field225.nonce; + const number230 = BigInt(field229); + const field231 = field225.timestamp; + const timestamp232 = SDK.Timestamp.toSchemaValue(field231); + const field233 = field225.entry_point; + const field234 = field225.payload; + const named226 = { + contract_address: contractAddress228, + nonce: number230, + timestamp: timestamp232, + entry_point: field233, + payload: field234, }; - const named193 = { - signature: map195, - signer: accountAddress203, - message: named205, + const named214 = { + signature: map216, + signer: accountAddress224, + message: named226, }; - return named193; + return named214; } /** @@ -1695,7 +1890,7 @@ export function dryRunPermit(contractClient: TrackAndTraceContract, parameter: P } /** Error message for dry-running update transaction for 'permit' entrypoint of the 'track_and_trace' contract. */ -export type ErrorMessagePermit = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; +export type ErrorMessagePermit = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; /** * Get and parse the error message from dry-running update transaction for 'permit' entrypoint of the 'track_and_trace' contract. @@ -1712,75 +1907,79 @@ export function parseErrorMessagePermit(invokeResult: SDK.InvokeContractResult): throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FQ8AAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQC'); - let match216: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match237: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; if ('ParseParams' in schemaJson) { - match216 = { + match237 = { type: 'ParseParams', }; } else if ('LogFull' in schemaJson) { - match216 = { + match237 = { type: 'LogFull', }; } else if ('LogMalformed' in schemaJson) { - match216 = { + match237 = { type: 'LogMalformed', }; } else if ('Unauthorized' in schemaJson) { - match216 = { + match237 = { type: 'Unauthorized', }; } else if ('ItemAlreadyExists' in schemaJson) { - match216 = { + match237 = { type: 'ItemAlreadyExists', }; } else if ('ItemDoesNotExist' in schemaJson) { - match216 = { + match237 = { type: 'ItemDoesNotExist', }; } else if ('FinalState' in schemaJson) { - match216 = { + match237 = { type: 'FinalState', }; } else if ('NoContract' in schemaJson) { - match216 = { + match237 = { type: 'NoContract', }; } else if ('MissingAccount' in schemaJson) { - match216 = { + match237 = { type: 'MissingAccount', }; } else if ('MalformedData' in schemaJson) { - match216 = { + match237 = { type: 'MalformedData', }; } else if ('WrongSignature' in schemaJson) { - match216 = { + match237 = { type: 'WrongSignature', }; } else if ('NonceMismatch' in schemaJson) { - match216 = { + match237 = { type: 'NonceMismatch', }; } else if ('WrongContract' in schemaJson) { - match216 = { + match237 = { type: 'WrongContract', }; } else if ('WrongEntryPoint' in schemaJson) { - match216 = { + match237 = { type: 'WrongEntryPoint', }; } else if ('Expired' in schemaJson) { - match216 = { + match237 = { type: 'Expired', }; + } else if ('UnSuccessful' in schemaJson) { + match237 = { + type: 'UnSuccessful', + }; } else { throw new Error("Unexpected enum variant"); } - return match216 + return match237 } /** Base64 encoding of the parameter schema type for update transactions to 'viewMessageHash' entrypoint of the 'track_and_trace' contract. */ const base64ViewMessageHashParameterSchema = 'FAADAAAACQAAAHNpZ25hdHVyZRIAAhIAAhUBAAAABwAAAEVkMjU1MTkBAQAAAB5AAAAABgAAAHNpZ25lcgsHAAAAbWVzc2FnZRQABQAAABAAAABjb250cmFjdF9hZGRyZXNzDAUAAABub25jZQUJAAAAdGltZXN0YW1wDQsAAABlbnRyeV9wb2ludBYBBwAAAHBheWxvYWQQAQI='; @@ -1815,44 +2014,44 @@ export type ViewMessageHashParameter = { * @returns {ViewMessageHashParameterSchemaJson} The smart contract parameter JSON. */ function createViewMessageHashParameterSchemaJson(parameter: ViewMessageHashParameter): ViewMessageHashParameterSchemaJson { - const field233 = parameter.signature; - const map234: [number, [number, {'Ed25519' : [string] }][]][] = [...field233.entries()].map(([key235, value236]) => { - const map237: [number, {'Ed25519' : [string] }][] = [...value236.entries()].map(([key238, value239]) => { - let match240: {'Ed25519' : [string] }; - switch (value239.type) { + const field255 = parameter.signature; + const map256: [number, [number, {'Ed25519' : [string] }][]][] = [...field255.entries()].map(([key257, value258]) => { + const map259: [number, {'Ed25519' : [string] }][] = [...value258.entries()].map(([key260, value261]) => { + let match262: {'Ed25519' : [string] }; + switch (value261.type) { case 'Ed25519': - match240 = { Ed25519: [value239.content], }; + match262 = { Ed25519: [value261.content], }; break; } - return [key238, match240]; + return [key260, match262]; }); - return [key235, map237]; + return [key257, map259]; }); - const field241 = parameter.signer; - const accountAddress242 = SDK.AccountAddress.toSchemaValue(field241); - const field243 = parameter.message; - const field245 = field243.contract_address; - const contractAddress246 = SDK.ContractAddress.toSchemaValue(field245); - const field247 = field243.nonce; - const number248 = BigInt(field247); - const field249 = field243.timestamp; - const timestamp250 = SDK.Timestamp.toSchemaValue(field249); - const field251 = field243.entry_point; - const field252 = field243.payload; - const named244 = { - contract_address: contractAddress246, - nonce: number248, - timestamp: timestamp250, - entry_point: field251, - payload: field252, + const field263 = parameter.signer; + const accountAddress264 = SDK.AccountAddress.toSchemaValue(field263); + const field265 = parameter.message; + const field267 = field265.contract_address; + const contractAddress268 = SDK.ContractAddress.toSchemaValue(field267); + const field269 = field265.nonce; + const number270 = BigInt(field269); + const field271 = field265.timestamp; + const timestamp272 = SDK.Timestamp.toSchemaValue(field271); + const field273 = field265.entry_point; + const field274 = field265.payload; + const named266 = { + contract_address: contractAddress268, + nonce: number270, + timestamp: timestamp272, + entry_point: field273, + payload: field274, }; - const named232 = { - signature: map234, - signer: accountAddress242, - message: named244, + const named254 = { + signature: map256, + signer: accountAddress264, + message: named266, }; - return named232; + return named254; } /** @@ -1940,7 +2139,7 @@ export function parseReturnValueViewMessageHash(invokeResult: SDK.InvokeContract } /** Error message for dry-running update transaction for 'viewMessageHash' entrypoint of the 'track_and_trace' contract. */ -export type ErrorMessageViewMessageHash = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; +export type ErrorMessageViewMessageHash = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; /** * Get and parse the error message from dry-running update transaction for 'viewMessageHash' entrypoint of the 'track_and_trace' contract. @@ -1957,75 +2156,79 @@ export function parseErrorMessageViewMessageHash(invokeResult: SDK.InvokeContrac throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FQ8AAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQC'); - let match257: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match279: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; if ('ParseParams' in schemaJson) { - match257 = { + match279 = { type: 'ParseParams', }; } else if ('LogFull' in schemaJson) { - match257 = { + match279 = { type: 'LogFull', }; } else if ('LogMalformed' in schemaJson) { - match257 = { + match279 = { type: 'LogMalformed', }; } else if ('Unauthorized' in schemaJson) { - match257 = { + match279 = { type: 'Unauthorized', }; } else if ('ItemAlreadyExists' in schemaJson) { - match257 = { + match279 = { type: 'ItemAlreadyExists', }; } else if ('ItemDoesNotExist' in schemaJson) { - match257 = { + match279 = { type: 'ItemDoesNotExist', }; } else if ('FinalState' in schemaJson) { - match257 = { + match279 = { type: 'FinalState', }; } else if ('NoContract' in schemaJson) { - match257 = { + match279 = { type: 'NoContract', }; } else if ('MissingAccount' in schemaJson) { - match257 = { + match279 = { type: 'MissingAccount', }; } else if ('MalformedData' in schemaJson) { - match257 = { + match279 = { type: 'MalformedData', }; } else if ('WrongSignature' in schemaJson) { - match257 = { + match279 = { type: 'WrongSignature', }; } else if ('NonceMismatch' in schemaJson) { - match257 = { + match279 = { type: 'NonceMismatch', }; } else if ('WrongContract' in schemaJson) { - match257 = { + match279 = { type: 'WrongContract', }; } else if ('WrongEntryPoint' in schemaJson) { - match257 = { + match279 = { type: 'WrongEntryPoint', }; } else if ('Expired' in schemaJson) { - match257 = { + match279 = { type: 'Expired', }; + } else if ('UnSuccessful' in schemaJson) { + match279 = { + type: 'UnSuccessful', + }; } else { throw new Error("Unexpected enum variant"); } - return match257 + return match279 } /** Base64 encoding of the parameter schema type for update transactions to 'supportsPermit' entrypoint of the 'track_and_trace' contract. */ const base64SupportsPermitParameterSchema = 'FAABAAAABwAAAHF1ZXJpZXMQARYB'; @@ -2044,11 +2247,11 @@ export type SupportsPermitParameter = { * @returns {SupportsPermitParameterSchemaJson} The smart contract parameter JSON. */ function createSupportsPermitParameterSchemaJson(parameter: SupportsPermitParameter): SupportsPermitParameterSchemaJson { - const field274 = parameter.queries; - const named273 = { - queries: field274, + const field297 = parameter.queries; + const named296 = { + queries: field297, }; - return named273; + return named296; } /** @@ -2132,25 +2335,25 @@ export function parseReturnValueSupportsPermit(invokeResult: SDK.InvokeContractR } const schemaJson = ] }>>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'EAEVAwAAAAkAAABOb1N1cHBvcnQCBwAAAFN1cHBvcnQCCQAAAFN1cHBvcnRCeQEBAAAAEAAM'); - const list277 = schemaJson.map((item278) => { - let match279: { type: 'NoSupport'} | { type: 'Support'} | { type: 'SupportBy', content: Array }; - if ('NoSupport' in item278) { - match279 = { + const list300 = schemaJson.map((item301) => { + let match302: { type: 'NoSupport'} | { type: 'Support'} | { type: 'SupportBy', content: Array }; + if ('NoSupport' in item301) { + match302 = { type: 'NoSupport', }; - } else if ('Support' in item278) { - match279 = { + } else if ('Support' in item301) { + match302 = { type: 'Support', }; - } else if ('SupportBy' in item278) { - const variant282 = item278.SupportBy; - const list283 = variant282[0].map((item284) => { - const contractAddress285 = SDK.ContractAddress.fromSchemaValue(item284); - return contractAddress285; + } else if ('SupportBy' in item301) { + const variant305 = item301.SupportBy; + const list306 = variant305[0].map((item307) => { + const contractAddress308 = SDK.ContractAddress.fromSchemaValue(item307); + return contractAddress308; }); - match279 = { + match302 = { type: 'SupportBy', - content: list283, + content: list306, }; } @@ -2158,13 +2361,13 @@ export function parseReturnValueSupportsPermit(invokeResult: SDK.InvokeContractR throw new Error("Unexpected enum variant"); } - return match279; + return match302; }); - return list277; + return list300; } /** Error message for dry-running update transaction for 'supportsPermit' entrypoint of the 'track_and_trace' contract. */ -export type ErrorMessageSupportsPermit = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; +export type ErrorMessageSupportsPermit = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; /** * Get and parse the error message from dry-running update transaction for 'supportsPermit' entrypoint of the 'track_and_trace' contract. @@ -2181,75 +2384,79 @@ export function parseErrorMessageSupportsPermit(invokeResult: SDK.InvokeContract throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FQ8AAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQC'); - let match286: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match309: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; if ('ParseParams' in schemaJson) { - match286 = { + match309 = { type: 'ParseParams', }; } else if ('LogFull' in schemaJson) { - match286 = { + match309 = { type: 'LogFull', }; } else if ('LogMalformed' in schemaJson) { - match286 = { + match309 = { type: 'LogMalformed', }; } else if ('Unauthorized' in schemaJson) { - match286 = { + match309 = { type: 'Unauthorized', }; } else if ('ItemAlreadyExists' in schemaJson) { - match286 = { + match309 = { type: 'ItemAlreadyExists', }; } else if ('ItemDoesNotExist' in schemaJson) { - match286 = { + match309 = { type: 'ItemDoesNotExist', }; } else if ('FinalState' in schemaJson) { - match286 = { + match309 = { type: 'FinalState', }; } else if ('NoContract' in schemaJson) { - match286 = { + match309 = { type: 'NoContract', }; } else if ('MissingAccount' in schemaJson) { - match286 = { + match309 = { type: 'MissingAccount', }; } else if ('MalformedData' in schemaJson) { - match286 = { + match309 = { type: 'MalformedData', }; } else if ('WrongSignature' in schemaJson) { - match286 = { + match309 = { type: 'WrongSignature', }; } else if ('NonceMismatch' in schemaJson) { - match286 = { + match309 = { type: 'NonceMismatch', }; } else if ('WrongContract' in schemaJson) { - match286 = { + match309 = { type: 'WrongContract', }; } else if ('WrongEntryPoint' in schemaJson) { - match286 = { + match309 = { type: 'WrongEntryPoint', }; } else if ('Expired' in schemaJson) { - match286 = { + match309 = { type: 'Expired', }; + } else if ('UnSuccessful' in schemaJson) { + match309 = { + type: 'UnSuccessful', + }; } else { throw new Error("Unexpected enum variant"); } - return match286 + return match309 } /** Base64 encoding of the parameter schema type for update transactions to 'serializationHelper' entrypoint of the 'track_and_trace' contract. */ const base64SerializationHelperParameterSchema = 'FAAFAAAAEAAAAGNvbnRyYWN0X2FkZHJlc3MMBQAAAG5vbmNlBQkAAAB0aW1lc3RhbXANCwAAAGVudHJ5X3BvaW50FgEHAAAAcGF5bG9hZBABAg=='; @@ -2276,22 +2483,22 @@ export type SerializationHelperParameter = { * @returns {SerializationHelperParameterSchemaJson} The smart contract parameter JSON. */ function createSerializationHelperParameterSchemaJson(parameter: SerializationHelperParameter): SerializationHelperParameterSchemaJson { - const field303 = parameter.contract_address; - const contractAddress304 = SDK.ContractAddress.toSchemaValue(field303); - const field305 = parameter.nonce; - const number306 = BigInt(field305); - const field307 = parameter.timestamp; - const timestamp308 = SDK.Timestamp.toSchemaValue(field307); - const field309 = parameter.entry_point; - const field310 = parameter.payload; - const named302 = { - contract_address: contractAddress304, - nonce: number306, - timestamp: timestamp308, - entry_point: field309, - payload: field310, + const field327 = parameter.contract_address; + const contractAddress328 = SDK.ContractAddress.toSchemaValue(field327); + const field329 = parameter.nonce; + const number330 = BigInt(field329); + const field331 = parameter.timestamp; + const timestamp332 = SDK.Timestamp.toSchemaValue(field331); + const field333 = parameter.entry_point; + const field334 = parameter.payload; + const named326 = { + contract_address: contractAddress328, + nonce: number330, + timestamp: timestamp332, + entry_point: field333, + payload: field334, }; - return named302; + return named326; } /** @@ -2368,11 +2575,11 @@ export type NonceOfParameter = Array; * @returns {NonceOfParameterSchemaJson} The smart contract parameter JSON. */ function createNonceOfParameterSchemaJson(parameter: NonceOfParameter): NonceOfParameterSchemaJson { - const list313 = parameter.map((item314) => { - const accountAddress315 = SDK.AccountAddress.toSchemaValue(item314); - return accountAddress315; + const list337 = parameter.map((item338) => { + const accountAddress339 = SDK.AccountAddress.toSchemaValue(item338); + return accountAddress339; }); - return list313; + return list337; } /** @@ -2460,7 +2667,7 @@ export function parseReturnValueNonceOf(invokeResult: SDK.InvokeContractResult): } /** Error message for dry-running update transaction for 'nonceOf' entrypoint of the 'track_and_trace' contract. */ -export type ErrorMessageNonceOf = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; +export type ErrorMessageNonceOf = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; /** * Get and parse the error message from dry-running update transaction for 'nonceOf' entrypoint of the 'track_and_trace' contract. @@ -2477,73 +2684,541 @@ export function parseErrorMessageNonceOf(invokeResult: SDK.InvokeContractResult) throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); } - const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FQ8AAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQC'); - let match318: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'}; + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match342: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; + if ('ParseParams' in schemaJson) { + match342 = { + type: 'ParseParams', + }; + } else if ('LogFull' in schemaJson) { + match342 = { + type: 'LogFull', + }; + } else if ('LogMalformed' in schemaJson) { + match342 = { + type: 'LogMalformed', + }; + } else if ('Unauthorized' in schemaJson) { + match342 = { + type: 'Unauthorized', + }; + } else if ('ItemAlreadyExists' in schemaJson) { + match342 = { + type: 'ItemAlreadyExists', + }; + } else if ('ItemDoesNotExist' in schemaJson) { + match342 = { + type: 'ItemDoesNotExist', + }; + } else if ('FinalState' in schemaJson) { + match342 = { + type: 'FinalState', + }; + } else if ('NoContract' in schemaJson) { + match342 = { + type: 'NoContract', + }; + } else if ('MissingAccount' in schemaJson) { + match342 = { + type: 'MissingAccount', + }; + } else if ('MalformedData' in schemaJson) { + match342 = { + type: 'MalformedData', + }; + } else if ('WrongSignature' in schemaJson) { + match342 = { + type: 'WrongSignature', + }; + } else if ('NonceMismatch' in schemaJson) { + match342 = { + type: 'NonceMismatch', + }; + } else if ('WrongContract' in schemaJson) { + match342 = { + type: 'WrongContract', + }; + } else if ('WrongEntryPoint' in schemaJson) { + match342 = { + type: 'WrongEntryPoint', + }; + } else if ('Expired' in schemaJson) { + match342 = { + type: 'Expired', + }; + } else if ('UnSuccessful' in schemaJson) { + match342 = { + type: 'UnSuccessful', + }; + } + + else { + throw new Error("Unexpected enum variant"); + } + + return match342 +} +/** Base64 encoding of the parameter schema type for update transactions to 'hasRole' entrypoint of the 'track_and_trace' contract. */ +const base64HasRoleParameterSchema = 'FAACAAAABwAAAGFkZHJlc3MVAgAAAAcAAABBY2NvdW50AQEAAAALCAAAAENvbnRyYWN0AQEAAAAMBAAAAHJvbGUVAQAAAAUAAABBZG1pbgI='; +/** Parameter JSON type needed by the schema for update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. */ +type HasRoleParameterSchemaJson = { + address: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }, + role: {'Admin' : [] }, + }; +/** Parameter type for update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. */ +export type HasRoleParameter = { + address: { type: 'Account', content: SDK.AccountAddress.Type } | { type: 'Contract', content: SDK.ContractAddress.Type }, + role: { type: 'Admin'}, + }; + +/** + * Construct schema JSON representation used in update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. + * @param {HasRoleParameter} parameter The structured parameter to construct from. + * @returns {HasRoleParameterSchemaJson} The smart contract parameter JSON. + */ +function createHasRoleParameterSchemaJson(parameter: HasRoleParameter): HasRoleParameterSchemaJson { + const field360 = parameter.address; + let match361: {'Account' : [SDK.AccountAddress.SchemaValue] } | {'Contract' : [SDK.ContractAddress.SchemaValue] }; + switch (field360.type) { + case 'Account': + const accountAddress362 = SDK.AccountAddress.toSchemaValue(field360.content); + match361 = { Account: [accountAddress362], }; + break; + case 'Contract': + const contractAddress363 = SDK.ContractAddress.toSchemaValue(field360.content); + match361 = { Contract: [contractAddress363], }; + break; + } + + const field364 = parameter.role; + let match365: {'Admin' : [] }; + switch (field364.type) { + case 'Admin': + match365 = { Admin: [], }; + break; + } + + const named359 = { + address: match361, + role: match365, + }; + return named359; +} + +/** + * Construct Parameter type used in update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. + * @param {HasRoleParameter} parameter The structured parameter to construct from. + * @returns {SDK.Parameter.Type} The smart contract parameter. + */ +export function createHasRoleParameter(parameter: HasRoleParameter): SDK.Parameter.Type { + return SDK.Parameter.fromBase64SchemaType(base64HasRoleParameterSchema, createHasRoleParameterSchemaJson(parameter)); +} + +/** + * Construct WebWallet parameter type used in update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. + * @param {HasRoleParameter} parameter The structured parameter to construct from. + * @returns The smart contract parameter support by the WebWallet. + */ +export function createHasRoleParameterWebWallet(parameter: HasRoleParameter) { + return { + parameters: createHasRoleParameterSchemaJson(parameter), + schema: { + type: 'TypeSchema' as const, + value: SDK.toBuffer(base64HasRoleParameterSchema, 'base64') + }, + } +} + +/** + * Send an update-contract transaction to the 'hasRole' entrypoint of the 'track_and_trace' contract. + * @param {TrackAndTraceContract} contractClient The client for a 'track_and_trace' smart contract instance on chain. + * @param {SDK.ContractTransactionMetadata} transactionMetadata - Metadata related to constructing a transaction for a smart contract. + * @param {HasRoleParameter} parameter - Parameter to provide the smart contract entrypoint as part of the transaction. + * @param {SDK.AccountSigner} signer - The signer of the update contract transaction. + * @throws If the entrypoint is not successfully invoked. + * @returns {SDK.TransactionHash.Type} Hash of the transaction. + */ +export function sendHasRole(contractClient: TrackAndTraceContract, transactionMetadata: SDK.ContractTransactionMetadata, parameter: HasRoleParameter, signer: SDK.AccountSigner): Promise { + return contractClient.genericContract.createAndSendUpdateTransaction( + SDK.EntrypointName.fromStringUnchecked('hasRole'), + SDK.Parameter.toBuffer, + transactionMetadata, + createHasRoleParameter(parameter), + signer + ); +} + +/** + * Dry-run an update-contract transaction to the 'hasRole' entrypoint of the 'track_and_trace' contract. + * @param {TrackAndTraceContract} contractClient The client for a 'track_and_trace' smart contract instance on chain. + * @param {SDK.ContractAddress.Type | SDK.AccountAddress.Type} invokeMetadata - The address of the account or contract which is invoking this transaction. + * @param {HasRoleParameter} parameter - Parameter to provide the smart contract entrypoint as part of the transaction. + * @param {SDK.BlockHash.Type} [blockHash] - Optional block hash allowing for dry-running the transaction at the end of a specific block. + * @throws {SDK.RpcError} If failing to communicate with the concordium node or if any of the checks fails. + * @returns {SDK.InvokeContractResult} The result of invoking the smart contract instance. + */ +export function dryRunHasRole(contractClient: TrackAndTraceContract, parameter: HasRoleParameter, invokeMetadata: SDK.ContractInvokeMetadata = {}, blockHash?: SDK.BlockHash.Type): Promise { + return contractClient.genericContract.dryRun.invokeMethod( + SDK.EntrypointName.fromStringUnchecked('hasRole'), + invokeMetadata, + SDK.Parameter.toBuffer, + createHasRoleParameter(parameter), + blockHash + ); +} + +/** Return value for dry-running update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. */ +export type ReturnValueHasRole = boolean; + +/** + * Get and parse the return value from dry-running update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. + * Returns undefined if the result is not successful. + * @param {SDK.InvokeContractResult} invokeResult The result from dry-running the transaction. + * @returns {ReturnValueHasRole | undefined} The structured return value or undefined if result was not a success. + */ +export function parseReturnValueHasRole(invokeResult: SDK.InvokeContractResult): ReturnValueHasRole | undefined { + if (invokeResult.tag !== 'success') { + return undefined; + } + + if (invokeResult.returnValue === undefined) { + throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); + } + + const schemaJson = SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'AQ=='); + return schemaJson; +} + +/** Error message for dry-running update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. */ +export type ErrorMessageHasRole = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; + +/** + * Get and parse the error message from dry-running update transaction for 'hasRole' entrypoint of the 'track_and_trace' contract. + * Returns undefined if the result is not a failure. + * @param {SDK.InvokeContractResult} invokeResult The result from dry-running the transaction. + * @returns {ErrorMessageHasRole | undefined} The structured error message or undefined if result was not a failure or failed for other reason than contract rejectedReceive. + */ +export function parseErrorMessageHasRole(invokeResult: SDK.InvokeContractResult): ErrorMessageHasRole | undefined { + if (invokeResult.tag !== 'failure' || invokeResult.reason.tag !== 'RejectedReceive') { + return undefined; + } + + if (invokeResult.returnValue === undefined) { + throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); + } + + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match366: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; + if ('ParseParams' in schemaJson) { + match366 = { + type: 'ParseParams', + }; + } else if ('LogFull' in schemaJson) { + match366 = { + type: 'LogFull', + }; + } else if ('LogMalformed' in schemaJson) { + match366 = { + type: 'LogMalformed', + }; + } else if ('Unauthorized' in schemaJson) { + match366 = { + type: 'Unauthorized', + }; + } else if ('ItemAlreadyExists' in schemaJson) { + match366 = { + type: 'ItemAlreadyExists', + }; + } else if ('ItemDoesNotExist' in schemaJson) { + match366 = { + type: 'ItemDoesNotExist', + }; + } else if ('FinalState' in schemaJson) { + match366 = { + type: 'FinalState', + }; + } else if ('NoContract' in schemaJson) { + match366 = { + type: 'NoContract', + }; + } else if ('MissingAccount' in schemaJson) { + match366 = { + type: 'MissingAccount', + }; + } else if ('MalformedData' in schemaJson) { + match366 = { + type: 'MalformedData', + }; + } else if ('WrongSignature' in schemaJson) { + match366 = { + type: 'WrongSignature', + }; + } else if ('NonceMismatch' in schemaJson) { + match366 = { + type: 'NonceMismatch', + }; + } else if ('WrongContract' in schemaJson) { + match366 = { + type: 'WrongContract', + }; + } else if ('WrongEntryPoint' in schemaJson) { + match366 = { + type: 'WrongEntryPoint', + }; + } else if ('Expired' in schemaJson) { + match366 = { + type: 'Expired', + }; + } else if ('UnSuccessful' in schemaJson) { + match366 = { + type: 'UnSuccessful', + }; + } + + else { + throw new Error("Unexpected enum variant"); + } + + return match366 +} +/** Base64 encoding of the parameter schema type for update transactions to 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. */ +const base64IsTransitionEdgeParameterSchema = 'FAADAAAABwAAAGFjY291bnQLCwAAAGZyb21fc3RhdHVzFQQAAAAIAAAAUHJvZHVjZWQCCQAAAEluVHJhbnNpdAIHAAAASW5TdG9yZQIEAAAAU29sZAIJAAAAdG9fc3RhdHVzFQQAAAAIAAAAUHJvZHVjZWQCCQAAAEluVHJhbnNpdAIHAAAASW5TdG9yZQIEAAAAU29sZAI='; +/** Parameter JSON type needed by the schema for update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. */ +type IsTransitionEdgeParameterSchemaJson = { + account: SDK.AccountAddress.SchemaValue, + from_status: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }, + to_status: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }, + }; +/** Parameter type for update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. */ +export type IsTransitionEdgeParameter = { + account: SDK.AccountAddress.Type, + from_status: { type: 'Produced'} | { type: 'InTransit'} | { type: 'InStore'} | { type: 'Sold'}, + to_status: { type: 'Produced'} | { type: 'InTransit'} | { type: 'InStore'} | { type: 'Sold'}, + }; + +/** + * Construct schema JSON representation used in update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. + * @param {IsTransitionEdgeParameter} parameter The structured parameter to construct from. + * @returns {IsTransitionEdgeParameterSchemaJson} The smart contract parameter JSON. + */ +function createIsTransitionEdgeParameterSchemaJson(parameter: IsTransitionEdgeParameter): IsTransitionEdgeParameterSchemaJson { + const field384 = parameter.account; + const accountAddress385 = SDK.AccountAddress.toSchemaValue(field384); + const field386 = parameter.from_status; + let match387: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }; + switch (field386.type) { + case 'Produced': + match387 = { Produced: [], }; + break; + case 'InTransit': + match387 = { InTransit: [], }; + break; + case 'InStore': + match387 = { InStore: [], }; + break; + case 'Sold': + match387 = { Sold: [], }; + break; + } + + const field388 = parameter.to_status; + let match389: {'Produced' : [] } | {'InTransit' : [] } | {'InStore' : [] } | {'Sold' : [] }; + switch (field388.type) { + case 'Produced': + match389 = { Produced: [], }; + break; + case 'InTransit': + match389 = { InTransit: [], }; + break; + case 'InStore': + match389 = { InStore: [], }; + break; + case 'Sold': + match389 = { Sold: [], }; + break; + } + + const named383 = { + account: accountAddress385, + from_status: match387, + to_status: match389, + }; + return named383; +} + +/** + * Construct Parameter type used in update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. + * @param {IsTransitionEdgeParameter} parameter The structured parameter to construct from. + * @returns {SDK.Parameter.Type} The smart contract parameter. + */ +export function createIsTransitionEdgeParameter(parameter: IsTransitionEdgeParameter): SDK.Parameter.Type { + return SDK.Parameter.fromBase64SchemaType(base64IsTransitionEdgeParameterSchema, createIsTransitionEdgeParameterSchemaJson(parameter)); +} + +/** + * Construct WebWallet parameter type used in update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. + * @param {IsTransitionEdgeParameter} parameter The structured parameter to construct from. + * @returns The smart contract parameter support by the WebWallet. + */ +export function createIsTransitionEdgeParameterWebWallet(parameter: IsTransitionEdgeParameter) { + return { + parameters: createIsTransitionEdgeParameterSchemaJson(parameter), + schema: { + type: 'TypeSchema' as const, + value: SDK.toBuffer(base64IsTransitionEdgeParameterSchema, 'base64') + }, + } +} + +/** + * Send an update-contract transaction to the 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. + * @param {TrackAndTraceContract} contractClient The client for a 'track_and_trace' smart contract instance on chain. + * @param {SDK.ContractTransactionMetadata} transactionMetadata - Metadata related to constructing a transaction for a smart contract. + * @param {IsTransitionEdgeParameter} parameter - Parameter to provide the smart contract entrypoint as part of the transaction. + * @param {SDK.AccountSigner} signer - The signer of the update contract transaction. + * @throws If the entrypoint is not successfully invoked. + * @returns {SDK.TransactionHash.Type} Hash of the transaction. + */ +export function sendIsTransitionEdge(contractClient: TrackAndTraceContract, transactionMetadata: SDK.ContractTransactionMetadata, parameter: IsTransitionEdgeParameter, signer: SDK.AccountSigner): Promise { + return contractClient.genericContract.createAndSendUpdateTransaction( + SDK.EntrypointName.fromStringUnchecked('isTransitionEdge'), + SDK.Parameter.toBuffer, + transactionMetadata, + createIsTransitionEdgeParameter(parameter), + signer + ); +} + +/** + * Dry-run an update-contract transaction to the 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. + * @param {TrackAndTraceContract} contractClient The client for a 'track_and_trace' smart contract instance on chain. + * @param {SDK.ContractAddress.Type | SDK.AccountAddress.Type} invokeMetadata - The address of the account or contract which is invoking this transaction. + * @param {IsTransitionEdgeParameter} parameter - Parameter to provide the smart contract entrypoint as part of the transaction. + * @param {SDK.BlockHash.Type} [blockHash] - Optional block hash allowing for dry-running the transaction at the end of a specific block. + * @throws {SDK.RpcError} If failing to communicate with the concordium node or if any of the checks fails. + * @returns {SDK.InvokeContractResult} The result of invoking the smart contract instance. + */ +export function dryRunIsTransitionEdge(contractClient: TrackAndTraceContract, parameter: IsTransitionEdgeParameter, invokeMetadata: SDK.ContractInvokeMetadata = {}, blockHash?: SDK.BlockHash.Type): Promise { + return contractClient.genericContract.dryRun.invokeMethod( + SDK.EntrypointName.fromStringUnchecked('isTransitionEdge'), + invokeMetadata, + SDK.Parameter.toBuffer, + createIsTransitionEdgeParameter(parameter), + blockHash + ); +} + +/** Return value for dry-running update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. */ +export type ReturnValueIsTransitionEdge = boolean; + +/** + * Get and parse the return value from dry-running update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. + * Returns undefined if the result is not successful. + * @param {SDK.InvokeContractResult} invokeResult The result from dry-running the transaction. + * @returns {ReturnValueIsTransitionEdge | undefined} The structured return value or undefined if result was not a success. + */ +export function parseReturnValueIsTransitionEdge(invokeResult: SDK.InvokeContractResult): ReturnValueIsTransitionEdge | undefined { + if (invokeResult.tag !== 'success') { + return undefined; + } + + if (invokeResult.returnValue === undefined) { + throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); + } + + const schemaJson = SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'AQ=='); + return schemaJson; +} + +/** Error message for dry-running update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. */ +export type ErrorMessageIsTransitionEdge = { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; + +/** + * Get and parse the error message from dry-running update transaction for 'isTransitionEdge' entrypoint of the 'track_and_trace' contract. + * Returns undefined if the result is not a failure. + * @param {SDK.InvokeContractResult} invokeResult The result from dry-running the transaction. + * @returns {ErrorMessageIsTransitionEdge | undefined} The structured error message or undefined if result was not a failure or failed for other reason than contract rejectedReceive. + */ +export function parseErrorMessageIsTransitionEdge(invokeResult: SDK.InvokeContractResult): ErrorMessageIsTransitionEdge | undefined { + if (invokeResult.tag !== 'failure' || invokeResult.reason.tag !== 'RejectedReceive') { + return undefined; + } + + if (invokeResult.returnValue === undefined) { + throw new Error('Unexpected missing \'returnValue\' in result of invocation. Client expected a V1 smart contract.'); + } + + const schemaJson = <{'ParseParams' : [] } | {'LogFull' : [] } | {'LogMalformed' : [] } | {'Unauthorized' : [] } | {'ItemAlreadyExists' : [] } | {'ItemDoesNotExist' : [] } | {'FinalState' : [] } | {'NoContract' : [] } | {'MissingAccount' : [] } | {'MalformedData' : [] } | {'WrongSignature' : [] } | {'NonceMismatch' : [] } | {'WrongContract' : [] } | {'WrongEntryPoint' : [] } | {'Expired' : [] } | {'UnSuccessful' : [] }>SDK.ReturnValue.parseWithSchemaTypeBase64(invokeResult.returnValue, 'FRAAAAALAAAAUGFyc2VQYXJhbXMCBwAAAExvZ0Z1bGwCDAAAAExvZ01hbGZvcm1lZAIMAAAAVW5hdXRob3JpemVkAhEAAABJdGVtQWxyZWFkeUV4aXN0cwIQAAAASXRlbURvZXNOb3RFeGlzdAIKAAAARmluYWxTdGF0ZQIKAAAATm9Db250cmFjdAIOAAAATWlzc2luZ0FjY291bnQCDQAAAE1hbGZvcm1lZERhdGECDgAAAFdyb25nU2lnbmF0dXJlAg0AAABOb25jZU1pc21hdGNoAg0AAABXcm9uZ0NvbnRyYWN0Ag8AAABXcm9uZ0VudHJ5UG9pbnQCBwAAAEV4cGlyZWQCDAAAAFVuU3VjY2Vzc2Z1bAI='); + let match390: { type: 'ParseParams'} | { type: 'LogFull'} | { type: 'LogMalformed'} | { type: 'Unauthorized'} | { type: 'ItemAlreadyExists'} | { type: 'ItemDoesNotExist'} | { type: 'FinalState'} | { type: 'NoContract'} | { type: 'MissingAccount'} | { type: 'MalformedData'} | { type: 'WrongSignature'} | { type: 'NonceMismatch'} | { type: 'WrongContract'} | { type: 'WrongEntryPoint'} | { type: 'Expired'} | { type: 'UnSuccessful'}; if ('ParseParams' in schemaJson) { - match318 = { + match390 = { type: 'ParseParams', }; } else if ('LogFull' in schemaJson) { - match318 = { + match390 = { type: 'LogFull', }; } else if ('LogMalformed' in schemaJson) { - match318 = { + match390 = { type: 'LogMalformed', }; } else if ('Unauthorized' in schemaJson) { - match318 = { + match390 = { type: 'Unauthorized', }; } else if ('ItemAlreadyExists' in schemaJson) { - match318 = { + match390 = { type: 'ItemAlreadyExists', }; } else if ('ItemDoesNotExist' in schemaJson) { - match318 = { + match390 = { type: 'ItemDoesNotExist', }; } else if ('FinalState' in schemaJson) { - match318 = { + match390 = { type: 'FinalState', }; } else if ('NoContract' in schemaJson) { - match318 = { + match390 = { type: 'NoContract', }; } else if ('MissingAccount' in schemaJson) { - match318 = { + match390 = { type: 'MissingAccount', }; } else if ('MalformedData' in schemaJson) { - match318 = { + match390 = { type: 'MalformedData', }; } else if ('WrongSignature' in schemaJson) { - match318 = { + match390 = { type: 'WrongSignature', }; } else if ('NonceMismatch' in schemaJson) { - match318 = { + match390 = { type: 'NonceMismatch', }; } else if ('WrongContract' in schemaJson) { - match318 = { + match390 = { type: 'WrongContract', }; } else if ('WrongEntryPoint' in schemaJson) { - match318 = { + match390 = { type: 'WrongEntryPoint', }; } else if ('Expired' in schemaJson) { - match318 = { + match390 = { type: 'Expired', }; + } else if ('UnSuccessful' in schemaJson) { + match390 = { + type: 'UnSuccessful', + }; } else { throw new Error("Unexpected enum variant"); } - return match318 + return match390 } diff --git a/trackAndTrace/frontend/global.d.ts b/trackAndTrace/frontend/global.d.ts index a33ff82d..d4c48bb7 100644 --- a/trackAndTrace/frontend/global.d.ts +++ b/trackAndTrace/frontend/global.d.ts @@ -18,7 +18,7 @@ declare namespace NodeJS { /** * The configuration built into the application when served from the backend API */ -type Config = { +interface Config { /** The URL of the node. Must have grpc-web enabled. */ node: string; /** The contract address of the track and trace instance used. */ @@ -27,7 +27,7 @@ type Config = { network: TargetNetwork; /** The URL of the sponsored transaction backend API. */ sponsoredTransactionBackend: string; -}; +} /** The configuration built into the application when served from the backend API */ declare const CONFIG: Config; diff --git a/trackAndTrace/frontend/package.json b/trackAndTrace/frontend/package.json index b292557f..9af229dc 100644 --- a/trackAndTrace/frontend/package.json +++ b/trackAndTrace/frontend/package.json @@ -1,12 +1,12 @@ { "name": "track-and-trace-front-end", "private": true, - "version": "1.0.2", + "version": "1.1.0", "type": "module", "scripts": { "dev": "vite", "build": "tsc && vite build", - "lint": "eslint", + "lint": "eslint . --cache --max-warnings 0 --ext .ts,.tsx", "lint-fix": "yarn lint --fix", "fmt-check": "prettier --check .", "fmt": "prettier --write .", diff --git a/trackAndTrace/frontend/src/App.tsx b/trackAndTrace/frontend/src/App.tsx new file mode 100644 index 00000000..cda30f79 --- /dev/null +++ b/trackAndTrace/frontend/src/App.tsx @@ -0,0 +1,124 @@ +import { useEffect } from 'react'; +import { BrowserRouter as Router, Route, Routes, Link } from 'react-router-dom'; +import { Button } from 'react-bootstrap'; + +import { WalletConnectionProps, useConnection, useConnect } from '@concordium/react-components'; + +import './styles.scss'; +import { AdminCreateItem } from './components/AdminCreateItem'; +import { AdminChangeRoles } from './components/AdminChangeRoles'; +import { ChangeItemStatus } from './components/ChangeItemStatus'; +import { Explorer } from './components/Explorer'; +import { AddTransitionRule } from './components/AddTransitionRule'; +import * as constants from './constants'; +import { version } from '../package.json'; + +export const App = (props: WalletConnectionProps) => { + const { setActiveConnectorType, activeConnectorError, activeConnector, connectedAccounts, genesisHashes } = props; + + const { connection, setConnection, account } = useConnection(connectedAccounts, genesisHashes); + const { connect } = useConnect(activeConnector, setConnection); + + useEffect(() => { + setActiveConnectorType(constants.BROWSER_WALLET); + }, [setActiveConnectorType]); + + return ( + +
+ + + Explorer + + + Admin1 + + + Admin2 + + + Admin3 + + + Admin4 + + +
+ + + } /> + + } + /> + + } + /> + + } + /> + + } + /> + } /> + +
+ ); +}; diff --git a/trackAndTrace/frontend/src/components/AddTransitionRule.tsx b/trackAndTrace/frontend/src/components/AddTransitionRule.tsx new file mode 100644 index 00000000..ec987291 --- /dev/null +++ b/trackAndTrace/frontend/src/components/AddTransitionRule.tsx @@ -0,0 +1,180 @@ +import { useState } from 'react'; +import { Controller, useForm, useWatch } from 'react-hook-form'; +import { Alert, Button, Form } from 'react-bootstrap'; +import Select from 'react-select'; +import Switch from 'react-switch'; + +import { WalletConnection } from '@concordium/wallet-connectors'; +import { AccountAddress } from '@concordium/web-sdk'; + +import { TxHashLink } from './CCDScanLinks'; +import { updateStateMachine } from '../track_and_trace_contract'; +import * as TrackAndTraceContract from '../../generated/module_track_and_trace'; +import { validateAccountAddress } from '../utils'; + +interface Props { + connection: WalletConnection | undefined; + accountAddress: string | undefined; + activeConnectorError: string | undefined; +} + +const STATE_OPTIONS = [ + { label: 'Produced', value: 'Produced' }, + { label: 'InTransit', value: 'InTransit' }, + { label: 'InStore', value: 'InStore' }, + { label: 'Sold', value: 'Sold' }, +]; + +export function AddTransitionRule(props: Props) { + const { connection, accountAddress, activeConnectorError } = props; + + interface FormType { + address: string | undefined; + fromStatus: 'Produced' | 'InTransit' | 'InStore' | 'Sold' | undefined; + toStatus: 'Produced' | 'InTransit' | 'InStore' | 'Sold' | undefined; + isUpdateAdd: boolean; + } + const { control, register, formState, handleSubmit } = useForm({ mode: 'all' }); + + const [isUpdateAdd, fromStatus, toStatus, address] = useWatch({ + control: control, + name: ['isUpdateAdd', 'fromStatus', 'toStatus', 'address'], + defaultValue: { isUpdateAdd: true }, + }); + + const [txHash, setTxHash] = useState(undefined); + const [error, setError] = useState(undefined); + + function onSubmit() { + setError(undefined); + + if (address === undefined) { + setError(`'address' input field is undefined`); + throw Error(`'address' input field is undefined`); + } + + if (fromStatus === undefined) { + setError(`'from_status' input field is undefined`); + throw Error(`'from_status' input field is undefined`); + } + + if (toStatus === undefined) { + setError(`'to_status' input field is undefined`); + throw Error(`'to_status' input field is undefined`); + } + + const parameter: TrackAndTraceContract.UpdateStateMachineParameter = { + address: AccountAddress.fromBase58(address), + to_status: { type: toStatus }, + from_status: { type: fromStatus }, + update: { type: isUpdateAdd ? 'Add' : 'Remove' }, + }; + + // Send transaction + if (accountAddress && connection) { + updateStateMachine(connection, AccountAddress.fromBase58(accountAddress), parameter) + .then((txHash: string) => { + setTxHash(txHash); + }) + .catch((e) => { + setError((e as Error).message); + }); + } else { + setError(`Wallet is not connected. Click 'Connect Wallet' button.`); + } + } + + return ( +
+
+

Change Transition Rule

+
+
+ + Add + ( + { + onChange(!value); + }} + onColor="#808080" + checked={!value} + checkedIcon={false} + uncheckedIcon={false} + /> + )} + /> + Remove + + + + From Status + ( + option.value} + options={STATE_OPTIONS} + onChange={(e) => { + onChange(e?.value); + }} + /> + )} + /> + + + + Address + + {formState.errors.address && ( + Address is required. {formState.errors.address.message} + )} + + + +
+ + {error && {error}} + {activeConnectorError && ( + + Connect Error: {activeConnectorError}. Refresh page if you have the browser wallet installed. + + )} + {txHash && ( + + + + )} +
+
+ ); +} diff --git a/trackAndTrace/frontend/src/components/AdminChangeRoles.tsx b/trackAndTrace/frontend/src/components/AdminChangeRoles.tsx index 4f3a90c4..74d3b5a4 100644 --- a/trackAndTrace/frontend/src/components/AdminChangeRoles.tsx +++ b/trackAndTrace/frontend/src/components/AdminChangeRoles.tsx @@ -1,7 +1,6 @@ import { useState } from 'react'; import { Controller, useForm, useWatch } from 'react-hook-form'; import { Alert, Button, Form } from 'react-bootstrap'; -import Select from 'react-select'; import Switch from 'react-switch'; import { WalletConnection } from '@concordium/wallet-connectors'; @@ -18,26 +17,19 @@ interface Props { activeConnectorError: string | undefined; } -const ROLE_OPTIONS = [ - { label: 'Admin', value: 'Admin' }, - { label: 'Producer', value: 'Producer' }, - { label: 'Transporter', value: 'Transporter' }, - { label: 'Seller', value: 'Seller' }, -]; - export function AdminChangeRoles(props: Props) { const { connection, accountAddress, activeConnectorError } = props; - type FormType = { + interface FormType { address: string | undefined; - role: 'Admin' | 'Producer' | 'Transporter' | 'Seller' | undefined; - toggle: boolean; - }; + addAdmin: boolean; + } const { control, register, formState, handleSubmit } = useForm({ mode: 'all' }); - const [toggle, role, address] = useWatch({ + const [addAdmin, address] = useWatch({ control: control, - name: ['toggle', 'role', 'address'], + name: ['addAdmin', 'address'], + defaultValue: { addAdmin: true }, }); const [txHash, setTxHash] = useState(undefined); @@ -51,85 +43,60 @@ export function AdminChangeRoles(props: Props) { throw Error(`'address' input field is undefined`); } - if (role === undefined) { - setError(`'role' input field is undefined`); - throw Error(`'role' input field is undefined`); - } - - if (toggle) { - const parameter: TrackAndTraceContract.GrantRoleParameter = { - address: { type: 'Account', content: AccountAddress.fromBase58(address) }, - role: { type: role }, - }; + const parameter: TrackAndTraceContract.RevokeRoleParameter = { + address: { type: 'Account', content: AccountAddress.fromBase58(address) }, + role: { type: 'Admin' }, + }; + if (accountAddress && connection) { // Send transaction - if (accountAddress && connection) { - addRole(connection, AccountAddress.fromBase58(accountAddress), parameter).then((txHash: string) => { - setTxHash(txHash); - }); + if (addAdmin) { + addRole(connection, AccountAddress.fromBase58(accountAddress), parameter) + .then((txHash: string) => { + setTxHash(txHash); + }) + .catch((e) => { + setError((e as Error).message); + }); } else { - setError(`Wallet is not connected. Click 'Connect Wallet' button.`); + removeRole(connection, AccountAddress.fromBase58(accountAddress), parameter) + .then((txHash: string) => { + setTxHash(txHash); + }) + .catch((e) => { + setError((e as Error).message); + }); } } else { - const parameter: TrackAndTraceContract.RevokeRoleParameter = { - address: { type: 'Account', content: AccountAddress.fromBase58(address) }, - role: { type: role }, - }; - - // Send transaction - if (accountAddress && connection) { - removeRole(connection, AccountAddress.fromBase58(accountAddress), parameter).then((txHash: string) => { - setTxHash(txHash); - }); - } else { - setError(`Wallet is not connected. Click 'Connect Wallet' button.`); - } + setError(`Wallet is not connected. Click 'Connect Wallet' button.`); } } return (
-

Change The Role Of An Address

+

Change Admin Role of an Address


- Add role + Add ( + defaultValue={true} + render={({ field: { onChange, value } }) => ( { - onChange(!toggle); + onChange(!value); }} onColor="#808080" - checked={!toggle} + checked={!value} checkedIcon={false} uncheckedIcon={false} /> )} /> - Remove old role - - - - Role - ( -