From e7d0f7a5a899073560a0e927dd598849d6975f61 Mon Sep 17 00:00:00 2001 From: Doris Benda Date: Thu, 4 Apr 2024 15:59:51 +0300 Subject: [PATCH 1/8] Add removing and adding of transition edges --- trackAndTrace/smart-contract/src/lib.rs | 172 +++++++++++++- trackAndTrace/smart-contract/tests/tests.rs | 242 ++++++++++++++------ 2 files changed, 330 insertions(+), 84 deletions(-) diff --git a/trackAndTrace/smart-contract/src/lib.rs b/trackAndTrace/smart-contract/src/lib.rs index fb1492a7..3b6cb1b2 100644 --- a/trackAndTrace/smart-contract/src/lib.rs +++ b/trackAndTrace/smart-contract/src/lib.rs @@ -2,18 +2,15 @@ //! //! ## Grant and Revoke roles: //! The contract has access control roles. The available roles are Admin (can -//! grant/revoke roles, create a new item), Producer, Transporter, and Seller. -//! The state machine defines which roles are authorized to update an item given -//! its current status. Several addresses can have the same role and an address -//! can have several roles. +//! grant/revoke roles, create a new item). //! //! ## State machine: //! The track-and-trace contract is modeled based on a state machine. The state //! machine is initialized when the contract is initialized. The flow of the //! state machine is as follows: The Admin creates a new item with status //! `Produced`. Each new item is assigned the `next_item_id`. The `next_item_id` -//! value is sequentially increased by 1 in the contract's state. The different -//! roles can update the item's status based on the rules of the state machine. +//! value is sequentially increased by 1 in the contract's state. The item's +//! status can be updated based on the rules of the state machine. //! //! For example to initialize the state machine with a linear supply chain use //! the following input parameter when the contract is initialized: @@ -151,12 +148,6 @@ struct AddressRoleState { pub enum Roles { /// Admin role. Admin, - /// Producer role. - Producer, - /// Transporter role. - Transporter, - /// Seller role. - Seller, } /// Enum of the statuses that an item can have. @@ -247,6 +238,8 @@ pub enum CustomContractError { WrongEntryPoint, // -14 /// Failed signature verification: Signature is expired. Expired, // -15 + /// Update of state machine was unsuccessful. + UnSuccessful, // -16 } /// Mapping account signature error to CustomContractError @@ -326,6 +319,24 @@ impl State { targets.insert(to) } + /// Remove a transition. Return if the transition was removed successfully. + pub fn remove( + &mut self, + builder: &mut StateBuilder, + from: Status, + address: AccountAddress, + to: Status, + ) -> bool { + let mut transition = self + .transitions + .entry(from) + .or_insert_with(|| StatusTransitions { + transitions: builder.new_map(), + }); + let mut targets = transition.targets(builder, address); + targets.remove(&to) + } + /// Get the item and the possible state transitions for that item in its /// current state. pub fn get_item_and_transitions( @@ -636,6 +647,84 @@ fn change_item_status( Ok(()) } +/// The update of a state transition. +#[derive(Debug, Serialize, Clone, Copy, SchemaType, PartialEq, Eq)] +pub enum Update { + /// Remove a state transition. + Remove, + /// Add a state transition. + Add, +} + +/// The parameter for the contract function `updateStateMachine` which updates +/// the state machine. +#[derive(Serialize, SchemaType)] +pub struct UpdateStateMachineParams { + /// The address that is involved in the state transition. + pub address: AccountAddress, + /// The from state of the state transition. + pub from_status: Status, + /// The to state of the state transition. + pub to_status: Status, + /// The update (remove or add). + pub update: Update, +} + +/// Update the state machine by adding or removing a transition. +/// +/// It rejects if: +/// - It fails to parse the parameter. +/// - The sender is not the Admin of the contract instance. +/// - The state machine cannot be updated with the given state transition. +#[receive( + contract = "track_and_trace", + name = "updateStateMachine", + parameter = "UpdateStateMachineParams", + error = "CustomContractError", + mutable +)] +fn contract_update_state_machine( + ctx: &ReceiveContext, + host: &mut Host, +) -> ContractResult<()> { + // Parse the parameter. + let params: UpdateStateMachineParams = ctx.parameter_cursor().get()?; + + let (state, state_builder) = host.state_and_builder(); + + // Get the sender who invoked this contract function. + let sender = ctx.sender(); + // Check that only the Admin is authorized to update the state machine. + ensure!( + state.has_role(&sender, Roles::Admin), + CustomContractError::Unauthorized + ); + + match params.update { + Update::Add => { + let success = state.add( + state_builder, + params.from_status, + params.address, + params.to_status, + ); + ensure!(success, CustomContractError::UnSuccessful); + } + Update::Remove => { + let success = state.remove( + state_builder, + params.from_status, + params.address, + params.to_status, + ); + + ensure!(success, CustomContractError::UnSuccessful); + } + }; + + Ok(()) +} + /// The parameter for the contract function `grantRole` which grants a role to /// an address. #[derive(Serialize, SchemaType)] @@ -679,6 +768,7 @@ fn contract_grant_role( // Grant role. state.grant_role(¶ms.address, params.role, state_builder); + // Log a GrantRoleEvent. logger.log(&Event::::GrantRole(GrantRoleEvent { address: params.address, @@ -1016,3 +1106,61 @@ fn contract_nonce_of( } Ok(NonceOfQueryResponse::from(response)) } + +/// The parameter for the `hasRole` function. +#[derive(Debug, Serialize, Clone, Copy, SchemaType, PartialEq, Eq)] +pub struct HasRoleParams { + /// The address to be checked. + pub address: Address, + /// The role to check for. + pub role: Roles, +} + +/// Check if an address has a specific role. +/// +/// It rejects if: +/// - It fails to parse the parameter. +#[receive( + contract = "track_and_trace", + name = "hasRole", + parameter = "HasRoleParams", + return_value = "bool", + error = "CustomContractError" +)] +fn has_role(ctx: &ReceiveContext, host: &Host) -> ContractResult { + // Parse the parameter. + let params: HasRoleParams = ctx.parameter_cursor().get()?; + Ok(host.state().has_role(¶ms.address, params.role)) +} + +/// The parameter for the `isTransitionEdge` function. +#[derive(Debug, Serialize, Clone, Copy, SchemaType, PartialEq, Eq)] +pub struct IsTransitionEdgeParams { + /// The account to be checked. + pub account: AccountAddress, + /// The from_status to check for. + pub from_status: Status, + /// The to_status to check for. + pub to_status: Status, +} + +/// Check if a transition edge exists in the state machine. +/// +/// It rejects if: +/// - It fails to parse the parameter. +#[receive( + contract = "track_and_trace", + name = "isTransitionEdge", + parameter = "IsTransitionEdgeParams", + return_value = "bool", + error = "CustomContractError" +)] +fn is_transition_edge(ctx: &ReceiveContext, host: &Host) -> ContractResult { + // Parse the parameter. + let params: IsTransitionEdgeParams = ctx.parameter_cursor().get()?; + + let Some(transitions) = host.state().transitions.get(¶ms.from_status) else { + return Ok(false); + }; + Ok(transitions.check(¶ms.account, ¶ms.to_status)) +} diff --git a/trackAndTrace/smart-contract/tests/tests.rs b/trackAndTrace/smart-contract/tests/tests.rs index 34643ead..d752bae5 100644 --- a/trackAndTrace/smart-contract/tests/tests.rs +++ b/trackAndTrace/smart-contract/tests/tests.rs @@ -13,9 +13,9 @@ const ADMIN_ADDR: Address = Address::Account(AccountAddress([0; 32])); const PRODUCER: AccountAddress = AccountAddress([1; 32]); const PRODUCER_ADDR: Address = Address::Account(AccountAddress([1; 32])); const TRANSPORTER: AccountAddress = AccountAddress([2; 32]); -const TRANSPORTER_ADDR: Address = Address::Account(AccountAddress([2; 32])); const SELLER: AccountAddress = AccountAddress([3; 32]); const SELLER_ADDR: Address = Address::Account(AccountAddress([3; 32])); +const NEW_ADDR: AccountAddress = AccountAddress([4; 32]); const SIGNER: Signer = Signer::with_one_key(); const ACC_INITIAL_BALANCE: Amount = Amount::from_ccd(10000); @@ -31,6 +31,174 @@ struct AccountKeypairs { producer: AccountKeys, } +/// Test that the `hasRole` view function works. +#[test] +fn test_has_role() { + let (chain, _, track_and_trace_contract_address) = initialize_chain_and_contract(); + + let param = HasRoleParams { + address: ADMIN_ADDR, + role: Roles::Admin, + }; + + let invoke = chain + .contract_invoke( + ADMIN, + ADMIN_ADDR, + Energy::from(10000), + UpdateContractPayload { + amount: Amount::zero(), + receive_name: OwnedReceiveName::new_unchecked( + "track_and_trace.hasRole".to_string(), + ), + address: track_and_trace_contract_address, + message: OwnedParameter::from_serial(¶m).expect("Serialize parameter"), + }, + ) + .expect("Invoke hasRole"); + + let has_role: bool = invoke.parse_return_value().expect("hasRole return value"); + + assert_eq!(has_role, true, "Admin should have role"); +} + +/// Test adding and removing state transition edges. +#[test] +fn test_add_and_remove_of_state_transition_edges() { + let (mut chain, _, track_and_trace_contract_address) = initialize_chain_and_contract(); + + let from_status = Status::InStore; + let to_status = Status::Sold; + let new_address = NEW_ADDR; + + let param = IsTransitionEdgeParams { + account: new_address, + from_status, + to_status, + }; + + let invoke = chain + .contract_invoke( + ADMIN, + ADMIN_ADDR, + Energy::from(10000), + UpdateContractPayload { + amount: Amount::zero(), + receive_name: OwnedReceiveName::new_unchecked( + "track_and_trace.isTransitionEdge".to_string(), + ), + address: track_and_trace_contract_address, + message: OwnedParameter::from_serial(¶m).expect("Serialize parameter"), + }, + ) + .expect("Invoke isTransitionEdge"); + + let is_transition_edge: bool = invoke + .parse_return_value() + .expect("isTransitionEdge return value"); + + assert_eq!( + is_transition_edge, false, + "Transition edge should not exist" + ); + + // Add a new transition edge. + let mut update_transition_edge = UpdateStateMachineParams { + address: NEW_ADDR, + from_status, + to_status, + update: Update::Add, + }; + + // Check the ADMIN can update the state machine (add transition). + let _update = chain + .contract_update( + SIGNER, + ADMIN, + ADMIN_ADDR, + Energy::from(10000), + UpdateContractPayload { + amount: Amount::from_ccd(0), + address: track_and_trace_contract_address, + receive_name: OwnedReceiveName::new_unchecked( + "track_and_trace.updateStateMachine".to_string(), + ), + message: OwnedParameter::from_serial(&update_transition_edge) + .expect("Serialize parameter"), + }, + ) + .expect("Should be able to update the state machine"); + + let invoke = chain + .contract_invoke( + ADMIN, + ADMIN_ADDR, + Energy::from(10000), + UpdateContractPayload { + amount: Amount::zero(), + receive_name: OwnedReceiveName::new_unchecked( + "track_and_trace.isTransitionEdge".to_string(), + ), + address: track_and_trace_contract_address, + message: OwnedParameter::from_serial(¶m).expect("Serialize parameter"), + }, + ) + .expect("Invoke isTransitionEdge"); + + let is_transition_edge: bool = invoke + .parse_return_value() + .expect("isTransitionEdge return value"); + + assert_eq!(is_transition_edge, true, "Transition edge should exist"); + + // Remove a transition edge. + update_transition_edge.update = Update::Remove; + + // Check the ADMIN can update the state machine (remove transition). + let _update = chain + .contract_update( + SIGNER, + ADMIN, + ADMIN_ADDR, + Energy::from(10000), + UpdateContractPayload { + amount: Amount::from_ccd(0), + address: track_and_trace_contract_address, + receive_name: OwnedReceiveName::new_unchecked( + "track_and_trace.updateStateMachine".to_string(), + ), + message: OwnedParameter::from_serial(&update_transition_edge) + .expect("Serialize parameter"), + }, + ) + .expect("Should be able to update the state machine"); + + let invoke = chain + .contract_invoke( + ADMIN, + ADMIN_ADDR, + Energy::from(10000), + UpdateContractPayload { + amount: Amount::zero(), + receive_name: OwnedReceiveName::new_unchecked( + "track_and_trace.isTransitionEdge".to_string(), + ), + address: track_and_trace_contract_address, + message: OwnedParameter::from_serial(¶m).expect("Serialize parameter"), + }, + ) + .expect("Invoke isTransitionEdge"); + + let is_transition_edge: bool = invoke + .parse_return_value() + .expect("isTransitionEdge return value"); + + assert_eq!( + is_transition_edge, false, + "Transition edge should not exist" + ); +} + // 1. Test that the ADMIN can create a new item. // 2. Test that the PRODUCER can update the item status to `InTransit`. // 3. Test that the SELLER can NOT update the item status to `InStore`. @@ -296,6 +464,7 @@ fn initialize_chain_and_contract() -> (Chain, AccountKeypairs, ContractAddress) let seller_keys = AccountKeys::singleton(&mut rng); // Create some accounts on the chain. + chain.create_account(Account::new(NEW_ADDR, ACC_INITIAL_BALANCE)); chain.create_account(Account::new_with_keys(ADMIN, balance, (&admin_keys).into())); chain.create_account(Account::new_with_keys( PRODUCER, @@ -372,77 +541,6 @@ fn initialize_chain_and_contract() -> (Chain, AccountKeypairs, ContractAddress) }) .expect("Initialize track_and_trace contract"); - // Grant PRODUCER role - let grant_role_params = GrantRoleParams { - address: PRODUCER_ADDR, - role: Roles::Producer, - }; - - let _update = chain - .contract_update( - SIGNER, - ADMIN, - ADMIN_ADDR, - Energy::from(10000), - UpdateContractPayload { - amount: Amount::zero(), - receive_name: OwnedReceiveName::new_unchecked( - "track_and_trace.grantRole".to_string(), - ), - address: track_and_trace.contract_address, - message: OwnedParameter::from_serial(&grant_role_params) - .expect("GrantRole params"), - }, - ) - .expect("PRODUCER should be granted role"); - - // Grant TRANSPORTER role - let grant_role_params = GrantRoleParams { - address: TRANSPORTER_ADDR, - role: Roles::Transporter, - }; - - let _update = chain - .contract_update( - SIGNER, - ADMIN, - ADMIN_ADDR, - Energy::from(10000), - UpdateContractPayload { - amount: Amount::zero(), - receive_name: OwnedReceiveName::new_unchecked( - "track_and_trace.grantRole".to_string(), - ), - address: track_and_trace.contract_address, - message: OwnedParameter::from_serial(&grant_role_params) - .expect("GrantRole params"), - }, - ) - .expect("TRANSPORTER should be granted role"); - - // Grant SELLER role - let grant_role_params = GrantRoleParams { - address: SELLER_ADDR, - role: Roles::Seller, - }; - - let _update = chain - .contract_update( - SIGNER, - ADMIN, - ADMIN_ADDR, - Energy::from(10000), - UpdateContractPayload { - amount: Amount::zero(), - receive_name: OwnedReceiveName::new_unchecked( - "track_and_trace.grantRole".to_string(), - ), - address: track_and_trace.contract_address, - message: OwnedParameter::from_serial(&grant_role_params) - .expect("GrantRole params"), - }, - ) - .expect("SELLER should be granted role"); (chain, account_keypairs, track_and_trace.contract_address) } From 3446fd3f673829ca3b350ae8019d09d591302504 Mon Sep 17 00:00:00 2001 From: Doris Benda Date: Thu, 4 Apr 2024 20:46:45 +0300 Subject: [PATCH 2/8] Add version to front end --- sponsoredTransactionsAuction/frontend/README.md | 2 +- trackAndTrace/README.md | 6 ++++++ trackAndTrace/frontend/src/main.tsx | 15 +++++++++++++-- trackAndTrace/frontend/vite.config.ts | 11 ++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/sponsoredTransactionsAuction/frontend/README.md b/sponsoredTransactionsAuction/frontend/README.md index 877ac15c..391000e0 100644 --- a/sponsoredTransactionsAuction/frontend/README.md +++ b/sponsoredTransactionsAuction/frontend/README.md @@ -23,7 +23,7 @@ The smart contract code at {index: AUCTION_CONTRACT_INDEX, subindex: 0} can be f - Run `yarn install` in a terminal in this folder. - Run `yarn build` in a terminal in this folder. -- Run `yarn dev` in a terminal in this folder. +- Run `TRACK_AND_TRACE_CONTRACT_ADDRESS="<8219,0>" yarn dev` in a terminal in this folder. - Open URL logged in console (typically http://127.0.0.1:5173). Hot-reload (useful for development) is enabled. diff --git a/trackAndTrace/README.md b/trackAndTrace/README.md index 32c7e5e8..826f1517 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. diff --git a/trackAndTrace/frontend/src/main.tsx b/trackAndTrace/frontend/src/main.tsx index 0875600b..24d641bc 100644 --- a/trackAndTrace/frontend/src/main.tsx +++ b/trackAndTrace/frontend/src/main.tsx @@ -11,6 +11,7 @@ import { AdminChangeRoles } from './components/AdminChangeRoles'; import { ChangeItemStatus } from './components/ChangeItemStatus'; import { Explorer } from './components/Explorer'; import * as constants from './constants'; +import { version } from '../package.json'; const App = (props: WalletConnectionProps) => { const { setActiveConnectorType, activeConnectorError, activeConnector, connectedAccounts, genesisHashes } = props; @@ -26,13 +27,23 @@ const App = (props: WalletConnectionProps) => {
diff --git a/trackAndTrace/frontend/vite.config.ts b/trackAndTrace/frontend/vite.config.ts index 50125531..bf11685b 100644 --- a/trackAndTrace/frontend/vite.config.ts +++ b/trackAndTrace/frontend/vite.config.ts @@ -33,7 +33,7 @@ function validateURL(envField: string, allowUnset = true): void { } } -function getConfig(): Config { +function getConfig() { // Validate network if (![undefined, 'mainnet', 'testnet'].includes(process.env.TRACK_AND_TRACE_NETWORK)) { throw new Error( @@ -84,6 +84,15 @@ const viteConfig: UserConfig = { stream: 'rollup-plugin-node-polyfills/polyfills/stream', }, }, + define: { + global: 'globalThis', + 'process.env': { + TRACK_AND_TRACE_NETWORK: process.env.TRACK_AND_TRACE_NETWORK, + TRACK_AND_TRACE_SPONSORED_BACKEND_API: process.env.TRACK_AND_TRACE_SPONSORED_BACKEND_API, + TRACK_AND_TRACE_NODE: process.env.TRACK_AND_TRACE_NODE, + TRACK_AND_TRACE_CONTRACT_ADDRESS: process.env.TRACK_AND_TRACE_CONTRACT_ADDRESS, + }, + }, }; // https://vitejs.dev/config/ From 59a9b9958fe5b504a66280bfffd95be10f65b222 Mon Sep 17 00:00:00 2001 From: Doris Benda Date: Fri, 5 Apr 2024 16:15:18 +0300 Subject: [PATCH 3/8] Add tab for updating the state machine --- trackAndTrace/frontend/generated/module.ts | 12 +- .../generated/module_track_and_trace.ts | 1597 ++++++++++++----- .../src/components/AddTransitionRule.tsx | 179 ++ .../src/components/AdminChangeRoles.tsx | 80 +- .../src/components/AdminCreateItem.tsx | 10 +- .../frontend/src/components/Explorer.tsx | 10 +- trackAndTrace/frontend/src/main.tsx | 14 + trackAndTrace/frontend/src/styles.scss | 2 +- .../frontend/src/track_and_trace_contract.tsx | 59 + trackAndTrace/frontend/vite.config.ts | 2 +- 10 files changed, 1433 insertions(+), 532 deletions(-) create mode 100644 trackAndTrace/frontend/src/components/AddTransitionRule.tsx 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/src/components/AddTransitionRule.tsx b/trackAndTrace/frontend/src/components/AddTransitionRule.tsx new file mode 100644 index 00000000..d5725b6a --- /dev/null +++ b/trackAndTrace/frontend/src/components/AddTransitionRule.tsx @@ -0,0 +1,179 @@ +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; + + type 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'], + }); + + 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(!isUpdateAdd); + }} + onColor="#808080" + checked={!isUpdateAdd} + 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..929f35fb 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,18 @@ 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 = { address: string | undefined; - role: 'Admin' | 'Producer' | 'Transporter' | 'Seller' | undefined; toggle: boolean; }; const { control, register, formState, handleSubmit } = useForm({ mode: 'all' }); - const [toggle, role, address] = useWatch({ + const [toggle, address] = useWatch({ control: control, - name: ['toggle', 'role', 'address'], + name: ['toggle', 'address'], }); const [txHash, setTxHash] = useState(undefined); @@ -51,36 +42,33 @@ 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`); - } + const parameter: TrackAndTraceContract.RevokeRoleParameter = { + address: { type: 'Account', content: AccountAddress.fromBase58(address) }, + role: { type: 'Admin' }, + }; + // Send transaction if (toggle) { - const parameter: TrackAndTraceContract.GrantRoleParameter = { - address: { type: 'Account', content: AccountAddress.fromBase58(address) }, - role: { type: role }, - }; - - // Send transaction if (accountAddress && connection) { - addRole(connection, AccountAddress.fromBase58(accountAddress), parameter).then((txHash: string) => { - setTxHash(txHash); - }); + 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.`); } } 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); - }); + removeRole(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.`); } @@ -90,11 +78,11 @@ export function AdminChangeRoles(props: Props) { return (
-

Change The Role Of An Address

+

Change Admin Role of an Address


- Add role + Add )} /> - Remove old role - - - - Role - ( -