diff --git a/.husky/pre-commit b/.husky/pre-commit index 7f800e3..039841a 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -3,6 +3,4 @@ set -e -npm run fmt:sol - -git add -A +npx lint-staged diff --git a/.lintstagedrc.json b/.lintstagedrc.json new file mode 100644 index 0000000..07f03fc --- /dev/null +++ b/.lintstagedrc.json @@ -0,0 +1,3 @@ +{ + "*.sol": ["npm run fmt:sol"] +} diff --git a/package.json b/package.json index 6ca2334..7f7261f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "postinstall": "husky && forge build", "clean": "rm -rf build", "test": "forge test -vvv", - "lint:sol": "solhint -f table 'src/**/*.sol' 'test/**/*.sol' 'script/**/*.sol'", + "lint:sol": "solhint -f table --max-warnings 0 'src/**/*.sol' 'test/**/*.sol' 'script/**/*.sol'", "fmt:sol": "forge fmt", "coverage:sol": "forge coverage --report lcov" }, diff --git a/proto/cross/core/initiator/Initiator.proto b/proto/cross/core/initiator/Initiator.proto new file mode 100644 index 0000000..15d0b0a --- /dev/null +++ b/proto/cross/core/initiator/Initiator.proto @@ -0,0 +1,77 @@ +syntax = "proto3"; + +import "google/protobuf/any.proto"; +import "gogoproto/gogo.proto"; +import "ibc/core/client/v1/client.proto"; +import "cross/core/tx/Tx.proto"; +import "cross/core/auth/Auth.proto"; + +option go_package = "github.com/datachainlab/cross/x/core/initiator/types"; +option (gogoproto.goproto_getters_all) = false; + +message MsgInitiateTx { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string chain_id = 1; + uint64 nonce = 2; + + Tx.CommitProtocol commit_protocol = 3; + + repeated ContractTransaction contract_transactions = 4 [(gogoproto.nullable) = false]; + + repeated Account signers = 5 [(gogoproto.nullable) = false]; + + ibc.core.client.v1.Height timeout_height = 6 + [(gogoproto.moretags) = "yaml:\"timeout_height\"", (gogoproto.nullable) = false]; + + uint64 timeout_timestamp = 7 + [(gogoproto.moretags) = "yaml:\"timeout_timestamp\""]; +} + +message MsgInitiateTxResponse { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + bytes txID = 1 [(gogoproto.casttype) = "github.com/datachainlab/cross/x/core/types.TxID"]; + + enum InitiateTxStatus { + option (gogoproto.goproto_enum_prefix) = false; + + INITIATE_TX_STATUS_UNKNOWN = 0; + INITIATE_TX_STATUS_PENDING = 1; + INITIATE_TX_STATUS_VERIFIED = 2; + } + + InitiateTxStatus status = 2; +} + +message QuerySelfXCCRequest {} + +message QuerySelfXCCResponse { + google.protobuf.Any xcc = 1 [(gogoproto.nullable) = true]; +} + +message ContractTransaction { + option (gogoproto.equal) = false; + + google.protobuf.Any cross_chain_channel = 1 [(gogoproto.nullable) = true]; + repeated Account signers = 2 [(gogoproto.nullable) = false]; + bytes call_info = 3 [(gogoproto.casttype) = "github.com/datachainlab/cross/x/core/tx/types.ContractCallInfo"]; + ReturnValue return_value = 4; + repeated Link links = 5 [(gogoproto.nullable) = false]; +} + +message Link { + uint32 src_index = 1; +} + +message GenesisState {} + +message InitiateTxState { + option (gogoproto.equal) = false; + + MsgInitiateTxResponse.InitiateTxStatus status = 1; + + MsgInitiateTx msg = 2 [(gogoproto.nullable) = false]; +} diff --git a/proto/cross/core/tx/Tx.proto b/proto/cross/core/tx/Tx.proto new file mode 100644 index 0000000..cfb2aeb --- /dev/null +++ b/proto/cross/core/tx/Tx.proto @@ -0,0 +1,58 @@ +syntax = "proto3"; + +import "gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; +import "ibc/core/client/v1/client.proto"; +import "cross/core/auth/Auth.proto"; + +option go_package = "github.com/datachainlab/cross/x/core/tx/types"; +option (gogoproto.goproto_getters_all) = false; + +message Tx { + option (gogoproto.equal) = false; + + bytes id = 1 [(gogoproto.casttype) = "github.com/datachainlab/cross/x/core/types.TxID"]; + + enum CommitProtocol { + option (gogoproto.goproto_enum_prefix) = false; + + COMMIT_PROTOCOL_UNKNOWN = 0; + COMMIT_PROTOCOL_SIMPLE = 1; + COMMIT_PROTOCOL_TPC = 2; + } + + CommitProtocol commit_protocol = 2; + + repeated ResolvedContractTransaction contract_transactions = 3 [(gogoproto.nullable) = false]; + + ibc.core.client.v1.Height timeout_height = 4 + [(gogoproto.moretags) = "yaml:\"timeout_height\"", (gogoproto.nullable) = false]; + + uint64 timeout_timestamp = 5 + [(gogoproto.moretags) = "yaml:\"timeout_timestamp\""]; +} + +message ResolvedContractTransaction { + option (gogoproto.equal) = false; + + google.protobuf.Any cross_chain_channel = 1 [(gogoproto.nullable) = true]; + repeated Account signers = 2 [(gogoproto.nullable) = false]; + bytes call_info = 3 [(gogoproto.casttype) = "ContractCallInfo"]; + ReturnValue return_value = 4; + repeated google.protobuf.Any call_results = 5 [(gogoproto.nullable) = false]; +} + +message ReturnValue { + bytes value = 1; +} + +message ConstantValueCallResult { + google.protobuf.Any cross_chain_channel = 1 [(gogoproto.nullable) = false]; + bytes k = 2; + bytes v = 3; +} + +message ContractCallResult { + bytes data = 1; + repeated google.protobuf.Any events = 2 [(gogoproto.nullable) = false]; +} diff --git a/src/core/IInitiator.sol b/src/core/IInitiator.sol new file mode 100644 index 0000000..e0d4a27 --- /dev/null +++ b/src/core/IInitiator.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.20; + +import {MsgInitiateTx, MsgInitiateTxResponse, QuerySelfXCCResponse} from "../proto/cross/core/initiator/Initiator.sol"; + +interface IInitiator { + event TxInitiated(bytes txId, address indexed proposer); + + function initiateTx(MsgInitiateTx.Data calldata msg_) external returns (MsgInitiateTxResponse.Data memory resp); + + function selfXCC() external view returns (QuerySelfXCCResponse.Data memory resp); +} diff --git a/src/proto/cross/core/atomic/simple/AtomicSimple.sol b/src/proto/cross/core/atomic/simple/AtomicSimple.sol index dd8c106..f134d72 100644 --- a/src/proto/cross/core/atomic/simple/AtomicSimple.sol +++ b/src/proto/cross/core/atomic/simple/AtomicSimple.sol @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.20; - import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/ProtoBufRuntime.sol"; import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol"; import "../../auth/Auth.sol"; @@ -599,7 +598,6 @@ library Header { if (r.fields.length != 0) { for (i = 0; i < r.fields.length; i++) { pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); - pointer += HeaderField._encode_nested(r.fields[i], pointer, bs); } } @@ -1434,7 +1432,6 @@ library PacketDataCallResolvedContractTransaction { if (r.signers.length != 0) { for (i = 0; i < r.signers.length; i++) { pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); - pointer += Account._encode_nested(r.signers[i], pointer, bs); } } @@ -1449,7 +1446,6 @@ library PacketDataCallResolvedContractTransaction { if (r.objects.length != 0) { for (i = 0; i < r.objects.length; i++) { pointer += ProtoBufRuntime._encode_key(5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); - pointer += GoogleProtobufAny._encode_nested(r.objects[i], pointer, bs); } } diff --git a/src/proto/cross/core/auth/Auth.sol b/src/proto/cross/core/auth/Auth.sol index 7c3c903..de440c9 100644 --- a/src/proto/cross/core/auth/Auth.sol +++ b/src/proto/cross/core/auth/Auth.sol @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.20; - import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/ProtoBufRuntime.sol"; import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol"; diff --git a/src/proto/cross/core/initiator/Initiator.sol b/src/proto/cross/core/initiator/Initiator.sol new file mode 100644 index 0000000..a9d6b93 --- /dev/null +++ b/src/proto/cross/core/initiator/Initiator.sol @@ -0,0 +1,2196 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.20; +import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/ProtoBufRuntime.sol"; +import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol"; +import "../../../ibc/core/client/v1/client.sol"; +import "../tx/Tx.sol"; +import "../auth/Auth.sol"; + +library MsgInitiateTx { + //struct definition + struct Data { + string chain_id; + uint64 nonce; + Tx.CommitProtocol commit_protocol; + ContractTransaction.Data[] contract_transactions; + Account.Data[] signers; + IbcCoreClientV1Height.Data timeout_height; + uint64 timeout_timestamp; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256[8] memory counters; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_chain_id(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_nonce(pointer, bs, r); + } else if (fieldId == 3) { + pointer += _read_commit_protocol(pointer, bs, r); + } else if (fieldId == 4) { + pointer += _read_unpacked_repeated_contract_transactions(pointer, bs, nil(), counters); + } else if (fieldId == 5) { + pointer += _read_unpacked_repeated_signers(pointer, bs, nil(), counters); + } else if (fieldId == 6) { + pointer += _read_timeout_height(pointer, bs, r); + } else if (fieldId == 7) { + pointer += _read_timeout_timestamp(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + pointer = offset; + if (counters[4] > 0) { + require(r.contract_transactions.length == 0); + r.contract_transactions = new ContractTransaction.Data[](counters[4]); + } + if (counters[5] > 0) { + require(r.signers.length == 0); + r.signers = new Account.Data[](counters[5]); + } + + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 4) { + pointer += _read_unpacked_repeated_contract_transactions(pointer, bs, r, counters); + } else if (fieldId == 5) { + pointer += _read_unpacked_repeated_signers(pointer, bs, r, counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_chain_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.chain_id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_nonce(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); + r.nonce = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_commit_protocol(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); + Tx.CommitProtocol x = Tx.decode_CommitProtocol(tmp); + r.commit_protocol = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_contract_transactions( + uint256 p, + bytes memory bs, + Data memory r, + uint256[8] memory counters + ) internal pure returns (uint256) { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (ContractTransaction.Data memory x, uint256 sz) = _decode_ContractTransaction(p, bs); + if (isNil(r)) { + counters[4] += 1; + } else { + r.contract_transactions[r.contract_transactions.length - counters[4]] = x; + counters[4] -= 1; + } + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_signers(uint256 p, bytes memory bs, Data memory r, uint256[8] memory counters) + internal + pure + returns (uint256) + { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (Account.Data memory x, uint256 sz) = _decode_Account(p, bs); + if (isNil(r)) { + counters[5] += 1; + } else { + r.signers[r.signers.length - counters[5]] = x; + counters[5] -= 1; + } + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_timeout_height(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (IbcCoreClientV1Height.Data memory x, uint256 sz) = _decode_IbcCoreClientV1Height(p, bs); + r.timeout_height = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_timeout_timestamp(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); + r.timeout_timestamp = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_ContractTransaction(uint256 p, bytes memory bs) + internal + pure + returns (ContractTransaction.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (ContractTransaction.Data memory r,) = ContractTransaction._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_Account(uint256 p, bytes memory bs) internal pure returns (Account.Data memory, uint256) { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (Account.Data memory r,) = Account._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_IbcCoreClientV1Height(uint256 p, bytes memory bs) + internal + pure + returns (IbcCoreClientV1Height.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (IbcCoreClientV1Height.Data memory r,) = IbcCoreClientV1Height._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + uint256 i; + if (bytes(r.chain_id).length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.chain_id, pointer, bs); + } + if (r.nonce != 0) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.Varint, pointer, bs); + pointer += ProtoBufRuntime._encode_uint64(r.nonce, pointer, bs); + } + if (uint256(r.commit_protocol) != 0) { + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.Varint, pointer, bs); + int32 _enum_commit_protocol = Tx.encode_CommitProtocol(r.commit_protocol); + pointer += ProtoBufRuntime._encode_enum(_enum_commit_protocol, pointer, bs); + } + if (r.contract_transactions.length != 0) { + for (i = 0; i < r.contract_transactions.length; i++) { + pointer += ProtoBufRuntime._encode_key(4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ContractTransaction._encode_nested(r.contract_transactions[i], pointer, bs); + } + } + if (r.signers.length != 0) { + for (i = 0; i < r.signers.length; i++) { + pointer += ProtoBufRuntime._encode_key(5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += Account._encode_nested(r.signers[i], pointer, bs); + } + } + + pointer += ProtoBufRuntime._encode_key(6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += IbcCoreClientV1Height._encode_nested(r.timeout_height, pointer, bs); + + if (r.timeout_timestamp != 0) { + pointer += ProtoBufRuntime._encode_key(7, ProtoBufRuntime.WireType.Varint, pointer, bs); + pointer += ProtoBufRuntime._encode_uint64(r.timeout_timestamp, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + uint256 i; + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.chain_id).length); + e += 1 + ProtoBufRuntime._sz_uint64(r.nonce); + e += 1 + ProtoBufRuntime._sz_enum(Tx.encode_CommitProtocol(r.commit_protocol)); + for (i = 0; i < r.contract_transactions.length; i++) { + e += 1 + ProtoBufRuntime._sz_lendelim(ContractTransaction._estimate(r.contract_transactions[i])); + } + for (i = 0; i < r.signers.length; i++) { + e += 1 + ProtoBufRuntime._sz_lendelim(Account._estimate(r.signers[i])); + } + e += 1 + ProtoBufRuntime._sz_lendelim(IbcCoreClientV1Height._estimate(r.timeout_height)); + e += 1 + ProtoBufRuntime._sz_uint64(r.timeout_timestamp); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (bytes(r.chain_id).length != 0) { + return false; + } + + if (r.nonce != 0) { + return false; + } + + if (uint256(r.commit_protocol) != 0) { + return false; + } + + if (r.contract_transactions.length != 0) { + return false; + } + + if (r.signers.length != 0) { + return false; + } + + if (r.timeout_timestamp != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.chain_id = input.chain_id; + output.nonce = input.nonce; + output.commit_protocol = input.commit_protocol; + + for (uint256 i4 = 0; i4 < input.contract_transactions.length; i4++) { + output.contract_transactions.push(input.contract_transactions[i4]); + } + + for (uint256 i5 = 0; i5 < input.signers.length; i5++) { + output.signers.push(input.signers[i5]); + } + + IbcCoreClientV1Height.store(input.timeout_height, output.timeout_height); + output.timeout_timestamp = input.timeout_timestamp; + } + + //array helpers for ContractTransactions + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addContractTransactions(Data memory self, ContractTransaction.Data memory value) internal pure { + /** + * First resize the array. Then add the new element to the end. + */ + ContractTransaction.Data[] memory tmp = new ContractTransaction.Data[](self.contract_transactions.length + 1); + for (uint256 i = 0; i < self.contract_transactions.length; i++) { + tmp[i] = self.contract_transactions[i]; + } + tmp[self.contract_transactions.length] = value; + self.contract_transactions = tmp; + } + + //array helpers for Signers + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addSigners(Data memory self, Account.Data memory value) internal pure { + /** + * First resize the array. Then add the new element to the end. + */ + Account.Data[] memory tmp = new Account.Data[](self.signers.length + 1); + for (uint256 i = 0; i < self.signers.length; i++) { + tmp[i] = self.signers[i]; + } + tmp[self.signers.length] = value; + self.signers = tmp; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library MsgInitiateTx + +library MsgInitiateTxResponse { + //enum definition + // Solidity enum definitions + enum InitiateTxStatus { + INITIATE_TX_STATUS_UNKNOWN, + INITIATE_TX_STATUS_PENDING, + INITIATE_TX_STATUS_VERIFIED + } + + // Solidity enum encoder + function encode_InitiateTxStatus(InitiateTxStatus x) internal pure returns (int32) { + if (x == InitiateTxStatus.INITIATE_TX_STATUS_UNKNOWN) { + return 0; + } + + if (x == InitiateTxStatus.INITIATE_TX_STATUS_PENDING) { + return 1; + } + + if (x == InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED) { + return 2; + } + revert(); + } + + // Solidity enum decoder + function decode_InitiateTxStatus(int64 x) internal pure returns (InitiateTxStatus) { + if (x == 0) { + return InitiateTxStatus.INITIATE_TX_STATUS_UNKNOWN; + } + + if (x == 1) { + return InitiateTxStatus.INITIATE_TX_STATUS_PENDING; + } + + if (x == 2) { + return InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED; + } + revert(); + } + + /** + * @dev The estimator for an packed enum array + * @return The number of bytes encoded + */ + function estimate_packed_repeated_InitiateTxStatus(InitiateTxStatus[] memory a) internal pure returns (uint256) { + uint256 e = 0; + for (uint256 i = 0; i < a.length; i++) { + e += ProtoBufRuntime._sz_enum(encode_InitiateTxStatus(a[i])); + } + return e; + } + + //struct definition + struct Data { + bytes txID; + MsgInitiateTxResponse.InitiateTxStatus status; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_txID(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_status(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_txID(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.txID = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_status(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); + MsgInitiateTxResponse.InitiateTxStatus x = decode_InitiateTxStatus(tmp); + r.status = x; + return sz; + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (r.txID.length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.txID, pointer, bs); + } + if (uint256(r.status) != 0) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.Varint, pointer, bs); + int32 _enum_status = encode_InitiateTxStatus(r.status); + pointer += ProtoBufRuntime._encode_enum(_enum_status, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(r.txID.length); + e += 1 + ProtoBufRuntime._sz_enum(encode_InitiateTxStatus(r.status)); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.txID.length != 0) { + return false; + } + + if (uint256(r.status) != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.txID = input.txID; + output.status = input.status; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library MsgInitiateTxResponse + +library QuerySelfXCCRequest { + //struct definition + struct Data { + bool x; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + } + return (r, sz); + } + + // field readers + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @return The number of bytes encoded in estimation + */ + function _estimate( + Data memory /* r */ + ) + internal + pure + returns (uint256) + { + uint256 e; + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal {} + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library QuerySelfXCCRequest + +library QuerySelfXCCResponse { + //struct definition + struct Data { + GoogleProtobufAny.Data xcc; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_xcc(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_xcc(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.xcc = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.xcc, pointer, bs); + + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.xcc)); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + GoogleProtobufAny.store(input.xcc, output.xcc); + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library QuerySelfXCCResponse + +library ContractTransaction { + //struct definition + struct Data { + GoogleProtobufAny.Data cross_chain_channel; + Account.Data[] signers; + bytes call_info; + ReturnValue.Data return_value; + Link.Data[] links; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256[6] memory counters; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_cross_chain_channel(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_unpacked_repeated_signers(pointer, bs, nil(), counters); + } else if (fieldId == 3) { + pointer += _read_call_info(pointer, bs, r); + } else if (fieldId == 4) { + pointer += _read_return_value(pointer, bs, r); + } else if (fieldId == 5) { + pointer += _read_unpacked_repeated_links(pointer, bs, nil(), counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + pointer = offset; + if (counters[2] > 0) { + require(r.signers.length == 0); + r.signers = new Account.Data[](counters[2]); + } + if (counters[5] > 0) { + require(r.links.length == 0); + r.links = new Link.Data[](counters[5]); + } + + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 2) { + pointer += _read_unpacked_repeated_signers(pointer, bs, r, counters); + } else if (fieldId == 5) { + pointer += _read_unpacked_repeated_links(pointer, bs, r, counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_cross_chain_channel(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.cross_chain_channel = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_signers(uint256 p, bytes memory bs, Data memory r, uint256[6] memory counters) + internal + pure + returns (uint256) + { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (Account.Data memory x, uint256 sz) = _decode_Account(p, bs); + if (isNil(r)) { + counters[2] += 1; + } else { + r.signers[r.signers.length - counters[2]] = x; + counters[2] -= 1; + } + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_call_info(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.call_info = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_return_value(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (ReturnValue.Data memory x, uint256 sz) = _decode_ReturnValue(p, bs); + r.return_value = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_links(uint256 p, bytes memory bs, Data memory r, uint256[6] memory counters) + internal + pure + returns (uint256) + { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (Link.Data memory x, uint256 sz) = _decode_Link(p, bs); + if (isNil(r)) { + counters[5] += 1; + } else { + r.links[r.links.length - counters[5]] = x; + counters[5] -= 1; + } + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_Account(uint256 p, bytes memory bs) internal pure returns (Account.Data memory, uint256) { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (Account.Data memory r,) = Account._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_ReturnValue(uint256 p, bytes memory bs) internal pure returns (ReturnValue.Data memory, uint256) { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (ReturnValue.Data memory r,) = ReturnValue._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_Link(uint256 p, bytes memory bs) internal pure returns (Link.Data memory, uint256) { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (Link.Data memory r,) = Link._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + uint256 i; + + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.cross_chain_channel, pointer, bs); + + if (r.signers.length != 0) { + for (i = 0; i < r.signers.length; i++) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += Account._encode_nested(r.signers[i], pointer, bs); + } + } + if (r.call_info.length != 0) { + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.call_info, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ReturnValue._encode_nested(r.return_value, pointer, bs); + + if (r.links.length != 0) { + for (i = 0; i < r.links.length; i++) { + pointer += ProtoBufRuntime._encode_key(5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += Link._encode_nested(r.links[i], pointer, bs); + } + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + uint256 i; + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.cross_chain_channel)); + for (i = 0; i < r.signers.length; i++) { + e += 1 + ProtoBufRuntime._sz_lendelim(Account._estimate(r.signers[i])); + } + e += 1 + ProtoBufRuntime._sz_lendelim(r.call_info.length); + e += 1 + ProtoBufRuntime._sz_lendelim(ReturnValue._estimate(r.return_value)); + for (i = 0; i < r.links.length; i++) { + e += 1 + ProtoBufRuntime._sz_lendelim(Link._estimate(r.links[i])); + } + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.signers.length != 0) { + return false; + } + + if (r.call_info.length != 0) { + return false; + } + + if (r.links.length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + GoogleProtobufAny.store(input.cross_chain_channel, output.cross_chain_channel); + + for (uint256 i2 = 0; i2 < input.signers.length; i2++) { + output.signers.push(input.signers[i2]); + } + + output.call_info = input.call_info; + ReturnValue.store(input.return_value, output.return_value); + + for (uint256 i5 = 0; i5 < input.links.length; i5++) { + output.links.push(input.links[i5]); + } + } + + //array helpers for Signers + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addSigners(Data memory self, Account.Data memory value) internal pure { + /** + * First resize the array. Then add the new element to the end. + */ + Account.Data[] memory tmp = new Account.Data[](self.signers.length + 1); + for (uint256 i = 0; i < self.signers.length; i++) { + tmp[i] = self.signers[i]; + } + tmp[self.signers.length] = value; + self.signers = tmp; + } + + //array helpers for Links + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addLinks(Data memory self, Link.Data memory value) internal pure { + /** + * First resize the array. Then add the new element to the end. + */ + Link.Data[] memory tmp = new Link.Data[](self.links.length + 1); + for (uint256 i = 0; i < self.links.length; i++) { + tmp[i] = self.links[i]; + } + tmp[self.links.length] = value; + self.links = tmp; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library ContractTransaction + +library Link { + //struct definition + struct Data { + uint32 src_index; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_src_index(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_src_index(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (uint32 x, uint256 sz) = ProtoBufRuntime._decode_uint32(p, bs); + r.src_index = x; + return sz; + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (r.src_index != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.Varint, pointer, bs); + pointer += ProtoBufRuntime._encode_uint32(r.src_index, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_uint32(r.src_index); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.src_index != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.src_index = input.src_index; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library Link + +library GenesisState { + //struct definition + struct Data { + bool x; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + } + return (r, sz); + } + + // field readers + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @return The number of bytes encoded in estimation + */ + function _estimate( + Data memory /* r */ + ) + internal + pure + returns (uint256) + { + uint256 e; + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal {} + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library GenesisState + +library InitiateTxState { + //struct definition + struct Data { + MsgInitiateTxResponse.InitiateTxStatus status; + MsgInitiateTx.Data msg; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_status(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_msg(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_status(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); + MsgInitiateTxResponse.InitiateTxStatus x = MsgInitiateTxResponse.decode_InitiateTxStatus(tmp); + r.status = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_msg(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (MsgInitiateTx.Data memory x, uint256 sz) = _decode_MsgInitiateTx(p, bs); + r.msg = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_MsgInitiateTx(uint256 p, bytes memory bs) + internal + pure + returns (MsgInitiateTx.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (MsgInitiateTx.Data memory r,) = MsgInitiateTx._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (uint256(r.status) != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.Varint, pointer, bs); + int32 _enum_status = MsgInitiateTxResponse.encode_InitiateTxStatus(r.status); + pointer += ProtoBufRuntime._encode_enum(_enum_status, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += MsgInitiateTx._encode_nested(r.msg, pointer, bs); + + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_enum(MsgInitiateTxResponse.encode_InitiateTxStatus(r.status)); + e += 1 + ProtoBufRuntime._sz_lendelim(MsgInitiateTx._estimate(r.msg)); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (uint256(r.status) != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.status = input.status; + MsgInitiateTx.store(input.msg, output.msg); + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library InitiateTxState diff --git a/src/proto/cross/core/tx/Tx.sol b/src/proto/cross/core/tx/Tx.sol new file mode 100644 index 0000000..314bbb9 --- /dev/null +++ b/src/proto/cross/core/tx/Tx.sol @@ -0,0 +1,1627 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.20; +import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/ProtoBufRuntime.sol"; +import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol"; +import "../../../ibc/core/client/v1/client.sol"; +import "../auth/Auth.sol"; + +library Tx { + //enum definition + // Solidity enum definitions + enum CommitProtocol { + COMMIT_PROTOCOL_UNKNOWN, + COMMIT_PROTOCOL_SIMPLE, + COMMIT_PROTOCOL_TPC + } + + // Solidity enum encoder + function encode_CommitProtocol(CommitProtocol x) internal pure returns (int32) { + if (x == CommitProtocol.COMMIT_PROTOCOL_UNKNOWN) { + return 0; + } + + if (x == CommitProtocol.COMMIT_PROTOCOL_SIMPLE) { + return 1; + } + + if (x == CommitProtocol.COMMIT_PROTOCOL_TPC) { + return 2; + } + revert(); + } + + // Solidity enum decoder + function decode_CommitProtocol(int64 x) internal pure returns (CommitProtocol) { + if (x == 0) { + return CommitProtocol.COMMIT_PROTOCOL_UNKNOWN; + } + + if (x == 1) { + return CommitProtocol.COMMIT_PROTOCOL_SIMPLE; + } + + if (x == 2) { + return CommitProtocol.COMMIT_PROTOCOL_TPC; + } + revert(); + } + + /** + * @dev The estimator for an packed enum array + * @return The number of bytes encoded + */ + function estimate_packed_repeated_CommitProtocol(CommitProtocol[] memory a) internal pure returns (uint256) { + uint256 e = 0; + for (uint256 i = 0; i < a.length; i++) { + e += ProtoBufRuntime._sz_enum(encode_CommitProtocol(a[i])); + } + return e; + } + + //struct definition + struct Data { + bytes id; + Tx.CommitProtocol commit_protocol; + ResolvedContractTransaction.Data[] contract_transactions; + IbcCoreClientV1Height.Data timeout_height; + uint64 timeout_timestamp; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256[6] memory counters; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_id(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_commit_protocol(pointer, bs, r); + } else if (fieldId == 3) { + pointer += _read_unpacked_repeated_contract_transactions(pointer, bs, nil(), counters); + } else if (fieldId == 4) { + pointer += _read_timeout_height(pointer, bs, r); + } else if (fieldId == 5) { + pointer += _read_timeout_timestamp(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + pointer = offset; + if (counters[3] > 0) { + require(r.contract_transactions.length == 0); + r.contract_transactions = new ResolvedContractTransaction.Data[](counters[3]); + } + + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 3) { + pointer += _read_unpacked_repeated_contract_transactions(pointer, bs, r, counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_commit_protocol(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); + Tx.CommitProtocol x = decode_CommitProtocol(tmp); + r.commit_protocol = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_contract_transactions( + uint256 p, + bytes memory bs, + Data memory r, + uint256[6] memory counters + ) internal pure returns (uint256) { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (ResolvedContractTransaction.Data memory x, uint256 sz) = _decode_ResolvedContractTransaction(p, bs); + if (isNil(r)) { + counters[3] += 1; + } else { + r.contract_transactions[r.contract_transactions.length - counters[3]] = x; + counters[3] -= 1; + } + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_timeout_height(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (IbcCoreClientV1Height.Data memory x, uint256 sz) = _decode_IbcCoreClientV1Height(p, bs); + r.timeout_height = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_timeout_timestamp(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); + r.timeout_timestamp = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_ResolvedContractTransaction(uint256 p, bytes memory bs) + internal + pure + returns (ResolvedContractTransaction.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (ResolvedContractTransaction.Data memory r,) = ResolvedContractTransaction._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_IbcCoreClientV1Height(uint256 p, bytes memory bs) + internal + pure + returns (IbcCoreClientV1Height.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (IbcCoreClientV1Height.Data memory r,) = IbcCoreClientV1Height._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + uint256 i; + if (r.id.length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.id, pointer, bs); + } + if (uint256(r.commit_protocol) != 0) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.Varint, pointer, bs); + int32 _enum_commit_protocol = encode_CommitProtocol(r.commit_protocol); + pointer += ProtoBufRuntime._encode_enum(_enum_commit_protocol, pointer, bs); + } + if (r.contract_transactions.length != 0) { + for (i = 0; i < r.contract_transactions.length; i++) { + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ResolvedContractTransaction._encode_nested(r.contract_transactions[i], pointer, bs); + } + } + + pointer += ProtoBufRuntime._encode_key(4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += IbcCoreClientV1Height._encode_nested(r.timeout_height, pointer, bs); + + if (r.timeout_timestamp != 0) { + pointer += ProtoBufRuntime._encode_key(5, ProtoBufRuntime.WireType.Varint, pointer, bs); + pointer += ProtoBufRuntime._encode_uint64(r.timeout_timestamp, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + uint256 i; + e += 1 + ProtoBufRuntime._sz_lendelim(r.id.length); + e += 1 + ProtoBufRuntime._sz_enum(encode_CommitProtocol(r.commit_protocol)); + for (i = 0; i < r.contract_transactions.length; i++) { + e += 1 + ProtoBufRuntime._sz_lendelim(ResolvedContractTransaction._estimate(r.contract_transactions[i])); + } + e += 1 + ProtoBufRuntime._sz_lendelim(IbcCoreClientV1Height._estimate(r.timeout_height)); + e += 1 + ProtoBufRuntime._sz_uint64(r.timeout_timestamp); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.id.length != 0) { + return false; + } + + if (uint256(r.commit_protocol) != 0) { + return false; + } + + if (r.contract_transactions.length != 0) { + return false; + } + + if (r.timeout_timestamp != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.id = input.id; + output.commit_protocol = input.commit_protocol; + + for (uint256 i3 = 0; i3 < input.contract_transactions.length; i3++) { + output.contract_transactions.push(input.contract_transactions[i3]); + } + + IbcCoreClientV1Height.store(input.timeout_height, output.timeout_height); + output.timeout_timestamp = input.timeout_timestamp; + } + + //array helpers for ContractTransactions + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addContractTransactions(Data memory self, ResolvedContractTransaction.Data memory value) internal pure { + /** + * First resize the array. Then add the new element to the end. + */ + ResolvedContractTransaction.Data[] memory tmp = + new ResolvedContractTransaction.Data[](self.contract_transactions.length + 1); + for (uint256 i = 0; i < self.contract_transactions.length; i++) { + tmp[i] = self.contract_transactions[i]; + } + tmp[self.contract_transactions.length] = value; + self.contract_transactions = tmp; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library Tx + +library ResolvedContractTransaction { + //struct definition + struct Data { + GoogleProtobufAny.Data cross_chain_channel; + Account.Data[] signers; + bytes call_info; + ReturnValue.Data return_value; + GoogleProtobufAny.Data[] call_results; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256[6] memory counters; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_cross_chain_channel(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_unpacked_repeated_signers(pointer, bs, nil(), counters); + } else if (fieldId == 3) { + pointer += _read_call_info(pointer, bs, r); + } else if (fieldId == 4) { + pointer += _read_return_value(pointer, bs, r); + } else if (fieldId == 5) { + pointer += _read_unpacked_repeated_call_results(pointer, bs, nil(), counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + pointer = offset; + if (counters[2] > 0) { + require(r.signers.length == 0); + r.signers = new Account.Data[](counters[2]); + } + if (counters[5] > 0) { + require(r.call_results.length == 0); + r.call_results = new GoogleProtobufAny.Data[](counters[5]); + } + + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 2) { + pointer += _read_unpacked_repeated_signers(pointer, bs, r, counters); + } else if (fieldId == 5) { + pointer += _read_unpacked_repeated_call_results(pointer, bs, r, counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_cross_chain_channel(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.cross_chain_channel = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_signers(uint256 p, bytes memory bs, Data memory r, uint256[6] memory counters) + internal + pure + returns (uint256) + { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (Account.Data memory x, uint256 sz) = _decode_Account(p, bs); + if (isNil(r)) { + counters[2] += 1; + } else { + r.signers[r.signers.length - counters[2]] = x; + counters[2] -= 1; + } + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_call_info(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.call_info = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_return_value(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (ReturnValue.Data memory x, uint256 sz) = _decode_ReturnValue(p, bs); + r.return_value = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_call_results( + uint256 p, + bytes memory bs, + Data memory r, + uint256[6] memory counters + ) internal pure returns (uint256) { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + if (isNil(r)) { + counters[5] += 1; + } else { + r.call_results[r.call_results.length - counters[5]] = x; + counters[5] -= 1; + } + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_Account(uint256 p, bytes memory bs) internal pure returns (Account.Data memory, uint256) { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (Account.Data memory r,) = Account._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_ReturnValue(uint256 p, bytes memory bs) internal pure returns (ReturnValue.Data memory, uint256) { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (ReturnValue.Data memory r,) = ReturnValue._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + uint256 i; + + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.cross_chain_channel, pointer, bs); + + if (r.signers.length != 0) { + for (i = 0; i < r.signers.length; i++) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += Account._encode_nested(r.signers[i], pointer, bs); + } + } + if (r.call_info.length != 0) { + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.call_info, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ReturnValue._encode_nested(r.return_value, pointer, bs); + + if (r.call_results.length != 0) { + for (i = 0; i < r.call_results.length; i++) { + pointer += ProtoBufRuntime._encode_key(5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.call_results[i], pointer, bs); + } + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + uint256 i; + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.cross_chain_channel)); + for (i = 0; i < r.signers.length; i++) { + e += 1 + ProtoBufRuntime._sz_lendelim(Account._estimate(r.signers[i])); + } + e += 1 + ProtoBufRuntime._sz_lendelim(r.call_info.length); + e += 1 + ProtoBufRuntime._sz_lendelim(ReturnValue._estimate(r.return_value)); + for (i = 0; i < r.call_results.length; i++) { + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.call_results[i])); + } + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.signers.length != 0) { + return false; + } + + if (r.call_info.length != 0) { + return false; + } + + if (r.call_results.length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + GoogleProtobufAny.store(input.cross_chain_channel, output.cross_chain_channel); + + for (uint256 i2 = 0; i2 < input.signers.length; i2++) { + output.signers.push(input.signers[i2]); + } + + output.call_info = input.call_info; + ReturnValue.store(input.return_value, output.return_value); + + for (uint256 i5 = 0; i5 < input.call_results.length; i5++) { + output.call_results.push(input.call_results[i5]); + } + } + + //array helpers for Signers + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addSigners(Data memory self, Account.Data memory value) internal pure { + /** + * First resize the array. Then add the new element to the end. + */ + Account.Data[] memory tmp = new Account.Data[](self.signers.length + 1); + for (uint256 i = 0; i < self.signers.length; i++) { + tmp[i] = self.signers[i]; + } + tmp[self.signers.length] = value; + self.signers = tmp; + } + + //array helpers for CallResults + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addCallResults(Data memory self, GoogleProtobufAny.Data memory value) internal pure { + /** + * First resize the array. Then add the new element to the end. + */ + GoogleProtobufAny.Data[] memory tmp = new GoogleProtobufAny.Data[](self.call_results.length + 1); + for (uint256 i = 0; i < self.call_results.length; i++) { + tmp[i] = self.call_results[i]; + } + tmp[self.call_results.length] = value; + self.call_results = tmp; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library ResolvedContractTransaction + +library ReturnValue { + //struct definition + struct Data { + bytes value; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_value(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_value(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.value = x; + return sz; + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (r.value.length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.value, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(r.value.length); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.value.length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.value = input.value; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library ReturnValue + +library ConstantValueCallResult { + //struct definition + struct Data { + GoogleProtobufAny.Data cross_chain_channel; + bytes k; + bytes v; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_cross_chain_channel(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_k(pointer, bs, r); + } else if (fieldId == 3) { + pointer += _read_v(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_cross_chain_channel(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.cross_chain_channel = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_k(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.k = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_v(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.v = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.cross_chain_channel, pointer, bs); + + if (r.k.length != 0) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.k, pointer, bs); + } + if (r.v.length != 0) { + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.v, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.cross_chain_channel)); + e += 1 + ProtoBufRuntime._sz_lendelim(r.k.length); + e += 1 + ProtoBufRuntime._sz_lendelim(r.v.length); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.k.length != 0) { + return false; + } + + if (r.v.length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + GoogleProtobufAny.store(input.cross_chain_channel, output.cross_chain_channel); + output.k = input.k; + output.v = input.v; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library ConstantValueCallResult + +library ContractCallResult { + //struct definition + struct Data { + bytes data; + GoogleProtobufAny.Data[] events; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256[3] memory counters; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_data(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_unpacked_repeated_events(pointer, bs, nil(), counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + pointer = offset; + if (counters[2] > 0) { + require(r.events.length == 0); + r.events = new GoogleProtobufAny.Data[](counters[2]); + } + + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 2) { + pointer += _read_unpacked_repeated_events(pointer, bs, r, counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_data(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.data = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_events(uint256 p, bytes memory bs, Data memory r, uint256[3] memory counters) + internal + pure + returns (uint256) + { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + if (isNil(r)) { + counters[2] += 1; + } else { + r.events[r.events.length - counters[2]] = x; + counters[2] -= 1; + } + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + uint256 i; + if (r.data.length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); + } + if (r.events.length != 0) { + for (i = 0; i < r.events.length; i++) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.events[i], pointer, bs); + } + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + uint256 i; + e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); + for (i = 0; i < r.events.length; i++) { + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.events[i])); + } + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.data.length != 0) { + return false; + } + + if (r.events.length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.data = input.data; + + for (uint256 i2 = 0; i2 < input.events.length; i2++) { + output.events.push(input.events[i2]); + } + } + + //array helpers for Events + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addEvents(Data memory self, GoogleProtobufAny.Data memory value) internal pure { + /** + * First resize the array. Then add the new element to the end. + */ + GoogleProtobufAny.Data[] memory tmp = new GoogleProtobufAny.Data[](self.events.length + 1); + for (uint256 i = 0; i < self.events.length; i++) { + tmp[i] = self.events[i]; + } + tmp[self.events.length] = value; + self.events = tmp; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library ContractCallResult diff --git a/src/proto/ibc/core/client/v1/client.sol b/src/proto/ibc/core/client/v1/client.sol new file mode 100644 index 0000000..8d91643 --- /dev/null +++ b/src/proto/ibc/core/client/v1/client.sol @@ -0,0 +1,2408 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.20; +import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/ProtoBufRuntime.sol"; +import "@hyperledger-labs/yui-ibc-solidity/contracts/proto/GoogleProtobufAny.sol"; + +library IbcCoreClientV1IdentifiedClientState { + //struct definition + struct Data { + string client_id; + GoogleProtobufAny.Data client_state; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_client_id(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_client_state(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.client_id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_state(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.client_state = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (bytes(r.client_id).length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.client_state, pointer, bs); + + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.client_state)); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (bytes(r.client_id).length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.client_id = input.client_id; + GoogleProtobufAny.store(input.client_state, output.client_state); + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1IdentifiedClientState + +library IbcCoreClientV1ConsensusStateWithHeight { + //struct definition + struct Data { + IbcCoreClientV1Height.Data height; + GoogleProtobufAny.Data consensus_state; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_height(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_consensus_state(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_height(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (IbcCoreClientV1Height.Data memory x, uint256 sz) = _decode_IbcCoreClientV1Height(p, bs); + r.height = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_consensus_state(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.consensus_state = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_IbcCoreClientV1Height(uint256 p, bytes memory bs) + internal + pure + returns (IbcCoreClientV1Height.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (IbcCoreClientV1Height.Data memory r,) = IbcCoreClientV1Height._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += IbcCoreClientV1Height._encode_nested(r.height, pointer, bs); + + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.consensus_state, pointer, bs); + + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(IbcCoreClientV1Height._estimate(r.height)); + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.consensus_state)); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + IbcCoreClientV1Height.store(input.height, output.height); + GoogleProtobufAny.store(input.consensus_state, output.consensus_state); + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1ConsensusStateWithHeight + +library IbcCoreClientV1ClientConsensusStates { + //struct definition + struct Data { + string client_id; + IbcCoreClientV1ConsensusStateWithHeight.Data[] consensus_states; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256[3] memory counters; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_client_id(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_unpacked_repeated_consensus_states(pointer, bs, nil(), counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + pointer = offset; + if (counters[2] > 0) { + require(r.consensus_states.length == 0); + r.consensus_states = new IbcCoreClientV1ConsensusStateWithHeight.Data[](counters[2]); + } + + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 2) { + pointer += _read_unpacked_repeated_consensus_states(pointer, bs, r, counters); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.client_id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @param counters The counters for repeated fields + * @return The number of bytes decoded + */ + function _read_unpacked_repeated_consensus_states( + uint256 p, + bytes memory bs, + Data memory r, + uint256[3] memory counters + ) internal pure returns (uint256) { + /** + * if `r` is NULL, then only counting the number of fields. + */ + (IbcCoreClientV1ConsensusStateWithHeight.Data memory x, uint256 sz) = + _decode_IbcCoreClientV1ConsensusStateWithHeight(p, bs); + if (isNil(r)) { + counters[2] += 1; + } else { + r.consensus_states[r.consensus_states.length - counters[2]] = x; + counters[2] -= 1; + } + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_IbcCoreClientV1ConsensusStateWithHeight(uint256 p, bytes memory bs) + internal + pure + returns (IbcCoreClientV1ConsensusStateWithHeight.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (IbcCoreClientV1ConsensusStateWithHeight.Data memory r,) = + IbcCoreClientV1ConsensusStateWithHeight._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + uint256 i; + if (bytes(r.client_id).length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); + } + if (r.consensus_states.length != 0) { + for (i = 0; i < r.consensus_states.length; i++) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += IbcCoreClientV1ConsensusStateWithHeight._encode_nested(r.consensus_states[i], pointer, bs); + } + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + uint256 i; + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); + for (i = 0; i < r.consensus_states.length; i++) { + e += 1 + + ProtoBufRuntime._sz_lendelim(IbcCoreClientV1ConsensusStateWithHeight._estimate(r.consensus_states[i])); + } + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (bytes(r.client_id).length != 0) { + return false; + } + + if (r.consensus_states.length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.client_id = input.client_id; + + for (uint256 i2 = 0; i2 < input.consensus_states.length; i2++) { + output.consensus_states.push(input.consensus_states[i2]); + } + } + + //array helpers for ConsensusStates + /** + * @dev Add value to an array + * @param self The in-memory struct + * @param value The value to add + */ + function addConsensusStates(Data memory self, IbcCoreClientV1ConsensusStateWithHeight.Data memory value) + internal + pure + { + /** + * First resize the array. Then add the new element to the end. + */ + IbcCoreClientV1ConsensusStateWithHeight.Data[] memory tmp = + new IbcCoreClientV1ConsensusStateWithHeight.Data[](self.consensus_states.length + 1); + for (uint256 i = 0; i < self.consensus_states.length; i++) { + tmp[i] = self.consensus_states[i]; + } + tmp[self.consensus_states.length] = value; + self.consensus_states = tmp; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1ClientConsensusStates + +library IbcCoreClientV1ClientUpdateProposal { + //struct definition + struct Data { + string title; + string description; + string client_id; + GoogleProtobufAny.Data header; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_title(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_description(pointer, bs, r); + } else if (fieldId == 3) { + pointer += _read_client_id(pointer, bs, r); + } else if (fieldId == 4) { + pointer += _read_header(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_title(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.title = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_description(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.description = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.client_id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_header(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.header = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (bytes(r.title).length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.title, pointer, bs); + } + if (bytes(r.description).length != 0) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.description, pointer, bs); + } + if (bytes(r.client_id).length != 0) { + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.header, pointer, bs); + + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.title).length); + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.description).length); + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.header)); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (bytes(r.title).length != 0) { + return false; + } + + if (bytes(r.description).length != 0) { + return false; + } + + if (bytes(r.client_id).length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.title = input.title; + output.description = input.description; + output.client_id = input.client_id; + GoogleProtobufAny.store(input.header, output.header); + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1ClientUpdateProposal + +library IbcCoreClientV1MsgCreateClient { + //struct definition + struct Data { + string client_id; + GoogleProtobufAny.Data client_state; + GoogleProtobufAny.Data consensus_state; + string signer; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_client_id(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_client_state(pointer, bs, r); + } else if (fieldId == 3) { + pointer += _read_consensus_state(pointer, bs, r); + } else if (fieldId == 4) { + pointer += _read_signer(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.client_id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_state(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.client_state = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_consensus_state(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.consensus_state = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_signer(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.signer = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (bytes(r.client_id).length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.client_state, pointer, bs); + + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.consensus_state, pointer, bs); + + if (bytes(r.signer).length != 0) { + pointer += ProtoBufRuntime._encode_key(4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.signer, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.client_state)); + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.consensus_state)); + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (bytes(r.client_id).length != 0) { + return false; + } + + if (bytes(r.signer).length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.client_id = input.client_id; + GoogleProtobufAny.store(input.client_state, output.client_state); + GoogleProtobufAny.store(input.consensus_state, output.consensus_state); + output.signer = input.signer; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1MsgCreateClient + +library IbcCoreClientV1MsgUpdateClient { + //struct definition + struct Data { + string client_id; + GoogleProtobufAny.Data header; + string signer; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_client_id(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_header(pointer, bs, r); + } else if (fieldId == 3) { + pointer += _read_signer(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.client_id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_header(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.header = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_signer(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.signer = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (bytes(r.client_id).length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.header, pointer, bs); + + if (bytes(r.signer).length != 0) { + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.signer, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.header)); + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (bytes(r.client_id).length != 0) { + return false; + } + + if (bytes(r.signer).length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.client_id = input.client_id; + GoogleProtobufAny.store(input.header, output.header); + output.signer = input.signer; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1MsgUpdateClient + +library IbcCoreClientV1MsgUpgradeClient { + //struct definition + struct Data { + string client_id; + GoogleProtobufAny.Data client_state; + IbcCoreClientV1Height.Data upgrade_height; + bytes proof_upgrade; + string signer; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_client_id(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_client_state(pointer, bs, r); + } else if (fieldId == 3) { + pointer += _read_upgrade_height(pointer, bs, r); + } else if (fieldId == 4) { + pointer += _read_proof_upgrade(pointer, bs, r); + } else if (fieldId == 5) { + pointer += _read_signer(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.client_id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_state(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.client_state = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_upgrade_height(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (IbcCoreClientV1Height.Data memory x, uint256 sz) = _decode_IbcCoreClientV1Height(p, bs); + r.upgrade_height = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_proof_upgrade(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); + r.proof_upgrade = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_signer(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.signer = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_IbcCoreClientV1Height(uint256 p, bytes memory bs) + internal + pure + returns (IbcCoreClientV1Height.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (IbcCoreClientV1Height.Data memory r,) = IbcCoreClientV1Height._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (bytes(r.client_id).length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.client_state, pointer, bs); + + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += IbcCoreClientV1Height._encode_nested(r.upgrade_height, pointer, bs); + + if (r.proof_upgrade.length != 0) { + pointer += ProtoBufRuntime._encode_key(4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_bytes(r.proof_upgrade, pointer, bs); + } + if (bytes(r.signer).length != 0) { + pointer += ProtoBufRuntime._encode_key(5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.signer, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.client_state)); + e += 1 + ProtoBufRuntime._sz_lendelim(IbcCoreClientV1Height._estimate(r.upgrade_height)); + e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_upgrade.length); + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (bytes(r.client_id).length != 0) { + return false; + } + + if (r.proof_upgrade.length != 0) { + return false; + } + + if (bytes(r.signer).length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.client_id = input.client_id; + GoogleProtobufAny.store(input.client_state, output.client_state); + IbcCoreClientV1Height.store(input.upgrade_height, output.upgrade_height); + output.proof_upgrade = input.proof_upgrade; + output.signer = input.signer; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1MsgUpgradeClient + +library IbcCoreClientV1MsgSubmitMisbehaviour { + //struct definition + struct Data { + string client_id; + GoogleProtobufAny.Data misbehaviour; + string signer; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_client_id(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_misbehaviour(pointer, bs, r); + } else if (fieldId == 3) { + pointer += _read_signer(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_client_id(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.client_id = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_misbehaviour(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (GoogleProtobufAny.Data memory x, uint256 sz) = _decode_GoogleProtobufAny(p, bs); + r.misbehaviour = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_signer(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); + r.signer = x; + return sz; + } + + // struct decoder + /** + * @dev The decoder for reading a inner struct field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The decoded inner-struct + * @return The number of bytes used to decode + */ + function _decode_GoogleProtobufAny(uint256 p, bytes memory bs) + internal + pure + returns (GoogleProtobufAny.Data memory, uint256) + { + uint256 pointer = p; + (uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs); + pointer += bytesRead; + (GoogleProtobufAny.Data memory r,) = GoogleProtobufAny._decode(pointer, bs, sz); + return (r, sz + bytesRead); + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (bytes(r.client_id).length != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); + } + + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += GoogleProtobufAny._encode_nested(r.misbehaviour, pointer, bs); + + if (bytes(r.signer).length != 0) { + pointer += ProtoBufRuntime._encode_key(3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs); + pointer += ProtoBufRuntime._encode_string(r.signer, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); + e += 1 + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.misbehaviour)); + e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (bytes(r.client_id).length != 0) { + return false; + } + + if (bytes(r.signer).length != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.client_id = input.client_id; + GoogleProtobufAny.store(input.misbehaviour, output.misbehaviour); + output.signer = input.signer; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1MsgSubmitMisbehaviour + +library IbcCoreClientV1Height { + //struct definition + struct Data { + uint64 version_number; + uint64 version_height; + } + + // Decoder section + + /** + * @dev The main decoder for memory + * @param bs The bytes array to be decoded + * @return The decoded struct + */ + function decode(bytes memory bs) internal pure returns (Data memory) { + (Data memory x,) = _decode(32, bs, bs.length); + return x; + } + + /** + * @dev The main decoder for storage + * @param self The in-storage struct + * @param bs The bytes array to be decoded + */ + function decode(Data storage self, bytes memory bs) internal { + (Data memory x,) = _decode(32, bs, bs.length); + store(x, self); + } + + // inner decoder + + /** + * @dev The decoder for internal usage + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param sz The number of bytes expected + * @return The decoded struct + * @return The number of bytes decoded + */ + function _decode(uint256 p, bytes memory bs, uint256 sz) internal pure returns (Data memory, uint256) { + Data memory r; + uint256 fieldId; + ProtoBufRuntime.WireType wireType; + uint256 bytesRead; + uint256 offset = p; + uint256 pointer = p; + while (pointer < offset + sz) { + (fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs); + pointer += bytesRead; + if (fieldId == 1) { + pointer += _read_version_number(pointer, bs, r); + } else if (fieldId == 2) { + pointer += _read_version_height(pointer, bs, r); + } else { + pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); + } + } + return (r, sz); + } + + // field readers + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_version_number(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); + r.version_number = x; + return sz; + } + + /** + * @dev The decoder for reading a field + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @param r The in-memory struct + * @return The number of bytes decoded + */ + function _read_version_height(uint256 p, bytes memory bs, Data memory r) internal pure returns (uint256) { + (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); + r.version_height = x; + return sz; + } + + // Encoder section + + /** + * @dev The main encoder for memory + * @param r The struct to be encoded + * @return The encoded byte array + */ + function encode(Data memory r) internal pure returns (bytes memory) { + bytes memory bs = new bytes(_estimate(r)); + uint256 sz = _encode(r, 32, bs); + assembly { + mstore(bs, sz) + } + return bs; + } + + // inner encoder + + /** + * @dev The encoder for internal usage + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + uint256 offset = p; + uint256 pointer = p; + + if (r.version_number != 0) { + pointer += ProtoBufRuntime._encode_key(1, ProtoBufRuntime.WireType.Varint, pointer, bs); + pointer += ProtoBufRuntime._encode_uint64(r.version_number, pointer, bs); + } + if (r.version_height != 0) { + pointer += ProtoBufRuntime._encode_key(2, ProtoBufRuntime.WireType.Varint, pointer, bs); + pointer += ProtoBufRuntime._encode_uint64(r.version_height, pointer, bs); + } + return pointer - offset; + } + + // nested encoder + + /** + * @dev The encoder for inner struct + * @param r The struct to be encoded + * @param p The offset of bytes array to start decode + * @param bs The bytes array to be decoded + * @return The number of bytes encoded + */ + function _encode_nested(Data memory r, uint256 p, bytes memory bs) internal pure returns (uint256) { + /** + * First encoded `r` into a temporary array, and encode the actual size used. + * Then copy the temporary array into `bs`. + */ + uint256 offset = p; + uint256 pointer = p; + bytes memory tmp = new bytes(_estimate(r)); + uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp); + uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs); + uint256 size = _encode(r, 32, tmp); + pointer += ProtoBufRuntime._encode_varint(size, pointer, bs); + ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size); + pointer += size; + delete tmp; + return pointer - offset; + } + + // estimator + + /** + * @dev The estimator for a struct + * @param r The struct to be encoded + * @return The number of bytes encoded in estimation + */ + function _estimate(Data memory r) internal pure returns (uint256) { + uint256 e; + e += 1 + ProtoBufRuntime._sz_uint64(r.version_number); + e += 1 + ProtoBufRuntime._sz_uint64(r.version_height); + return e; + } + // empty checker + + function _empty(Data memory r) internal pure returns (bool) { + if (r.version_number != 0) { + return false; + } + + if (r.version_height != 0) { + return false; + } + + return true; + } + + //store function + /** + * @dev Store in-memory struct to storage + * @param input The in-memory struct + * @param output The in-storage struct + */ + function store(Data memory input, Data storage output) internal { + output.version_number = input.version_number; + output.version_height = input.version_height; + } + + //utility functions + /** + * @dev Return an empty struct + * @return r The empty struct + */ + function nil() internal pure returns (Data memory r) { + assembly { + r := 0 + } + } + + /** + * @dev Test whether a struct is empty + * @param x The struct to be tested + * @return r True if it is empty + */ + function isNil(Data memory x) internal pure returns (bool r) { + assembly { + r := iszero(x) + } + } +} +//library IbcCoreClientV1Height