diff --git a/app/scripts/abi.sh b/app/scripts/abi.sh index 4a92977c63..824915972f 100644 --- a/app/scripts/abi.sh +++ b/app/scripts/abi.sh @@ -8,10 +8,10 @@ nix build .#evm-contracts --print-build-logs IBC_HANDLER=$(jq --slurp 'map(.abi) | add' \ result/out/IBCClient.sol/IBCClient.json \ - result/out/IBCPacket.sol/IBCPacket.json \ - result/out/IBCConnection.sol/IBCConnection.json \ + result/out/IBCPacket.sol/IBCPacketImpl.json \ + result/out/IBCConnection.sol/IBCConnectionImpl.json \ result/out/OwnableIBCHandler.sol/OwnableIBCHandler.json \ - result/out/IBCChannelHandshake.sol/IBCChannelHandshake.json) + result/out/IBCChannel.sol/IBCChannelImpl.json) echo "export const ibcHandlerAbi = ${IBC_HANDLER}" >| app/src/lib/abi/ibc-handler.ts diff --git a/evm/ARCHITECTURE.md b/evm/ARCHITECTURE.md index 7d4e05e4d8..5b6373f6a9 100644 --- a/evm/ARCHITECTURE.md +++ b/evm/ARCHITECTURE.md @@ -67,7 +67,7 @@ sequenceDiagram ``` -To relax the contract size limit of ethereum, each ICS implementation is split into [IBCClient](contracts/core/02-client/IBCClient.sol), [IBCConnection](contracts/core/03-connection/IBCConnection.sol), [IBCChannel](contracts/core/04-channel/IBCChannelHandshake.sol), [IBCPacket](contracts/core/04-channel/IBCPacket.sol), and [IBCHandler](contracts/core/25-handler/IBCHandler.sol) contracts, as shown in the above figure. +To relax the contract size limit of ethereum, each ICS implementation is split into [IBCClient](contracts/core/02-client/IBCClient.sol), [IBCConnection](contracts/core/03-connection/IBCConnection.sol), [IBCChannel](contracts/core/04-channel/IBCChannel.sol), [IBCPacket](contracts/core/04-channel/IBCPacket.sol), and [IBCHandler](contracts/core/25-handler/IBCHandler.sol) contracts, as shown in the above figure. In general, such a design causes storage splitting, so it is required to implement unnecessary authentication and accessors for inter-contract calls. diff --git a/evm/contracts/Glue.sol b/evm/contracts/Glue.sol deleted file mode 100644 index abd8ce38c1..0000000000 --- a/evm/contracts/Glue.sol +++ /dev/null @@ -1,39 +0,0 @@ -pragma solidity ^0.8.23; - -import "./core/02-client/ILightClient.sol"; -import "./core/02-client/IBCHeight.sol"; -import "./proto/ibc/core/client/v1/client.sol"; -import "./proto/ibc/core/commitment/v1/commitment.sol"; -import "./proto/ibc/core/connection/v1/connection.sol"; -import "./proto/ibc/lightclients/tendermint/v1/tendermint.sol"; -import "./proto/cosmos/ics23/v1/proofs.sol"; -import "./proto/tendermint/types/types.sol"; -import "./proto/tendermint/types/canonical.sol"; -import "./proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; -import "./proto/union/ibc/lightclients/cosmosincosmos/v1/cosmosincosmos.sol"; -import "./proto/ibc/lightclients/wasm/v1/wasm.sol"; -import "./lib/Common.sol"; -import "./clients/CosmosInCosmosClient.sol"; -import "./clients/CometblsClientV2.sol"; - -contract Glue { - function typesTelescope( - UnionIbcLightclientsCometblsV1ClientState.Data memory, - UnionIbcLightclientsCometblsV1ConsensusState.Data memory, - UnionIbcLightclientsCometblsV1Header.Data memory, - UnionIbcLightclientsCosmosincosmosV1ClientState.Data memory, - UnionIbcLightclientsCosmosincosmosV1Header.Data memory, - OptimizedCosmosInCosmosConsensusState memory, - TendermintTypesHeader.Data memory, - TendermintTypesCommit.Data memory, - IbcCoreClientV1Height.Data memory, - OptimizedConsensusState memory, - ProcessedMoment memory, - TendermintTypesCanonicalVote.Data memory, - IbcLightclientsTendermintV1ClientState.Data memory, - IbcLightclientsTendermintV1ConsensusState.Data memory, - IbcLightclientsTendermintV1Header.Data memory, - IbcCoreCommitmentV1MerkleProof.Data memory, - IbcCoreConnectionV1ConnectionEnd.Data memory - ) public pure {} -} diff --git a/evm/contracts/Multicall.sol b/evm/contracts/Multicall.sol index b259499c3d..d4c412eeb9 100644 --- a/evm/contracts/Multicall.sol +++ b/evm/contracts/Multicall.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; struct Call3 { address target; @@ -14,11 +14,9 @@ struct Result { event MulticallResult(Result[]); contract Multicall { - function multicall(Call3[] calldata calls) - public - payable - returns (Result[] memory returnData) - { + function multicall( + Call3[] calldata calls + ) public payable returns (Result[] memory returnData) { uint256 length = calls.length; returnData = new Result[](length); Call3 calldata calli; diff --git a/evm/contracts/apps/Base.sol b/evm/contracts/apps/Base.sol index 71a2fbbc27..4652bd0d3f 100644 --- a/evm/contracts/apps/Base.sol +++ b/evm/contracts/apps/Base.sol @@ -1,9 +1,10 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "../core/05-port/IIBCModule.sol"; library IBCAppLib { error ErrNotIBC(); + error ErrNotImplemented(); } /** @@ -35,56 +36,52 @@ abstract contract IBCAppBase is IIBCModule { /** * @dev See IIBCModule-onChanOpenInit * - * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. + * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanOpenInit( - IbcCoreChannelV1GlobalEnums.Order, - string[] calldata connectionHops, - string calldata portId, - string calldata channelId, - IbcCoreChannelV1Counterparty.Data calldata counterpartyEndpoint, - string calldata version, - address relayer + IBCChannelOrder, + uint32, + uint32, + IBCChannelCounterparty calldata, + bytes32, + address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onChanOpenTry * - * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. + * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order, - string[] calldata connectionHops, - string calldata portId, - string calldata channelId, - IbcCoreChannelV1Counterparty.Data calldata counterpartyEndpoint, - string calldata version, - string calldata counterpartyVersion, - address relayer + IBCChannelOrder, + uint32, + uint32, + IBCChannelCounterparty calldata, + bytes32, + bytes32, + address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onChanOpenAck * - * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. + * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanOpenAck( - string calldata portId, - string calldata channelId, - string calldata counterpartyChannelId, - string calldata counterpartyVersion, - address relayer + uint32, + uint32, + bytes32, + address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onChanOpenConfirm * - * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. + * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanOpenConfirm( - string calldata portId, - string calldata channelId, - address relayer + uint32, + address ) external virtual override onlyIBC {} /** @@ -93,9 +90,8 @@ abstract contract IBCAppBase is IIBCModule { * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanCloseInit( - string calldata portId, - string calldata channelId, - address relayer + uint32, + address ) external virtual override onlyIBC {} /** @@ -104,19 +100,19 @@ abstract contract IBCAppBase is IIBCModule { * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanCloseConfirm( - string calldata portId, - string calldata channelId, - address relayer + uint32, + address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onRecvPacket * - * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. + * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onRecvPacket( - IbcCoreChannelV1Packet.Data calldata packet, - address relayer + IBCPacket calldata, + address, + bytes calldata ) external virtual @@ -125,24 +121,37 @@ abstract contract IBCAppBase is IIBCModule { returns (bytes memory acknowledgement) {} + /** + * @dev See IIBCModule-onRecvIntentPacket + * + * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. + */ + function onRecvIntentPacket( + IBCPacket calldata, + address, + bytes calldata + ) external virtual override onlyIBC returns (bytes memory) { + revert IBCAppLib.ErrNotImplemented(); + } + /** * @dev See IIBCModule-onAcknowledgementPacket * - * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. + * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onAcknowledgementPacket( - IbcCoreChannelV1Packet.Data calldata packet, - bytes calldata acknowledgement, - address relayer + IBCPacket calldata, + bytes calldata, + address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onTimeoutPacket * - * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. + * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onTimeoutPacket( - IbcCoreChannelV1Packet.Data calldata packet, - address relayer + IBCPacket calldata, + address ) external virtual override onlyIBC {} } diff --git a/evm/contracts/apps/ucs/00-pingpong/PingPong.sol b/evm/contracts/apps/ucs/00-pingpong/PingPong.sol index 1e5094282c..40bd34159b 100644 --- a/evm/contracts/apps/ucs/00-pingpong/PingPong.sol +++ b/evm/contracts/apps/ucs/00-pingpong/PingPong.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "../../Base.sol"; import "../../../core/25-handler/IBCHandler.sol"; @@ -21,19 +21,15 @@ library PingPongLib { event TimedOut(); event Acknowledged(); - function encode(PingPongPacket memory packet) - internal - pure - returns (bytes memory) - { + function encode( + PingPongPacket memory packet + ) internal pure returns (bytes memory) { return abi.encode(packet.ping, packet.counterpartyTimeout); } - function decode(bytes memory packet) - internal - pure - returns (PingPongPacket memory) - { + function decode( + bytes memory packet + ) internal pure returns (PingPongPacket memory) { (bool ping, uint64 counterpartyTimeout) = abi.decode(packet, (bool, uint64)); return PingPongPacket({ @@ -47,17 +43,11 @@ contract PingPong is IBCAppBase { using PingPongLib for *; IBCHandler private ibcHandler; - string private channelId; - uint64 private revisionNumber; + uint32 private srcChannelId; uint64 private timeout; - constructor( - IBCHandler _ibcHandler, - uint64 _revisionNumber, - uint64 _timeout - ) { + constructor(IBCHandler _ibcHandler, uint64 _timeout) { ibcHandler = _ibcHandler; - revisionNumber = _revisionNumber; timeout = _timeout; } @@ -69,13 +59,13 @@ contract PingPong is IBCAppBase { PingPongPacket memory packet, uint64 localTimeout ) public { - if (bytes(channelId).length == 0) { + if (srcChannelId == 0) { revert PingPongLib.ErrNoChannel(); } ibcHandler.sendPacket( - channelId, + srcChannelId, // No height timeout - IbcCoreClientV1Height.Data({revision_number: 0, revision_height: 0}), + 0, // Timestamp timeout localTimeout, // Raw protocol packet @@ -84,8 +74,9 @@ contract PingPong is IBCAppBase { } function onRecvPacket( - IbcCoreChannelV1Packet.Data calldata packet, - address + IBCPacket calldata packet, + address, + bytes calldata ) external virtual @@ -100,7 +91,7 @@ contract PingPong is IBCAppBase { uint64 localTimeout = pp.counterpartyTimeout; pp.ping = !pp.ping; - pp.counterpartyTimeout = uint64(block.timestamp) + timeout; + pp.counterpartyTimeout = uint64(block.timestamp * 1e9) + timeout; // Send back the packet after having reversed the bool and set the counterparty timeout initiate(pp, localTimeout); @@ -110,7 +101,7 @@ contract PingPong is IBCAppBase { } function onAcknowledgementPacket( - IbcCoreChannelV1Packet.Data calldata, + IBCPacket calldata, bytes calldata acknowledgement, address ) external virtual override onlyIBC { @@ -129,7 +120,7 @@ contract PingPong is IBCAppBase { } function onTimeoutPacket( - IbcCoreChannelV1Packet.Data calldata, + IBCPacket calldata, address ) external virtual override onlyIBC { /* @@ -140,59 +131,54 @@ contract PingPong is IBCAppBase { } function onChanOpenInit( - IbcCoreChannelV1GlobalEnums.Order, - string[] calldata, - string calldata, - string calldata, - IbcCoreChannelV1Counterparty.Data calldata, - string calldata, + IBCChannelOrder, + uint32, + uint32, + IBCChannelCounterparty calldata, + bytes32, address ) external virtual override onlyIBC { // This protocol is only accepting a single counterparty. - if (bytes(channelId).length != 0) { + if (srcChannelId != 0) { revert PingPongLib.ErrOnlyOneChannel(); } } function onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order, - string[] calldata, - string calldata, - string calldata, - IbcCoreChannelV1Counterparty.Data calldata, - string calldata, - string calldata, + IBCChannelOrder, + uint32, + uint32, + IBCChannelCounterparty calldata, + bytes32, + bytes32, address ) external virtual override onlyIBC { // Symmetric to onChanOpenInit - if (bytes(channelId).length != 0) { + if (srcChannelId != 0) { revert PingPongLib.ErrOnlyOneChannel(); } } function onChanOpenAck( - string calldata, - string calldata _channelId, - string calldata, - string calldata, + uint32 channelId, + uint32, + bytes32, address ) external virtual override onlyIBC { // Store the port/channel needed to send packets. - channelId = _channelId; + srcChannelId = channelId; } function onChanOpenConfirm( - string calldata, - string calldata _channelId, + uint32 channelId, address ) external virtual override onlyIBC { // Symmetric to onChanOpenAck - channelId = _channelId; + srcChannelId = channelId; } function onChanCloseInit( - string calldata, - string calldata, + uint32, address ) external virtual override onlyIBC { // The ping-pong is infinite, closing the channel is disallowed. @@ -200,8 +186,7 @@ contract PingPong is IBCAppBase { } function onChanCloseConfirm( - string calldata, - string calldata, + uint32, address ) external virtual override onlyIBC { // Symmetric to onChanCloseInit diff --git a/evm/contracts/apps/ucs/01-relay/ERC20Denom.sol b/evm/contracts/apps/ucs/01-relay/ERC20Denom.sol index 155e2b9bb8..d672daee27 100644 --- a/evm/contracts/apps/ucs/01-relay/ERC20Denom.sol +++ b/evm/contracts/apps/ucs/01-relay/ERC20Denom.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "@openzeppelin/token/ERC20/ERC20.sol"; import "./IERC20Denom.sol"; @@ -12,7 +12,9 @@ contract ERC20Denom is ERC20, IERC20Denom { string private _symbol; uint8 private _decimals; - constructor(string memory denomName) ERC20(denomName, denomName) { + constructor( + string memory denomName + ) ERC20(denomName, denomName) { admin = msg.sender; } diff --git a/evm/contracts/apps/ucs/01-relay/IERC20Denom.sol b/evm/contracts/apps/ucs/01-relay/IERC20Denom.sol index 950cb18c61..8feba8b444 100644 --- a/evm/contracts/apps/ucs/01-relay/IERC20Denom.sol +++ b/evm/contracts/apps/ucs/01-relay/IERC20Denom.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "@openzeppelin/token/ERC20/IERC20.sol"; import "@openzeppelin/token/ERC20/extensions/IERC20Metadata.sol"; diff --git a/evm/contracts/apps/ucs/01-relay/Relay.sol b/evm/contracts/apps/ucs/01-relay/Relay.sol index 516b1ef362..ffb4949191 100644 --- a/evm/contracts/apps/ucs/01-relay/Relay.sol +++ b/evm/contracts/apps/ucs/01-relay/Relay.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; @@ -42,21 +42,21 @@ struct RelayPacket { interface IRelay is IIBCModule { function getDenomAddress( - string memory sourceChannel, + uint32 sourceChannel, string memory denom ) external view returns (address); function getOutstanding( - string memory sourceChannel, + uint32 sourceChannel, address token ) external view returns (uint256); function send( - string calldata sourceChannel, + uint32 sourceChannel, bytes calldata receiver, LocalToken[] calldata tokens, string calldata extension, - IbcCoreClientV1Height.Data calldata timeoutHeight, + uint64 timeoutHeight, uint64 timeoutTimestamp ) external; } @@ -73,22 +73,22 @@ library RelayLib { error ErrInvalidAmount(); error ErrUnstoppable(); - IbcCoreChannelV1GlobalEnums.Order public constant ORDER = - IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED; - string public constant VERSION = "ucs01-relay-1"; + IBCChannelOrder public constant ORDER = IBCChannelOrder.Unordered; + + bytes32 public constant VERSION = keccak256("ucs01-relay-1"); bytes1 public constant ACK_SUCCESS = 0x01; bytes1 public constant ACK_FAILURE = 0x00; uint256 public constant ACK_LENGTH = 1; event DenomCreated( uint64 indexed packetSequence, - string channelId, + uint32 channelId, string denom, address token ); event Received( uint64 packetSequence, - string channelId, + uint32 channelId, string sender, address indexed receiver, string denom, @@ -97,7 +97,7 @@ library RelayLib { ); event FeePaid( uint64 packetSequence, - string channelId, + uint32 channelId, string sender, address indexed receiver, string denom, @@ -106,7 +106,7 @@ library RelayLib { ); event Sent( uint64 packetSequence, - string channelId, + uint32 channelId, address indexed sender, string receiver, string denom, @@ -115,7 +115,7 @@ library RelayLib { ); event Refunded( uint64 packetSequence, - string channelId, + uint32 channelId, address indexed sender, string receiver, string denom, @@ -123,40 +123,36 @@ library RelayLib { uint256 amount ); - function isValidVersion(string memory version) - internal - pure - returns (bool) - { - return version.eq(VERSION); + function isValidVersion( + bytes32 version + ) internal pure returns (bool) { + return version == VERSION; } function isFromChannel( - string memory portId, - string memory channelId, + uint32 channelId, string memory denom ) internal pure returns (bool) { return bytes(denom).length > 0 - && denom.startsWith(makeDenomPrefix(portId, channelId)); + && denom.startsWith(makeDenomPrefix(channelId)); } function makeDenomPrefix( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (string memory) { - return string(abi.encodePacked(portId, "/", channelId, "/")); + return string(abi.encodePacked(channelId, "/")); } function makeForeignDenom( - string memory portId, - string memory channelId, + uint32 channelId, string memory denom ) internal pure returns (string memory) { - return - string(abi.encodePacked(makeDenomPrefix(portId, channelId), denom)); + return string(abi.encodePacked(makeDenomPrefix(channelId), denom)); } - function bytesToAddress(bytes memory b) internal pure returns (address) { + function bytesToAddress( + bytes memory b + ) internal pure returns (address) { if (b.length != 20) { revert ErrInvalidBytesAddress(); } @@ -165,21 +161,17 @@ library RelayLib { } library RelayPacketLib { - function encode(RelayPacket memory packet) - internal - pure - returns (bytes memory) - { + function encode( + RelayPacket memory packet + ) internal pure returns (bytes memory) { return abi.encode( packet.sender, packet.receiver, packet.tokens, packet.extension ); } - function decode(bytes calldata stream) - internal - pure - returns (RelayPacket calldata) - { + function decode( + bytes calldata stream + ) internal pure returns (RelayPacket calldata) { RelayPacket calldata packet; assembly { packet := stream.offset @@ -203,11 +195,11 @@ contract UCS01Relay is IIBCPacket private ibcHandler; // A mapping from remote denom to local ERC20 wrapper. - mapping(string => mapping(string => address)) private denomToAddress; + mapping(uint32 => mapping(string => address)) private denomToAddress; // A mapping from a local ERC20 wrapper to the remote denom. // Required to determine whether an ERC20 token is originating from a remote chain. - mapping(string => mapping(address => string)) private addressToDenom; - mapping(string => mapping(address => uint256)) private outstanding; + mapping(uint32 => mapping(address => string)) private addressToDenom; + mapping(uint32 => mapping(address => uint256)) private outstanding; constructor() { _disableInitializers(); @@ -227,7 +219,7 @@ contract UCS01Relay is // Return the ERC20 wrapper for the given remote-native denom. function getDenomAddress( - string memory sourceChannel, + uint32 sourceChannel, string memory denom ) external view override returns (address) { return denomToAddress[sourceChannel][denom]; @@ -235,7 +227,7 @@ contract UCS01Relay is // Return the amount of tokens submitted through the given port/channel. function getOutstanding( - string memory sourceChannel, + uint32 sourceChannel, address token ) external view override returns (uint256) { return outstanding[sourceChannel][token]; @@ -244,7 +236,7 @@ contract UCS01Relay is // Increase the oustanding amount on the given port/channel. // Happens when we send the token. function increaseOutstanding( - string memory sourceChannel, + uint32 sourceChannel, address token, uint256 amount ) internal { @@ -254,7 +246,7 @@ contract UCS01Relay is // Decrease the outstanding amount on the given port/channel. // Happens either when receiving previously sent tokens or when refunding. function decreaseOutstanding( - string memory sourceChannel, + uint32 sourceChannel, address token, uint256 amount ) internal { @@ -276,7 +268,7 @@ contract UCS01Relay is // If token is native, we increase the oustanding amount and escrow it. Otherwise, we burn the amount. // The operation is symmetric with the counterparty, if we burn locally, the remote relay will unescrow. If we escrow locally, the remote relay will mint. function sendToken( - string calldata sourceChannel, + uint32 sourceChannel, LocalToken calldata localToken ) internal returns (string memory) { if (localToken.amount == 0) { @@ -306,11 +298,11 @@ contract UCS01Relay is } function send( - string calldata sourceChannel, + uint32 sourceChannel, bytes calldata receiver, LocalToken[] calldata tokens, string calldata extension, - IbcCoreClientV1Height.Data calldata timeoutHeight, + uint64 timeoutHeight, uint64 timeoutTimestamp ) external override { Token[] memory normalizedTokens = new Token[](tokens.length); @@ -347,7 +339,7 @@ contract UCS01Relay is function refundTokens( uint64 sequence, - string memory channelId, + uint32 channelId, RelayPacket calldata packet ) internal { string memory receiver = packet.receiver.toHexString(); @@ -392,7 +384,7 @@ contract UCS01Relay is } function onRecvLocalTransfer( - string memory destinationChannel, + uint32 destinationChannel, string memory denom, address receiver, uint256 amount, @@ -412,7 +404,7 @@ contract UCS01Relay is function onRecvRemoteTransfer( uint64 sequence, - string memory destinationChannel, + uint32 destinationChannel, string memory denom, address receiver, uint256 amount, @@ -437,16 +429,14 @@ contract UCS01Relay is } function onRecvPacketProcessing( - IbcCoreChannelV1Packet.Data calldata ibcPacket, + IBCPacket calldata ibcPacket, address relayer ) public { if (msg.sender != address(this)) { revert RelayLib.ErrUnauthorized(); } RelayPacket calldata packet = RelayPacketLib.decode(ibcPacket.data); - string memory prefix = RelayLib.makeDenomPrefix( - ibcPacket.source_port, ibcPacket.source_channel - ); + string memory prefix = RelayLib.makeDenomPrefix(ibcPacket.sourceChannel); uint256 packetTokensLength = packet.tokens.length; for (uint256 i; i < packetTokensLength; i++) { Token memory token = packet.tokens[i]; @@ -460,11 +450,11 @@ contract UCS01Relay is string memory denom; if (token.denom.startsWith(prefix)) { // In this branch the token was originating from - // this chain as it was prefixed by the local channel/port. + // this chain as it was prefixed by the remote channel/port. // We need to unescrow the amount. denom = token.denom.slice(bytes(prefix).length); denomAddress = onRecvLocalTransfer( - ibcPacket.destination_channel, + ibcPacket.destinationChannel, denom, receiver, actualAmount, @@ -475,13 +465,11 @@ contract UCS01Relay is // In this branch the token was originating from the // counterparty chain. We need to prefix the denom and mint the amount. denom = RelayLib.makeForeignDenom( - ibcPacket.destination_port, - ibcPacket.destination_channel, - token.denom + ibcPacket.destinationChannel, token.denom ); denomAddress = onRecvRemoteTransfer( ibcPacket.sequence, - ibcPacket.destination_channel, + ibcPacket.destinationChannel, denom, receiver, actualAmount, @@ -492,7 +480,7 @@ contract UCS01Relay is string memory senderAddress = packet.sender.toHexString(); emit RelayLib.Received( ibcPacket.sequence, - ibcPacket.destination_channel, + ibcPacket.destinationChannel, senderAddress, receiver, denom, @@ -502,7 +490,7 @@ contract UCS01Relay is if (feeAmount > 0) { emit RelayLib.FeePaid( ibcPacket.sequence, - ibcPacket.destination_channel, + ibcPacket.destinationChannel, senderAddress, relayer, denom, @@ -514,8 +502,9 @@ contract UCS01Relay is } function onRecvPacket( - IbcCoreChannelV1Packet.Data calldata ibcPacket, - address relayer + IBCPacket calldata ibcPacket, + address relayer, + bytes calldata ) external override(IBCAppBase, IIBCModule) @@ -538,7 +527,7 @@ contract UCS01Relay is } function onAcknowledgementPacket( - IbcCoreChannelV1Packet.Data calldata ibcPacket, + IBCPacket calldata ibcPacket, bytes calldata acknowledgement, address ) external override(IBCAppBase, IIBCModule) onlyIBC { @@ -555,30 +544,29 @@ contract UCS01Relay is if (acknowledgement[0] == RelayLib.ACK_FAILURE) { refundTokens( ibcPacket.sequence, - ibcPacket.source_channel, + ibcPacket.sourceChannel, RelayPacketLib.decode(ibcPacket.data) ); } } function onTimeoutPacket( - IbcCoreChannelV1Packet.Data calldata ibcPacket, + IBCPacket calldata ibcPacket, address ) external override(IBCAppBase, IIBCModule) onlyIBC { refundTokens( ibcPacket.sequence, - ibcPacket.source_channel, + ibcPacket.sourceChannel, RelayPacketLib.decode(ibcPacket.data) ); } function onChanOpenInit( - IbcCoreChannelV1GlobalEnums.Order order, - string[] calldata, - string calldata, - string calldata, - IbcCoreChannelV1Counterparty.Data calldata, - string calldata version, + IBCChannelOrder order, + uint32, + uint32, + IBCChannelCounterparty calldata, + bytes32 version, address ) external view override(IBCAppBase, IIBCModule) onlyIBC { if (!RelayLib.isValidVersion(version)) { @@ -590,13 +578,12 @@ contract UCS01Relay is } function onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order order, - string[] calldata, - string calldata, - string calldata, - IbcCoreChannelV1Counterparty.Data calldata, - string calldata version, - string calldata counterpartyVersion, + IBCChannelOrder order, + uint32, + uint32, + IBCChannelCounterparty calldata, + bytes32 version, + bytes32 counterpartyVersion, address ) external view override(IBCAppBase, IIBCModule) onlyIBC { if (!RelayLib.isValidVersion(version)) { @@ -611,10 +598,9 @@ contract UCS01Relay is } function onChanOpenAck( - string calldata, - string calldata, - string calldata, - string calldata counterpartyVersion, + uint32, + uint32, + bytes32 counterpartyVersion, address ) external view override(IBCAppBase, IIBCModule) onlyIBC { if (!RelayLib.isValidVersion(counterpartyVersion)) { @@ -622,31 +608,21 @@ contract UCS01Relay is } } - function onChanOpenConfirm( - string calldata, - string calldata, - address - ) external override(IBCAppBase, IIBCModule) onlyIBC {} - function onChanCloseInit( - string calldata, - string calldata, + uint32, address ) external view override(IBCAppBase, IIBCModule) onlyIBC { revert RelayLib.ErrUnstoppable(); } function onChanCloseConfirm( - string calldata, - string calldata, + uint32, address ) external view override(IBCAppBase, IIBCModule) onlyIBC { revert RelayLib.ErrUnstoppable(); } - function _authorizeUpgrade(address newImplementation) - internal - override - onlyOwner - {} + function _authorizeUpgrade( + address newImplementation + ) internal override onlyOwner {} } diff --git a/evm/contracts/apps/ucs/02-nft/ERC721Denom.sol b/evm/contracts/apps/ucs/02-nft/ERC721Denom.sol index 71be21f715..d3531e06f8 100644 --- a/evm/contracts/apps/ucs/02-nft/ERC721Denom.sol +++ b/evm/contracts/apps/ucs/02-nft/ERC721Denom.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "@openzeppelin/token/ERC721/extensions/ERC721URIStorage.sol"; import "./IERC721Denom.sol"; @@ -27,7 +27,9 @@ contract ERC721Denom is ERC721URIStorage, IERC721Denom { _setTokenURI(tokenId, tokenURI); } - function burn(uint256 tokenId) external { + function burn( + uint256 tokenId + ) external { if (msg.sender != admin) { revert ERC721Unauthorized(); } diff --git a/evm/contracts/apps/ucs/02-nft/IERC721Denom.sol b/evm/contracts/apps/ucs/02-nft/IERC721Denom.sol index 586925fbb7..39b5beff0f 100644 --- a/evm/contracts/apps/ucs/02-nft/IERC721Denom.sol +++ b/evm/contracts/apps/ucs/02-nft/IERC721Denom.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "@openzeppelin/token/ERC721/IERC721.sol"; @@ -9,5 +9,7 @@ interface IERC721Denom is IERC721 { string calldata tokenURI ) external; - function burn(uint256 tokenId) external; + function burn( + uint256 tokenId + ) external; } diff --git a/evm/contracts/apps/ucs/02-nft/NFT.sol b/evm/contracts/apps/ucs/02-nft/NFT.sol index 28731387e6..ea1547e91f 100644 --- a/evm/contracts/apps/ucs/02-nft/NFT.sol +++ b/evm/contracts/apps/ucs/02-nft/NFT.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; @@ -16,7 +16,7 @@ import "solidity-stringutils/strings.sol"; import "solidity-bytes-utils/BytesLib.sol"; import "../../../core/04-channel/IIBCPacket.sol"; -import "../../../core/02-client/IBCHeight.sol"; +import "../../../core/Types.sol"; import "../../../lib/Hex.sol"; import "../../Base.sol"; import "./IERC721Denom.sol"; @@ -35,11 +35,9 @@ struct NFTPacket { } library NFTPacketLib { - function encode(NFTPacket memory packet) - internal - pure - returns (bytes memory) - { + function encode( + NFTPacket memory packet + ) internal pure returns (bytes memory) { return abi.encode( packet.classOwner, packet.classId, @@ -53,11 +51,9 @@ library NFTPacketLib { ); } - function decode(bytes calldata stream) - internal - pure - returns (NFTPacket calldata) - { + function decode( + bytes calldata stream + ) internal pure returns (NFTPacket calldata) { NFTPacket calldata packet; assembly { packet := stream.offset @@ -78,19 +74,18 @@ library NFTLib { error ErrInvalidCounterpartyProtocolVersion(); error ErrUnstoppable(); - IbcCoreChannelV1GlobalEnums.Order public constant ORDER = - IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED; - string public constant VERSION = "ucs02-nft-1"; + IBCChannelOrder public constant ORDER = IBCChannelOrder.Unordered; + bytes32 public constant VERSION = keccak256("ucs02-nft-1"); bytes1 public constant ACK_SUCCESS = 0x01; bytes1 public constant ACK_FAILURE = 0x00; uint256 public constant ACK_LENGTH = 1; event ClassCreated( - uint64 packetSequence, string channelId, address indexed nftClass + uint64 packetSequence, uint32 channelId, address indexed nftClass ); event Received( uint64 packetSequence, - string channelId, + uint32 channelId, string sender, address receiver, address indexed nftClass, @@ -98,7 +93,7 @@ library NFTLib { ); event Sent( uint64 packetSequence, - string channelId, + uint32 channelId, address sender, string receiver, address indexed nftClass, @@ -106,48 +101,43 @@ library NFTLib { ); event Refunded( uint64 packetSequence, - string channelId, + uint32 channelId, address sender, string receiver, address indexed nftClass, uint256[] tokenIds ); - function isValidVersion(string memory version) - internal - pure - returns (bool) - { - return version.eq(VERSION); + function isValidVersion( + bytes32 version + ) internal pure returns (bool) { + return version == VERSION; } function isFromChannel( - string memory portId, - string memory channelId, + uint32 channelId, string memory nftDenom ) internal pure returns (bool) { return bytes(nftDenom).length > 0 - && nftDenom.startsWith(makeDenomPrefix(portId, channelId)); + && nftDenom.startsWith(makeDenomPrefix(channelId)); } function makeDenomPrefix( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (string memory) { - return string(abi.encodePacked(portId, "/", channelId, "/")); + return string(abi.encodePacked(channelId, "/")); } function makeForeignDenom( - string memory portId, - string memory channelId, + uint32 channelId, string memory nftDenom ) internal pure returns (string memory) { - return string( - abi.encodePacked(makeDenomPrefix(portId, channelId), nftDenom) - ); + return string(abi.encodePacked(makeDenomPrefix(channelId), nftDenom)); } - function bytesToAddress(bytes memory b) internal pure returns (address) { + function bytesToAddress( + bytes memory b + ) internal pure returns (address) { if (b.length != 20) { revert ErrInvalidBytesAddress(); } @@ -171,11 +161,11 @@ contract UCS02NFT is IIBCPacket private ibcHandler; // A mapping from remote denom to local ERC721 wrapper. - mapping(string => mapping(string => address)) private denomToNft; + mapping(uint32 => mapping(string => address)) private denomToNft; // A mapping from a local ERC721 wrapper to the remote denom. // Required to determine whether an ERC721 token is originating from a remote chain. - mapping(string => mapping(address => string)) private nftToDenom; - mapping(string => mapping(address => uint256)) private outstanding; + mapping(uint32 => mapping(address => string)) private nftToDenom; + mapping(uint32 => mapping(address => uint256)) private outstanding; constructor() { _disableInitializers(); @@ -202,28 +192,28 @@ contract UCS02NFT is return address(ibcHandler); } - // Return the amount of tokens submitted through the given port/channel. + // Return the amount of tokens submitted through the given channel. function getOutstanding( - string memory sourceChannel, + uint32 sourceChannel, address token ) external view returns (uint256) { return outstanding[sourceChannel][token]; } - // Increase the oustanding amount on the given port/channel. + // Increase the oustanding amount on the given channel. // Happens when we send the token. function increaseOutstanding( - string memory sourceChannel, + uint32 sourceChannel, address nftClass, uint256 amount ) internal { outstanding[sourceChannel][nftClass] += amount; } - // Decrease the outstanding amount on the given port/channel. + // Decrease the outstanding amount on the given channel. // Happens either when receiving previously sent tokens or when refunding. function decreaseOutstanding( - string memory sourceChannel, + uint32 sourceChannel, address nftClass, uint256 amount ) internal { @@ -242,7 +232,7 @@ contract UCS02NFT is } function sendLocalNative( - string calldata sourceChannel, + uint32 sourceChannel, address nftClass, uint256[] calldata tokens ) internal { @@ -296,7 +286,7 @@ contract UCS02NFT is } function send( - string calldata sourceChannel, + uint32 sourceChannel, string calldata receiver, address nftClass, uint256[] calldata tokens, @@ -325,9 +315,8 @@ contract UCS02NFT is sendRemoteNative(nftClass, tokens); } - uint64 packetSequence = ibcHandler.sendPacket( - sourceChannel, IBCHeight.zero(), timeoutTimestamp, data - ); + uint64 packetSequence = + ibcHandler.sendPacket(sourceChannel, 0, timeoutTimestamp, data); emit NFTLib.Sent( packetSequence, @@ -340,8 +329,9 @@ contract UCS02NFT is } function onRecvPacket( - IbcCoreChannelV1Packet.Data calldata ibcPacket, - address relayer + IBCPacket calldata ibcPacket, + address relayer, + bytes calldata ) external override onlyIBC returns (bytes memory) { // TODO: maybe consider threading _res in the failure ack (bool success,) = address(this).call( @@ -359,19 +349,19 @@ contract UCS02NFT is } function receiveRemoteNative( - IbcCoreChannelV1Packet.Data calldata ibcPacket, + IBCPacket calldata ibcPacket, NFTPacket calldata packet, address receiver, string memory nftDenom ) internal returns (address) { - address nftClass = denomToNft[ibcPacket.destination_channel][nftDenom]; + address nftClass = denomToNft[ibcPacket.destinationChannel][nftDenom]; if (nftClass == address(0)) { nftClass = address(new ERC721Denom(packet.className, packet.classSymbol)); - denomToNft[ibcPacket.destination_channel][nftDenom] = nftClass; - nftToDenom[ibcPacket.destination_channel][nftClass] = nftDenom; + denomToNft[ibcPacket.destinationChannel][nftDenom] = nftClass; + nftToDenom[ibcPacket.destinationChannel][nftClass] = nftDenom; emit NFTLib.ClassCreated( - ibcPacket.sequence, ibcPacket.source_channel, nftClass + ibcPacket.sequence, ibcPacket.sourceChannel, nftClass ); } uint256 tokenIdsLength = packet.tokenIds.length; @@ -387,7 +377,7 @@ contract UCS02NFT is } function receiveLocalNative( - IbcCoreChannelV1Packet.Data calldata ibcPacket, + IBCPacket calldata ibcPacket, NFTPacket calldata packet, address receiver, string memory nftDenom @@ -395,7 +385,7 @@ contract UCS02NFT is address nftClass = Hex.hexToAddress(nftDenom); uint256 tokenIdsLength = packet.tokenIds.length; decreaseOutstanding( - ibcPacket.destination_channel, nftClass, tokenIdsLength + ibcPacket.destinationChannel, nftClass, tokenIdsLength ); for (uint256 i; i < tokenIdsLength; i++) { uint256 tokenId = packet.tokenIds[i]; @@ -407,19 +397,17 @@ contract UCS02NFT is } function onRecvPacketProcessing( - IbcCoreChannelV1Packet.Data calldata ibcPacket, + IBCPacket calldata ibcPacket, address ) public { if (msg.sender != address(this)) { revert NFTLib.ErrUnauthorized(); } NFTPacket calldata packet = NFTPacketLib.decode(ibcPacket.data); - // {src_port}/{src_channel}/denom + // {src_channel}/denom // This will trim the denom in-place IFF it is prefixed strings.slice memory trimedClassId = packet.classId.toSlice().beyond( - NFTLib.makeDenomPrefix( - ibcPacket.source_port, ibcPacket.source_channel - ).toSlice() + NFTLib.makeDenomPrefix(ibcPacket.sourceChannel).toSlice() ); address receiver = Hex.hexToAddress(packet.receiver); address nftClass; @@ -427,9 +415,7 @@ contract UCS02NFT is // In this branch the token was originating from the // counterparty chain. We need to mint the amount. string memory nftDenom = NFTLib.makeForeignDenom( - ibcPacket.destination_port, - ibcPacket.destination_channel, - packet.classId + ibcPacket.destinationChannel, packet.classId ); receiveRemoteNative(ibcPacket, packet, receiver, nftDenom); } else { @@ -440,7 +426,7 @@ contract UCS02NFT is } emit NFTLib.Received( ibcPacket.sequence, - ibcPacket.source_channel, + ibcPacket.sourceChannel, packet.sender, receiver, nftClass, @@ -449,7 +435,7 @@ contract UCS02NFT is } function onAcknowledgementPacket( - IbcCoreChannelV1Packet.Data calldata ibcPacket, + IBCPacket calldata ibcPacket, bytes calldata acknowledgement, address ) external override onlyIBC { @@ -466,7 +452,7 @@ contract UCS02NFT is if (acknowledgement[0] == NFTLib.ACK_FAILURE) { refundTokens( ibcPacket.sequence, - ibcPacket.source_channel, + ibcPacket.sourceChannel, NFTPacketLib.decode(ibcPacket.data) ); } @@ -474,7 +460,7 @@ contract UCS02NFT is function refundTokens( uint64 sequence, - string memory channelId, + uint32 channelId, NFTPacket calldata packet ) internal { // We're going to refund, the receiver will be the sender. @@ -517,23 +503,22 @@ contract UCS02NFT is } function onTimeoutPacket( - IbcCoreChannelV1Packet.Data calldata ibcPacket, + IBCPacket calldata ibcPacket, address ) external override onlyIBC { refundTokens( ibcPacket.sequence, - ibcPacket.source_channel, + ibcPacket.sourceChannel, NFTPacketLib.decode(ibcPacket.data) ); } function onChanOpenInit( - IbcCoreChannelV1GlobalEnums.Order order, - string[] calldata, - string calldata, - string calldata, - IbcCoreChannelV1Counterparty.Data calldata, - string calldata version, + IBCChannelOrder order, + uint32, + uint32, + IBCChannelCounterparty calldata, + bytes32 version, address ) external view override onlyIBC { if (!NFTLib.isValidVersion(version)) { @@ -545,13 +530,12 @@ contract UCS02NFT is } function onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order order, - string[] calldata, - string calldata, - string calldata, - IbcCoreChannelV1Counterparty.Data calldata, - string calldata version, - string calldata counterpartyVersion, + IBCChannelOrder order, + uint32, + uint32, + IBCChannelCounterparty calldata, + bytes32 version, + bytes32 counterpartyVersion, address ) external view override onlyIBC { if (!NFTLib.isValidVersion(version)) { @@ -566,10 +550,9 @@ contract UCS02NFT is } function onChanOpenAck( - string calldata, - string calldata, - string calldata, - string calldata counterpartyVersion, + uint32, + uint32, + bytes32 counterpartyVersion, address ) external view override onlyIBC { if (!NFTLib.isValidVersion(counterpartyVersion)) { @@ -577,31 +560,20 @@ contract UCS02NFT is } } - function onChanOpenConfirm( - string calldata, - string calldata, - address - ) external override onlyIBC {} + function onChanOpenConfirm(uint32, address) external override onlyIBC {} - function onChanCloseInit( - string calldata, - string calldata, - address - ) external view override onlyIBC { + function onChanCloseInit(uint32, address) external view override onlyIBC { revert NFTLib.ErrUnstoppable(); } function onChanCloseConfirm( - string calldata, - string calldata, + uint32, address ) external view override onlyIBC { revert NFTLib.ErrUnstoppable(); } - function _authorizeUpgrade(address newImplementation) - internal - override - onlyOwner - {} + function _authorizeUpgrade( + address newImplementation + ) internal override onlyOwner {} } diff --git a/evm/contracts/clients/CometblsClient.sol b/evm/contracts/clients/CometblsClient.sol new file mode 100644 index 0000000000..344b18f5e3 --- /dev/null +++ b/evm/contracts/clients/CometblsClient.sol @@ -0,0 +1,548 @@ +pragma solidity ^0.8.27; + +import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol"; +import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; +import "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol"; +import "@openzeppelin-upgradeable/utils/PausableUpgradeable.sol"; + +import "./ICS23MembershipVerifier.sol"; +import "./Verifier.sol"; + +import "../core/02-client/ILightClient.sol"; +import "../core/24-host/IBCStore.sol"; +import "../core/24-host/IBCCommitment.sol"; +import "../lib/Common.sol"; +import "../lib/ICS23.sol"; + +struct SignedHeader { + uint64 height; + uint64 secs; + uint64 nanos; + bytes32 validatorsHash; + bytes32 nextValidatorsHash; + bytes32 appHash; +} + +struct Header { + SignedHeader signedHeader; + uint64 trustedHeight; + bytes zeroKnowledgeProof; +} + +struct ClientState { + bytes31 chainId; + uint64 trustingPeriod; + uint64 maxClockDrift; + uint64 frozenHeight; + uint64 latestHeight; +} + +struct ConsensusState { + uint64 timestamp; + bytes32 appHash; + bytes32 nextValidatorsHash; +} + +library CometblsClientLib { + error ErrNotIBC(); + error ErrTrustedConsensusStateNotFound(); + error ErrUntrustedHeightLTETrustedHeight(); + error ErrUntrustedTimestampLTETrustedTimestamp(); + error ErrHeaderExpired(); + error ErrMaxClockDriftExceeded(); + error ErrInvalidZKP(); + error ErrInvalidUntrustedValidatorsHash(); + error ErrInvalidMisbehaviorHeadersSequence(); + error ErrInvalidMisbehavior(); + error ErrClientFrozen(); + error ErrInvalidInitialConsensusState(); + + function isExpired( + uint64 headerTime, + uint64 trustingPeriod, + uint64 currentTime + ) internal pure returns (bool) { + return currentTime > (headerTime + trustingPeriod); + } + + function encodeMemory( + Header memory header + ) internal pure returns (bytes memory) { + return abi.encode( + header.signedHeader, header.trustedHeight, header.zeroKnowledgeProof + ); + } + + function encode( + Header calldata header + ) internal pure returns (bytes memory) { + return abi.encode( + header.signedHeader, header.trustedHeight, header.zeroKnowledgeProof + ); + } + + function decodeHeader( + bytes calldata bz + ) internal pure returns (Header calldata) { + Header calldata header; + assembly { + header := bz.offset + } + return header; + } + + function encodeMemory( + ClientState memory clientState + ) internal pure returns (bytes memory) { + return abi.encode( + clientState.chainId, + clientState.trustingPeriod, + clientState.maxClockDrift, + clientState.frozenHeight, + clientState.latestHeight + ); + } + + function decodeClientState( + bytes calldata bz + ) internal pure returns (ClientState calldata) { + ClientState calldata clientState; + assembly { + clientState := bz.offset + } + return clientState; + } + + function encodeMemory( + ConsensusState memory consensusState + ) internal pure returns (bytes memory) { + return abi.encode( + consensusState.timestamp, + consensusState.appHash, + consensusState.nextValidatorsHash + ); + } + + function decodeConsensusState( + bytes calldata bz + ) internal pure returns (ConsensusState calldata) { + ConsensusState calldata consensusState; + assembly { + consensusState := bz.offset + } + return consensusState; + } + + function decodeConsensusStateMemory( + bytes memory bz + ) internal pure returns (ConsensusState memory) { + ConsensusState memory consensusState; + (uint64 timestamp, bytes32 appHash, bytes32 nextValidatorsHash) = + abi.decode(bz, (uint64, bytes32, bytes32)); + consensusState.timestamp = timestamp; + consensusState.appHash = appHash; + consensusState.nextValidatorsHash = nextValidatorsHash; + return consensusState; + } + + function commit( + ConsensusState memory consensusState + ) internal pure returns (bytes32) { + return keccak256(encodeMemory(consensusState)); + } + + function commit( + ClientState memory clientState + ) internal pure returns (bytes32) { + return keccak256(encodeMemory(clientState)); + } +} + +contract CometblsClient is + ILightClient, + Initializable, + UUPSUpgradeable, + OwnableUpgradeable, + PausableUpgradeable +{ + using CometblsClientLib for *; + + address private ibcHandler; + + mapping(uint32 => ClientState) private clientStates; + mapping(uint32 => mapping(uint64 => ConsensusState)) private consensusStates; + mapping(uint32 => mapping(uint64 => ProcessedMoment)) private + processedMoments; + + constructor() { + _disableInitializers(); + } + + function initialize( + address _ibcHandler, + address admin + ) public initializer { + __Ownable_init(admin); + ibcHandler = _ibcHandler; + } + + function createClient( + uint32 clientId, + bytes calldata clientStateBytes, + bytes calldata consensusStateBytes + ) external override onlyIBC returns (ConsensusStateUpdate memory update) { + ClientState calldata clientState = clientStateBytes.decodeClientState(); + ConsensusState calldata consensusState = + consensusStateBytes.decodeConsensusState(); + if (clientState.latestHeight == 0 || consensusState.timestamp == 0) { + revert CometblsClientLib.ErrInvalidInitialConsensusState(); + } + clientStates[clientId] = clientState; + consensusStates[clientId][clientState.latestHeight] = consensusState; + // Normalize to nanosecond because ibc-go recvPacket expects nanos... + processedMoments[clientId][clientState.latestHeight] = ProcessedMoment({ + timestamp: block.timestamp * 1e9, + height: block.number + }); + return ConsensusStateUpdate({ + clientStateCommitment: clientState.commit(), + consensusStateCommitment: consensusState.commit(), + height: clientState.latestHeight + }); + } + + function misbehavior( + uint32 clientId, + Header calldata headerA, + Header calldata headerB + ) public { + ClientState storage clientState = clientStates[clientId]; + bool fraud = checkMisbehavior(clientId, clientState, headerA, headerB); + if (!fraud) { + revert CometblsClientLib.ErrInvalidMisbehavior(); + } + // Similar to tendermint https://github.com/cosmos/ibc-go/blob/bbdcc8c6e965c8a2f607dfb2b61cd13712dd966a/modules/light-clients/07-tendermint/misbehaviour.go#L19 + clientState.frozenHeight = 1; + } + + function checkMisbehavior( + uint32 clientId, + ClientState storage clientState, + Header calldata headerA, + Header calldata headerB + ) internal returns (bool) { + // Ensures that A > B to simplify the misbehavior of time violation check + if (headerA.trustedHeight < headerB.trustedHeight) { + revert CometblsClientLib.ErrInvalidMisbehaviorHeadersSequence(); + } + + ConsensusState storage consensusStateA = + consensusStates[clientId][headerA.trustedHeight]; + ConsensusState storage consensusStateB = + consensusStates[clientId][headerB.trustedHeight]; + + // Check that the headers would have been accepted in an update + (, uint64 untrustedTimestampA,) = + verifyHeader(headerA, consensusStateA, clientState); + (, uint64 untrustedTimestampB,) = + verifyHeader(headerB, consensusStateB, clientState); + + if (headerA.trustedHeight == headerB.trustedHeight) { + bytes32 hashA = keccak256(abi.encode(headerA.signedHeader)); + bytes32 hashB = keccak256(abi.encode(headerB.signedHeader)); + if (hashA != hashB) { + // Misbehavior of a fork + return true; + } + } else { + // Guarantee that A > B + if (untrustedTimestampA <= untrustedTimestampB) { + // Misbehavior of time violation + return true; + } + } + return false; + } + + function verifyHeader( + Header calldata header, + ConsensusState storage consensusState, + ClientState storage clientState + ) internal returns (uint64, uint64, bytes32) { + if (consensusState.timestamp == 0) { + revert CometblsClientLib.ErrTrustedConsensusStateNotFound(); + } + + uint64 untrustedHeightNumber = header.signedHeader.height; + uint64 trustedHeightNumber = header.trustedHeight; + if (untrustedHeightNumber <= trustedHeightNumber) { + revert CometblsClientLib.ErrUntrustedHeightLTETrustedHeight(); + } + + uint64 trustedTimestamp = consensusState.timestamp; + // Normalize to nanosecond because ibc-go recvPacket expects nanos... + uint64 untrustedTimestamp = + header.signedHeader.secs * 1e9 + header.signedHeader.nanos; + if (untrustedTimestamp <= trustedTimestamp) { + revert CometblsClientLib.ErrUntrustedTimestampLTETrustedTimestamp(); + } + + // Normalize to nanosecond because ibc-go recvPacket expects nanos... + uint64 currentTime = uint64(block.timestamp * 1e9); + if ( + CometblsClientLib.isExpired( + untrustedTimestamp, clientState.trustingPeriod, currentTime + ) + ) { + revert CometblsClientLib.ErrHeaderExpired(); + } + + uint64 maxClockDrift = currentTime + clientState.maxClockDrift; + + if (untrustedTimestamp >= maxClockDrift) { + revert CometblsClientLib.ErrMaxClockDriftExceeded(); + } + + /* + We want to verify that 1/3 of trusted valset & 2/3 of untrusted valset signed. + In adjacent verification, trusted vals = untrusted vals. + In non adjacent verification, untrusted vals are coming from the untrusted header. + */ + bytes32 trustedValidatorsHash = consensusState.nextValidatorsHash; + bytes32 untrustedValidatorsHash; + bool adjacent = untrustedHeightNumber == trustedHeightNumber + 1; + if (adjacent) { + if (header.signedHeader.validatorsHash != trustedValidatorsHash) { + revert CometblsClientLib.ErrInvalidUntrustedValidatorsHash(); + } + } + + bool ok = internalVerifyZKP( + header.zeroKnowledgeProof, + clientState.chainId, + trustedValidatorsHash, + header.signedHeader + ); + if (!ok) { + revert CometblsClientLib.ErrInvalidZKP(); + } + + return + (untrustedHeightNumber, untrustedTimestamp, untrustedValidatorsHash); + } + + function updateClient( + uint32 clientId, + bytes calldata clientMessageBytes + ) external override onlyIBC returns (ConsensusStateUpdate memory) { + ClientState storage clientState = clientStates[clientId]; + + if (clientState.frozenHeight > 0) { + revert CometblsClientLib.ErrClientFrozen(); + } + + Header calldata header = clientMessageBytes.decodeHeader(); + + ConsensusState storage consensusState = + consensusStates[clientId][header.trustedHeight]; + + (uint64 untrustedHeightNumber, uint64 untrustedTimestamp,) = + verifyHeader(header, consensusState, clientState); + + // Update states + if (untrustedHeightNumber > clientState.latestHeight) { + clientState.latestHeight = untrustedHeightNumber; + } + + consensusState = consensusStates[clientId][header.trustedHeight]; + consensusState.timestamp = untrustedTimestamp; + consensusState.appHash = header.signedHeader.appHash; + consensusState.nextValidatorsHash = + header.signedHeader.nextValidatorsHash; + + ProcessedMoment storage processed = + processedMoments[clientId][header.trustedHeight]; + processed.timestamp = block.timestamp * 1e9; + processed.height = block.number; + + return ConsensusStateUpdate({ + clientStateCommitment: clientState.commit(), + consensusStateCommitment: consensusState.commit(), + height: header.trustedHeight + }); + } + + function verifyMembership( + uint32 clientId, + uint64 height, + bytes calldata proof, + bytes calldata path, + bytes calldata value + ) external virtual returns (bool) { + if (isFrozenImpl(clientId)) { + revert CometblsClientLib.ErrClientFrozen(); + } + bytes32 appHash = consensusStates[clientId][height].appHash; + return ICS23MembershipVerifier.verifyMembership( + appHash, + proof, + abi.encodePacked(IBCStoreLib.COMMITMENT_PREFIX), + path, + value + ); + } + + function verifyNonMembership( + uint32 clientId, + uint64 height, + bytes calldata proof, + bytes calldata path + ) external virtual returns (bool) { + if (isFrozenImpl(clientId)) { + revert CometblsClientLib.ErrClientFrozen(); + } + bytes32 appHash = consensusStates[clientId][height].appHash; + return ICS23MembershipVerifier.verifyNonMembership( + appHash, + proof, + abi.encodePacked(IBCStoreLib.COMMITMENT_PREFIX), + path + ); + } + + function getClientState( + uint32 clientId + ) external view returns (bytes memory) { + return clientStates[clientId].encodeMemory(); + } + + function getConsensusState( + uint32 clientId, + uint64 height + ) external view returns (bytes memory) { + return consensusStates[clientId][height].encodeMemory(); + } + + function getTimestampAtHeight( + uint32 clientId, + uint64 height + ) external view override returns (uint64) { + return consensusStates[clientId][height].timestamp; + } + + function getLatestHeight( + uint32 clientId + ) external view override returns (uint64) { + return clientStates[clientId].latestHeight; + } + + function isFrozen( + uint32 clientId + ) external view virtual returns (bool) { + return isFrozenImpl(clientId); + } + + function isFrozenImpl( + uint32 clientId + ) internal view returns (bool) { + return clientStates[clientId].frozenHeight > 0; + } + + // ZKP VERIFICATION + uint256 constant PRIME_R = + 21888242871839275222246405745257275088548364400416034343698204186575808495617; + uint256 constant PRIME_R_MINUS_ONE = PRIME_R - 1; + + bytes constant HMAC_I = + hex"75595B5342747A653636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636"; + bytes constant HMAC_O = + hex"1F333139281E100F5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C"; + + function hmac_keccak( + bytes memory message + ) internal pure returns (bytes32) { + return keccak256( + abi.encodePacked( + HMAC_O, keccak256(abi.encodePacked(HMAC_I, message)) + ) + ); + } + + // Union whitepaper: (1) H_{hmac_r} + function hashToField( + bytes memory message + ) internal pure returns (uint256) { + return (uint256(hmac_keccak(message)) % PRIME_R_MINUS_ONE) + 1; + } + + struct ZKP { + uint256[8] proof; + uint256[2] proofCommitment; + uint256[2] proofCommitmentPOK; + } + + function verifyZKP( + bytes calldata zkpBytes, + bytes31 chainId, + bytes32 trustedValidatorsHash, + SignedHeader calldata header + ) public virtual returns (bool) { + return + internalVerifyZKP(zkpBytes, chainId, trustedValidatorsHash, header); + } + + function internalVerifyZKP( + bytes calldata zkpBytes, + bytes31 chainId, + bytes32 trustedValidatorsHash, + SignedHeader calldata header + ) internal virtual returns (bool) { + ZKP calldata zkp; + assembly { + zkp := zkpBytes.offset + } + + uint256 commitmentHash = + hashToField(abi.encodePacked(zkp.proofCommitment)); + + // Drop the most significant byte to fit in F_r + bytes32 inputsHash = sha256( + abi.encodePacked( + bytes32(chainId), + bytes32(uint256(header.height)), + bytes32(uint256(header.secs)), + bytes32(uint256(header.nanos)), + header.validatorsHash, + header.nextValidatorsHash, + header.appHash, + trustedValidatorsHash + ) + ) & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; + + uint256[2] memory publicInputs = [ + uint256(inputsHash), + // Gnark commitment API extend internal inputs with the following commitment hash and proof commitment + // See https://github.com/ConsenSys/gnark/issues/652 + commitmentHash + ]; + + return Verifier.verifyProof( + zkp.proof, zkp.proofCommitment, zkp.proofCommitmentPOK, publicInputs + ); + } + + function _authorizeUpgrade( + address newImplementation + ) internal override onlyOwner {} + + function _onlyIBC() internal view { + if (msg.sender != ibcHandler) { + revert CometblsClientLib.ErrNotIBC(); + } + } + + modifier onlyIBC() { + _onlyIBC(); + _; + } +} diff --git a/evm/contracts/clients/CometblsClientV2.sol b/evm/contracts/clients/CometblsClientV2.sol deleted file mode 100644 index 27b051f5b8..0000000000 --- a/evm/contracts/clients/CometblsClientV2.sol +++ /dev/null @@ -1,642 +0,0 @@ -pragma solidity ^0.8.23; - -import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol"; -import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; -import "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol"; -import "@openzeppelin-upgradeable/utils/PausableUpgradeable.sol"; -import "solidity-bytes-utils/BytesLib.sol"; - -import "../core/02-client/ILightClient.sol"; -import "../core/02-client/IBCHeight.sol"; -import "../proto/ibc/core/client/v1/client.sol"; -import "../proto/ibc/lightclients/tendermint/v1/tendermint.sol"; -import "../proto/cosmos/ics23/v1/proofs.sol"; -import "../proto/tendermint/types/types.sol"; -import "../proto/tendermint/types/canonical.sol"; -import "../proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; -import "../proto/ibc/lightclients/wasm/v1/wasm.sol"; -import "../lib/Common.sol"; -import "../lib/ICS23.sol"; -import "./ICS23MembershipVerifier.sol"; -import "./Verifier.sol"; - -struct OptimizedConsensusState { - uint64 timestamp; - bytes32 appHash; - bytes32 nextValidatorsHash; -} - -library CometblsClientLib { - error ErrNotIBC(); - error ErrTrustedConsensusStateNotFound(); - error ErrUntrustedHeightLTETrustedHeight(); - error ErrUntrustedTimestampLTETrustedTimestamp(); - error ErrHeaderExpired(); - error ErrMaxClockDriftExceeded(); - error ErrInvalidZKP(); - error ErrDelayPeriodNotExpired(); - error ErrInvalidUntrustedValidatorsHash(); - error ErrInvalidMisbehaviorHeadersSequence(); - error ErrInvalidMisbehavior(); - error ErrClientFrozen(); - - function isExpired( - uint64 headerTime, - uint64 trustingPeriod, - uint64 currentTime - ) internal pure returns (bool) { - return currentTime > (headerTime + trustingPeriod); - } - - function encodeMemory( - UnionIbcLightclientsCometblsV1Header.Data memory header - ) internal pure returns (bytes memory) { - return abi.encode( - header.signed_header, - header.trusted_height, - header.zero_knowledge_proof - ); - } - - function encode(UnionIbcLightclientsCometblsV1Header.Data calldata header) - internal - pure - returns (bytes memory) - { - return abi.encode( - header.signed_header, - header.trusted_height, - header.zero_knowledge_proof - ); - } - - function decodeHeader(bytes calldata bz) - internal - pure - returns (UnionIbcLightclientsCometblsV1Header.Data calldata) - { - UnionIbcLightclientsCometblsV1Header.Data calldata header; - assembly { - header := bz.offset - } - return header; - } - - function encodeMemory( - UnionIbcLightclientsCometblsV1ClientState.Data memory clientState - ) internal pure returns (bytes memory) { - return abi.encode( - clientState.chain_id, - clientState.trusting_period, - clientState.unbonding_period, - clientState.max_clock_drift, - clientState.frozen_height, - clientState.latest_height - ); - } - - function decodeClientState(bytes calldata bz) - internal - pure - returns (UnionIbcLightclientsCometblsV1ClientState.Data calldata) - { - UnionIbcLightclientsCometblsV1ClientState.Data calldata clientState; - assembly { - clientState := bz.offset - } - return clientState; - } - - function encodeMemory(OptimizedConsensusState memory consensusState) - internal - pure - returns (bytes memory) - { - return abi.encode( - consensusState.timestamp, - consensusState.appHash, - consensusState.nextValidatorsHash - ); - } - - function decodeConsensusState(bytes calldata bz) - internal - pure - returns (OptimizedConsensusState calldata) - { - OptimizedConsensusState calldata consensusState; - assembly { - consensusState := bz.offset - } - return consensusState; - } - - function decodeConsensusStateMemory(bytes memory bz) - internal - pure - returns (OptimizedConsensusState memory) - { - OptimizedConsensusState memory consensusState; - (uint64 timestamp, bytes32 appHash, bytes32 nextValidatorsHash) = - abi.decode(bz, (uint64, bytes32, bytes32)); - consensusState.timestamp = timestamp; - consensusState.appHash = appHash; - consensusState.nextValidatorsHash = nextValidatorsHash; - return consensusState; - } - - function commit(OptimizedConsensusState memory consensusState) - internal - pure - returns (bytes32) - { - return keccak256(encodeMemory(consensusState)); - } - - function commit( - UnionIbcLightclientsCometblsV1ClientState.Data memory clientState - ) internal pure returns (bytes32) { - return keccak256(encodeMemory(clientState)); - } -} - -contract CometblsClient is - ILightClient, - Initializable, - UUPSUpgradeable, - OwnableUpgradeable, - PausableUpgradeable -{ - using BytesLib for bytes; - using IBCHeight for IbcCoreClientV1Height.Data; - using CometblsClientLib for *; - - address private ibcHandler; - - mapping(string => UnionIbcLightclientsCometblsV1ClientState.Data) private - clientStates; - mapping(string => mapping(uint128 => OptimizedConsensusState)) private - consensusStates; - mapping(string => mapping(uint128 => ProcessedMoment)) private - processedMoments; - - constructor() { - _disableInitializers(); - } - - function initialize( - address _ibcHandler, - address admin - ) public initializer { - __Ownable_init(admin); - ibcHandler = _ibcHandler; - } - - function createClient( - string calldata clientId, - bytes calldata clientStateBytes, - bytes calldata consensusStateBytes - ) - external - override - onlyIBC - returns ( - bytes32 clientStateCommitment, - ConsensusStateUpdate memory update, - bool ok - ) - { - UnionIbcLightclientsCometblsV1ClientState.Data calldata clientState = - clientStateBytes.decodeClientState(); - OptimizedConsensusState calldata consensusState = - consensusStateBytes.decodeConsensusState(); - if ( - clientState.latest_height.revision_height == 0 - || consensusState.timestamp == 0 - ) { - return (clientStateCommitment, update, false); - } - // ChainID can't exceed 31 bytes (ensures its big-endian repr fit in F_r) - if (bytes(clientState.chain_id).length > 31) { - return (clientStateCommitment, update, false); - } - clientStates[clientId] = clientState; - uint128 latestHeight = clientState.latest_height.toUint128(); - consensusStates[clientId][latestHeight] = consensusState; - // Normalize to nanosecond because ibc-go recvPacket expects nanos... - processedMoments[clientId][latestHeight] = ProcessedMoment({ - timestamp: block.timestamp * 1e9, - height: block.number - }); - return ( - clientState.commit(), - ConsensusStateUpdate({ - consensusStateCommitment: consensusState.commit(), - height: clientState.latest_height - }), - true - ); - } - - function misbehavior( - string calldata clientId, - UnionIbcLightclientsCometblsV1Header.Data calldata headerA, - UnionIbcLightclientsCometblsV1Header.Data calldata headerB - ) public { - UnionIbcLightclientsCometblsV1ClientState.Data storage clientState = - clientStates[clientId]; - bool fraud = checkMisbehavior(clientId, clientState, headerA, headerB); - if (!fraud) { - revert CometblsClientLib.ErrInvalidMisbehavior(); - } - // Similar to tendermint https://github.com/cosmos/ibc-go/blob/bbdcc8c6e965c8a2f607dfb2b61cd13712dd966a/modules/light-clients/07-tendermint/misbehaviour.go#L19 - clientState.frozen_height = - IbcCoreClientV1Height.Data({revision_number: 0, revision_height: 1}); - } - - function checkMisbehavior( - string calldata clientId, - UnionIbcLightclientsCometblsV1ClientState.Data storage clientState, - UnionIbcLightclientsCometblsV1Header.Data calldata headerA, - UnionIbcLightclientsCometblsV1Header.Data calldata headerB - ) internal returns (bool) { - // Ensures that A >= B to simplify the misbehavior of time violation check - if (!headerA.trusted_height.gte(headerB.trusted_height)) { - revert CometblsClientLib.ErrInvalidMisbehaviorHeadersSequence(); - } - - OptimizedConsensusState storage consensusStateA = - consensusStates[clientId][headerA.trusted_height.toUint128()]; - OptimizedConsensusState storage consensusStateB = - consensusStates[clientId][headerB.trusted_height.toUint128()]; - - // Check that the headers would have been accepted in an update - (, uint64 untrustedTimestampA,) = - verifyHeader(headerA, consensusStateA, clientState); - (, uint64 untrustedTimestampB,) = - verifyHeader(headerB, consensusStateB, clientState); - - if (headerA.trusted_height.eq(headerB.trusted_height)) { - bytes32 hashA = keccak256(abi.encode(headerA.signed_header)); - bytes32 hashB = keccak256(abi.encode(headerB.signed_header)); - if (hashA != hashB) { - // Misbehavior of a fork - return true; - } - } else { - // Guarantee that A > B - if (untrustedTimestampA <= untrustedTimestampB) { - // Misbehavior of time violation - return true; - } - } - return false; - } - - function verifyHeader( - UnionIbcLightclientsCometblsV1Header.Data calldata header, - OptimizedConsensusState storage consensusState, - UnionIbcLightclientsCometblsV1ClientState.Data storage clientState - ) internal returns (uint64, uint64, bytes32) { - if (consensusState.timestamp == 0) { - revert CometblsClientLib.ErrTrustedConsensusStateNotFound(); - } - - uint64 untrustedHeightNumber = uint64(header.signed_header.height); - uint64 trustedHeightNumber = header.trusted_height.revision_height; - if (untrustedHeightNumber <= trustedHeightNumber) { - revert CometblsClientLib.ErrUntrustedHeightLTETrustedHeight(); - } - - uint64 trustedTimestamp = consensusState.timestamp; - // Normalize to nanosecond because ibc-go recvPacket expects nanos... - uint64 untrustedTimestamp = uint64(header.signed_header.time.secs) * 1e9 - + uint64(header.signed_header.time.nanos); - if (untrustedTimestamp <= trustedTimestamp) { - revert CometblsClientLib.ErrUntrustedTimestampLTETrustedTimestamp(); - } - - // Normalize to nanosecond because ibc-go recvPacket expects nanos... - uint64 currentTime = uint64(block.timestamp * 1e9); - if ( - CometblsClientLib.isExpired( - untrustedTimestamp, clientState.trusting_period, currentTime - ) - ) { - revert CometblsClientLib.ErrHeaderExpired(); - } - - uint64 maxClockDrift = currentTime + clientState.max_clock_drift; - - if (untrustedTimestamp >= maxClockDrift) { - revert CometblsClientLib.ErrMaxClockDriftExceeded(); - } - - /* - We want to verify that 1/3 of trusted valset & 2/3 of untrusted valset signed. - In adjacent verification, trusted vals = untrusted vals. - In non adjacent verification, untrusted vals are coming from the untrusted header. - */ - bytes32 trustedValidatorsHash = consensusState.nextValidatorsHash; - bytes32 untrustedValidatorsHash; - bool adjacent = untrustedHeightNumber == trustedHeightNumber + 1; - if (adjacent) { - if ( - keccak256(header.signed_header.validators_hash) - != keccak256(abi.encodePacked(trustedValidatorsHash)) - ) { - revert CometblsClientLib.ErrInvalidUntrustedValidatorsHash(); - } - } - - bool ok = internalVerifyZKP( - header.zero_knowledge_proof, - clientState.chain_id, - trustedValidatorsHash, - header.signed_header - ); - if (!ok) { - revert CometblsClientLib.ErrInvalidZKP(); - } - - return - (untrustedHeightNumber, untrustedTimestamp, untrustedValidatorsHash); - } - - function updateClient( - string calldata clientId, - bytes calldata clientMessageBytes - ) - external - override - onlyIBC - returns (bytes32, ConsensusStateUpdate[] memory) - { - UnionIbcLightclientsCometblsV1Header.Data calldata header = - clientMessageBytes.decodeHeader(); - UnionIbcLightclientsCometblsV1ClientState.Data storage clientState = - clientStates[clientId]; - - if (!clientState.frozen_height.isZero()) { - revert CometblsClientLib.ErrClientFrozen(); - } - - OptimizedConsensusState storage consensusState = - consensusStates[clientId][header.trusted_height.toUint128()]; - - (uint64 untrustedHeightNumber, uint64 untrustedTimestamp,) = - verifyHeader(header, consensusState, clientState); - - // Update states - if (untrustedHeightNumber > clientState.latest_height.revision_height) { - clientState.latest_height.revision_height = untrustedHeightNumber; - } - - IbcCoreClientV1Height.Data memory untrustedHeight = - IbcCoreClientV1Height.Data({ - revision_number: header.trusted_height.revision_number, - revision_height: untrustedHeightNumber - }); - - uint128 untrustedHeightIndex = untrustedHeight.toUint128(); - - consensusState = consensusStates[clientId][untrustedHeightIndex]; - consensusState.timestamp = untrustedTimestamp; - consensusState.appHash = header.signed_header.app_hash.toBytes32(0); - consensusState.nextValidatorsHash = - header.signed_header.next_validators_hash.toBytes32(0); - - ProcessedMoment storage processed = - processedMoments[clientId][untrustedHeightIndex]; - processed.timestamp = block.timestamp * 1e9; - processed.height = block.number; - - ConsensusStateUpdate[] memory updates = new ConsensusStateUpdate[](1); - updates[0] = ConsensusStateUpdate({ - consensusStateCommitment: consensusState.commit(), - height: untrustedHeight - }); - - return (clientState.commit(), updates); - } - - function verifyMembership( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayPeriodTime, - uint64 delayPeriodBlocks, - bytes calldata proof, - bytes calldata prefix, - bytes calldata path, - bytes calldata value - ) external virtual returns (bool) { - if (isFrozenImpl(clientId)) { - revert CometblsClientLib.ErrClientFrozen(); - } - bytes32 appHash = validateDelayPeriod( - clientId, height, delayPeriodTime, delayPeriodBlocks - ); - return ICS23MembershipVerifier.verifyMembership( - appHash, proof, prefix, path, value - ); - } - - function verifyNonMembership( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayPeriodTime, - uint64 delayPeriodBlocks, - bytes calldata proof, - bytes calldata prefix, - bytes calldata path - ) external virtual returns (bool) { - if (isFrozenImpl(clientId)) { - revert CometblsClientLib.ErrClientFrozen(); - } - bytes32 appHash = validateDelayPeriod( - clientId, height, delayPeriodTime, delayPeriodBlocks - ); - return ICS23MembershipVerifier.verifyNonMembership( - appHash, proof, prefix, path - ); - } - - function validateDelayPeriod( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayPeriodTime, - uint64 delayPeriodBlocks - ) internal view returns (bytes32) { - OptimizedConsensusState storage consensusState = - consensusStates[clientId][height.toUint128()]; - if (consensusState.timestamp == 0) { - revert CometblsClientLib.ErrTrustedConsensusStateNotFound(); - } - ProcessedMoment storage moment = - processedMoments[clientId][height.toUint128()]; - uint64 currentTime = uint64(block.timestamp * 1e9); - uint64 validTime = uint64(moment.timestamp) + delayPeriodTime; - if (delayPeriodTime != 0 && currentTime < validTime) { - revert CometblsClientLib.ErrDelayPeriodNotExpired(); - } - uint64 currentHeight = uint64(block.number); - uint64 validHeight = uint64(moment.height) + delayPeriodBlocks; - if (delayPeriodBlocks != 0 && currentHeight < validHeight) { - revert CometblsClientLib.ErrDelayPeriodNotExpired(); - } - return consensusState.appHash; - } - - function getClientState(string calldata clientId) - external - view - returns (bytes memory) - { - return clientStates[clientId].encodeMemory(); - } - - function getConsensusState( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height - ) external view returns (bytes memory) { - return consensusStates[clientId][height.toUint128()].encodeMemory(); - } - - function getTimestampAtHeight( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height - ) external view override returns (uint64) { - return consensusStates[clientId][height.toUint128()].timestamp; - } - - function getLatestHeight(string calldata clientId) - external - view - override - returns (IbcCoreClientV1Height.Data memory) - { - return clientStates[clientId].latest_height; - } - - function isFrozen(string calldata clientId) - external - view - virtual - returns (bool) - { - return isFrozenImpl(clientId); - } - - function isFrozenImpl(string calldata clientId) - internal - view - returns (bool) - { - return !clientStates[clientId].frozen_height.isZero(); - } - - // ZKP VERIFICATION - uint256 constant PRIME_R = - 21888242871839275222246405745257275088548364400416034343698204186575808495617; - uint256 constant PRIME_R_MINUS_ONE = PRIME_R - 1; - - bytes constant HMAC_I = - hex"75595B5342747A653636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636"; - bytes constant HMAC_O = - hex"1F333139281E100F5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C"; - - function hmac_keccak(bytes memory message) - internal - pure - returns (bytes32) - { - return keccak256( - abi.encodePacked(HMAC_O, keccak256(HMAC_I.concat(message))) - ); - } - - // Union whitepaper: (1) H_{hmac_r} - function hashToField(bytes memory message) - internal - pure - returns (uint256) - { - return (uint256(hmac_keccak(message)) % PRIME_R_MINUS_ONE) + 1; - } - - struct ZKP { - uint256[8] proof; - uint256[2] proofCommitment; - uint256[2] proofCommitmentPOK; - } - - function verifyZKP( - bytes calldata zkpBytes, - string calldata chainId, - bytes32 trustedValidatorsHash, - UnionIbcLightclientsCometblsV1LightHeader.Data calldata header - ) public virtual returns (bool) { - return - internalVerifyZKP(zkpBytes, chainId, trustedValidatorsHash, header); - } - - function internalVerifyZKP( - bytes calldata zkpBytes, - string memory chainId, - bytes32 trustedValidatorsHash, - UnionIbcLightclientsCometblsV1LightHeader.Data calldata header - ) internal virtual returns (bool) { - ZKP calldata zkp; - assembly { - zkp := zkpBytes.offset - } - - uint256 commitmentHash = - hashToField(abi.encodePacked(zkp.proofCommitment)); - - uint256 l = bytes(chainId).length; - bytes memory paddedChainId = new bytes(32 - l).concat(bytes(chainId)); - - // Drop the most significant byte to fit in F_r - bytes32 inputsHash = sha256( - abi.encodePacked( - bytes32(paddedChainId), - bytes32(uint256(int256(header.height))), - bytes32(uint256(int256(header.time.secs))), - bytes32(uint256(int256(header.time.nanos))), - bytes32(header.validators_hash), - bytes32(header.next_validators_hash), - bytes32(header.app_hash), - trustedValidatorsHash - ) - ) & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; - - uint256[2] memory publicInputs = [ - uint256(inputsHash), - // Gnark commitment API extend internal inputs with the following commitment hash and proof commitment - // See https://github.com/ConsenSys/gnark/issues/652 - commitmentHash - ]; - - return Verifier.verifyProof( - zkp.proof, zkp.proofCommitment, zkp.proofCommitmentPOK, publicInputs - ); - } - - function _authorizeUpgrade(address newImplementation) - internal - override - onlyOwner - {} - - function _onlyIBC() private view { - if (msg.sender != ibcHandler) { - revert CometblsClientLib.ErrNotIBC(); - } - } - - modifier onlyIBC() { - _onlyIBC(); - _; - } -} diff --git a/evm/contracts/clients/CosmosInCosmosClient.sol b/evm/contracts/clients/CosmosInCosmosClient.sol index 28ef2bad32..09b760988b 100644 --- a/evm/contracts/clients/CosmosInCosmosClient.sol +++ b/evm/contracts/clients/CosmosInCosmosClient.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; @@ -7,27 +7,34 @@ import "@openzeppelin-upgradeable/utils/PausableUpgradeable.sol"; import "solidity-bytes-utils/BytesLib.sol"; import "../core/02-client/ILightClient.sol"; -import "../core/02-client/IBCHeight.sol"; import "../core/24-host/IBCStore.sol"; import "../core/24-host/IBCCommitment.sol"; -import "../proto/ibc/core/client/v1/client.sol"; -import {IbcLightclientsTendermintV1ConsensusState as TendermintConsensusState} - from "../proto/ibc/lightclients/tendermint/v1/tendermint.sol"; -import "../proto/cosmos/ics23/v1/proofs.sol"; -import "../proto/tendermint/types/types.sol"; -import "../proto/tendermint/types/canonical.sol"; -import { - UnionIbcLightclientsCosmosincosmosV1ClientState as CosmosInCosmosClientState, - UnionIbcLightclientsCosmosincosmosV1Header as CosmosInCosmosHeader -} from "../proto/union/ibc/lightclients/cosmosincosmos/v1/cosmosincosmos.sol"; -import {UnionIbcLightclientsCometblsV1ClientState as CometblsClientState} from - "../proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; -import "../proto/ibc/lightclients/wasm/v1/wasm.sol"; import "../lib/ICS23.sol"; +import "../lib/Common.sol"; + import "./ICS23MembershipVerifier.sol"; -import {ProcessedMoment} from "../lib/Common.sol"; -struct OptimizedCosmosInCosmosConsensusState { +struct TendermintConsensusState { + uint64 timestamp; + bytes32 appHash; + bytes32 nextValidatorsHash; +} + +struct Header { + uint64 l1Height; + uint64 l2Height; + bytes l2InclusionProof; + bytes l2ConsensusState; +} + +struct ClientState { + string l2ChainId; + uint32 l1ClientId; + uint32 l2ClientId; + uint64 latestHeight; +} + +struct ConsensusState { uint64 timestamp; bytes32 appHash; } @@ -35,44 +42,36 @@ struct OptimizedCosmosInCosmosConsensusState { library CosmosInCosmosLib { error ErrNotIBC(); error ErrTrustedConsensusStateNotFound(); - error ErrDelayPeriodNotExpired(); error ErrClientFrozen(); error ErrInvalidL1Proof(); + error ErrInvalidInitialConsensusState(); - function encode(OptimizedCosmosInCosmosConsensusState memory consensusState) - internal - pure - returns (bytes memory) - { + function encode( + ConsensusState memory consensusState + ) internal pure returns (bytes memory) { return abi.encode(consensusState.timestamp, consensusState.appHash); } - function encode(CosmosInCosmosClientState.Data memory clientState) - internal - pure - returns (bytes memory) - { + function encode( + ClientState memory clientState + ) internal pure returns (bytes memory) { return abi.encode( - clientState.l2_chain_id, - clientState.l1_client_id, - clientState.l2_client_id, - clientState.latest_height + clientState.l2ChainId, + clientState.l1ClientId, + clientState.l2ClientId, + clientState.latestHeight ); } - function commit(OptimizedCosmosInCosmosConsensusState memory consensusState) - internal - pure - returns (bytes32) - { + function commit( + ConsensusState memory consensusState + ) internal pure returns (bytes32) { return keccak256(encode(consensusState)); } - function commit(CosmosInCosmosClientState.Data memory clientState) - internal - pure - returns (bytes32) - { + function commit( + ClientState memory clientState + ) internal pure returns (bytes32) { return keccak256(encode(clientState)); } } @@ -84,16 +83,13 @@ contract CosmosInCosmosClient is OwnableUpgradeable, PausableUpgradeable { - using BytesLib for bytes; - using IBCHeight for IbcCoreClientV1Height.Data; using CosmosInCosmosLib for *; address private ibcHandler; - mapping(string => CosmosInCosmosClientState.Data) private clientStates; - mapping(string => mapping(uint128 => OptimizedCosmosInCosmosConsensusState)) - private consensusStates; - mapping(string => mapping(uint128 => ProcessedMoment)) private + mapping(uint32 => ClientState) private clientStates; + mapping(uint32 => mapping(uint64 => ConsensusState)) private consensusStates; + mapping(uint32 => mapping(uint64 => ProcessedMoment)) private processedMoments; constructor() { @@ -109,49 +105,33 @@ contract CosmosInCosmosClient is } function createClient( - string calldata clientId, + uint32 clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes - ) - external - override - onlyIBC - returns ( - bytes32 clientStateCommitment, - ConsensusStateUpdate memory update, - bool ok - ) - { - CosmosInCosmosClientState.Data calldata clientState; + ) external override onlyIBC returns (ConsensusStateUpdate memory update) { + ClientState calldata clientState; assembly { clientState := clientStateBytes.offset } - OptimizedCosmosInCosmosConsensusState calldata consensusState; + ConsensusState calldata consensusState; assembly { consensusState := consensusStateBytes.offset } - if ( - clientState.latest_height.revision_height == 0 - || consensusState.timestamp == 0 - ) { - return (clientStateCommitment, update, false); + if (clientState.latestHeight == 0 || consensusState.timestamp == 0) { + revert CosmosInCosmosLib.ErrInvalidInitialConsensusState(); } clientStates[clientId] = clientState; - uint128 latestHeight = clientState.latest_height.toUint128(); - consensusStates[clientId][latestHeight] = consensusState; + consensusStates[clientId][clientState.latestHeight] = consensusState; // Normalize to nanosecond because ibc-go recvPacket expects nanos... - processedMoments[clientId][latestHeight] = ProcessedMoment({ + processedMoments[clientId][clientState.latestHeight] = ProcessedMoment({ timestamp: block.timestamp * 1e9, height: block.number }); - return ( - clientState.commit(), - ConsensusStateUpdate({ - consensusStateCommitment: consensusState.commit(), - height: clientState.latest_height - }), - true - ); + return ConsensusStateUpdate({ + clientStateCommitment: clientState.commit(), + consensusStateCommitment: consensusState.commit(), + height: clientState.latestHeight + }); } /* @@ -159,201 +139,146 @@ contract CosmosInCosmosClient is * Given an L₂ and L₁ heights (H₂, H₁), we prove that L₂[H₂] ∈ L₁[H₁]. */ function updateClient( - string calldata clientId, + uint32 clientId, bytes calldata clientMessageBytes - ) - external - override - onlyIBC - returns (bytes32, ConsensusStateUpdate[] memory) - { - CosmosInCosmosHeader.Data calldata header; + ) external override onlyIBC returns (ConsensusStateUpdate memory) { + Header calldata header; assembly { header := clientMessageBytes.offset } - CosmosInCosmosClientState.Data memory clientState = - clientStates[clientId]; + ClientState memory clientState = clientStates[clientId]; ILightClient l1Client = - IBCStore(ibcHandler).getClient(clientState.l1_client_id); + IBCStore(ibcHandler).getClient(clientState.l1ClientId); // L₂[H₂] ∈ L₁[H₁] if ( !l1Client.verifyMembership( - clientState.l1_client_id, - header.l1_height, - 0, - 0, - header.l2_inclusion_proof, - bytes(IBCStoreLib.COMMITMENT_PREFIX), - IBCCommitment.consensusStatePath( - clientState.l2_client_id, - header.l2_height.revision_number, - header.l2_height.revision_height + clientState.l1ClientId, + header.l1Height, + header.l2InclusionProof, + abi.encodePacked( + IBCCommitment.consensusStateCommitmentKey( + clientState.l2ClientId, header.l2Height + ) ), - header.l2_consensus_state + abi.encodePacked(keccak256(abi.encode(header.l2ConsensusState))) ) ) { revert CosmosInCosmosLib.ErrInvalidL1Proof(); } - TendermintConsensusState.Data memory l2ConsensusState = - TendermintConsensusState.decode(header.l2_consensus_state); - if (header.l2_height.gt(clientState.latest_height)) { - clientState.latest_height = header.l2_height; + TendermintConsensusState calldata l2ConsensusState; + bytes calldata rawL2ConsensusState = header.l2ConsensusState; + assembly { + l2ConsensusState := rawL2ConsensusState.offset } - uint128 l2HeightIndex = header.l2_height.toUint128(); - - // Cosmos expects nanos... - uint64 l2Timestamp = uint64(l2ConsensusState.timestamp.secs) * 1e9 - + uint64(l2ConsensusState.timestamp.nanos); + if (header.l2Height > clientState.latestHeight) { + clientState.latestHeight = header.l2Height; + } - // L₂[H₂] = optimize(S₂) - // The default tendermint consensus state is stored as protobuf. + // L₂[H₂] = S₂ // We use ethereum native encoding to make it more efficient. - OptimizedCosmosInCosmosConsensusState storage consensusState = - consensusStates[clientId][l2HeightIndex]; - consensusState.timestamp = l2Timestamp; - consensusState.appHash = l2ConsensusState.root.hash.toBytes32(0); + ConsensusState storage consensusState = + consensusStates[clientId][header.l2Height]; + consensusState.timestamp = l2ConsensusState.timestamp; + consensusState.appHash = l2ConsensusState.appHash; // P[H₂] = now() ProcessedMoment storage processed = - processedMoments[clientId][l2HeightIndex]; + processedMoments[clientId][header.l2Height]; processed.timestamp = block.timestamp * 1e9; processed.height = block.number; - // commit(optimize(S₂)) - ConsensusStateUpdate[] memory updates = new ConsensusStateUpdate[](1); - updates[0] = ConsensusStateUpdate({ + // commit(S₂) + return ConsensusStateUpdate({ + clientStateCommitment: clientState.commit(), consensusStateCommitment: consensusState.commit(), - height: header.l2_height + height: header.l2Height }); - - return (clientState.commit(), updates); } function verifyMembership( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayPeriodTime, - uint64 delayPeriodBlocks, + uint32 clientId, + uint64 height, bytes calldata proof, - bytes calldata prefix, bytes calldata path, bytes calldata value ) external virtual returns (bool) { if (isFrozenImpl(clientId)) { revert CosmosInCosmosLib.ErrClientFrozen(); } - bytes32 appHash = validateDelayPeriod( - clientId, height, delayPeriodTime, delayPeriodBlocks - ); + bytes32 appHash = consensusStates[clientId][height].appHash; return ICS23MembershipVerifier.verifyMembership( - appHash, proof, prefix, path, value + appHash, + proof, + abi.encodePacked(IBCStoreLib.COMMITMENT_PREFIX), + path, + value ); } function verifyNonMembership( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayPeriodTime, - uint64 delayPeriodBlocks, + uint32 clientId, + uint64 height, bytes calldata proof, - bytes calldata prefix, bytes calldata path ) external virtual returns (bool) { if (isFrozenImpl(clientId)) { revert CosmosInCosmosLib.ErrClientFrozen(); } - bytes32 appHash = validateDelayPeriod( - clientId, height, delayPeriodTime, delayPeriodBlocks - ); + bytes32 appHash = consensusStates[clientId][height].appHash; return ICS23MembershipVerifier.verifyNonMembership( - appHash, proof, prefix, path + appHash, + proof, + abi.encodePacked(IBCStoreLib.COMMITMENT_PREFIX), + path ); } - function validateDelayPeriod( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayPeriodTime, - uint64 delayPeriodBlocks - ) internal view returns (bytes32) { - OptimizedCosmosInCosmosConsensusState storage consensusState = - consensusStates[clientId][height.toUint128()]; - if (consensusState.timestamp == 0) { - revert CosmosInCosmosLib.ErrTrustedConsensusStateNotFound(); - } - ProcessedMoment storage moment = - processedMoments[clientId][height.toUint128()]; - uint64 currentTime = uint64(block.timestamp * 1e9); - uint64 validTime = uint64(moment.timestamp) + delayPeriodTime; - if (delayPeriodTime != 0 && currentTime < validTime) { - revert CosmosInCosmosLib.ErrDelayPeriodNotExpired(); - } - uint64 currentHeight = uint64(block.number); - uint64 validHeight = uint64(moment.height) + delayPeriodBlocks; - if (delayPeriodBlocks != 0 && currentHeight < validHeight) { - revert CosmosInCosmosLib.ErrDelayPeriodNotExpired(); - } - return consensusState.appHash; - } - - function getClientState(string calldata clientId) - external - view - returns (bytes memory) - { + function getClientState( + uint32 clientId + ) external view returns (bytes memory) { return clientStates[clientId].encode(); } function getConsensusState( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height + uint32 clientId, + uint64 height ) external view returns (bytes memory) { - return consensusStates[clientId][height.toUint128()].encode(); + return consensusStates[clientId][height].encode(); } function getTimestampAtHeight( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height + uint32 clientId, + uint64 height ) external view override returns (uint64) { - return consensusStates[clientId][height.toUint128()].timestamp; + return consensusStates[clientId][height].timestamp; } - function getLatestHeight(string calldata clientId) - external - view - override - returns (IbcCoreClientV1Height.Data memory) - { - return clientStates[clientId].latest_height; + function getLatestHeight( + uint32 clientId + ) external view override returns (uint64) { + return clientStates[clientId].latestHeight; } - function isFrozen(string calldata clientId) - external - view - virtual - returns (bool) - { + function isFrozen( + uint32 clientId + ) external view virtual returns (bool) { return isFrozenImpl(clientId); } - function isFrozenImpl(string calldata clientId) - internal - view - returns (bool) - { - string memory l1ClientId = clientStates[clientId].l1_client_id; + function isFrozenImpl( + uint32 clientId + ) internal view returns (bool) { + uint32 l1ClientId = clientStates[clientId].l1ClientId; return IBCStore(ibcHandler).getClient(l1ClientId).isFrozen(l1ClientId); } - function _authorizeUpgrade(address newImplementation) - internal - override - onlyOwner - {} + function _authorizeUpgrade( + address newImplementation + ) internal override onlyOwner {} - function _onlyIBC() private view { + function _onlyIBC() internal view { if (msg.sender != ibcHandler) { revert CosmosInCosmosLib.ErrNotIBC(); } diff --git a/evm/contracts/clients/ICS23MembershipVerifier.sol b/evm/contracts/clients/ICS23MembershipVerifier.sol index 47604b7e01..e17211e769 100644 --- a/evm/contracts/clients/ICS23MembershipVerifier.sol +++ b/evm/contracts/clients/ICS23MembershipVerifier.sol @@ -1,15 +1,13 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "../lib/ICS23.sol"; import "../lib/UnionICS23.sol"; -import "../proto/cosmos/ics23/v1/proofs.sol"; -import "../proto/ibc/core/commitment/v1/commitment.sol"; library ICS23MembershipVerifier { function verifyMembership( bytes32 root, bytes calldata proof, - bytes calldata prefix, + bytes memory prefix, bytes calldata path, bytes calldata value ) internal pure returns (bool) { @@ -30,7 +28,7 @@ library ICS23MembershipVerifier { function verifyNonMembership( bytes32 root, bytes calldata proof, - bytes calldata prefix, + bytes memory prefix, bytes calldata path ) internal pure returns (bool) { NonMembershipProof calldata nonexistenceProof; diff --git a/evm/contracts/clients/Verifier.sol b/evm/contracts/clients/Verifier.sol index 4a538dad9d..fcf8ebf26c 100644 --- a/evm/contracts/clients/Verifier.sol +++ b/evm/contracts/clients/Verifier.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; /// @title Groth16 verifier template. /// @author Remco Bloemen diff --git a/evm/contracts/core/02-client/IBCClient.sol b/evm/contracts/core/02-client/IBCClient.sol index b883e2896d..ab49ed1eae 100644 --- a/evm/contracts/core/02-client/IBCClient.sol +++ b/evm/contracts/core/02-client/IBCClient.sol @@ -1,135 +1,83 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "@openzeppelin/utils/Strings.sol"; import "./ILightClient.sol"; import "../25-handler/IBCMsgs.sol"; import "../24-host/IBCStore.sol"; import "../24-host/IBCCommitment.sol"; import "../02-client/IIBCClient.sol"; -import "../../proto/ibc/core/client/v1/client.sol"; library IBCClientLib { - event ClientRegistered(string clientType, address clientAddress); - event ClientCreated(string clientId); - event ClientUpdated(string clientId, IbcCoreClientV1Height.Data height); + event ClientRegistered(bytes32 clientType, address clientAddress); + event ClientCreated(bytes32 clientType, uint32 clientId); + event ClientUpdated(uint32 clientId, uint64 height); error ErrClientTypeAlreadyExists(); - error ErrClientMustNotBeSelf(); error ErrClientTypeNotFound(); - error ErrFailedToCreateClient(); - error ErrFailedToUpdateClient(); } /** * @dev IBCClient is a contract that implements [ICS-2](https://github.com/cosmos/ibc/tree/main/spec/core/ics-002-client-semantics). */ -contract IBCClient is IBCStore, IIBCClient { +abstract contract IBCClient is IBCStore, IIBCClient { /** * @dev registerClient registers a new client type into the client registry */ function registerClient( - string calldata clientType, + bytes32 clientType, ILightClient client ) external override { if (address(clientRegistry[clientType]) != address(0)) { revert IBCClientLib.ErrClientTypeAlreadyExists(); } - if (address(client) == address(this)) { - revert IBCClientLib.ErrClientMustNotBeSelf(); - } clientRegistry[clientType] = address(client); - emit IBCClientLib.ClientRegistered(clientType, address(client)); } /** * @dev createClient creates a new client state and populates it with a given consensus state */ - function createClient(IBCMsgs.MsgCreateClient calldata msg_) - external - override - returns (string memory clientId) - { + function createClient( + IBCMsgs.MsgCreateClient calldata msg_ + ) external override returns (uint32) { address clientImpl = clientRegistry[msg_.clientType]; if (clientImpl == address(0)) { revert IBCClientLib.ErrClientTypeNotFound(); } - clientId = generateClientIdentifier(msg_.clientType); + uint32 clientId = generateClientIdentifier(); clientTypes[clientId] = msg_.clientType; clientImpls[clientId] = clientImpl; - ( - bytes32 clientStateCommitment, - ConsensusStateUpdate memory update, - bool ok - ) = ILightClient(clientImpl).createClient( - clientId, msg_.clientStateBytes, msg_.consensusStateBytes - ); - if (!ok) { - revert IBCClientLib.ErrFailedToCreateClient(); - } - - // update commitments - commitments[keccak256(IBCCommitment.clientStatePath(clientId))] = - clientStateCommitment; + ConsensusStateUpdate memory update = ILightClient(clientImpl) + .createClient(clientId, msg_.clientStateBytes, msg_.consensusStateBytes); + commitments[IBCCommitment.clientStateCommitmentKey(clientId)] = + update.clientStateCommitment; commitments[IBCCommitment.consensusStateCommitmentKey( - clientId, - update.height.revision_number, - update.height.revision_height + clientId, update.height )] = update.consensusStateCommitment; - - emit IBCClientLib.ClientCreated(clientId); - + emit IBCClientLib.ClientCreated(msg_.clientType, clientId); return clientId; } /** * @dev updateClient updates the consensus state and the state root from a provided header */ - function updateClient(IBCMsgs.MsgUpdateClient calldata msg_) - external - override - { - if ( - commitments[IBCCommitment.clientStateCommitmentKey(msg_.clientId)] - == bytes32(0) - ) { - revert IBCStoreLib.ErrClientNotFound(); - } - (bytes32 clientStateCommitment, ConsensusStateUpdate[] memory updates) = - getClient(msg_.clientId).updateClient(msg_.clientId, msg_.clientMessage); - uint256 updatesLength = updates.length; - if (updatesLength == 0) { - revert IBCClientLib.ErrFailedToUpdateClient(); - } - - // update commitments - commitments[keccak256(IBCCommitment.clientStatePath(msg_.clientId))] = - clientStateCommitment; - for (uint256 i; i < updatesLength; i++) { - commitments[IBCCommitment.consensusStateCommitmentKey( - msg_.clientId, - updates[i].height.revision_number, - updates[i].height.revision_height - )] = updates[i].consensusStateCommitment; - emit IBCClientLib.ClientUpdated(msg_.clientId, updates[i].height); - } + function updateClient( + IBCMsgs.MsgUpdateClient calldata msg_ + ) external override { + ConsensusStateUpdate memory update = getClientInternal(msg_.clientId) + .updateClient(msg_.clientId, msg_.clientMessage); + commitments[IBCCommitment.clientStateCommitmentKey(msg_.clientId)] = + update.clientStateCommitment; + commitments[IBCCommitment.consensusStateCommitmentKey( + msg_.clientId, update.height + )] = update.consensusStateCommitment; + emit IBCClientLib.ClientUpdated(msg_.clientId, update.height); } - function generateClientIdentifier(string calldata clientType) - private - returns (string memory) - { - uint256 nextClientSequence = - uint256(commitments[nextClientSequencePath]); - - string memory identifier = string( - abi.encodePacked( - clientType, "-", Strings.toString(nextClientSequence) - ) - ); - - commitments[nextClientSequencePath] = bytes32(nextClientSequence + 1); - - return identifier; + function generateClientIdentifier() internal returns (uint32) { + uint32 nextClientSequence = + uint32(uint256(commitments[nextClientSequencePath])); + commitments[nextClientSequencePath] = + bytes32(uint256(nextClientSequence + 1)); + return nextClientSequence; } } diff --git a/evm/contracts/core/02-client/IBCHeight.sol b/evm/contracts/core/02-client/IBCHeight.sol deleted file mode 100644 index f6d7cb8d31..0000000000 --- a/evm/contracts/core/02-client/IBCHeight.sol +++ /dev/null @@ -1,89 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../proto/ibc/core/client/v1/client.sol"; - -library IBCHeight { - function toUint128(IbcCoreClientV1Height.Data memory self) - internal - pure - returns (uint128) - { - return (uint128(self.revision_number) << 64) - | uint128(self.revision_height); - } - - function fromUint128(uint128 composite) - internal - pure - returns (IbcCoreClientV1Height.Data memory) - { - return IbcCoreClientV1Height.Data({ - revision_number: uint64(composite >> 64), - revision_height: uint64(composite) - }); - } - - function isZero(IbcCoreClientV1Height.Data memory self) - internal - pure - returns (bool) - { - return self.revision_number == 0 && self.revision_height == 0; - } - - function lt( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) internal pure returns (bool) { - return self.revision_number < other.revision_number - || ( - self.revision_number == other.revision_number - && self.revision_height < other.revision_height - ); - } - - function lte( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) internal pure returns (bool) { - return self.revision_number < other.revision_number - || ( - self.revision_number == other.revision_number - && self.revision_height <= other.revision_height - ); - } - - function eq( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) internal pure returns (bool) { - return self.revision_number == other.revision_number - && self.revision_height == other.revision_height; - } - - function gt( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) internal pure returns (bool) { - return self.revision_number > other.revision_number - || ( - self.revision_number == other.revision_number - && self.revision_height > other.revision_height - ); - } - - function gte( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) internal pure returns (bool) { - return self.revision_number > other.revision_number - || ( - self.revision_number == other.revision_number - && self.revision_height >= other.revision_height - ); - } - - function zero() internal pure returns (IbcCoreClientV1Height.Data memory) { - return fromUint128(0); - } -} diff --git a/evm/contracts/core/02-client/IIBCClient.sol b/evm/contracts/core/02-client/IIBCClient.sol index ac0fc74494..ddc3c4beb5 100644 --- a/evm/contracts/core/02-client/IIBCClient.sol +++ b/evm/contracts/core/02-client/IIBCClient.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "./ILightClient.sol"; import "../25-handler/IBCMsgs.sol"; @@ -7,20 +7,19 @@ interface IIBCClient { /** * @dev registerClient registers a new client type into the client registry */ - function registerClient( - string calldata clientType, - ILightClient client - ) external; + function registerClient(bytes32 clientType, ILightClient client) external; /** * @dev createClient creates a new client state and populates it with a given consensus state */ - function createClient(IBCMsgs.MsgCreateClient calldata msg_) - external - returns (string memory clientId); + function createClient( + IBCMsgs.MsgCreateClient calldata msg_ + ) external returns (uint32 clientId); /** * @dev updateClient updates the consensus state and the state root from a provided header */ - function updateClient(IBCMsgs.MsgUpdateClient calldata msg_) external; + function updateClient( + IBCMsgs.MsgUpdateClient calldata msg_ + ) external; } diff --git a/evm/contracts/core/02-client/ILightClient.sol b/evm/contracts/core/02-client/ILightClient.sol index 4e38c762cd..5d775e5ff9 100644 --- a/evm/contracts/core/02-client/ILightClient.sol +++ b/evm/contracts/core/02-client/ILightClient.sol @@ -1,12 +1,11 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "../../proto/ibc/core/client/v1/client.sol"; +import "../Types.sol"; struct ConsensusStateUpdate { - // commitment for updated consensusState + bytes32 clientStateCommitment; bytes32 consensusStateCommitment; - // updated height - IbcCoreClientV1Height.Data height; + uint64 height; } /** @@ -19,32 +18,25 @@ interface ILightClient { * If succeeded, it returns a commitment for the initial state. */ function createClient( - string calldata clientId, + uint32 clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes - ) - external - returns ( - bytes32 clientStateCommitment, - ConsensusStateUpdate memory update, - bool ok - ); + ) external returns (ConsensusStateUpdate memory update); /** * @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height. */ function getTimestampAtHeight( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height + uint32 clientId, + uint64 height ) external view returns (uint64); /** * @dev getLatestHeight returns the latest height of the client state corresponding to `clientId`. */ - function getLatestHeight(string calldata clientId) - external - view - returns (IbcCoreClientV1Height.Data memory); + function getLatestHeight( + uint32 clientId + ) external view returns (uint64 height); /** * @dev updateClient updates the client corresponding to `clientId`. @@ -59,26 +51,18 @@ interface ILightClient { * 5. persist the state(s) on the host */ function updateClient( - string calldata clientId, + uint32 clientId, bytes calldata clientMessageBytes - ) - external - returns ( - bytes32 clientStateCommitment, - ConsensusStateUpdate[] memory updates - ); + ) external returns (ConsensusStateUpdate memory update); /** * @dev verifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height. * The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). */ function verifyMembership( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayTimePeriod, - uint64 delayBlockPeriod, + uint32 clientId, + uint64 height, bytes calldata proof, - bytes calldata prefix, bytes calldata path, bytes calldata value ) external returns (bool); @@ -88,33 +72,31 @@ interface ILightClient { * The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). */ function verifyNonMembership( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayTimePeriod, - uint64 delayBlockPeriod, + uint32 clientId, + uint64 height, bytes calldata proof, - bytes calldata prefix, bytes calldata path ) external returns (bool); /** * @dev getClientState returns the clientState corresponding to `clientId`. */ - function getClientState(string calldata clientId) - external - view - returns (bytes memory); + function getClientState( + uint32 clientId + ) external view returns (bytes memory); /** * @dev getConsensusState returns the consensusState corresponding to `clientId` and `height`. */ function getConsensusState( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height + uint32 clientId, + uint64 height ) external view returns (bytes memory); /** * @dev isFrozen returns whether the `clientId` is frozen or not. */ - function isFrozen(string calldata clientId) external view returns (bool); + function isFrozen( + uint32 clientId + ) external view returns (bool); } diff --git a/evm/contracts/core/03-connection/IBCConnection.sol b/evm/contracts/core/03-connection/IBCConnection.sol index 7f1788929f..e518157d94 100644 --- a/evm/contracts/core/03-connection/IBCConnection.sol +++ b/evm/contracts/core/03-connection/IBCConnection.sol @@ -1,383 +1,57 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "solady/utils/LibString.sol"; -import "@openzeppelin/utils/Strings.sol"; -import "../../proto/ibc/core/client/v1/client.sol"; -import "../../proto/ibc/core/connection/v1/connection.sol"; -import "../25-handler/IBCMsgs.sol"; import "../24-host/IBCStore.sol"; +import "../25-handler/IBCMsgs.sol"; import "../24-host/IBCCommitment.sol"; import "../03-connection/IIBCConnection.sol"; library IBCConnectionLib { event ConnectionOpenInit( - string connectionId, string clientId, string counterpartyClientId + uint32 connectionId, uint32 clientId, uint32 counterpartyClientId ); event ConnectionOpenTry( - string connectionId, - string clientId, - string counterpartyClientId, - string counterpartyConnectionId + uint32 connectionId, + uint32 clientId, + uint32 counterpartyClientId, + uint32 counterpartyConnectionId ); event ConnectionOpenAck( - string connectionId, - string clientId, - string counterpartyClientId, - string counterpartyConnectionId + uint32 connectionId, + uint32 clientId, + uint32 counterpartyClientId, + uint32 counterpartyConnectionId ); event ConnectionOpenConfirm( - string connectionId, - string clientId, - string counterpartyClientId, - string counterpartyConnectionId + uint32 connectionId, + uint32 clientId, + uint32 counterpartyClientId, + uint32 counterpartyConnectionId ); - error ErrConnectionAlreadyExists(); - error ErrValidateSelfClient(); - error ErrNoCounterpartyVersion(); - error ErrUnsupportedVersion(); - error ErrVersionMustBeUnset(); - error ErrInvalidConnectionProof(); - error ErrInvalidClientStateProof(); + error ErrInvalidProof(); error ErrInvalidConnectionState(); - - // yes, these are all defined as strings in the ibc spec - string internal constant IBC_VERSION_IDENTIFIER = "1"; - string internal constant ORDER_ORDERED = "ORDER_ORDERED"; - string internal constant ORDER_UNORDERED = "ORDER_UNORDERED"; - - /** - * @dev defaultIBCVersion returns the latest supported version of IBC used in connection version negotiation - */ - function defaultIBCVersion() - internal - pure - returns (IbcCoreConnectionV1Version.Data memory) - { - IbcCoreConnectionV1Version.Data memory version = - IbcCoreConnectionV1Version.Data({ - identifier: IBC_VERSION_IDENTIFIER, - features: new string[](2) - }); - version.features[0] = ORDER_ORDERED; - version.features[1] = ORDER_UNORDERED; - return version; - } - - /** - * @dev setSupportedVersions sets the supported versions to a given array. - * - * NOTE: `dst` must be an empty array - */ - function setSupportedVersions( - IbcCoreConnectionV1Version.Data[] memory supportedVersions, - IbcCoreConnectionV1Version.Data[] storage dst - ) internal { - if (dst.length != 0) { - revert ErrVersionMustBeUnset(); - } - uint256 supportedVersionsLength = supportedVersions.length; - for (uint256 i; i < supportedVersionsLength; i++) { - dst.push(supportedVersions[i]); - } - } - - /** - * @dev isSupportedVersion returns true if the proposed version has a matching version - * identifier and its entire feature set is supported or the version identifier - * supports an empty feature set. - */ - function isSupportedVersion( - IbcCoreConnectionV1Version.Data[] memory supportedVersions, - IbcCoreConnectionV1Version.Data memory version - ) internal pure returns (bool) { - (IbcCoreConnectionV1Version.Data memory supportedVersion, bool found) = - findSupportedVersion(version, supportedVersions); - if (!found) { - return false; - } - return verifyProposedVersion(supportedVersion, version); - } - - function isSupported( - IbcCoreConnectionV1Version.Data[] storage supportedVersions, - string memory feature - ) internal view returns (bool) { - uint256 supportedVersionsLength = supportedVersions.length; - for (uint256 i; i < supportedVersionsLength; i++) { - if (verifySupportedFeature(supportedVersions[i], feature)) { - return true; - } - } - return false; - } - - /** - * @dev verifyProposedVersion verifies that the entire feature set in the - * proposed version is supported by this chain. If the feature set is - * empty it verifies that this is allowed for the specified version - * identifier. - */ - function verifyProposedVersion( - IbcCoreConnectionV1Version.Data memory supportedVersion, - IbcCoreConnectionV1Version.Data memory proposedVersion - ) internal pure returns (bool) { - if ( - keccak256(abi.encodePacked(proposedVersion.identifier)) - != keccak256(abi.encodePacked(supportedVersion.identifier)) - ) { - return false; - } - uint256 proposedVersionFeaturesLength = proposedVersion.features.length; - if (proposedVersionFeaturesLength == 0) { - return false; - } - for (uint256 i; i < proposedVersionFeaturesLength; i++) { - if ( - !contains(proposedVersion.features[i], supportedVersion.features) - ) { - return false; - } - } - return true; - } - - /** - * @dev findSupportedVersion returns the version with a matching version identifier - * if it exists. The returned boolean is true if the version is found and - * false otherwise. - */ - function findSupportedVersion( - IbcCoreConnectionV1Version.Data memory version, - IbcCoreConnectionV1Version.Data[] memory supportedVersions - ) - internal - pure - returns ( - IbcCoreConnectionV1Version.Data memory supportedVersion, - bool found - ) - { - uint256 supportedVersionsLength = supportedVersions.length; - for (uint256 i; i < supportedVersionsLength; i++) { - supportedVersion = supportedVersions[i]; - if ( - keccak256(abi.encodePacked(supportedVersion.identifier)) - == keccak256(abi.encodePacked(version.identifier)) - ) { - return (supportedVersion, true); - } - } - return (supportedVersion, false); - } - - function pickVersion( - IbcCoreConnectionV1Version.Data[] memory supportedVersions, - IbcCoreConnectionV1Version.Data[] memory counterpartyVersions - ) internal pure returns (IbcCoreConnectionV1Version.Data memory) { - uint256 supportedVersionsLength = supportedVersions.length; - for (uint256 i; i < supportedVersionsLength; i++) { - IbcCoreConnectionV1Version.Data memory supportedVersion = - supportedVersions[i]; - ( - IbcCoreConnectionV1Version.Data memory counterpartyVersion, - bool found - ) = findSupportedVersion(supportedVersion, counterpartyVersions); - if (!found) { - continue; - } - string[] memory featureSet = getFeatureSetIntersection( - supportedVersion.features, counterpartyVersion.features - ); - if (featureSet.length > 0) { - return IbcCoreConnectionV1Version.Data({ - identifier: supportedVersion.identifier, - features: featureSet - }); - } - } - revert ErrUnsupportedVersion(); - } - - /** - * @dev copyVersions copies `src` to `dst` - */ - function copyVersions( - IbcCoreConnectionV1Version.Data[] memory src, - IbcCoreConnectionV1Version.Data[] storage dst - ) internal { - uint256 srcLength = src.length; - uint256 dstLength = dst.length; - if (srcLength == dstLength) { - for (uint256 i; i < srcLength; i++) { - copyVersion(src[i], dst[i]); - } - } else if (srcLength > dstLength) { - for (uint256 i; i < dstLength; i++) { - copyVersion(src[i], dst[i]); - } - for (uint256 i = dstLength; i < srcLength; i++) { - dst.push(src[i]); - } - } else { - for (uint256 i; i < srcLength; i++) { - copyVersion(src[i], dst[i]); - } - for (uint256 i = srcLength; i < dstLength; i++) { - dst.pop(); - } - } - } - - /** - * @dev newVersions returns a new array with a given version - */ - function newVersions(IbcCoreConnectionV1Version.Data memory version) - internal - pure - returns (IbcCoreConnectionV1Version.Data[] memory ret) - { - ret = new IbcCoreConnectionV1Version.Data[](1); - ret[0] = version; - } - - /** - * @dev verifySupportedFeature takes in a version and feature string and returns - * true if the feature is supported by the version and false otherwise. - */ - function verifySupportedFeature( - IbcCoreConnectionV1Version.Data memory version, - string memory feature - ) internal pure returns (bool) { - bytes32 hashedFeature = keccak256(bytes(feature)); - uint256 versionFeaturesLength = version.features.length; - for (uint256 i; i < versionFeaturesLength; i++) { - if (keccak256(bytes(version.features[i])) == hashedFeature) { - return true; - } - } - return false; - } - - function getFeatureSetIntersection( - string[] memory sourceFeatureSet, - string[] memory counterpartyFeatureSet - ) private pure returns (string[] memory) { - uint256 sourceFeatureSetLength = sourceFeatureSet.length; - string[] memory featureSet = new string[](sourceFeatureSetLength); - uint256 featureSetLength; - for (uint256 i; i < sourceFeatureSetLength; i++) { - if (contains(sourceFeatureSet[i], counterpartyFeatureSet)) { - featureSet[featureSetLength] = sourceFeatureSet[i]; - featureSetLength++; - } - } - string[] memory ret = new string[](featureSetLength); - for (uint256 i; i < featureSetLength; i++) { - ret[i] = featureSet[i]; - } - return ret; - } - - function copyVersion( - IbcCoreConnectionV1Version.Data memory src, - IbcCoreConnectionV1Version.Data storage dst - ) private { - dst.identifier = src.identifier; - uint256 srcLength = src.features.length; - uint256 dstLength = dst.features.length; - - if (srcLength == dstLength) { - for (uint256 i; i < srcLength; i++) { - dst.features[i] = src.features[i]; - } - } else if (srcLength > dstLength) { - for (uint256 i; i < dstLength; i++) { - dst.features[i] = src.features[i]; - } - for (uint256 i = dstLength; i < srcLength; i++) { - dst.features.push(src.features[i]); - } - } else { - for (uint256 i; i < srcLength; i++) { - dst.features[i] = src.features[i]; - } - for (uint256 i = srcLength; i < dstLength; i++) { - dst.features.pop(); - } - } - } - - function contains( - string memory elem, - string[] memory set - ) private pure returns (bool) { - bytes32 hashedElem = keccak256(bytes(elem)); - uint256 setLength = set.length; - for (uint256 i; i < setLength; i++) { - if (keccak256(bytes(set[i])) == hashedElem) { - return true; - } - } - return false; - } } /** * @dev IBCConnection is a contract that implements [ICS-3](https://github.com/cosmos/ibc/tree/main/spec/core/ics-003-connection-semantics). */ -contract IBCConnection is IBCStore, IIBCConnectionHandshake { - using LibString for *; - - /* Handshake functions */ - +abstract contract IBCConnectionImpl is IBCStore, IIBCConnection { /** * @dev connectionOpenInit initialises a connection attempt on chain A. The generated connection identifier * is returned. */ - function connectionOpenInit(IBCMsgs.MsgConnectionOpenInit calldata msg_) - external - override - returns (string memory) - { - string memory connectionId = generateConnectionIdentifier(); - IbcCoreConnectionV1ConnectionEnd.Data storage connection = - connections[connectionId]; - if ( - connection.state - != IbcCoreConnectionV1GlobalEnums - .State - .STATE_UNINITIALIZED_UNSPECIFIED - ) { - revert IBCConnectionLib.ErrConnectionAlreadyExists(); - } - - connection.client_id = msg_.clientId; - - if (msg_.version.features.length > 0) { - if ( - !IBCConnectionLib.isSupportedVersion( - getCompatibleVersions(), msg_.version - ) - ) { - revert IBCConnectionLib.ErrUnsupportedVersion(); - } - connection.versions.push(msg_.version); - } else { - IBCConnectionLib.setSupportedVersions( - getCompatibleVersions(), connection.versions - ); - } - - connection.state = IbcCoreConnectionV1GlobalEnums.State.STATE_INIT; - connection.delay_period = msg_.delayPeriod; + function connectionOpenInit( + IBCMsgs.MsgConnectionOpenInit calldata msg_ + ) external override returns (uint32) { + uint32 connectionId = generateConnectionIdentifier(); + IBCConnection storage connection = connections[connectionId]; + connection.clientId = msg_.clientId; + connection.state = IBCConnectionState.Init; connection.counterparty = msg_.counterparty; - updateConnectionCommitment(connectionId); - + commitConnection(connectionId, connection); emit IBCConnectionLib.ConnectionOpenInit( - connectionId, msg_.clientId, msg_.counterparty.client_id + connectionId, msg_.clientId, msg_.counterparty.clientId ); - return connectionId; } @@ -385,88 +59,40 @@ contract IBCConnection is IBCStore, IIBCConnectionHandshake { * @dev connectionOpenTry relays notice of a connection attempt on chain A to chain B (this * code is executed on chain B). */ - function connectionOpenTry(IBCMsgs.MsgConnectionOpenTry calldata msg_) - external - override - returns (string memory) - { - if (!validateSelfClient(msg_.clientStateBytes)) { - revert IBCConnectionLib.ErrValidateSelfClient(); - } - if (msg_.counterpartyVersions.length == 0) { - revert IBCConnectionLib.ErrNoCounterpartyVersion(); - } - - string memory connectionId = generateConnectionIdentifier(); - IbcCoreConnectionV1ConnectionEnd.Data storage connection = - connections[connectionId]; - - if ( - connection.state - != IbcCoreConnectionV1GlobalEnums - .State - .STATE_UNINITIALIZED_UNSPECIFIED - ) { - revert IBCConnectionLib.ErrConnectionAlreadyExists(); - } - - connection.client_id = msg_.clientId; - connection.versions.push( - IBCConnectionLib.pickVersion( - getCompatibleVersions(), msg_.counterpartyVersions - ) - ); - connection.state = IbcCoreConnectionV1GlobalEnums.State.STATE_TRYOPEN; - connection.delay_period = msg_.delayPeriod; + function connectionOpenTry( + IBCMsgs.MsgConnectionOpenTry calldata msg_ + ) external override returns (uint32) { + uint32 connectionId = generateConnectionIdentifier(); + IBCConnection storage connection = connections[connectionId]; + connection.clientId = msg_.clientId; + connection.state = IBCConnectionState.TryOpen; connection.counterparty = msg_.counterparty; - - IbcCoreConnectionV1ConnectionEnd.Data memory expectedConnection = - IbcCoreConnectionV1ConnectionEnd.Data({ - client_id: msg_.counterparty.client_id, - versions: msg_.counterpartyVersions, - state: IbcCoreConnectionV1GlobalEnums.State.STATE_INIT, - delay_period: msg_.delayPeriod, - counterparty: IbcCoreConnectionV1Counterparty.Data({ - client_id: msg_.clientId, - connection_id: "", - prefix: IbcCoreCommitmentV1MerklePrefix.Data({ - key_prefix: bytes(COMMITMENT_PREFIX) - }) + IBCConnection memory expectedConnection = IBCConnection({ + clientId: msg_.counterparty.clientId, + state: IBCConnectionState.Init, + counterparty: IBCConnectionCounterparty({ + clientId: msg_.clientId, + connectionId: 0 }) }); - if ( !verifyConnectionState( connection, msg_.proofHeight, msg_.proofInit, - msg_.counterparty.connection_id, + msg_.counterparty.connectionId, expectedConnection ) ) { - revert IBCConnectionLib.ErrInvalidConnectionProof(); + revert IBCConnectionLib.ErrInvalidProof(); } - if ( - !verifyClientState( - connection, - msg_.proofHeight, - IBCCommitment.clientStatePath(connection.counterparty.client_id), - msg_.proofClient, - msg_.clientStateBytes - ) - ) { - revert IBCConnectionLib.ErrInvalidClientStateProof(); - } - - updateConnectionCommitment(connectionId); - + commitConnection(connectionId, connection); emit IBCConnectionLib.ConnectionOpenTry( connectionId, msg_.clientId, - msg_.counterparty.client_id, - msg_.counterparty.connection_id + msg_.counterparty.clientId, + msg_.counterparty.connectionId ); - return connectionId; } @@ -474,80 +100,42 @@ contract IBCConnection is IBCStore, IIBCConnectionHandshake { * @dev connectionOpenAck relays acceptance of a connection open attempt from chain B back * to chain A (this code is executed on chain A). */ - function connectionOpenAck(IBCMsgs.MsgConnectionOpenAck calldata msg_) - external - override - { - IbcCoreConnectionV1ConnectionEnd.Data storage connection = - connections[msg_.connectionId]; - if (connection.state != IbcCoreConnectionV1GlobalEnums.State.STATE_INIT) - { + function connectionOpenAck( + IBCMsgs.MsgConnectionOpenAck calldata msg_ + ) external override { + IBCConnection storage connection = connections[msg_.connectionId]; + if (connection.state != IBCConnectionState.Init) { revert IBCConnectionLib.ErrInvalidConnectionState(); } - if ( - !IBCConnectionLib.isSupportedVersion( - connection.versions, msg_.version - ) - ) { - revert IBCConnectionLib.ErrUnsupportedVersion(); - } - if (!validateSelfClient(msg_.clientStateBytes)) { - revert IBCConnectionLib.ErrValidateSelfClient(); - } - - IbcCoreConnectionV1Counterparty.Data memory expectedCounterparty = - IbcCoreConnectionV1Counterparty.Data({ - client_id: connection.client_id, - connection_id: msg_.connectionId, - prefix: IbcCoreCommitmentV1MerklePrefix.Data({ - key_prefix: bytes(COMMITMENT_PREFIX) - }) + IBCConnectionCounterparty memory expectedCounterparty = + IBCConnectionCounterparty({ + clientId: connection.clientId, + connectionId: msg_.connectionId }); - - IbcCoreConnectionV1ConnectionEnd.Data memory expectedConnection = - IbcCoreConnectionV1ConnectionEnd.Data({ - client_id: connection.counterparty.client_id, - versions: IBCConnectionLib.newVersions(msg_.version), - state: IbcCoreConnectionV1GlobalEnums.State.STATE_TRYOPEN, - delay_period: connection.delay_period, + IBCConnection memory expectedConnection = IBCConnection({ + clientId: connection.counterparty.clientId, + state: IBCConnectionState.TryOpen, counterparty: expectedCounterparty }); - if ( !verifyConnectionState( connection, msg_.proofHeight, msg_.proofTry, - msg_.counterpartyConnectionID, + msg_.counterpartyConnectionId, expectedConnection ) ) { - revert IBCConnectionLib.ErrInvalidConnectionProof(); + revert IBCConnectionLib.ErrInvalidProof(); } - if ( - !verifyClientState( - connection, - msg_.proofHeight, - IBCCommitment.clientStatePath(connection.counterparty.client_id), - msg_.proofClient, - msg_.clientStateBytes - ) - ) { - revert IBCConnectionLib.ErrInvalidClientStateProof(); - } - - connection.state = IbcCoreConnectionV1GlobalEnums.State.STATE_OPEN; - IBCConnectionLib.copyVersions( - expectedConnection.versions, connection.versions - ); - connection.counterparty.connection_id = msg_.counterpartyConnectionID; - updateConnectionCommitment(msg_.connectionId); - + connection.state = IBCConnectionState.Open; + connection.counterparty.connectionId = msg_.counterpartyConnectionId; + commitConnection(msg_.connectionId, connection); emit IBCConnectionLib.ConnectionOpenAck( msg_.connectionId, - connection.client_id, - connection.counterparty.client_id, - connection.counterparty.connection_id + connection.clientId, + connection.counterparty.clientId, + connection.counterparty.connectionId ); } @@ -558,145 +146,84 @@ contract IBCConnection is IBCStore, IIBCConnectionHandshake { function connectionOpenConfirm( IBCMsgs.MsgConnectionOpenConfirm calldata msg_ ) external override { - IbcCoreConnectionV1ConnectionEnd.Data storage connection = - connections[msg_.connectionId]; - if ( - connection.state - != IbcCoreConnectionV1GlobalEnums.State.STATE_TRYOPEN - ) { + IBCConnection storage connection = connections[msg_.connectionId]; + if (connection.state != IBCConnectionState.TryOpen) { revert IBCConnectionLib.ErrInvalidConnectionState(); } - - IbcCoreConnectionV1Counterparty.Data memory expectedCounterparty = - IbcCoreConnectionV1Counterparty.Data({ - client_id: connection.client_id, - connection_id: msg_.connectionId, - prefix: IbcCoreCommitmentV1MerklePrefix.Data({ - key_prefix: bytes(COMMITMENT_PREFIX) - }) + IBCConnectionCounterparty memory expectedCounterparty = + IBCConnectionCounterparty({ + clientId: connection.clientId, + connectionId: msg_.connectionId }); - - IbcCoreConnectionV1ConnectionEnd.Data memory expectedConnection = - IbcCoreConnectionV1ConnectionEnd.Data({ - client_id: connection.counterparty.client_id, - versions: connection.versions, - state: IbcCoreConnectionV1GlobalEnums.State.STATE_OPEN, - delay_period: connection.delay_period, + IBCConnection memory expectedConnection = IBCConnection({ + clientId: connection.counterparty.clientId, + state: IBCConnectionState.Open, counterparty: expectedCounterparty }); - if ( !verifyConnectionState( connection, msg_.proofHeight, msg_.proofAck, - connection.counterparty.connection_id, + connection.counterparty.connectionId, expectedConnection ) ) { - revert IBCConnectionLib.ErrInvalidClientStateProof(); + revert IBCConnectionLib.ErrInvalidProof(); } - - connection.state = IbcCoreConnectionV1GlobalEnums.State.STATE_OPEN; - updateConnectionCommitment(msg_.connectionId); - + connection.state = IBCConnectionState.Open; + commitConnection(msg_.connectionId, connection); emit IBCConnectionLib.ConnectionOpenConfirm( msg_.connectionId, - connection.client_id, - connection.counterparty.client_id, - connection.counterparty.connection_id + connection.clientId, + connection.counterparty.clientId, + connection.counterparty.connectionId ); } - function updateConnectionCommitment(string memory connectionId) private { - commitments[IBCCommitment.connectionCommitmentKey(connectionId)] = - keccak256( - IbcCoreConnectionV1ConnectionEnd.encode(connections[connectionId]) - ); + function encodeConnection( + IBCConnection memory connection + ) internal pure returns (bytes32) { + return keccak256(abi.encode(connection)); } - /* Verification functions */ + function encodeConnectionStorage( + IBCConnection storage connection + ) internal pure returns (bytes32) { + return keccak256(abi.encode(connection)); + } - function verifyClientState( - IbcCoreConnectionV1ConnectionEnd.Data storage connection, - IbcCoreClientV1Height.Data memory height, - bytes memory path, - bytes memory proof, - bytes memory clientStateBytes - ) private returns (bool) { - return getClient(connection.client_id).verifyMembership( - connection.client_id, - height, - 0, - 0, - proof, - connection.counterparty.prefix.key_prefix, - path, - clientStateBytes - ); + function commitConnection( + uint32 connectionId, + IBCConnection storage connection + ) internal { + commitments[IBCCommitment.connectionCommitmentKey(connectionId)] = + encodeConnectionStorage(connection); } function verifyConnectionState( - IbcCoreConnectionV1ConnectionEnd.Data storage connection, - IbcCoreClientV1Height.Data memory height, - bytes memory proof, - string memory connectionId, - IbcCoreConnectionV1ConnectionEnd.Data memory counterpartyConnection - ) private returns (bool) { - return getClient(connection.client_id).verifyMembership( - connection.client_id, + IBCConnection storage connection, + uint64 height, + bytes calldata proof, + uint32 connectionId, + IBCConnection memory counterpartyConnection + ) internal returns (bool) { + return getClientInternal(connection.clientId).verifyMembership( + connection.clientId, height, - 0, - 0, proof, - connection.counterparty.prefix.key_prefix, - IBCCommitment.connectionPath(connectionId), - IbcCoreConnectionV1ConnectionEnd.encode(counterpartyConnection) - ); - } - - /* Internal functions */ - - function generateConnectionIdentifier() private returns (string memory) { - uint256 nextConnectionSequence = - uint256(commitments[nextConnectionSequencePath]); - - string memory identifier = string( abi.encodePacked( - "connection-", Strings.toString(nextConnectionSequence) - ) + IBCCommitment.connectionCommitmentKey(connectionId) + ), + abi.encodePacked(encodeConnection(counterpartyConnection)) ); - commitments[nextConnectionSequencePath] = - bytes32(nextConnectionSequence + 1); - return identifier; } - /** - * @dev validateSelfClient validates the client parameters for a client of the host chain. - * - * NOTE: Developers can override this function to support an arbitrary EVM chain. - */ - function validateSelfClient(bytes memory) - internal - view - virtual - returns (bool) - { - return true; - } - - /** - * @dev getCompatibleVersions returns the supported versions of the host chain. - */ - function getCompatibleVersions() - public - pure - virtual - returns (IbcCoreConnectionV1Version.Data[] memory) - { - IbcCoreConnectionV1Version.Data[] memory versions = - new IbcCoreConnectionV1Version.Data[](1); - versions[0] = IBCConnectionLib.defaultIBCVersion(); - return versions; + function generateConnectionIdentifier() internal returns (uint32) { + uint32 nextConnectionSequence = + uint32(uint256(commitments[nextConnectionSequencePath])); + commitments[nextConnectionSequencePath] = + bytes32(uint256(nextConnectionSequence + 1)); + return nextConnectionSequence; } } diff --git a/evm/contracts/core/03-connection/IIBCConnection.sol b/evm/contracts/core/03-connection/IIBCConnection.sol index ab8094ecdc..bf744f7e5a 100644 --- a/evm/contracts/core/03-connection/IIBCConnection.sol +++ b/evm/contracts/core/03-connection/IIBCConnection.sol @@ -1,32 +1,33 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "../25-handler/IBCMsgs.sol"; -interface IIBCConnectionHandshake { +interface IIBCConnection { /* Handshake functions */ /** * @dev connectionOpenInit initialises a connection attempt on chain A. The generated connection identifier * is returned. */ - function connectionOpenInit(IBCMsgs.MsgConnectionOpenInit calldata msg_) - external - returns (string memory); + function connectionOpenInit( + IBCMsgs.MsgConnectionOpenInit calldata msg_ + ) external returns (uint32); /** * @dev connectionOpenTry relays notice of a connection attempt on chain A to chain B (this * code is executed on chain B). */ - function connectionOpenTry(IBCMsgs.MsgConnectionOpenTry calldata msg_) - external - returns (string memory); + function connectionOpenTry( + IBCMsgs.MsgConnectionOpenTry calldata msg_ + ) external returns (uint32); /** * @dev connectionOpenAck relays acceptance of a connection open attempt from chain B back * to chain A (this code is executed on chain A). */ - function connectionOpenAck(IBCMsgs.MsgConnectionOpenAck calldata msg_) - external; + function connectionOpenAck( + IBCMsgs.MsgConnectionOpenAck calldata msg_ + ) external; /** * @dev connectionOpenConfirm confirms opening of a connection on chain A to chain B, after diff --git a/evm/contracts/core/04-channel/IBCChannel.sol b/evm/contracts/core/04-channel/IBCChannel.sol new file mode 100644 index 0000000000..f64c929b44 --- /dev/null +++ b/evm/contracts/core/04-channel/IBCChannel.sol @@ -0,0 +1,361 @@ +pragma solidity ^0.8.27; + +import "../24-host/IBCStore.sol"; +import "../25-handler/IBCMsgs.sol"; +import "../24-host/IBCCommitment.sol"; +import "../04-channel/IIBCChannel.sol"; +import "../05-port/IIBCModule.sol"; + +library IBCChannelLib { + event ChannelOpenInit( + address portId, uint32 channelId, uint32 connectionId, bytes32 version + ); + event ChannelOpenTry( + address portId, + uint32 channelId, + uint32 counterpartyChannelId, + uint32 connectionId, + bytes32 version + ); + event ChannelOpenAck( + address portId, + uint32 channelId, + uint32 counterpartyChannelId, + uint32 connectionId + ); + event ChannelOpenConfirm( + address portId, + uint32 channelId, + uint32 counterpartyChannelId, + uint32 connectionId + ); + event ChannelCloseInit(address portId, uint32 channelId); + event ChannelCloseConfirm(address portId, uint32 channelId); + + error ErrPortIdMustBeLowercase(); + error ErrConnNotSingleHop(); + error ErrConnNotSingleVersion(); + error ErrInvalidConnectionState(); + error ErrUnsupportedFeature(); + error ErrInvalidChannelState(); + error ErrCounterpartyChannelNotEmpty(); + error ErrInvalidProof(); + error ErrInvalidChannelOrdering(); +} + +/** + * @dev IBCChannelHandshake is a contract that implements [ICS-4](https://github.com/cosmos/ibc/tree/main/spec/core/ics-004-channel-and-packet-semantics). + */ +abstract contract IBCChannelImpl is IBCStore, IIBCChannel { + /** + * @dev channelOpenInit is called by a module to initiate a channel opening handshake with a module on another chain. + */ + function channelOpenInit( + IBCMsgs.MsgChannelOpenInit calldata msg_ + ) external override returns (uint32) { + if (msg_.channel.state != IBCChannelState.Init) { + revert IBCChannelLib.ErrInvalidChannelState(); + } + if ( + msg_.channel.ordering != IBCChannelOrder.Unordered + && msg_.channel.ordering != IBCChannelOrder.Ordered + ) { + revert IBCChannelLib.ErrInvalidChannelOrdering(); + } + uint32 channelId = generateChannelIdentifier(); + channels[channelId] = msg_.channel; + initializeChannelSequences(channelId); + commitChannelCalldata(channelId, msg_.channel); + claimChannel(msg_.portId, channelId); + IIBCModule(msg_.portId).onChanOpenInit( + msg_.channel.ordering, + msg_.channel.connectionId, + channelId, + msg_.channel.counterparty, + msg_.channel.version, + msg_.relayer + ); + emit IBCChannelLib.ChannelOpenInit( + msg_.portId, + channelId, + msg_.channel.connectionId, + msg_.channel.version + ); + return channelId; + } + + /** + * @dev channelOpenTry is called by a module to accept the first step of a channel opening handshake initiated by a module on another chain. + */ + function channelOpenTry( + IBCMsgs.MsgChannelOpenTry calldata msg_ + ) external override returns (uint32) { + if ( + msg_.channel.ordering != IBCChannelOrder.Unordered + && msg_.channel.ordering != IBCChannelOrder.Ordered + ) { + revert IBCChannelLib.ErrInvalidChannelOrdering(); + } + if (msg_.channel.state != IBCChannelState.TryOpen) { + revert IBCChannelLib.ErrInvalidChannelState(); + } + uint32 clientId = ensureConnectionState(msg_.channel.connectionId); + IBCChannelCounterparty memory expectedCounterparty = + IBCChannelCounterparty({channelId: 0}); + IBCChannel memory expectedChannel = IBCChannel({ + state: IBCChannelState.Init, + ordering: msg_.channel.ordering, + counterparty: expectedCounterparty, + connectionId: getCounterpartyConnection(msg_.channel.connectionId), + version: msg_.counterpartyVersion + }); + if ( + !verifyChannelState( + clientId, + msg_.proofHeight, + msg_.proofInit, + msg_.channel.counterparty.channelId, + expectedChannel + ) + ) { + revert IBCChannelLib.ErrInvalidProof(); + } + uint32 channelId = generateChannelIdentifier(); + channels[channelId] = msg_.channel; + initializeChannelSequences(channelId); + commitChannelCalldata(channelId, msg_.channel); + claimChannel(msg_.portId, channelId); + IIBCModule(msg_.portId).onChanOpenTry( + msg_.channel.ordering, + msg_.channel.connectionId, + channelId, + msg_.channel.counterparty, + msg_.channel.version, + msg_.counterpartyVersion, + msg_.relayer + ); + emit IBCChannelLib.ChannelOpenTry( + msg_.portId, + channelId, + msg_.channel.counterparty.channelId, + msg_.channel.connectionId, + msg_.counterpartyVersion + ); + return channelId; + } + + /** + * @dev channelOpenAck is called by the handshake-originating module to acknowledge the acceptance of the initial request by the counterparty module on the other chain. + */ + function channelOpenAck( + IBCMsgs.MsgChannelOpenAck calldata msg_ + ) external override { + IBCChannel storage channel = channels[msg_.channelId]; + if (channel.state != IBCChannelState.Init) { + revert IBCChannelLib.ErrInvalidChannelState(); + } + uint32 clientId = ensureConnectionState(channel.connectionId); + IBCChannelCounterparty memory expectedCounterparty = + IBCChannelCounterparty({channelId: msg_.channelId}); + IBCChannel memory expectedChannel = IBCChannel({ + state: IBCChannelState.TryOpen, + ordering: channel.ordering, + counterparty: expectedCounterparty, + connectionId: getCounterpartyConnection(channel.connectionId), + version: msg_.counterpartyVersion + }); + if ( + !verifyChannelState( + clientId, + msg_.proofHeight, + msg_.proofTry, + msg_.counterpartyChannelId, + expectedChannel + ) + ) { + revert IBCChannelLib.ErrInvalidProof(); + } + channel.state = IBCChannelState.Open; + channel.version = msg_.counterpartyVersion; + channel.counterparty.channelId = msg_.counterpartyChannelId; + commitChannel(msg_.channelId, channel); + IIBCModule(msg_.portId).onChanOpenAck( + msg_.channelId, + msg_.counterpartyChannelId, + msg_.counterpartyVersion, + msg_.relayer + ); + emit IBCChannelLib.ChannelOpenAck( + msg_.portId, + msg_.channelId, + msg_.counterpartyChannelId, + channel.connectionId + ); + } + + /** + * @dev channelOpenConfirm is called by the counterparty module to close their end of the channel, since the other end has been closed. + */ + function channelOpenConfirm( + IBCMsgs.MsgChannelOpenConfirm calldata msg_ + ) external override { + IBCChannel storage channel = channels[msg_.channelId]; + if (channel.state != IBCChannelState.TryOpen) { + revert IBCChannelLib.ErrInvalidChannelState(); + } + uint32 clientId = ensureConnectionState(channel.connectionId); + IBCChannelCounterparty memory expectedCounterparty = + IBCChannelCounterparty({channelId: msg_.channelId}); + IBCChannel memory expectedChannel = IBCChannel({ + state: IBCChannelState.Open, + ordering: channel.ordering, + counterparty: expectedCounterparty, + connectionId: getCounterpartyConnection(channel.connectionId), + version: channel.version + }); + if ( + !verifyChannelState( + clientId, + msg_.proofHeight, + msg_.proofAck, + channel.counterparty.channelId, + expectedChannel + ) + ) { + revert IBCChannelLib.ErrInvalidProof(); + } + channel.state = IBCChannelState.Open; + commitChannel(msg_.channelId, channel); + IIBCModule(msg_.portId).onChanOpenConfirm(msg_.channelId, msg_.relayer); + emit IBCChannelLib.ChannelOpenConfirm( + msg_.portId, + msg_.channelId, + channel.counterparty.channelId, + channel.connectionId + ); + } + + /** + * @dev channelCloseInit is called by either module to close their end of the channel. Once closed, channels cannot be reopened. + */ + function channelCloseInit( + IBCMsgs.MsgChannelCloseInit calldata msg_ + ) external override { + IBCChannel storage channel = channels[msg_.channelId]; + if (channel.state != IBCChannelState.Open) { + revert IBCChannelLib.ErrInvalidChannelState(); + } + ensureConnectionState(channel.connectionId); + channel.state = IBCChannelState.Closed; + commitChannel(msg_.channelId, channel); + IIBCModule(msg_.portId).onChanCloseInit(msg_.channelId, msg_.relayer); + emit IBCChannelLib.ChannelCloseInit(msg_.portId, msg_.channelId); + } + + /** + * @dev channelCloseConfirm is called by the counterparty module to close their end of the + * channel, since the other end has been closed. + */ + function channelCloseConfirm( + IBCMsgs.MsgChannelCloseConfirm calldata msg_ + ) external override { + IBCChannel storage channel = channels[msg_.channelId]; + if (channel.state != IBCChannelState.Open) { + revert IBCChannelLib.ErrInvalidChannelState(); + } + uint32 clientId = ensureConnectionState(channel.connectionId); + IBCChannelCounterparty memory expectedCounterparty = + IBCChannelCounterparty({channelId: msg_.channelId}); + IBCChannel memory expectedChannel = IBCChannel({ + state: IBCChannelState.Closed, + ordering: channel.ordering, + counterparty: expectedCounterparty, + connectionId: getCounterpartyConnection(channel.connectionId), + version: channel.version + }); + if ( + !verifyChannelState( + clientId, + msg_.proofHeight, + msg_.proofInit, + channel.counterparty.channelId, + expectedChannel + ) + ) { + revert IBCChannelLib.ErrInvalidProof(); + } + channel.state = IBCChannelState.Closed; + commitChannel(msg_.channelId, channel); + IIBCModule(msg_.portId).onChanCloseConfirm(msg_.channelId, msg_.relayer); + emit IBCChannelLib.ChannelCloseConfirm(msg_.portId, msg_.channelId); + } + + function encodeChannel( + IBCChannel memory channel + ) internal pure returns (bytes32) { + return keccak256(abi.encode(channel)); + } + + function commitChannel( + uint32 channelId, + IBCChannel storage channel + ) internal { + commitments[IBCCommitment.channelCommitmentKey(channelId)] = + encodeChannel(channel); + } + + function encodeChannelCalldata( + IBCChannel calldata channel + ) internal pure returns (bytes32) { + return keccak256(abi.encode(channel)); + } + + function commitChannelCalldata( + uint32 channelId, + IBCChannel calldata channel + ) internal { + commitments[IBCCommitment.channelCommitmentKey(channelId)] = + encodeChannelCalldata(channel); + } + + function verifyChannelState( + uint32 clientId, + uint64 height, + bytes calldata proof, + uint32 channelId, + IBCChannel memory channel + ) internal returns (bool) { + return getClientInternal(clientId).verifyMembership( + clientId, + height, + proof, + abi.encodePacked(IBCCommitment.channelCommitmentKey(channelId)), + abi.encodePacked(encodeChannel(channel)) + ); + } + + function getCounterpartyConnection( + uint32 connectionId + ) internal view returns (uint32) { + return connections[connectionId].counterparty.connectionId; + } + + function generateChannelIdentifier() internal returns (uint32) { + uint32 nextChannelSequence = + uint32(uint256(commitments[nextChannelSequencePath])); + commitments[nextChannelSequencePath] = + bytes32(uint256(nextChannelSequence + 1)); + return nextChannelSequence; + } + + function initializeChannelSequences( + uint32 channelId + ) internal { + commitments[IBCCommitment.nextSequenceSendCommitmentKey(channelId)] = + bytes32(uint256(1)); + commitments[IBCCommitment.nextSequenceRecvCommitmentKey(channelId)] = + bytes32(uint256(1)); + commitments[IBCCommitment.nextSequenceAckCommitmentKey(channelId)] = + bytes32(uint256(1)); + } +} diff --git a/evm/contracts/core/04-channel/IBCChannelHandshake.sol b/evm/contracts/core/04-channel/IBCChannelHandshake.sol deleted file mode 100644 index 6c29e2ed0e..0000000000 --- a/evm/contracts/core/04-channel/IBCChannelHandshake.sol +++ /dev/null @@ -1,551 +0,0 @@ -pragma solidity ^0.8.23; - -import "@openzeppelin/utils/Strings.sol"; -import "solady/utils/LibString.sol"; - -import "../../proto/ibc/core/channel/v1/channel.sol"; -import "../25-handler/IBCMsgs.sol"; -import "../02-client/IBCHeight.sol"; -import "../24-host/IBCCommitment.sol"; -import "../04-channel/IIBCChannel.sol"; -import "../05-port/ModuleManager.sol"; -import "../05-port/IIBCModule.sol"; - -library IBCChannelLib { - event ChannelOpenInit( - string portId, - string channelId, - string counterpartyPortId, - string connectionId, - string version - ); - event ChannelOpenTry( - string portId, - string channelId, - string counterpartyPortId, - string counterpartyChannelId, - string connectionId, - string version - ); - event ChannelOpenAck( - string portId, - string channelId, - string counterpartyPortId, - string counterpartyChannelId, - string connectionId - ); - event ChannelOpenConfirm( - string portId, - string channelId, - string counterpartyPortId, - string counterpartyChannelId, - string connectionId - ); - event ChannelCloseInit(string channelId, string portId); - event ChannelCloseConfirm(string channelId, string portId); - - error ErrPortIdMustBeLowercase(); - error ErrConnNotSingleHop(); - error ErrConnNotSingleVersion(); - error ErrInvalidConnectionState(); - error ErrUnsupportedFeature(); - error ErrInvalidChannelState(); - error ErrCounterpartyChannelNotEmpty(); - error ErrInvalidProof(); - - string public constant ORDER_ORDERED = "ORDER_ORDERED"; - string public constant ORDER_UNORDERED = "ORDER_UNORDERED"; - string public constant ORDER_INVALID = "_ORDER_INVALID_"; - - function verifySupportedFeature( - IbcCoreConnectionV1Version.Data memory version, - string memory feature - ) internal pure returns (bool) { - bytes32 h = keccak256(bytes(feature)); - for (uint256 i; i < version.features.length; i++) { - if (keccak256(bytes(version.features[i])) == h) { - return true; - } - } - return false; - } - - function toString(IbcCoreChannelV1GlobalEnums.Order ordering) - internal - pure - returns (string memory) - { - if (ordering == IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED) { - return ORDER_UNORDERED; - } else if (ordering == IbcCoreChannelV1GlobalEnums.Order.ORDER_ORDERED) - { - return ORDER_ORDERED; - } else { - return ORDER_INVALID; - } - } -} - -/** - * @dev IBCChannelHandshake is a contract that implements [ICS-4](https://github.com/cosmos/ibc/tree/main/spec/core/ics-004-channel-and-packet-semantics). - */ -contract IBCChannelHandshake is ModuleManager, IIBCChannelHandshake { - using IBCHeight for IbcCoreClientV1Height.Data; - using LibString for *; - - /* Handshake functions */ - - /** - * @dev channelOpenInit is called by a module to initiate a channel opening handshake with a module on another chain. - */ - function channelOpenInit(IBCMsgs.MsgChannelOpenInit calldata msg_) - external - override - returns (string memory) - { - if (!msg_.portId.lower().eq(msg_.portId)) { - revert IBCChannelLib.ErrPortIdMustBeLowercase(); - } - (string memory connectionId,) = ensureConnectionFeature( - msg_.channel.connection_hops, msg_.channel.ordering - ); - if (msg_.channel.state != IbcCoreChannelV1GlobalEnums.State.STATE_INIT) - { - revert IBCChannelLib.ErrInvalidChannelState(); - } - if (bytes(msg_.channel.counterparty.channel_id).length != 0) { - revert IBCChannelLib.ErrCounterpartyChannelNotEmpty(); - } - - string memory channelId = generateChannelIdentifier(); - channels[msg_.portId][channelId] = msg_.channel; - - commitments[IBCCommitment.nextSequenceSendCommitmentKey( - msg_.portId, channelId - )] = bytes32(uint256(1)); - commitments[IBCCommitment.nextSequenceRecvCommitmentKey( - msg_.portId, channelId - )] = bytes32(uint256(1)); - - commitments[IBCCommitment.nextSequenceAckCommitmentKey( - msg_.portId, channelId - )] = bytes32(uint256(1)); - - updateChannelCommitment(msg_.portId, channelId); - - IIBCModule module = lookupModuleByPort(msg_.portId); - - claimCapability( - channelCapabilityPath(msg_.portId, channelId), address(module) - ); - - module.onChanOpenInit( - msg_.channel.ordering, - msg_.channel.connection_hops, - msg_.portId, - channelId, - msg_.channel.counterparty, - msg_.channel.version, - msg_.relayer - ); - - emit IBCChannelLib.ChannelOpenInit( - msg_.portId, - channelId, - msg_.channel.counterparty.port_id, - connectionId, - msg_.channel.version - ); - - return channelId; - } - - /** - * @dev channelOpenTry is called by a module to accept the first step of a channel opening handshake initiated by a module on another chain. - */ - function channelOpenTry(IBCMsgs.MsgChannelOpenTry calldata msg_) - external - override - returns (string memory) - { - if (!msg_.portId.lower().eq(msg_.portId)) { - revert IBCChannelLib.ErrPortIdMustBeLowercase(); - } - ( - string memory connectionId, - IbcCoreConnectionV1ConnectionEnd.Data memory connection - ) = ensureConnectionFeature( - msg_.channel.connection_hops, msg_.channel.ordering - ); - if ( - msg_.channel.state - != IbcCoreChannelV1GlobalEnums.State.STATE_TRYOPEN - ) { - revert IBCChannelLib.ErrInvalidChannelState(); - } - - IbcCoreChannelV1Counterparty.Data memory expectedCounterparty = - IbcCoreChannelV1Counterparty.Data({port_id: msg_.portId, channel_id: ""}); - IbcCoreChannelV1Channel.Data memory expectedChannel = - IbcCoreChannelV1Channel.Data({ - state: IbcCoreChannelV1GlobalEnums.State.STATE_INIT, - ordering: msg_.channel.ordering, - counterparty: expectedCounterparty, - connection_hops: getCounterpartyHops(msg_.channel.connection_hops[0]), - version: msg_.counterpartyVersion - }); - - if ( - !verifyChannelState( - connection, - msg_.proofHeight, - msg_.proofInit, - msg_.channel.counterparty.port_id, - msg_.channel.counterparty.channel_id, - IbcCoreChannelV1Channel.encode(expectedChannel) - ) - ) { - revert IBCChannelLib.ErrInvalidProof(); - } - - string memory channelId = generateChannelIdentifier(); - - emit IBCChannelLib.ChannelOpenTry( - msg_.portId, - channelId, - msg_.channel.counterparty.port_id, - msg_.channel.counterparty.channel_id, - connectionId, - msg_.counterpartyVersion - ); - - channels[msg_.portId][channelId] = msg_.channel; - commitments[IBCCommitment.nextSequenceSendCommitmentKey( - msg_.portId, channelId - )] = bytes32(uint256(1)); - commitments[IBCCommitment.nextSequenceRecvCommitmentKey( - msg_.portId, channelId - )] = bytes32(uint256(1)); - commitments[IBCCommitment.nextSequenceAckCommitmentKey( - msg_.portId, channelId - )] = bytes32(uint256(1)); - updateChannelCommitment(msg_.portId, channelId); - - IIBCModule module = lookupModuleByPort(msg_.portId); - - claimCapability( - channelCapabilityPath(msg_.portId, channelId), address(module) - ); - - module.onChanOpenTry( - msg_.channel.ordering, - msg_.channel.connection_hops, - msg_.portId, - channelId, - msg_.channel.counterparty, - msg_.channel.version, - msg_.counterpartyVersion, - msg_.relayer - ); - - return channelId; - } - - /** - * @dev channelOpenAck is called by the handshake-originating module to acknowledge the acceptance of the initial request by the counterparty module on the other chain. - */ - function channelOpenAck(IBCMsgs.MsgChannelOpenAck calldata msg_) - external - override - { - IbcCoreChannelV1Channel.Data storage channel = - channels[msg_.portId][msg_.channelId]; - if (channel.state != IbcCoreChannelV1GlobalEnums.State.STATE_INIT) { - revert IBCChannelLib.ErrInvalidChannelState(); - } - - emit IBCChannelLib.ChannelOpenAck( - msg_.portId, - msg_.channelId, - channel.counterparty.port_id, - // haven't been saved yet, but we have to yield the even early to avoid overflowing the stack - msg_.counterpartyChannelId, - channel.connection_hops[0] - ); - - IbcCoreConnectionV1ConnectionEnd.Data memory connection = - ensureConnectionState(channel.connection_hops[0]); - - IbcCoreChannelV1Counterparty.Data memory expectedCounterparty = - IbcCoreChannelV1Counterparty.Data({ - port_id: msg_.portId, - channel_id: msg_.channelId - }); - IbcCoreChannelV1Channel.Data memory expectedChannel = - IbcCoreChannelV1Channel.Data({ - state: IbcCoreChannelV1GlobalEnums.State.STATE_TRYOPEN, - ordering: channel.ordering, - counterparty: expectedCounterparty, - connection_hops: getCounterpartyHops(channel.connection_hops[0]), - version: msg_.counterpartyVersion - }); - - if ( - !verifyChannelState( - connection, - msg_.proofHeight, - msg_.proofTry, - channel.counterparty.port_id, - msg_.counterpartyChannelId, - IbcCoreChannelV1Channel.encode(expectedChannel) - ) - ) { - revert IBCChannelLib.ErrInvalidProof(); - } - - channel.state = IbcCoreChannelV1GlobalEnums.State.STATE_OPEN; - channel.version = msg_.counterpartyVersion; - channel.counterparty.channel_id = msg_.counterpartyChannelId; - updateChannelCommitment(msg_.portId, msg_.channelId); - - lookupModuleByPort(msg_.portId).onChanOpenAck( - msg_.portId, - msg_.channelId, - msg_.counterpartyChannelId, - msg_.counterpartyVersion, - msg_.relayer - ); - } - - /** - * @dev channelOpenConfirm is called by the counterparty module to close their end of the channel, since the other end has been closed. - */ - function channelOpenConfirm(IBCMsgs.MsgChannelOpenConfirm calldata msg_) - external - override - { - IbcCoreChannelV1Channel.Data storage channel = - channels[msg_.portId][msg_.channelId]; - if (channel.state != IbcCoreChannelV1GlobalEnums.State.STATE_TRYOPEN) { - revert IBCChannelLib.ErrInvalidChannelState(); - } - - emit IBCChannelLib.ChannelOpenConfirm( - msg_.portId, - msg_.channelId, - channel.counterparty.port_id, - channel.counterparty.channel_id, - channel.connection_hops[0] - ); - - IbcCoreConnectionV1ConnectionEnd.Data memory connection = - ensureConnectionState(channel.connection_hops[0]); - - IbcCoreChannelV1Counterparty.Data memory expectedCounterparty = - IbcCoreChannelV1Counterparty.Data({ - port_id: msg_.portId, - channel_id: msg_.channelId - }); - IbcCoreChannelV1Channel.Data memory expectedChannel = - IbcCoreChannelV1Channel.Data({ - state: IbcCoreChannelV1GlobalEnums.State.STATE_OPEN, - ordering: channel.ordering, - counterparty: expectedCounterparty, - connection_hops: getCounterpartyHops(channel.connection_hops[0]), - version: channel.version - }); - - if ( - !verifyChannelState( - connection, - msg_.proofHeight, - msg_.proofAck, - channel.counterparty.port_id, - channel.counterparty.channel_id, - IbcCoreChannelV1Channel.encode(expectedChannel) - ) - ) { - revert IBCChannelLib.ErrInvalidProof(); - } - - channel.state = IbcCoreChannelV1GlobalEnums.State.STATE_OPEN; - updateChannelCommitment(msg_.portId, msg_.channelId); - - lookupModuleByPort(msg_.portId).onChanOpenConfirm( - msg_.portId, msg_.channelId, msg_.relayer - ); - } - - /** - * @dev channelCloseInit is called by either module to close their end of the channel. Once closed, channels cannot be reopened. - */ - function channelCloseInit(IBCMsgs.MsgChannelCloseInit calldata msg_) - external - override - { - IbcCoreChannelV1Channel.Data storage channel = - channels[msg_.portId][msg_.channelId]; - if (channel.state != IbcCoreChannelV1GlobalEnums.State.STATE_OPEN) { - revert IBCChannelLib.ErrInvalidChannelState(); - } - - ensureConnectionState(channel.connection_hops[0]); - - channel.state = IbcCoreChannelV1GlobalEnums.State.STATE_CLOSED; - updateChannelCommitment(msg_.portId, msg_.channelId); - - lookupModuleByPort(msg_.portId).onChanCloseInit( - msg_.portId, msg_.channelId, msg_.relayer - ); - - emit IBCChannelLib.ChannelCloseInit(msg_.channelId, msg_.portId); - } - - /** - * @dev channelCloseConfirm is called by the counterparty module to close their end of the - * channel, since the other end has been closed. - */ - function channelCloseConfirm(IBCMsgs.MsgChannelCloseConfirm calldata msg_) - external - override - { - IbcCoreChannelV1Channel.Data storage channel = - channels[msg_.portId][msg_.channelId]; - if (channel.state != IbcCoreChannelV1GlobalEnums.State.STATE_OPEN) { - revert IBCChannelLib.ErrInvalidChannelState(); - } - - IbcCoreConnectionV1ConnectionEnd.Data memory connection = - ensureConnectionState(channel.connection_hops[0]); - - IbcCoreChannelV1Counterparty.Data memory expectedCounterparty = - IbcCoreChannelV1Counterparty.Data({ - port_id: msg_.portId, - channel_id: msg_.channelId - }); - IbcCoreChannelV1Channel.Data memory expectedChannel = - IbcCoreChannelV1Channel.Data({ - state: IbcCoreChannelV1GlobalEnums.State.STATE_CLOSED, - ordering: channel.ordering, - counterparty: expectedCounterparty, - connection_hops: getCounterpartyHops(channel.connection_hops[0]), - version: channel.version - }); - - if ( - !verifyChannelState( - connection, - msg_.proofHeight, - msg_.proofInit, - channel.counterparty.port_id, - channel.counterparty.channel_id, - IbcCoreChannelV1Channel.encode(expectedChannel) - ) - ) { - revert IBCChannelLib.ErrInvalidProof(); - } - - channel.state = IbcCoreChannelV1GlobalEnums.State.STATE_CLOSED; - updateChannelCommitment(msg_.portId, msg_.channelId); - - lookupModuleByPort(msg_.portId).onChanCloseConfirm( - msg_.portId, msg_.channelId, msg_.relayer - ); - - emit IBCChannelLib.ChannelCloseConfirm(msg_.channelId, msg_.portId); - } - - function updateChannelCommitment( - string memory portId, - string memory channelId - ) private { - commitments[IBCCommitment.channelCommitmentKey(portId, channelId)] = - keccak256(IbcCoreChannelV1Channel.encode(channels[portId][channelId])); - } - - /* Verification functions */ - - function verifyChannelState( - IbcCoreConnectionV1ConnectionEnd.Data memory connection, - IbcCoreClientV1Height.Data calldata height, - bytes calldata proof, - string memory portId, - string memory channelId, - bytes memory channelBytes - ) private returns (bool) { - return getClient(connection.client_id).verifyMembership( - connection.client_id, - height, - 0, - 0, - proof, - connection.counterparty.prefix.key_prefix, - IBCCommitment.channelPath(portId, channelId), - channelBytes - ); - } - - /* Internal functions */ - - function getCounterpartyHops(string memory connectionId) - internal - view - returns (string[] memory hops) - { - hops = new string[](1); - hops[0] = connections[connectionId].counterparty.connection_id; - return hops; - } - - function generateChannelIdentifier() internal returns (string memory) { - uint256 nextChannelSequence = - uint256(commitments[nextChannelSequencePath]); - - string memory identifier = string( - abi.encodePacked("channel-", Strings.toString(nextChannelSequence)) - ); - commitments[nextChannelSequencePath] = bytes32(nextChannelSequence + 1); - return identifier; - } - - function ensureConnectionState(string memory connectionId) - internal - view - returns (IbcCoreConnectionV1ConnectionEnd.Data memory) - { - IbcCoreConnectionV1ConnectionEnd.Data memory connection = - connections[connectionId]; - if (connection.state != IbcCoreConnectionV1GlobalEnums.State.STATE_OPEN) - { - revert IBCChannelLib.ErrInvalidConnectionState(); - } - return connection; - } - - function ensureConnectionFeature( - string[] calldata connectionHops, - IbcCoreChannelV1GlobalEnums.Order ordering - ) - internal - view - returns (string memory, IbcCoreConnectionV1ConnectionEnd.Data memory) - { - if (connectionHops.length != 1) { - revert IBCChannelLib.ErrConnNotSingleHop(); - } - string memory connectionId = connectionHops[0]; - IbcCoreConnectionV1ConnectionEnd.Data memory connection = - ensureConnectionState(connectionId); - if (connection.versions.length != 1) { - revert IBCChannelLib.ErrConnNotSingleVersion(); - } - if ( - !IBCChannelLib.verifySupportedFeature( - connection.versions[0], IBCChannelLib.toString(ordering) - ) - ) { - revert IBCChannelLib.ErrUnsupportedFeature(); - } - return (connectionId, connection); - } -} diff --git a/evm/contracts/core/04-channel/IBCPacket.sol b/evm/contracts/core/04-channel/IBCPacket.sol index 90d76add50..301afe4f15 100644 --- a/evm/contracts/core/04-channel/IBCPacket.sol +++ b/evm/contracts/core/04-channel/IBCPacket.sol @@ -1,602 +1,577 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "solady/utils/LibString.sol"; -import "@openzeppelin/utils/Strings.sol"; - -import "../../proto/ibc/core/channel/v1/channel.sol"; +import "../24-host/IBCStore.sol"; import "../25-handler/IBCMsgs.sol"; -import "../02-client/IBCHeight.sol"; import "../24-host/IBCStore.sol"; import "../24-host/IBCCommitment.sol"; import "../04-channel/IIBCPacket.sol"; -import "../05-port/ModuleManager.sol"; import "../05-port/IIBCModule.sol"; +import "../Types.sol"; library IBCPacketLib { - event SendPacket( - uint64 sequence, - string sourcePort, - string sourceChannel, - IbcCoreClientV1Height.Data timeoutHeight, - uint64 timeoutTimestamp, - bytes data - ); - event RecvPacket(IbcCoreChannelV1Packet.Data packet); - event WriteAcknowledgement( - IbcCoreChannelV1Packet.Data packet, bytes acknowledgement + bytes32 public constant COMMITMENT_MAGIC = + 0x0100000000000000000000000000000000000000000000000000000000000000; + bytes32 public constant COMMITMENT_NULL = bytes32(uint256(0)); + + event SendPacket(IBCPacket packet); + event RecvPacket(IBCPacket packets, address relayer, bytes relayerMsg); + event RecvIntentPacket( + IBCPacket packet, address marketMaker, bytes marketMakerMsg ); + event WriteAcknowledgement(IBCPacket packet, bytes acknowledgement); event AcknowledgePacket( - IbcCoreChannelV1Packet.Data packet, bytes acknowledgement + IBCPacket packet, bytes acknowledgement, address relayer ); - event TimeoutPacket(IbcCoreChannelV1Packet.Data packet); + event TimeoutPacket(IBCPacket packet, address relayer); error ErrUnauthorized(); - error ErrInvalidChannelState(); - error ErrLatestHeightNotFound(); error ErrLatestTimestampNotFound(); - error ErrInvalidTimeoutHeight(); - error ErrInvalidTimeoutTimestamp(); error ErrTimeoutMustBeSet(); - error ErrSourceAndCounterpartyPortMismatch(); - error ErrSourceAndCounterpartyChannelMismatch(); - error ErrDestinationAndCounterpartyPortMismatch(); - error ErrDestinationAndCounterpartyChannelMismatch(); - error ErrInvalidConnectionState(); error ErrHeightTimeout(); error ErrTimestampTimeout(); error ErrInvalidProof(); - error ErrPacketAlreadyReceived(); error ErrPacketSequenceNextSequenceMismatch(); - error ErrUnknownChannelOrdering(); + error ErrPacketSequenceAckSequenceMismatch(); error ErrAcknowledgementIsEmpty(); + error ErrPacketNotReceived(); error ErrAcknowledgementAlreadyExists(); error ErrPacketCommitmentNotFound(); - error ErrInvalidPacketCommitment(); error ErrTimeoutHeightNotReached(); error ErrTimeoutTimestampNotReached(); - error ErrNextSequenceMustBeGreaterThanTimeoutSequence(); + error ErrNextSequenceMustBeLEQThanTimeoutSequence(); + error ErrNotEnoughPackets(); + error ErrCommittedAckNotPresent(); + error ErrCannotIntentOrderedPacket(); + + function commitAcksMemory( + bytes[] memory acks + ) internal pure returns (bytes32) { + return mergeAck(keccak256(abi.encode(acks))); + } + + function commitAcks( + bytes[] calldata acks + ) internal pure returns (bytes32) { + return mergeAck(keccak256(abi.encode(acks))); + } + + function commitAck( + bytes calldata ack + ) internal pure returns (bytes32) { + return mergeAck(keccak256(abi.encodePacked(ack))); + } + + function commitAckMemory( + bytes memory ack + ) internal pure returns (bytes32) { + return mergeAck(keccak256(abi.encodePacked(ack))); + } + + function commitPacketsMemory( + IBCPacket[] memory packets + ) internal pure returns (bytes32) { + return keccak256(abi.encode(packets)); + } + + function commitPackets( + IBCPacket[] calldata packets + ) internal pure returns (bytes32) { + return keccak256(abi.encode(packets)); + } + + function commitPacketMemory( + IBCPacket memory packet + ) internal pure returns (bytes32) { + return keccak256(abi.encode(packet)); + } + + function commitPacket( + IBCPacket calldata packet + ) internal pure returns (bytes32) { + return keccak256(abi.encode(packet)); + } + + function commitRecvSeq( + uint64 sequence + ) internal pure returns (bytes32) { + return keccak256(abi.encodePacked(sequence)); + } + + function mergeAck( + bytes32 ack + ) internal pure returns (bytes32) { + return COMMITMENT_MAGIC + | ( + ack + & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + ); + } } /** * @dev IBCPacket is a contract that implements [ICS-4](https://github.com/cosmos/ibc/tree/main/spec/core/ics-004-channel-and-packet-semantics). */ -contract IBCPacket is IBCStore, IIBCPacket, ModuleManager { - using IBCHeight for IbcCoreClientV1Height.Data; - using LibString for *; - - /** - * @dev sendPacket is called by a module in order to send an IBC packet on a channel. - * The packet sequence generated for the packet to be sent is returned. An error - * is returned if one occurs. - */ +abstract contract IBCPacketImpl is IBCStore, IIBCPacket { + function batchSend( + IBCMsgs.MsgBatchSend calldata msg_ + ) external override { + uint256 l = msg_.packets.length; + // No reason to batch less than 2 packets as they are already individually committed. + if (l < 2) { + revert IBCPacketLib.ErrNotEnoughPackets(); + } + for (uint256 i = 0; i < l; i++) { + IBCPacket calldata packet = msg_.packets[i]; + // If the channel mismatch, the commitment will be zero + bytes32 commitment = commitments[IBCCommitment + .batchPacketsCommitmentKey( + msg_.sourceChannel, IBCPacketLib.commitPacket(packet) + )]; + // Every packet must have been previously sent to be batched + if (commitment != IBCPacketLib.COMMITMENT_MAGIC) { + revert IBCPacketLib.ErrPacketCommitmentNotFound(); + } + } + commitments[IBCCommitment.batchPacketsCommitmentKey( + msg_.sourceChannel, IBCPacketLib.commitPackets(msg_.packets) + )] = IBCPacketLib.COMMITMENT_MAGIC; + } + + function batchAcks( + IBCMsgs.MsgBatchAcks calldata msg_ + ) external override { + uint256 l = msg_.packets.length; + // No reason to batch less than 2 packets as they are already individually committed. + if (l < 2) { + revert IBCPacketLib.ErrNotEnoughPackets(); + } + for (uint256 i = 0; i < l; i++) { + IBCPacket calldata packet = msg_.packets[i]; + bytes calldata ack = msg_.acks[i]; + // If the channel mismatch, the commitment will be zero. + bytes32 commitment = commitments[IBCCommitment + .batchReceiptsCommitmentKey( + msg_.sourceChannel, IBCPacketLib.commitPacket(packet) + )]; + // Can't batch an empty ack. + if ( + commitment == IBCPacketLib.COMMITMENT_NULL + || commitment == IBCPacketLib.COMMITMENT_MAGIC + ) { + revert IBCPacketLib.ErrAcknowledgementIsEmpty(); + } + // Of course the ack must match. + if (commitment != IBCPacketLib.commitAck(ack)) { + revert IBCPacketLib.ErrCommittedAckNotPresent(); + } + } + commitments[IBCCommitment.batchReceiptsCommitmentKey( + msg_.sourceChannel, IBCPacketLib.commitPackets(msg_.packets) + )] = IBCPacketLib.commitAcks(msg_.acks); + } + function sendPacket( - string calldata sourceChannel, - IbcCoreClientV1Height.Data calldata timeoutHeight, + uint32 sourceChannel, + uint64 timeoutHeight, uint64 timeoutTimestamp, bytes calldata data ) external override returns (uint64) { - string memory sourcePort = msg.sender.toHexString(); - if ( - !authenticateCapability( - channelCapabilityPath(sourcePort, sourceChannel) - ) - ) { - revert IBCPacketLib.ErrUnauthorized(); - } - - IbcCoreChannelV1Channel.Data storage channel = - ensureChannelState(sourcePort, sourceChannel); - - if (timeoutTimestamp == 0 && timeoutHeight.isZero()) { + if (timeoutTimestamp == 0 && timeoutHeight == 0) { revert IBCPacketLib.ErrTimeoutMustBeSet(); } - - string memory clientId = - connections[channel.connection_hops[0]].client_id; - ILightClient client = getClient(clientId); - - IbcCoreClientV1Height.Data memory latestHeight = - client.getLatestHeight(clientId); - if (latestHeight.revision_height == 0) { - revert IBCPacketLib.ErrLatestHeightNotFound(); - } - if (!timeoutHeight.isZero() && latestHeight.gte(timeoutHeight)) { - revert IBCPacketLib.ErrInvalidTimeoutHeight(); + if (!authenticateChannelOwner(sourceChannel)) { + revert IBCPacketLib.ErrUnauthorized(); } + IBCChannel storage channel = ensureChannelState(sourceChannel); + uint64 sequence = generatePacketSequence(sourceChannel); + IBCPacket memory packet = IBCPacket({ + sequence: sequence, + sourceChannel: sourceChannel, + destinationChannel: channel.counterparty.channelId, + data: data, + timeoutHeight: timeoutHeight, + timeoutTimestamp: timeoutTimestamp + }); + commitments[IBCCommitment.batchPacketsCommitmentKey( + sourceChannel, IBCPacketLib.commitPacketMemory(packet) + )] = IBCPacketLib.COMMITMENT_MAGIC; + emit IBCPacketLib.SendPacket(packet); + return sequence; + } - uint64 latestTimestamp; - latestTimestamp = client.getTimestampAtHeight(clientId, latestHeight); - if (latestTimestamp == 0) { - revert IBCPacketLib.ErrLatestTimestampNotFound(); - } - if (timeoutTimestamp != 0 && latestTimestamp >= timeoutTimestamp) { - revert IBCPacketLib.ErrInvalidTimeoutTimestamp(); + function setPacketReceive( + bytes32 commitmentKey + ) internal returns (bool) { + bool alreadyReceived = + commitments[commitmentKey] != IBCPacketLib.COMMITMENT_NULL; + if (!alreadyReceived) { + commitments[commitmentKey] = IBCPacketLib.COMMITMENT_MAGIC; } + return alreadyReceived; + } - uint64 packetSequence = uint64( + function setNextSequenceRecv( + uint32 destinationChannel, + uint64 receivedSequence + ) internal { + uint64 expectedRecvSequence = uint64( uint256( - commitments[IBCCommitment.nextSequenceSendCommitmentKey( - sourcePort, sourceChannel + commitments[IBCCommitment.nextSequenceRecvCommitmentKey( + destinationChannel )] ) ); - commitments[IBCCommitment.nextSequenceSendCommitmentKey( - sourcePort, sourceChannel - )] = bytes32(uint256(packetSequence + 1)); - commitments[IBCCommitment.packetCommitmentKey( - sourcePort, sourceChannel, packetSequence - )] = keccak256( - abi.encodePacked( - sha256( - abi.encodePacked( - timeoutTimestamp, - timeoutHeight.revision_number, - timeoutHeight.revision_height, - sha256(data) - ) - ) - ) - ); - - emit IBCPacketLib.SendPacket( - packetSequence, - sourcePort, - sourceChannel, - timeoutHeight, - timeoutTimestamp, - data - ); - - return packetSequence; - } - - /** - * @dev recvPacket is called by a module in order to receive & process an IBC packet - * sent on the corresponding channel end on the counterparty chain. - */ - function recvPacket(IBCMsgs.MsgPacketRecv calldata msg_) - external - override - { - IbcCoreChannelV1Channel.Data storage channel = ensureChannelState( - msg_.packet.destination_port, msg_.packet.destination_channel - ); - - if ( - hashString(msg_.packet.source_port) - != hashString(channel.counterparty.port_id) - ) { - revert IBCPacketLib.ErrSourceAndCounterpartyPortMismatch(); - } - if ( - hashString(msg_.packet.source_channel) - != hashString(channel.counterparty.channel_id) - ) { - revert IBCPacketLib.ErrSourceAndCounterpartyChannelMismatch(); - } - - IbcCoreConnectionV1ConnectionEnd.Data storage connection = - connections[channel.connection_hops[0]]; - if (connection.state != IbcCoreConnectionV1GlobalEnums.State.STATE_OPEN) - { - revert IBCPacketLib.ErrInvalidConnectionState(); - } - - if ( - msg_.packet.timeout_height.revision_height != 0 - && (block.number >= msg_.packet.timeout_height.revision_height) - ) { - revert IBCPacketLib.ErrHeightTimeout(); - } - - // For some reason cosmos is using nanos, we try to follow their convention to avoid friction - uint64 currentTimestamp = uint64(block.timestamp * 1e9); - if ( - msg_.packet.timeout_timestamp != 0 - && (currentTimestamp >= msg_.packet.timeout_timestamp) - ) { - revert IBCPacketLib.ErrTimestampTimeout(); + if (expectedRecvSequence != receivedSequence) { + revert IBCPacketLib.ErrPacketSequenceNextSequenceMismatch(); } + commitments[IBCCommitment.nextSequenceRecvCommitmentKey( + destinationChannel + )] = bytes32(uint256(expectedRecvSequence + 1)); + } - if ( - !verifyCommitment( - connection, - msg_.proofHeight, - msg_.proof, - IBCCommitment.packetCommitmentPath( - msg_.packet.source_port, - msg_.packet.source_channel, - msg_.packet.sequence - ), - abi.encodePacked( - sha256( - abi.encodePacked( - msg_.packet.timeout_timestamp, - msg_.packet.timeout_height.revision_number, - msg_.packet.timeout_height.revision_height, - sha256(msg_.packet.data) - ) - ) + function processReceive( + IBCPacket[] calldata packets, + address maker, + bytes[] calldata makerMsgs, + uint64 proofHeight, + bytes calldata proof, + bool intent + ) internal { + uint256 l = packets.length; + if (l == 0) { + revert IBCPacketLib.ErrNotEnoughPackets(); + } + uint32 destinationChannel = packets[0].destinationChannel; + IBCChannel storage channel = ensureChannelState(destinationChannel); + uint32 clientId = ensureConnectionState(channel.connectionId); + if (!intent) { + bytes32 proofCommitmentKey; + if (l == 1) { + proofCommitmentKey = IBCCommitment.batchReceiptsCommitmentKey( + destinationChannel, IBCPacketLib.commitPacket(packets[0]) + ); + } else { + proofCommitmentKey = IBCCommitment.batchReceiptsCommitmentKey( + destinationChannel, IBCPacketLib.commitPackets(packets) + ); + } + if ( + !verifyCommitment( + clientId, + proofHeight, + proof, + proofCommitmentKey, + IBCPacketLib.COMMITMENT_MAGIC ) - ) - ) { - revert IBCPacketLib.ErrInvalidProof(); + ) { + revert IBCPacketLib.ErrInvalidProof(); + } } + IBCChannelOrder ordering = channel.ordering; + IIBCModule module = lookupModuleByChannel(destinationChannel); + for (uint256 i = 0; i < l; i++) { + IBCPacket calldata packet = packets[i]; + // Check packet height timeout + if ( + packet.timeoutHeight > 0 + && (block.number >= packet.timeoutHeight) + ) { + revert IBCPacketLib.ErrHeightTimeout(); + } + // Check packet timestamp timeout + // For some reason cosmos is using nanos, we try to follow their convention to avoid friction + uint64 currentTimestamp = uint64(block.timestamp * 1e9); + if ( + packet.timeoutTimestamp != 0 + && (currentTimestamp >= packet.timeoutTimestamp) + ) { + revert IBCPacketLib.ErrTimestampTimeout(); + } - if ( - channel.ordering - == IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED - ) { - bytes32 receiptCommitmentKey = IBCCommitment - .packetReceiptCommitmentKey( - msg_.packet.destination_port, - msg_.packet.destination_channel, - msg_.packet.sequence + bytes32 commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( + destinationChannel, IBCPacketLib.commitPacket(packet) ); - bytes32 receipt = commitments[receiptCommitmentKey]; - if (receipt != bytes32(0)) { - revert IBCPacketLib.ErrPacketAlreadyReceived(); + + // Allow unordered channels to have packets already received. + bool alreadyReceived = false; + if (ordering == IBCChannelOrder.Unordered) { + alreadyReceived = setPacketReceive(commitmentKey); + } else if (ordering == IBCChannelOrder.Ordered) { + // We increase the sequence, hence can't avoid proofs + if (intent) { + revert IBCPacketLib.ErrCannotIntentOrderedPacket(); + } + setNextSequenceRecv(destinationChannel, packet.sequence); } - commitments[receiptCommitmentKey] = bytes32(uint256(1)); - } else if ( - channel.ordering == IbcCoreChannelV1GlobalEnums.Order.ORDER_ORDERED - ) { - uint64 expectedRecvSequence = uint64( - uint256( - commitments[IBCCommitment.nextSequenceRecvCommitmentKey( - msg_.packet.destination_port, - msg_.packet.destination_channel - )] - ) - ); - if (expectedRecvSequence != msg_.packet.sequence) { - revert IBCPacketLib.ErrPacketSequenceNextSequenceMismatch(); + + if (!alreadyReceived) { + bytes memory acknowledgement; + bytes calldata makerMsg = makerMsgs[i]; + if (intent) { + acknowledgement = + module.onRecvIntentPacket(packet, maker, makerMsg); + emit IBCPacketLib.RecvIntentPacket(packet, maker, makerMsg); + } else { + acknowledgement = + module.onRecvPacket(packet, maker, makerMsg); + emit IBCPacketLib.RecvPacket(packet, maker, makerMsg); + } + if (acknowledgement.length > 0) { + _writeAcknowledgement(commitmentKey, acknowledgement); + emit IBCPacketLib.WriteAcknowledgement( + packet, acknowledgement + ); + } } - commitments[IBCCommitment.nextSequenceRecvCommitmentKey( - msg_.packet.destination_port, msg_.packet.destination_channel - )] = bytes32(uint256(expectedRecvSequence + 1)); - } else { - revert IBCPacketLib.ErrUnknownChannelOrdering(); } + } - IIBCModule module = lookupModuleByChannel( - msg_.packet.destination_port, msg_.packet.destination_channel + function recvPacket( + IBCMsgs.MsgPacketRecv calldata msg_ + ) external { + processReceive( + msg_.packets, + msg_.relayer, + msg_.relayerMsgs, + msg_.proofHeight, + msg_.proof, + false + ); + } + + function recvIntentPacket( + IBCMsgs.MsgIntentPacketRecv calldata msg_ + ) external override { + processReceive( + msg_.packets, + msg_.marketMaker, + msg_.marketMakerMsgs, + 0, + msg_.emptyProof, + true ); - bytes memory acknowledgement = - module.onRecvPacket(msg_.packet, msg_.relayer); - if (acknowledgement.length > 0) { - _writeAcknowledgement(msg_.packet, acknowledgement); - } - emit IBCPacketLib.RecvPacket(msg_.packet); } function _writeAcknowledgement( - IbcCoreChannelV1Packet.Data calldata packet, + bytes32 commitmentKey, bytes memory acknowledgement ) internal { - if (acknowledgement.length == 0) { - revert IBCPacketLib.ErrAcknowledgementIsEmpty(); + bytes32 commitment = commitments[commitmentKey]; + if (commitment == IBCPacketLib.COMMITMENT_NULL) { + revert IBCPacketLib.ErrPacketNotReceived(); } - - ensureChannelState(packet.destination_port, packet.destination_channel); - - bytes32 ackCommitmentKey = IBCCommitment - .packetAcknowledgementCommitmentKey( - packet.destination_port, packet.destination_channel, packet.sequence - ); - bytes32 ackCommitment = commitments[ackCommitmentKey]; - if (ackCommitment != bytes32(0)) { + if (commitment != IBCPacketLib.COMMITMENT_MAGIC) { revert IBCPacketLib.ErrAcknowledgementAlreadyExists(); } - commitments[ackCommitmentKey] = - keccak256(abi.encodePacked(sha256(acknowledgement))); - - emit IBCPacketLib.WriteAcknowledgement(packet, acknowledgement); + commitments[commitmentKey] = + IBCPacketLib.commitAckMemory(acknowledgement); } - /** - * @dev writeAcknowledgement writes the packet execution acknowledgement to the state, - * which will be verified by the counterparty chain using AcknowledgePacket. - */ function writeAcknowledgement( - IbcCoreChannelV1Packet.Data calldata packet, + IBCPacket calldata packet, bytes memory acknowledgement ) external override { - string memory destinationPort = msg.sender.toHexString(); - if ( - !authenticateCapability( - channelCapabilityPath( - destinationPort, packet.destination_channel - ) - ) - ) { + if (acknowledgement.length == 0) { + revert IBCPacketLib.ErrAcknowledgementIsEmpty(); + } + if (!authenticateChannelOwner(packet.destinationChannel)) { revert IBCPacketLib.ErrUnauthorized(); } - _writeAcknowledgement(packet, acknowledgement); - } - - /** - * @dev AcknowledgePacket is called by a module to process the acknowledgement of a - * packet previously sent by the calling module on a channel to a counterparty - * module on the counterparty chain. Its intended usage is within the ante - * handler. AcknowledgePacket will clean up the packet commitment, - * which is no longer necessary since the packet has been received and acted upon. - * It will also increment NextSequenceAck in case of ORDERED channels. - */ - function acknowledgePacket(IBCMsgs.MsgPacketAcknowledgement calldata msg_) - external - override - { - IbcCoreChannelV1Channel.Data storage channel = ensureChannelState( - msg_.packet.source_port, msg_.packet.source_channel + ensureChannelState(packet.destinationChannel); + bytes32 commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( + packet.destinationChannel, IBCPacketLib.commitPacket(packet) ); + _writeAcknowledgement(commitmentKey, acknowledgement); + emit IBCPacketLib.WriteAcknowledgement(packet, acknowledgement); + } - if ( - hashString(msg_.packet.destination_port) - != hashString(channel.counterparty.port_id) - ) { - revert IBCPacketLib.ErrDestinationAndCounterpartyPortMismatch(); - } - if ( - hashString(msg_.packet.destination_channel) - != hashString(channel.counterparty.channel_id) - ) { - revert IBCPacketLib.ErrDestinationAndCounterpartyChannelMismatch(); - } - - IbcCoreConnectionV1ConnectionEnd.Data storage connection = - connections[channel.connection_hops[0]]; - if (connection.state != IbcCoreConnectionV1GlobalEnums.State.STATE_OPEN) - { - revert IBCPacketLib.ErrInvalidConnectionState(); - } - - bytes32 packetCommitmentKey = IBCCommitment.packetCommitmentKey( - msg_.packet.source_port, - msg_.packet.source_channel, - msg_.packet.sequence - ); - bytes32 expectedPacketCommitment = commitments[packetCommitmentKey]; - if (expectedPacketCommitment == bytes32(0)) { - revert IBCPacketLib.ErrPacketCommitmentNotFound(); - } - bytes32 packetCommitment = keccak256( - abi.encodePacked( - sha256( - abi.encodePacked( - msg_.packet.timeout_timestamp, - msg_.packet.timeout_height.revision_number, - msg_.packet.timeout_height.revision_height, - sha256(msg_.packet.data) - ) - ) + function setNextSequenceAck( + uint32 sourceChannel, + uint64 ackSequence + ) internal { + uint64 expectedAckSequence = uint64( + uint256( + commitments[IBCCommitment.nextSequenceAckCommitmentKey( + sourceChannel + )] ) ); - if (expectedPacketCommitment != packetCommitment) { - revert IBCPacketLib.ErrInvalidPacketCommitment(); + if (expectedAckSequence != ackSequence) { + revert IBCPacketLib.ErrPacketSequenceAckSequenceMismatch(); } + commitments[IBCCommitment.nextSequenceAckCommitmentKey(sourceChannel)] = + bytes32(uint256(expectedAckSequence + 1)); + } + function acknowledgePacket( + IBCMsgs.MsgPacketAcknowledgement calldata msg_ + ) external override { + uint256 l = msg_.packets.length; + if (l == 0) { + revert IBCPacketLib.ErrNotEnoughPackets(); + } + uint32 sourceChannel = msg_.packets[0].sourceChannel; + uint32 destinationChannel = msg_.packets[0].destinationChannel; + IBCChannel storage channel = ensureChannelState(sourceChannel); + uint32 clientId = ensureConnectionState(channel.connectionId); + bytes32 commitmentKey; + if (l == 1) { + commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( + destinationChannel, IBCPacketLib.commitPacket(msg_.packets[0]) + ); + } else { + commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( + destinationChannel, IBCPacketLib.commitPackets(msg_.packets) + ); + } if ( !verifyCommitment( - connection, + clientId, msg_.proofHeight, msg_.proof, - IBCCommitment.packetAcknowledgementCommitmentPath( - msg_.packet.destination_port, - msg_.packet.destination_channel, - msg_.packet.sequence - ), - abi.encodePacked(sha256(msg_.acknowledgement)) + commitmentKey, + IBCPacketLib.commitAcks(msg_.acknowledgements) ) ) { revert IBCPacketLib.ErrInvalidProof(); } - - if (channel.ordering == IbcCoreChannelV1GlobalEnums.Order.ORDER_ORDERED) - { - uint64 expectedAckSequence = uint64( - uint256( - commitments[IBCCommitment.nextSequenceAckCommitmentKey( - msg_.packet.source_port, msg_.packet.source_channel - )] - ) - ); - if (expectedAckSequence != msg_.packet.sequence) { - revert IBCPacketLib.ErrPacketSequenceNextSequenceMismatch(); + IBCChannelOrder ordering = channel.ordering; + IIBCModule module = lookupModuleByChannel(sourceChannel); + for (uint256 i = 0; i < l; i++) { + IBCPacket calldata packet = msg_.packets[i]; + deletePacketCommitment(sourceChannel, packet); + bytes calldata acknowledgement = msg_.acknowledgements[i]; + if (ordering == IBCChannelOrder.Ordered) { + setNextSequenceAck(sourceChannel, packet.sequence); } - commitments[IBCCommitment.nextSequenceAckCommitmentKey( - msg_.packet.source_port, msg_.packet.source_channel - )] = bytes32(uint256(expectedAckSequence + 1)); + module.onAcknowledgementPacket( + packet, acknowledgement, msg_.relayer + ); + emit IBCPacketLib.AcknowledgePacket( + packet, acknowledgement, msg_.relayer + ); } - - delete commitments[packetCommitmentKey]; - - IIBCModule module = lookupModuleByChannel( - msg_.packet.source_port, msg_.packet.source_channel - ); - module.onAcknowledgementPacket( - msg_.packet, msg_.acknowledgement, msg_.relayer - ); - - emit IBCPacketLib.AcknowledgePacket(msg_.packet, msg_.acknowledgement); - } - - function hashString(string memory s) private pure returns (bytes32) { - return keccak256(abi.encodePacked(s)); } - function timeoutPacket(IBCMsgs.MsgPacketTimeout calldata msg_) - external - override - { - IbcCoreChannelV1Channel.Data storage channel = ensureChannelState( - msg_.packet.source_port, msg_.packet.source_channel - ); - - if ( - hashString(msg_.packet.destination_port) - != hashString(channel.counterparty.port_id) - ) { - revert IBCPacketLib.ErrDestinationAndCounterpartyPortMismatch(); - } - if ( - hashString(msg_.packet.destination_channel) - != hashString(channel.counterparty.channel_id) - ) { - revert IBCPacketLib.ErrDestinationAndCounterpartyChannelMismatch(); - } - - IbcCoreConnectionV1ConnectionEnd.Data storage connection = - connections[channel.connection_hops[0]]; - if (connection.state != IbcCoreConnectionV1GlobalEnums.State.STATE_OPEN) - { - revert IBCPacketLib.ErrInvalidConnectionState(); - } - - bytes32 packetCommitmentKey = IBCCommitment.packetCommitmentKey( - msg_.packet.source_port, - msg_.packet.source_channel, - msg_.packet.sequence - ); - bytes32 expectedPacketCommitment = commitments[packetCommitmentKey]; - if (expectedPacketCommitment == bytes32(0)) { - revert IBCPacketLib.ErrPacketCommitmentNotFound(); - } - bytes32 packetCommitment = keccak256( - abi.encodePacked( - sha256( - abi.encodePacked( - msg_.packet.timeout_timestamp, - msg_.packet.timeout_height.revision_number, - msg_.packet.timeout_height.revision_height, - sha256(msg_.packet.data) - ) - ) - ) - ); - if (expectedPacketCommitment != packetCommitment) { - revert IBCPacketLib.ErrInvalidPacketCommitment(); - } - - ILightClient client = getClient(connection.client_id); + function timeoutPacket( + IBCMsgs.MsgPacketTimeout calldata msg_ + ) external override { + IBCPacket calldata packet = msg_.packet; + uint32 sourceChannel = packet.sourceChannel; + uint32 destinationChannel = packet.destinationChannel; + IBCChannel storage channel = ensureChannelState(sourceChannel); + uint32 clientId = ensureConnectionState(channel.connectionId); + ILightClient client = getClientInternal(clientId); uint64 proofTimestamp = - client.getTimestampAtHeight(connection.client_id, msg_.proofHeight); + client.getTimestampAtHeight(clientId, msg_.proofHeight); if (proofTimestamp == 0) { revert IBCPacketLib.ErrLatestTimestampNotFound(); } - - if ( - msg_.packet.timeout_timestamp > 0 - && msg_.packet.timeout_timestamp >= proofTimestamp - ) { - revert IBCPacketLib.ErrTimeoutTimestampNotReached(); - } - if ( - !msg_.packet.timeout_height.isZero() - && msg_.packet.timeout_height.gte(msg_.proofHeight) - ) { - revert IBCPacketLib.ErrTimeoutHeightNotReached(); - } - - bool isOrdered = - channel.ordering == IbcCoreChannelV1GlobalEnums.Order.ORDER_ORDERED; - bool isUnordered = channel.ordering - == IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED; - if (isOrdered) { - if (msg_.nextSequenceRecv <= msg_.packet.sequence) { - revert - IBCPacketLib - .ErrNextSequenceMustBeGreaterThanTimeoutSequence(); - } + IBCChannelOrder ordering = channel.ordering; + if (ordering == IBCChannelOrder.Ordered) { if ( !verifyCommitment( - connection, + clientId, msg_.proofHeight, msg_.proof, - IBCCommitment.nextSequenceRecvCommitmentPath( - msg_.packet.destination_port, - msg_.packet.destination_channel + IBCCommitment.nextSequenceRecvCommitmentKey( + destinationChannel ), - abi.encodePacked(msg_.nextSequenceRecv) + IBCPacketLib.commitRecvSeq(msg_.nextSequenceRecv) ) ) { revert IBCPacketLib.ErrInvalidProof(); } - channel.state = IbcCoreChannelV1GlobalEnums.State.STATE_CLOSED; - } else if (isUnordered) { + } else if (ordering == IBCChannelOrder.Unordered) { + bytes32 commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( + destinationChannel, IBCPacketLib.commitPacket(packet) + ); if ( !verifyAbsentCommitment( - connection, - msg_.proofHeight, - msg_.proof, - IBCCommitment.packetReceiptCommitmentPath( - msg_.packet.destination_port, - msg_.packet.destination_channel, - msg_.packet.sequence - ) + clientId, msg_.proofHeight, msg_.proof, commitmentKey ) ) { revert IBCPacketLib.ErrInvalidProof(); } - } else { - revert IBCPacketLib.ErrUnknownChannelOrdering(); } - - delete commitments[packetCommitmentKey]; - - IIBCModule module = lookupModuleByChannel( - msg_.packet.source_port, msg_.packet.source_channel - ); - module.onTimeoutPacket(msg_.packet, msg_.relayer); - - emit IBCPacketLib.TimeoutPacket(msg_.packet); + IIBCModule module = lookupModuleByChannel(sourceChannel); + deletePacketCommitment(sourceChannel, packet); + if (packet.timeoutTimestamp == 0 && packet.timeoutHeight == 0) { + revert IBCPacketLib.ErrTimeoutMustBeSet(); + } + if ( + packet.timeoutTimestamp > 0 + && packet.timeoutTimestamp > proofTimestamp + ) { + revert IBCPacketLib.ErrTimeoutTimestampNotReached(); + } + if (packet.timeoutHeight > 0 && packet.timeoutHeight > msg_.proofHeight) + { + revert IBCPacketLib.ErrTimeoutHeightNotReached(); + } + if (ordering == IBCChannelOrder.Ordered) { + if (msg_.nextSequenceRecv > packet.sequence) { + revert IBCPacketLib.ErrNextSequenceMustBeLEQThanTimeoutSequence( + ); + } + } + module.onTimeoutPacket(packet, msg_.relayer); + emit IBCPacketLib.TimeoutPacket(packet, msg_.relayer); } function verifyCommitment( - IbcCoreConnectionV1ConnectionEnd.Data storage connection, - IbcCoreClientV1Height.Data calldata height, + uint32 clientId, + uint64 height, bytes calldata proof, - bytes memory path, - bytes memory commitment - ) private returns (bool) { - return getClient(connection.client_id).verifyMembership( - connection.client_id, + bytes32 path, + bytes32 commitment + ) internal virtual returns (bool) { + return getClientInternal(clientId).verifyMembership( + clientId, height, - connection.delay_period, - 0, proof, - connection.counterparty.prefix.key_prefix, - path, - commitment + abi.encodePacked(path), + abi.encodePacked(commitment) ); } function verifyAbsentCommitment( - IbcCoreConnectionV1ConnectionEnd.Data storage connection, - IbcCoreClientV1Height.Data calldata height, + uint32 clientId, + uint64 height, bytes calldata proof, - bytes memory path - ) private returns (bool) { - return getClient(connection.client_id).verifyNonMembership( - connection.client_id, - height, - connection.delay_period, - 0, - proof, - connection.counterparty.prefix.key_prefix, - path + bytes32 path + ) internal virtual returns (bool) { + return getClientInternal(clientId).verifyNonMembership( + clientId, height, proof, abi.encodePacked(path) + ); + } + + function generatePacketSequence( + uint32 channelId + ) internal returns (uint64) { + uint64 seq = uint64( + uint256( + commitments[IBCCommitment.nextSequenceSendCommitmentKey( + channelId + )] + ) ); + commitments[IBCCommitment.nextSequenceSendCommitmentKey(channelId)] = + bytes32(uint256(seq + 1)); + return seq; } - function ensureChannelState( - string memory portId, - string calldata channelId - ) internal view returns (IbcCoreChannelV1Channel.Data storage) { - IbcCoreChannelV1Channel.Data storage channel = - channels[portId][channelId]; - if (channel.state != IbcCoreChannelV1GlobalEnums.State.STATE_OPEN) { - revert IBCPacketLib.ErrInvalidChannelState(); + function deletePacketCommitment( + uint32 sourceChannel, + IBCPacket calldata packet + ) internal { + bytes32 commitmentKey = IBCCommitment.batchPacketsCommitmentKey( + sourceChannel, IBCPacketLib.commitPacket(packet) + ); + bytes32 commitment = commitments[commitmentKey]; + if (commitment != IBCPacketLib.COMMITMENT_MAGIC) { + revert IBCPacketLib.ErrPacketCommitmentNotFound(); } - return channel; + delete commitments[commitmentKey]; } } diff --git a/evm/contracts/core/04-channel/IIBCChannel.sol b/evm/contracts/core/04-channel/IIBCChannel.sol index 970b3eeee8..3b8af0fae3 100644 --- a/evm/contracts/core/04-channel/IIBCChannel.sol +++ b/evm/contracts/core/04-channel/IIBCChannel.sol @@ -1,43 +1,48 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "../25-handler/IBCMsgs.sol"; -interface IIBCChannelHandshake { +interface IIBCChannel { /** * @dev channelOpenInit is called by a module to initiate a channel opening handshake with a module on another chain. */ - function channelOpenInit(IBCMsgs.MsgChannelOpenInit calldata msg_) - external - returns (string memory); + function channelOpenInit( + IBCMsgs.MsgChannelOpenInit calldata msg_ + ) external returns (uint32); /** * @dev channelOpenTry is called by a module to accept the first step of a channel opening handshake initiated by a module on another chain. */ - function channelOpenTry(IBCMsgs.MsgChannelOpenTry calldata msg_) - external - returns (string memory); + function channelOpenTry( + IBCMsgs.MsgChannelOpenTry calldata msg_ + ) external returns (uint32); /** * @dev channelOpenAck is called by the handshake-originating module to acknowledge the acceptance of the initial request by the counterparty module on the other chain. */ - function channelOpenAck(IBCMsgs.MsgChannelOpenAck calldata msg_) external; + function channelOpenAck( + IBCMsgs.MsgChannelOpenAck calldata msg_ + ) external; /** * @dev channelOpenConfirm is called by the counterparty module to close their end of the channel, since the other end has been closed. */ - function channelOpenConfirm(IBCMsgs.MsgChannelOpenConfirm calldata msg_) - external; + function channelOpenConfirm( + IBCMsgs.MsgChannelOpenConfirm calldata msg_ + ) external; /** * @dev channelCloseInit is called by either module to close their end of the channel. Once closed, channels cannot be reopened. */ - function channelCloseInit(IBCMsgs.MsgChannelCloseInit calldata msg_) - external; + function channelCloseInit( + IBCMsgs.MsgChannelCloseInit calldata msg_ + ) external; /** * @dev channelCloseConfirm is called by the counterparty module to close their end of the * channel, since the other end has been closed. */ - function channelCloseConfirm(IBCMsgs.MsgChannelCloseConfirm calldata msg_) - external; + function channelCloseConfirm( + IBCMsgs.MsgChannelCloseConfirm calldata msg_ + ) external; } diff --git a/evm/contracts/core/04-channel/IIBCPacket.sol b/evm/contracts/core/04-channel/IIBCPacket.sol index c0f336d4a3..c7cd5fd1b8 100644 --- a/evm/contracts/core/04-channel/IIBCPacket.sol +++ b/evm/contracts/core/04-channel/IIBCPacket.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "../25-handler/IBCMsgs.sol"; @@ -9,8 +9,8 @@ interface IIBCPacket { * is returned if one occurs. */ function sendPacket( - string calldata sourceChannel, - IbcCoreClientV1Height.Data calldata timeoutHeight, + uint32 sourceChannel, + uint64 timeoutHeight, uint64 timeoutTimestamp, bytes calldata data ) external returns (uint64); @@ -19,14 +19,25 @@ interface IIBCPacket { * @dev recvPacket is called by a module in order to receive & process an IBC packet * sent on the corresponding channel end on the counterparty chain. */ - function recvPacket(IBCMsgs.MsgPacketRecv calldata msg_) external; + function recvPacket( + IBCMsgs.MsgPacketRecv calldata msg_ + ) external; + + /** + * @dev recvIntentPacket is called by a module in order to receive & process an IBC intent packet + * for an IBC packet sent on the corresponding channel end on the counterparty chain. + * Note that no verification is done by the handler, the protocol must ensure that the market maker fullfilling the intent executes the expected effects. + */ + function recvIntentPacket( + IBCMsgs.MsgIntentPacketRecv calldata msg_ + ) external; /** * @dev writeAcknowledgement writes the packet execution acknowledgement to the state, * which will be verified by the counterparty chain using AcknowledgePacket. */ function writeAcknowledgement( - IbcCoreChannelV1Packet.Data calldata packet, + IBCPacket calldata packet, bytes memory acknowledgement ) external; @@ -38,12 +49,33 @@ interface IIBCPacket { * which is no longer necessary since the packet has been received and acted upon. * It will also increment NextSequenceAck in case of ORDERED channels. */ - function acknowledgePacket(IBCMsgs.MsgPacketAcknowledgement calldata msg_) - external; + function acknowledgePacket( + IBCMsgs.MsgPacketAcknowledgement calldata msg_ + ) external; /** * @dev timeoutPacket is called by a module in order to receive & process an IBC packet * sent on the corresponding channel end on the counterparty chain. */ - function timeoutPacket(IBCMsgs.MsgPacketTimeout calldata msg_) external; + function timeoutPacket( + IBCMsgs.MsgPacketTimeout calldata msg_ + ) external; + + /** + * @dev batchSend is called by a module in order to commit multiple IBC packets that have been previously sent. + * An error occur if any of the packets wasn't sent. + * If successful, a new commitment is registered for the batch. + */ + function batchSend( + IBCMsgs.MsgBatchSend calldata msg_ + ) external; + + /** + * @dev batchAcks is called by a module in order to commit multiple IBC packets acknowledgements. + * An error occur if any of the packets wasn't received. + * If successful, a new commitment is registered for the batch. + */ + function batchAcks( + IBCMsgs.MsgBatchAcks calldata msg_ + ) external; } diff --git a/evm/contracts/core/05-port/IIBCModule.sol b/evm/contracts/core/05-port/IIBCModule.sol index b771206156..7163c50079 100644 --- a/evm/contracts/core/05-port/IIBCModule.sol +++ b/evm/contracts/core/05-port/IIBCModule.sol @@ -1,71 +1,60 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "../../proto/ibc/core/channel/v1/channel.sol"; +import "../Types.sol"; // IIBCModule defines an interface that implements all the callbacks // that modules must define as specified in ICS-26 // https://github.com/cosmos/ibc/blob/2921c5cec7b18e4ef77677e16a6b693051ae3b35/spec/core/ics-026-routing-module/README.md interface IIBCModule { function onChanOpenInit( - IbcCoreChannelV1GlobalEnums.Order, - string[] calldata connectionHops, - string calldata portId, - string calldata channelId, - IbcCoreChannelV1Counterparty.Data calldata counterparty, - string calldata version, + IBCChannelOrder order, + uint32 connectionId, + uint32 channelId, + IBCChannelCounterparty calldata counterparty, + bytes32 version, address relayer ) external; function onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order, - string[] calldata connectionHops, - string calldata portId, - string calldata channelId, - IbcCoreChannelV1Counterparty.Data calldata counterparty, - string calldata version, - string calldata counterpartyVersion, + IBCChannelOrder order, + uint32 connectionId, + uint32 channelId, + IBCChannelCounterparty calldata counterparty, + bytes32 version, + bytes32 counterpartyVersion, address relayer ) external; function onChanOpenAck( - string calldata portId, - string calldata channelId, - string calldata counterpartyChannelId, - string calldata counterpartyVersion, + uint32 channelId, + uint32 counterpartyChannelId, + bytes32 counterpartyVersion, address relayer ) external; - function onChanOpenConfirm( - string calldata portId, - string calldata channelId, - address relayer - ) external; + function onChanOpenConfirm(uint32 channelId, address relayer) external; - function onChanCloseInit( - string calldata portId, - string calldata channelId, - address relayer - ) external; + function onChanCloseInit(uint32 channelId, address relayer) external; - function onChanCloseConfirm( - string calldata portId, - string calldata channelId, - address relayer - ) external; + function onChanCloseConfirm(uint32 channelId, address relayer) external; + + function onRecvIntentPacket( + IBCPacket calldata packet, + address marketMaker, + bytes calldata marketMakerMsg + ) external returns (bytes memory); function onRecvPacket( - IbcCoreChannelV1Packet.Data calldata, - address relayer + IBCPacket calldata packet, + address relayer, + bytes calldata relayerMsg ) external returns (bytes memory); function onAcknowledgementPacket( - IbcCoreChannelV1Packet.Data calldata, + IBCPacket calldata packet, bytes calldata acknowledgement, address relayer ) external; - function onTimeoutPacket( - IbcCoreChannelV1Packet.Data calldata, - address relayer - ) external; + function onTimeoutPacket(IBCPacket calldata, address relayer) external; } diff --git a/evm/contracts/core/05-port/ModuleManager.sol b/evm/contracts/core/05-port/ModuleManager.sol deleted file mode 100644 index a1fb80bb8f..0000000000 --- a/evm/contracts/core/05-port/ModuleManager.sol +++ /dev/null @@ -1,80 +0,0 @@ -pragma solidity ^0.8.23; - -import "./IIBCModule.sol"; -import "../24-host/IBCStore.sol"; -import "../../lib/Hex.sol"; - -library ModuleManagerLib { - error ErrModuleNotFound(); - error ErrCapabilityAlreadyClaimed(); -} - -/** - * @dev ModuleManager is an abstract contract that provides the functions defined in [ICS 5](https://github.com/cosmos/ibc/tree/main/spec/core/ics-005-port-allocation) and [ICS 26](https://github.com/cosmos/ibc/blob/main/spec/core/ics-005-port-module/README.md). - */ -abstract contract ModuleManager is IBCStore { - /** - * @dev lookupModuleByPort will return the IBCModule along with the capability associated with a given portID - */ - function lookupModuleByPort(string memory portId) - internal - view - virtual - returns (IIBCModule) - { - return IIBCModule(Hex.hexToAddress(portId)); - } - - /** - * @dev lookupModuleByChannel will return the IBCModule along with the capability associated with a given channel defined by its portID and channelID - */ - function lookupModuleByChannel( - string memory portId, - string memory channelId - ) internal view virtual returns (IIBCModule) { - address module = lookupModule(channelCapabilityPath(portId, channelId)); - if (module == address(0)) { - revert ModuleManagerLib.ErrModuleNotFound(); - } - return IIBCModule(module); - } - - /** - * @dev channelCapabilityPath returns the path under which module address associated with a port and channel should be stored. - */ - function channelCapabilityPath( - string memory portId, - string memory channelId - ) public pure returns (string memory) { - return string.concat(portId, "/", channelId); - } - - /** - * @dev claimCapability allows the IBC app module to claim a capability that core IBC passes to it - */ - function claimCapability(string memory name, address addr) internal { - if (capabilities[name] != address(0)) { - revert ModuleManagerLib.ErrCapabilityAlreadyClaimed(); - } - capabilities[name] = addr; - } - - /** - * @dev authenticateCapability attempts to authenticate a given name from a caller. - * It allows for a caller to check that a capability does in fact correspond to a particular name. - */ - function authenticateCapability(string memory name) - internal - view - returns (bool) - { - return msg.sender == capabilities[name]; - } - - /** - * @dev lookupModule will return the IBCModule address bound to a given name. - */ - function lookupModule(string memory name) internal view returns (address) { - return capabilities[name]; - } -} diff --git a/evm/contracts/core/24-host/IBCCommitment.sol b/evm/contracts/core/24-host/IBCCommitment.sol index e7f880c980..767067f46b 100644 --- a/evm/contracts/core/24-host/IBCCommitment.sol +++ b/evm/contracts/core/24-host/IBCCommitment.sol @@ -1,202 +1,143 @@ -pragma solidity ^0.8.23; - -import "solady/utils/LibString.sol"; +pragma solidity ^0.8.27; library IBCCommitment { - // Commitment path generators that comply with https://github.com/cosmos/ibc/tree/main/spec/core/ics-024-host-requirements#path-space - - function clientStatePath(string memory clientId) - internal - pure - returns (bytes memory) - { - return abi.encodePacked("clients/", clientId, "/clientState"); + bytes1 public constant CLIENT_STATE = 0x00; + bytes1 public constant CONSENSUS_STATE = 0x01; + bytes1 public constant CONNECTIONS = 0x02; + bytes1 public constant CHANNELS = 0x03; + bytes1 public constant PACKETS = 0x04; + bytes1 public constant PACKET_ACKS = 0x05; + bytes1 public constant NEXT_SEQ_SEND = 0x06; + bytes1 public constant NEXT_SEQ_RECV = 0x07; + bytes1 public constant NEXT_SEQ_ACK = 0x08; + + function clientStatePath( + uint32 clientId + ) internal pure returns (bytes memory) { + return abi.encodePacked(CLIENT_STATE, clientId); } function consensusStatePath( - string memory clientId, - uint64 revisionNumber, - uint64 revisionHeight + uint32 clientId, + uint64 height ) internal pure returns (bytes memory) { - return abi.encodePacked( - "clients/", - clientId, - "/consensusStates/", - LibString.toString(revisionNumber), - "-", - LibString.toString(revisionHeight) - ); + return abi.encodePacked(CONSENSUS_STATE, clientId, height); } - function connectionPath(string memory connectionId) - internal - pure - returns (bytes memory) - { - return abi.encodePacked("connections/", connectionId); + function connectionPath( + uint32 connectionId + ) internal pure returns (bytes memory) { + return abi.encodePacked(CONNECTIONS, connectionId); } function channelPath( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (bytes memory) { - return abi.encodePacked( - "channelEnds/ports/", portId, "/channels/", channelId - ); + return abi.encodePacked(CHANNELS, channelId); } function packetCommitmentPath( - string memory portId, - string memory channelId, + uint32 channelId, uint64 sequence ) internal pure returns (bytes memory) { - return abi.encodePacked( - "commitments/ports/", - portId, - "/channels/", - channelId, - "/sequences/", - LibString.toString(sequence) - ); - } - - function packetAcknowledgementCommitmentPath( - string memory portId, - string memory channelId, - uint64 sequence + return abi.encodePacked(PACKETS, channelId, sequence); + } + + function batchPacketsCommitmentPath( + uint32 channelId, + bytes32 batchHash ) internal pure returns (bytes memory) { - return abi.encodePacked( - "acks/ports/", - portId, - "/channels/", - channelId, - "/sequences/", - LibString.toString(sequence) - ); - } - - function packetReceiptCommitmentPath( - string memory portId, - string memory channelId, - uint64 sequence + return abi.encodePacked(PACKETS, channelId, batchHash); + } + + function batchReceiptsCommitmentPath( + uint32 channelId, + bytes32 batchHash ) internal pure returns (bytes memory) { - return abi.encodePacked( - "receipts/ports/", - portId, - "/channels/", - channelId, - "/sequences/", - LibString.toString(sequence) - ); + return abi.encodePacked(PACKET_ACKS, channelId, batchHash); } function nextSequenceSendCommitmentPath( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (bytes memory) { - return abi.encodePacked( - "nextSequenceSend/ports/", portId, "/channels/", channelId - ); + return abi.encodePacked(NEXT_SEQ_SEND, channelId); } function nextSequenceRecvCommitmentPath( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (bytes memory) { - return abi.encodePacked( - "nextSequenceRecv/ports/", portId, "/channels/", channelId - ); + return abi.encodePacked(NEXT_SEQ_RECV, channelId); } function nextSequenceAckCommitmentPath( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (bytes memory) { - return abi.encodePacked( - "nextSequenceAck/ports/", portId, "/channels/", channelId - ); + return abi.encodePacked(NEXT_SEQ_ACK, channelId); } // Key generators for Commitment mapping - function clientStateCommitmentKey(string memory clientId) - internal - pure - returns (bytes32) - { + function clientStateCommitmentKey( + uint32 clientId + ) internal pure returns (bytes32) { return keccak256(clientStatePath(clientId)); } function consensusStateCommitmentKey( - string memory clientId, - uint64 revisionNumber, - uint64 revisionHeight + uint32 clientId, + uint64 height ) internal pure returns (bytes32) { - return keccak256( - consensusStatePath(clientId, revisionNumber, revisionHeight) - ); + return keccak256(consensusStatePath(clientId, height)); } - function connectionCommitmentKey(string memory connectionId) - internal - pure - returns (bytes32) - { + function connectionCommitmentKey( + uint32 connectionId + ) internal pure returns (bytes32) { return keccak256(connectionPath(connectionId)); } function channelCommitmentKey( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (bytes32) { - return keccak256(channelPath(portId, channelId)); + return keccak256(channelPath(channelId)); } function packetCommitmentKey( - string memory portId, - string memory channelId, + uint32 channelId, uint64 sequence ) internal pure returns (bytes32) { - return keccak256(packetCommitmentPath(portId, channelId, sequence)); + return keccak256(packetCommitmentPath(channelId, sequence)); } - function packetAcknowledgementCommitmentKey( - string memory portId, - string memory channelId, - uint64 sequence + function batchPacketsCommitmentKey( + uint32 channelId, + bytes32 batchHash ) internal pure returns (bytes32) { - return keccak256( - packetAcknowledgementCommitmentPath(portId, channelId, sequence) - ); + return keccak256(batchPacketsCommitmentPath(channelId, batchHash)); } - function packetReceiptCommitmentKey( - string memory portId, - string memory channelId, - uint64 sequence + function batchReceiptsCommitmentKey( + uint32 channelId, + bytes32 batchHash ) internal pure returns (bytes32) { - return - keccak256(packetReceiptCommitmentPath(portId, channelId, sequence)); + return keccak256(batchReceiptsCommitmentPath(channelId, batchHash)); } function nextSequenceSendCommitmentKey( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (bytes32) { - return keccak256(nextSequenceSendCommitmentPath(portId, channelId)); + return keccak256(nextSequenceSendCommitmentPath(channelId)); } function nextSequenceRecvCommitmentKey( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (bytes32) { - return keccak256(nextSequenceRecvCommitmentPath(portId, channelId)); + return keccak256(nextSequenceRecvCommitmentPath(channelId)); } function nextSequenceAckCommitmentKey( - string memory portId, - string memory channelId + uint32 channelId ) internal pure returns (bytes32) { - return keccak256(nextSequenceAckCommitmentPath(portId, channelId)); + return keccak256(nextSequenceAckCommitmentPath(channelId)); } } diff --git a/evm/contracts/core/24-host/IBCHost.sol b/evm/contracts/core/24-host/IBCHost.sol deleted file mode 100644 index 65ae7808ab..0000000000 --- a/evm/contracts/core/24-host/IBCHost.sol +++ /dev/null @@ -1,24 +0,0 @@ -pragma solidity ^0.8.23; - -import "@openzeppelin/utils/Context.sol"; -import "../../proto/ibc/core/client/v1/client.sol"; -import "../02-client/ILightClient.sol"; -import "../24-host/IBCStore.sol"; -import "../05-port/ModuleManager.sol"; - -function passthrough(address impl) { - assembly { - // copy function selector and any arguments - calldatacopy(0, 0, calldatasize()) - // execute function call using the facet - let result := delegatecall(gas(), impl, 0, calldatasize(), 0, 0) - // get any return value - returndatacopy(0, 0, returndatasize()) - // return any return value or error back to the caller - switch result - case 0 { revert(0, returndatasize()) } - default { return(0, returndatasize()) } - } -} - -abstract contract IBCHost is ModuleManager {} diff --git a/evm/contracts/core/24-host/IBCStore.sol b/evm/contracts/core/24-host/IBCStore.sol index 1a53bfd10e..258fd6dc85 100644 --- a/evm/contracts/core/24-host/IBCStore.sol +++ b/evm/contracts/core/24-host/IBCStore.sol @@ -1,28 +1,37 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "../../proto/ibc/core/connection/v1/connection.sol"; -import "../../proto/ibc/core/channel/v1/channel.sol"; import "../02-client/ILightClient.sol"; +import "../05-port/IIBCModule.sol"; +import "../Types.sol"; library IBCStoreLib { - string public constant COMMITMENT_PREFIX = "ibc"; + bytes32 public constant COMMITMENT_PREFIX = keccak256("ethibc"); error ErrClientNotFound(); + error ErrModuleNotFound(); + error ErrInvalidConnectionState(); + error ErrInvalidChannelState(); } abstract contract IBCStore { + bytes32 public constant COMMITMENT_PREFIX = IBCStoreLib.COMMITMENT_PREFIX; + // Commitments // keccak256(IBC-compatible-store-path) => keccak256(IBC-compatible-commitment) mapping(bytes32 => bytes32) public commitments; - // Store - mapping(string => address) public clientRegistry; - mapping(string => string) public clientTypes; - mapping(string => address) public clientImpls; - mapping(string => IbcCoreConnectionV1ConnectionEnd.Data) public connections; - mapping(string => mapping(string => IbcCoreChannelV1Channel.Data)) public - channels; - mapping(string => address) public capabilities; + // ClientType -> Address + mapping(bytes32 => address) public clientRegistry; + // ClientId -> ClientType + mapping(uint32 => bytes32) public clientTypes; + // ClientId -> Address + mapping(uint32 => address) public clientImpls; + // ConnectionId -> Connection + mapping(uint32 => IBCConnection) public connections; + // ChannelId -> Channel + mapping(uint32 => IBCChannel) public channels; + // ChannelId -> PortId + mapping(uint32 => address) public channelOwner; // Sequences for identifier bytes32 public constant nextClientSequencePath = @@ -32,18 +41,59 @@ abstract contract IBCStore { bytes32 public constant nextChannelSequencePath = keccak256("nextChannelSequence"); - string public constant COMMITMENT_PREFIX = IBCStoreLib.COMMITMENT_PREFIX; + function getClient( + uint32 clientId + ) public view returns (ILightClient) { + return getClientInternal(clientId); + } - // Storage accessors - function getClient(string memory clientId) - public - view - returns (ILightClient) - { + function getClientInternal( + uint32 clientId + ) internal view returns (ILightClient) { address clientImpl = clientImpls[clientId]; if (clientImpl == address(0)) { revert IBCStoreLib.ErrClientNotFound(); } return ILightClient(clientImpl); } + + function lookupModuleByChannel( + uint32 channelId + ) internal view virtual returns (IIBCModule) { + address module = channelOwner[channelId]; + if (module == address(0)) { + revert IBCStoreLib.ErrModuleNotFound(); + } + return IIBCModule(module); + } + + function claimChannel(address portId, uint32 channelId) internal { + channelOwner[channelId] = portId; + } + + function authenticateChannelOwner( + uint32 channelId + ) internal view returns (bool) { + return msg.sender == channelOwner[channelId]; + } + + function ensureConnectionState( + uint32 connectionId + ) internal view returns (uint32) { + IBCConnection storage connection = connections[connectionId]; + if (connection.state != IBCConnectionState.Open) { + revert IBCStoreLib.ErrInvalidConnectionState(); + } + return connection.clientId; + } + + function ensureChannelState( + uint32 channelId + ) internal view returns (IBCChannel storage) { + IBCChannel storage channel = channels[channelId]; + if (channel.state != IBCChannelState.Open) { + revert IBCStoreLib.ErrInvalidChannelState(); + } + return channel; + } } diff --git a/evm/contracts/core/25-handler/IBCChannelHandler.sol b/evm/contracts/core/25-handler/IBCChannelHandler.sol deleted file mode 100644 index 64ddb6d079..0000000000 --- a/evm/contracts/core/25-handler/IBCChannelHandler.sol +++ /dev/null @@ -1,58 +0,0 @@ -pragma solidity ^0.8.23; - -import "../25-handler/IBCMsgs.sol"; -import "../24-host/IBCHost.sol"; -import "../04-channel/IIBCChannel.sol"; -import "../05-port/IIBCModule.sol"; -import "../05-port/ModuleManager.sol"; - -/** - * @dev IBCChannelHandler is a contract that calls a contract that implements `IIBCChannelHandshake` with delegatecall. - */ -abstract contract IBCChannelHandler is IIBCChannelHandshake { - address ibcChannel; - - function channelOpenInit(IBCMsgs.MsgChannelOpenInit calldata) - external - override - returns (string memory) - { - passthrough(ibcChannel); - } - - function channelOpenTry(IBCMsgs.MsgChannelOpenTry calldata) - external - override - returns (string memory) - { - passthrough(ibcChannel); - } - - function channelOpenAck(IBCMsgs.MsgChannelOpenAck calldata) - external - override - { - passthrough(ibcChannel); - } - - function channelOpenConfirm(IBCMsgs.MsgChannelOpenConfirm calldata) - external - override - { - passthrough(ibcChannel); - } - - function channelCloseInit(IBCMsgs.MsgChannelCloseInit calldata) - external - override - { - passthrough(ibcChannel); - } - - function channelCloseConfirm(IBCMsgs.MsgChannelCloseConfirm calldata) - external - override - { - passthrough(ibcChannel); - } -} diff --git a/evm/contracts/core/25-handler/IBCClientHandler.sol b/evm/contracts/core/25-handler/IBCClientHandler.sol deleted file mode 100644 index b8fead9be0..0000000000 --- a/evm/contracts/core/25-handler/IBCClientHandler.sol +++ /dev/null @@ -1,36 +0,0 @@ -pragma solidity ^0.8.23; - -import "../24-host/IBCHost.sol"; -import "../02-client/IIBCClient.sol"; - -/** - * @dev IBCClientHandler is a contract that calls a contract that implements `IIBCClient` with delegatecall. - */ -abstract contract IBCClientHandler is IIBCClient { - address ibcClient; - - /** - * @dev registerClient registers a new client type into the client registry - */ - function registerClient(string calldata, ILightClient) public virtual { - passthrough(ibcClient); - } - - /** - * @dev createClient creates a new client state and populates it with a given consensus state - */ - function createClient(IBCMsgs.MsgCreateClient calldata) - external - override - returns (string memory) - { - passthrough(ibcClient); - } - - /** - * @dev updateClient updates the consensus state and the state root from a provided header - */ - function updateClient(IBCMsgs.MsgUpdateClient calldata) external override { - passthrough(ibcClient); - } -} diff --git a/evm/contracts/core/25-handler/IBCConnectionHandler.sol b/evm/contracts/core/25-handler/IBCConnectionHandler.sol deleted file mode 100644 index a584f444f7..0000000000 --- a/evm/contracts/core/25-handler/IBCConnectionHandler.sol +++ /dev/null @@ -1,42 +0,0 @@ -pragma solidity ^0.8.23; - -import "../25-handler/IBCMsgs.sol"; -import "../24-host/IBCHost.sol"; -import "../03-connection/IIBCConnection.sol"; - -/** - * @dev IBCConnectionHandler is a contract that calls a contract that implements `IIBCConnectionHandshake` with delegatecall. - */ -abstract contract IBCConnectionHandler is IIBCConnectionHandshake { - address ibcConnection; - - function connectionOpenInit(IBCMsgs.MsgConnectionOpenInit calldata) - external - override - returns (string memory) - { - passthrough(ibcConnection); - } - - function connectionOpenTry(IBCMsgs.MsgConnectionOpenTry calldata) - external - override - returns (string memory) - { - passthrough(ibcConnection); - } - - function connectionOpenAck(IBCMsgs.MsgConnectionOpenAck calldata) - external - override - { - passthrough(ibcConnection); - } - - function connectionOpenConfirm(IBCMsgs.MsgConnectionOpenConfirm calldata) - external - override - { - passthrough(ibcConnection); - } -} diff --git a/evm/contracts/core/25-handler/IBCHandler.sol b/evm/contracts/core/25-handler/IBCHandler.sol index 86fb5bf05e..a6841466a5 100644 --- a/evm/contracts/core/25-handler/IBCHandler.sol +++ b/evm/contracts/core/25-handler/IBCHandler.sol @@ -1,16 +1,14 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "../24-host/IBCHost.sol"; -import "./IBCClientHandler.sol"; -import "./IBCConnectionHandler.sol"; -import "./IBCChannelHandler.sol"; -import "./IBCPacketHandler.sol"; -import "./IBCQuerier.sol"; +import "../24-host/IBCStore.sol"; +import "../02-client/IBCClient.sol"; +import "../03-connection/IBCConnection.sol"; +import "../04-channel/IBCChannel.sol"; +import "../04-channel/IBCPacket.sol"; import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol"; -import "@openzeppelin-upgradeable/utils/PausableUpgradeable.sol"; import "@openzeppelin-upgradeable/utils/ContextUpgradeable.sol"; import "@openzeppelin/utils/Context.sol"; @@ -21,55 +19,24 @@ abstract contract IBCHandler is Initializable, UUPSUpgradeable, OwnableUpgradeable, - PausableUpgradeable, - IBCHost, - IBCClientHandler, - IBCConnectionHandler, - IBCChannelHandler, - IBCPacketHandler, - IBCQuerier + IBCStore, + IBCClient, + IBCConnectionImpl, + IBCChannelImpl, + IBCPacketImpl { constructor() { _disableInitializers(); } - /** - * @dev The arguments of constructor must satisfy the followings: - * @param _ibcClient is the address of a contract that implements `IIBCClient`. - * @param _ibcConnection is the address of a contract that implements `IIBCConnectionHandshake`. - * @param _ibcChannel is the address of a contract that implements `IIBCChannelHandshake`. - * @param _ibcPacket is the address of a contract that implements `IIBCPacket`. - */ function initialize( - address _ibcClient, - address _ibcConnection, - address _ibcChannel, - address _ibcPacket, address admin ) public virtual initializer { __Ownable_init(admin); __UUPSUpgradeable_init(); - ibcClient = _ibcClient; - ibcConnection = _ibcConnection; - ibcChannel = _ibcChannel; - ibcPacket = _ibcPacket; } - function _authorizeUpgrade(address newImplementation) - internal - override - onlyOwner - {} - - function upgradeImpls( - address _ibcClient, - address _ibcConnection, - address _ibcChannel, - address _ibcPacket - ) public onlyOwner { - ibcClient = _ibcClient; - ibcConnection = _ibcConnection; - ibcChannel = _ibcChannel; - ibcPacket = _ibcPacket; - } + function _authorizeUpgrade( + address newImplementation + ) internal override onlyOwner {} } diff --git a/evm/contracts/core/25-handler/IBCMsgs.sol b/evm/contracts/core/25-handler/IBCMsgs.sol index a4122b39b9..acf8186424 100644 --- a/evm/contracts/core/25-handler/IBCMsgs.sol +++ b/evm/contracts/core/25-handler/IBCMsgs.sol @@ -1,143 +1,139 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "../../proto/ibc/core/client/v1/client.sol"; -import "../../proto/ibc/core/connection/v1/connection.sol"; -import "../../proto/ibc/core/channel/v1/channel.sol"; +import "../Types.sol"; /** * @dev IBCMsgs provides datagram types in [ICS-26](https://github.com/cosmos/ibc/tree/main/spec/core/ics-026-routing-module#datagram-handlers-write) */ library IBCMsgs { - /* Client */ - struct MsgCreateClient { - string clientType; + bytes32 clientType; bytes clientStateBytes; bytes consensusStateBytes; address relayer; } struct MsgUpdateClient { - string clientId; + uint32 clientId; bytes clientMessage; address relayer; } - /* Connection */ - struct MsgConnectionOpenInit { - string clientId; - IbcCoreConnectionV1Version.Data version; - IbcCoreConnectionV1Counterparty.Data counterparty; - uint64 delayPeriod; + uint32 clientId; + IBCConnectionCounterparty counterparty; address relayer; } struct MsgConnectionOpenTry { - IbcCoreConnectionV1Counterparty.Data counterparty; // counterpartyConnectionIdentifier, counterpartyPrefix and counterpartyClientIdentifier - uint64 delayPeriod; - string clientId; // clientID of chainA - bytes clientStateBytes; // clientState that chainA has for chainB - IbcCoreConnectionV1Version.Data[] counterpartyVersions; // supported versions of chain A - bytes proofInit; // proof that chainA stored connectionEnd in state (on ConnOpenInit) - bytes proofClient; // proof that chainA stored a light client of chainB - bytes proofConsensus; // proof that chainA stored chainB's consensus state at consensus height - IbcCoreClientV1Height.Data proofHeight; // height at which relayer constructs proof of A storing connectionEnd in state - IbcCoreClientV1Height.Data consensusHeight; // latest height of chain B which chain A has stored in its chain B client + IBCConnectionCounterparty counterparty; + uint32 clientId; + bytes proofInit; + uint64 proofHeight; address relayer; } struct MsgConnectionOpenAck { - string connectionId; - bytes clientStateBytes; // client state for chainA on chainB - IbcCoreConnectionV1Version.Data version; // version that ChainB chose in ConnOpenTry - string counterpartyConnectionID; - bytes proofTry; // proof that connectionEnd was added to ChainB state in ConnOpenTry - bytes proofClient; // proof of client state on chainB for chainA - bytes proofConsensus; // proof that chainB has stored ConsensusState of chainA on its client - IbcCoreClientV1Height.Data proofHeight; // height that relayer constructed proofTry - IbcCoreClientV1Height.Data consensusHeight; // latest height of chainA that chainB has stored on its chainA client + uint32 connectionId; + uint32 counterpartyConnectionId; + bytes proofTry; + uint64 proofHeight; address relayer; } struct MsgConnectionOpenConfirm { - string connectionId; + uint32 connectionId; bytes proofAck; - IbcCoreClientV1Height.Data proofHeight; + uint64 proofHeight; address relayer; } - /* Channel */ - struct MsgChannelOpenInit { - string portId; - IbcCoreChannelV1Channel.Data channel; + address portId; + IBCChannel channel; address relayer; } struct MsgChannelOpenTry { - string portId; - IbcCoreChannelV1Channel.Data channel; - string counterpartyVersion; + address portId; + IBCChannel channel; + bytes32 counterpartyVersion; bytes proofInit; - IbcCoreClientV1Height.Data proofHeight; + uint64 proofHeight; address relayer; } struct MsgChannelOpenAck { - string portId; - string channelId; - string counterpartyVersion; - string counterpartyChannelId; + address portId; + uint32 channelId; + bytes32 counterpartyVersion; + uint32 counterpartyChannelId; bytes proofTry; - IbcCoreClientV1Height.Data proofHeight; + uint64 proofHeight; address relayer; } struct MsgChannelOpenConfirm { - string portId; - string channelId; + address portId; + uint32 channelId; bytes proofAck; - IbcCoreClientV1Height.Data proofHeight; + uint64 proofHeight; address relayer; } struct MsgChannelCloseInit { - string portId; - string channelId; + address portId; + uint32 channelId; address relayer; } struct MsgChannelCloseConfirm { - string portId; - string channelId; + address portId; + uint32 channelId; bytes proofInit; - IbcCoreClientV1Height.Data proofHeight; + uint64 proofHeight; address relayer; } - /* Packet relay */ - struct MsgPacketRecv { - IbcCoreChannelV1Packet.Data packet; - bytes proof; - IbcCoreClientV1Height.Data proofHeight; + IBCPacket[] packets; + bytes[] relayerMsgs; address relayer; + bytes proof; + uint64 proofHeight; } struct MsgPacketAcknowledgement { - IbcCoreChannelV1Packet.Data packet; - bytes acknowledgement; + IBCPacket[] packets; + bytes[] acknowledgements; bytes proof; - IbcCoreClientV1Height.Data proofHeight; + uint64 proofHeight; address relayer; } struct MsgPacketTimeout { - IbcCoreChannelV1Packet.Data packet; + IBCPacket packet; bytes proof; - IbcCoreClientV1Height.Data proofHeight; + uint64 proofHeight; uint64 nextSequenceRecv; address relayer; } + + struct MsgIntentPacketRecv { + IBCPacket[] packets; + bytes[] marketMakerMsgs; + address marketMaker; + bytes emptyProof; + } + + struct MsgBatchSend { + uint32 sourceChannel; + IBCPacket[] packets; + } + + struct MsgBatchAcks { + uint32 sourceChannel; + IBCPacket[] packets; + bytes[] acks; + } } diff --git a/evm/contracts/core/25-handler/IBCPacketHandler.sol b/evm/contracts/core/25-handler/IBCPacketHandler.sol deleted file mode 100644 index a3c568cbfc..0000000000 --- a/evm/contracts/core/25-handler/IBCPacketHandler.sol +++ /dev/null @@ -1,48 +0,0 @@ -pragma solidity ^0.8.23; - -import "../25-handler/IBCMsgs.sol"; -import "../24-host/IBCHost.sol"; -import "../04-channel/IIBCPacket.sol"; -import "../05-port/ModuleManager.sol"; - -/** - * @dev IBCPacketHandler is a contract that calls a contract that implements `IIBCPacket` with delegatecall. - */ -abstract contract IBCPacketHandler is IIBCPacket, ModuleManager { - // IBC Packet contract address - address ibcPacket; - - function sendPacket( - string calldata, - IbcCoreClientV1Height.Data calldata, - uint64, - bytes calldata - ) external virtual override returns (uint64) { - passthrough(ibcPacket); - } - - function recvPacket(IBCMsgs.MsgPacketRecv calldata) external override { - passthrough(ibcPacket); - } - - function writeAcknowledgement( - IbcCoreChannelV1Packet.Data calldata, - bytes memory - ) external override { - passthrough(ibcPacket); - } - - function acknowledgePacket(IBCMsgs.MsgPacketAcknowledgement calldata) - external - override - { - passthrough(ibcPacket); - } - - function timeoutPacket(IBCMsgs.MsgPacketTimeout calldata) - external - override - { - passthrough(ibcPacket); - } -} diff --git a/evm/contracts/core/25-handler/IBCQuerier.sol b/evm/contracts/core/25-handler/IBCQuerier.sol deleted file mode 100644 index 3c86e13246..0000000000 --- a/evm/contracts/core/25-handler/IBCQuerier.sol +++ /dev/null @@ -1,24 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../proto/ibc/core/client/v1/client.sol"; -import "../02-client/ILightClient.sol"; -import "../24-host/IBCStore.sol"; -import "../05-port/ModuleManager.sol"; -import "../24-host/IBCCommitment.sol"; - -abstract contract IBCQuerier is IBCStore { - function getConnection(string calldata connectionId) - external - view - returns (IbcCoreConnectionV1ConnectionEnd.Data memory) - { - return connections[connectionId]; - } - - function getChannel( - string calldata portId, - string calldata channelId - ) external view returns (IbcCoreChannelV1Channel.Data memory) { - return channels[portId][channelId]; - } -} diff --git a/evm/contracts/core/IZKVerifierV2.sol b/evm/contracts/core/IZKVerifierV2.sol deleted file mode 100644 index f0594d6557..0000000000 --- a/evm/contracts/core/IZKVerifierV2.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma solidity ^0.8.18; - -interface IZKVerifierV2 { - function verifyProof( - uint256[8] calldata proof, - uint256[2] calldata proofCommitment, - uint256[2] calldata proofCommitmentPOK, - uint256[2] calldata input - ) external returns (bool); -} diff --git a/evm/contracts/core/OwnableIBCHandler.sol b/evm/contracts/core/OwnableIBCHandler.sol index 51e2e00f14..c3266bca20 100644 --- a/evm/contracts/core/OwnableIBCHandler.sol +++ b/evm/contracts/core/OwnableIBCHandler.sol @@ -1,37 +1,18 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import "solady/utils/LibString.sol"; import "./25-handler/IBCHandler.sol"; /** * @dev OwnableIBCHandler is a contract that implements [ICS-25](https://github.com/cosmos/ibc/tree/main/spec/core/ics-025-handler-interface). */ contract OwnableIBCHandler is IBCHandler { - using LibString for *; - constructor() { _disableInitializers(); } function initialize( - address ibcClient, - address ibcConnection, - address ibcChannel, - address ibcPacket, address admin ) public override initializer { - IBCHandler.initialize( - ibcClient, ibcConnection, ibcChannel, ibcPacket, admin - ); - } - - /** - * @dev registerClient registers a new client type into the client registry - */ - function registerClient( - string calldata clientType, - ILightClient client - ) public override onlyOwner { - super.registerClient(clientType, client); + IBCHandler.initialize(admin); } } diff --git a/evm/contracts/core/Types.sol b/evm/contracts/core/Types.sol new file mode 100644 index 0000000000..7fa3cc5353 --- /dev/null +++ b/evm/contracts/core/Types.sol @@ -0,0 +1,54 @@ +pragma solidity ^0.8.27; + +enum IBCConnectionState { + Unspecified, + Init, + TryOpen, + Open +} + +struct IBCConnectionCounterparty { + uint32 clientId; + uint32 connectionId; +} + +struct IBCConnection { + IBCConnectionState state; + IBCConnectionCounterparty counterparty; + uint32 clientId; +} + +enum IBCChannelState { + Unspecified, + Init, + TryOpen, + Open, + Closed +} + +enum IBCChannelOrder { + Unspecified, + Unordered, + Ordered +} + +struct IBCChannelCounterparty { + uint32 channelId; +} + +struct IBCChannel { + IBCChannelState state; + IBCChannelOrder ordering; + uint32 connectionId; + IBCChannelCounterparty counterparty; + bytes32 version; +} + +struct IBCPacket { + uint64 sequence; + uint32 sourceChannel; + uint32 destinationChannel; + bytes data; + uint64 timeoutHeight; + uint64 timeoutTimestamp; +} diff --git a/evm/contracts/lib/Common.sol b/evm/contracts/lib/Common.sol index a432627cd8..4144add9d9 100644 --- a/evm/contracts/lib/Common.sol +++ b/evm/contracts/lib/Common.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; struct ProcessedMoment { uint256 timestamp; diff --git a/evm/contracts/lib/Hex.sol b/evm/contracts/lib/Hex.sol index 683c4f5ed5..b677d72a15 100644 --- a/evm/contracts/lib/Hex.sol +++ b/evm/contracts/lib/Hex.sol @@ -1,10 +1,12 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; library Hex { error ErrInvalidHexAddress(); // Convert 32 hexadecimal digits into 16 bytes. - function hexToBytes16(bytes32 h) internal pure returns (bytes16 b) { + function hexToBytes16( + bytes32 h + ) internal pure returns (bytes16 b) { unchecked { // Ensure all chars below 128 if ( @@ -198,7 +200,9 @@ library Hex { } } - function hexToAddress(string memory s) internal pure returns (address) { + function hexToAddress( + string memory s + ) internal pure returns (address) { if (bytes(s).length != 42) { revert ErrInvalidHexAddress(); } @@ -218,7 +222,9 @@ library Hex { return address(bytes20(left) | (bytes20(right) >> 32)); } - function atoi(bytes1 b) internal pure returns (uint8 res) { + function atoi( + bytes1 b + ) internal pure returns (uint8 res) { if (b >= "0" && b <= "9") { return uint8(b) - uint8(bytes1("0")); } else if (b >= "A" && b <= "F") { @@ -229,7 +235,9 @@ library Hex { return uint8(b); } - function hexToUint256(string memory s) internal pure returns (uint256) { + function hexToUint256( + string memory s + ) internal pure returns (uint256) { bytes memory b = bytes(s); uint256 number; for (uint256 i = 2; i < b.length; i++) { diff --git a/evm/contracts/lib/ICS23.sol b/evm/contracts/lib/ICS23.sol index 9bdf271bcd..d1cee04194 100644 --- a/evm/contracts/lib/ICS23.sol +++ b/evm/contracts/lib/ICS23.sol @@ -1,9 +1,6 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; -import {ProtoBufRuntime} from "../proto/ProtoBufRuntime.sol"; import {Math} from "@openzeppelin/utils/math/Math.sol"; -import "../proto/ibc/core/commitment/v1/commitment.sol"; -import "../proto/cosmos/ics23/v1/proofs.sol"; import "./UnionICS23.sol"; library Ics23 { @@ -32,7 +29,7 @@ library Ics23 { UnionIcs23.NonExistenceProof calldata nonExistProof, UnionIcs23.ExistenceProof calldata existProof, bytes32 root, - bytes calldata prefix, + bytes memory prefix, bytes calldata key ) internal pure returns (VerifyChainedNonMembershipError) { (bytes32 subroot, Proof.CalculateRootError rCode) = @@ -130,7 +127,7 @@ library Ics23 { function verifyChainedMembership( UnionIcs23.ExistenceProof[2] calldata proofs, bytes32 root, - bytes calldata prefix, + bytes memory prefix, bytes calldata key, bytes calldata value ) internal pure returns (VerifyChainedMembershipError) { @@ -165,11 +162,9 @@ library Ics23 { return VerifyChainedMembershipError.None; } - function convertExistenceError(Proof.VerifyExistenceError vCode) - internal - pure - returns (VerifyChainedMembershipError) - { + function convertExistenceError( + Proof.VerifyExistenceError vCode + ) internal pure returns (VerifyChainedMembershipError) { if (vCode == Proof.VerifyExistenceError.KeyNotMatching) { return VerifyChainedMembershipError.KeyMismatch; } else if (vCode == Proof.VerifyExistenceError.ValueNotMatching) { @@ -211,6 +206,45 @@ library Ops { ValueLength } + function _sz_varint( + uint256 i + ) internal pure returns (uint256) { + uint256 count = 1; + assembly { + i := shr(7, i) + for {} gt(i, 0) {} { + i := shr(7, i) + count := add(count, 1) + } + } + return count; + } + + function _encode_varint( + uint256 x, + uint256 p, + bytes memory bs + ) internal pure returns (uint256) { + /** + * Refer to https://developers.google.com/protocol-buffers/docs/encoding + */ + uint256 sz = 0; + assembly { + let bsptr := add(bs, p) + let byt := and(x, 0x7f) + for {} gt(shr(7, x), 0) {} { + mstore8(bsptr, or(0x80, byt)) + bsptr := add(bsptr, 1) + sz := add(sz, 1) + x := shr(7, x) + byt := and(x, 0x7f) + } + mstore8(bsptr, byt) + sz := add(sz, 1) + } + return sz; + } + // LeafOp operations function applyLeafOp( bytes calldata prefix, @@ -223,14 +257,13 @@ library Ops { if (value.length == 0) return ("", ApplyLeafOpError.ValueLength); // tm/iavl specs set hashOp for prehash_key to NOOP and lengthOp to VAR_PROTO - bytes memory encodedKey = - new bytes(ProtoBufRuntime._sz_varint(key.length)); - ProtoBufRuntime._encode_varint(key.length, 32, encodedKey); + bytes memory encodedKey = new bytes(_sz_varint(key.length)); + _encode_varint(key.length, 32, encodedKey); // tm/iavl specs set hashOp for prehash_value to SHA256 and lengthOp to VAR_PROTO bytes32 hashedValue = sha256(value); - bytes memory encodedValue = new bytes(ProtoBufRuntime._sz_varint(32)); - ProtoBufRuntime._encode_varint(32, 32, encodedValue); + bytes memory encodedValue = new bytes(_sz_varint(32)); + _encode_varint(32, 32, encodedValue); bytes32 data = sha256( abi.encodePacked(prefix, encodedKey, key, encodedValue, hashedValue) @@ -304,7 +337,7 @@ library Proof { function verifyNoRootCheck( UnionIcs23.ExistenceProof calldata proof, UnionIcs23.ProofSpec memory spec, - bytes calldata key, + bytes memory key, bytes memory value ) internal pure returns (VerifyExistenceError) { //require(BytesLib.equal(proof.key, key)); // dev: Provided key doesn't match proof @@ -328,7 +361,7 @@ library Proof { UnionIcs23.ExistenceProof calldata proof, UnionIcs23.ProofSpec memory spec, bytes32 commitmentRoot, - bytes calldata key, + bytes memory key, bytes memory value ) internal pure returns (VerifyExistenceError) { //require(BytesLib.equal(proof.key, key)); // dev: Provided key doesn't match proof @@ -363,11 +396,9 @@ library Proof { EmptyProof } - function calculateRoot(UnionIcs23.ExistenceProof calldata proof) - internal - pure - returns (bytes32, CalculateRootError) - { + function calculateRoot( + UnionIcs23.ExistenceProof calldata proof + ) internal pure returns (bytes32, CalculateRootError) { //require(LeafOp.isNil(proof.leaf) == false); // dev: Existence Proof needs defined LeafOp if (proof.leafPrefix.length == 0) { return ("", CalculateRootError.LeafNil); @@ -513,11 +544,9 @@ library Proof { return VerifyNonExistenceError.None; } - function calculateRoot(UnionIcs23.NonExistenceProof calldata proof) - internal - pure - returns (bytes32, CalculateRootError) - { + function calculateRoot( + UnionIcs23.NonExistenceProof calldata proof + ) internal pure returns (bytes32, CalculateRootError) { if (!UnionIcs23.empty(proof.left)) { return calculateRoot(proof.left); } diff --git a/evm/contracts/lib/UnionICS23.sol b/evm/contracts/lib/UnionICS23.sol index eee4082e49..f106955c68 100644 --- a/evm/contracts/lib/UnionICS23.sol +++ b/evm/contracts/lib/UnionICS23.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; library UnionIcs23 { struct ExistenceProof { @@ -85,11 +85,9 @@ library UnionIcs23 { ProofSpec({childSize: 32, minPrefixLength: 1, maxPrefixLength: 1}); } - function empty(NonExistenceProof calldata proof) - internal - pure - returns (bool) - { + function empty( + NonExistenceProof calldata proof + ) internal pure returns (bool) { if (proof.key.length != 0) { return false; } @@ -97,11 +95,9 @@ library UnionIcs23 { return empty(proof.left) && empty(proof.right); } - function empty(ExistenceProof calldata proof) - internal - pure - returns (bool) - { + function empty( + ExistenceProof calldata proof + ) internal pure returns (bool) { if (proof.key.length != 0) { return false; } diff --git a/evm/contracts/proto/GoogleProtobufAny.sol b/evm/contracts/proto/GoogleProtobufAny.sol deleted file mode 100644 index cfd79e7919..0000000000 --- a/evm/contracts/proto/GoogleProtobufAny.sol +++ /dev/null @@ -1,269 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "./ProtoBufRuntime.sol"; - -library GoogleProtobufAny { - //struct definition - struct Data { - string type_url; - 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[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_type_url(pointer, bs, r, counters); - } else if (fieldId == 2) { - pointer += _read_value(pointer, bs, r, counters); - } else { - if (wireType == ProtoBufRuntime.WireType.Fixed64) { - uint256 size; - (, size) = ProtoBufRuntime._decode_fixed64(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.Fixed32) { - uint256 size; - (, size) = ProtoBufRuntime._decode_fixed32(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.Varint) { - uint256 size; - (, size) = ProtoBufRuntime._decode_varint(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - uint256 size; - (, size) = ProtoBufRuntime._decode_lendelim(pointer, bs); - pointer += size; - } - } - } - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_type_url( - 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. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.type_url = x; - if (counters[1] > 0) counters[1] -= 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_value( - 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. - */ - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.value = x; - if (counters[2] > 0) counters[2] -= 1; - } - 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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.type_url, pointer, bs); - pointer += ProtoBufRuntime._encode_key( - 2, 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(bytes(r.type_url).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.value.length); - return e; - } - - //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.type_url = input.type_url; - 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 Any diff --git a/evm/contracts/proto/MockClient.sol b/evm/contracts/proto/MockClient.sol deleted file mode 100644 index 196de1f3cd..0000000000 --- a/evm/contracts/proto/MockClient.sol +++ /dev/null @@ -1,717 +0,0 @@ -pragma solidity ^0.8.23; - -import "./ProtoBufRuntime.sol"; -import "./GoogleProtobufAny.sol"; -import "./ibc/core/connection/v1/connection.sol"; -import "./ibc/core/client/v1/client.sol"; - -library IbcLightclientsMockV1ClientState { - //struct definition - struct Data { - IbcCoreClientV1Height.Data latest_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_latest_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_latest_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_Height(p, bs); - r.latest_height = 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_Height( - 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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.latest_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_lendelim( - IbcCoreClientV1Height._estimate(r.latest_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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.latest_height, output.latest_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 IbcLightclientsMockV1ClientState - -library IbcLightclientsMockV1ConsensusState { - //struct definition - struct Data { - uint64 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 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_timestamp(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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.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.timestamp = input.timestamp; - } - - //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 IbcLightclientsMockV1ConsensusState - -library IbcLightclientsMockV1Header { - //struct definition - struct Data { - IbcCoreClientV1Height.Data height; - uint64 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 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_timestamp(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_Height(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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.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_Height( - 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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.height, pointer, bs); - - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.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 { - IbcCoreClientV1Height.store(input.height, output.height); - output.timestamp = input.timestamp; - } - - //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 IbcLightclientsMockV1Header diff --git a/evm/contracts/proto/ProtoBufRuntime.sol b/evm/contracts/proto/ProtoBufRuntime.sol deleted file mode 100644 index 7bfacbc698..0000000000 --- a/evm/contracts/proto/ProtoBufRuntime.sol +++ /dev/null @@ -1,3544 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -library GoogleProtobufDuration { - //struct definition - struct Data { - int64 Seconds; - int32 nanos; - } - - // 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_Seconds(pointer, bs, r, counters); - } else if (fieldId == 2) { - pointer += _read_nanos(pointer, bs, r, counters); - } else { - if (wireType == ProtoBufRuntime.WireType.Fixed64) { - uint256 size; - (, size) = ProtoBufRuntime._decode_fixed64(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.Fixed32) { - uint256 size; - (, size) = ProtoBufRuntime._decode_fixed32(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.Varint) { - uint256 size; - (, size) = ProtoBufRuntime._decode_varint(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - uint256 size; - (, size) = ProtoBufRuntime._decode_lendelim(pointer, bs); - pointer += size; - } - } - } - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_Seconds( - 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. - */ - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.Seconds = x; - if (counters[1] > 0) counters[1] -= 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_nanos( - 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. - */ - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.nanos = x; - if (counters[2] > 0) counters[2] -= 1; - } - 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.Seconds != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.Seconds, pointer, bs); - } - if (r.nanos != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int32(r.nanos, 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_int64(r.Seconds); - e += 1 + ProtoBufRuntime._sz_int32(r.nanos); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.Seconds != 0) { - return false; - } - - if (r.nanos != 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.Seconds = input.Seconds; - output.nanos = input.nanos; - } - - //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 Duration - -library GoogleProtobufTimestamp { - //struct definition - struct Data { - int64 secs; - int64 nanos; - } - - // 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_secs(pointer, bs, r, counters); - } else if (fieldId == 2) { - pointer += _read_nanos(pointer, bs, r, counters); - } else { - if (wireType == ProtoBufRuntime.WireType.Fixed64) { - uint256 size; - (, size) = ProtoBufRuntime._decode_fixed64(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.Fixed32) { - uint256 size; - (, size) = ProtoBufRuntime._decode_fixed32(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.Varint) { - uint256 size; - (, size) = ProtoBufRuntime._decode_varint(pointer, bs); - pointer += size; - } - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - uint256 size; - (, size) = ProtoBufRuntime._decode_lendelim(pointer, bs); - pointer += size; - } - } - } - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_secs( - 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. - */ - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.secs = x; - if (counters[1] > 0) counters[1] -= 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_nanos( - 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. - */ - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.nanos = x; - if (counters[2] > 0) counters[2] -= 1; - } - 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.secs != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.secs, pointer, bs); - } - if (r.nanos != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.nanos, 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_int64(r.secs); - e += 1 + ProtoBufRuntime._sz_int64(r.nanos); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.secs != 0) { - return false; - } - - if (r.nanos != 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.secs = input.secs; - output.nanos = input.nanos; - } - - //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 Timestamp - -/** - * @title Runtime library for ProtoBuf serialization and/or deserialization. - * All ProtoBuf generated code will use this library. - */ -library ProtoBufRuntime { - // Types defined in ProtoBuf - enum WireType { - Varint, - Fixed64, - LengthDelim, - StartGroup, - EndGroup, - Fixed32 - } - // Constants for bytes calculation - - uint256 constant WORD_LENGTH = 32; - uint256 constant HEADER_SIZE_LENGTH_IN_BYTES = 4; - uint256 constant BYTE_SIZE = 8; - uint256 constant REMAINING_LENGTH = - WORD_LENGTH - HEADER_SIZE_LENGTH_IN_BYTES; - string constant OVERFLOW_MESSAGE = "length overflow"; - - //Storages - /** - * @dev Encode to storage location using assembly to save storage space. - * @param location The location of storage - * @param encoded The encoded ProtoBuf bytes - */ - function encodeStorage( - bytes storage location, - bytes memory encoded - ) internal { - /** - * This code use the first four bytes as size, - * and then put the rest of `encoded` bytes. - */ - uint256 length = encoded.length; - uint256 firstWord; - uint256 wordLength = WORD_LENGTH; - uint256 remainingLength = REMAINING_LENGTH; - - assembly { - firstWord := mload(add(encoded, wordLength)) - } - firstWord = (firstWord >> (BYTE_SIZE * HEADER_SIZE_LENGTH_IN_BYTES)) - | (length << (BYTE_SIZE * REMAINING_LENGTH)); - - assembly { - sstore(location.slot, firstWord) - } - - if (length > REMAINING_LENGTH) { - length -= REMAINING_LENGTH; - for (uint256 i; i < ceil(length, WORD_LENGTH); i++) { - assembly { - let offset := add(mul(i, wordLength), remainingLength) - let slotIndex := add(i, 1) - sstore( - add(location.slot, slotIndex), - mload(add(add(encoded, wordLength), offset)) - ) - } - } - } - } - - /** - * @dev Decode storage location using assembly using the format in `encodeStorage`. - * @param location The location of storage - * @return The encoded bytes - */ - function decodeStorage(bytes storage location) - internal - view - returns (bytes memory) - { - /** - * This code is to decode the first four bytes as size, - * and then decode the rest using the decoded size. - */ - uint256 firstWord; - uint256 remainingLength = REMAINING_LENGTH; - uint256 wordLength = WORD_LENGTH; - - assembly { - firstWord := sload(location.slot) - } - - uint256 length = firstWord >> (BYTE_SIZE * REMAINING_LENGTH); - bytes memory encoded = new bytes(length); - - assembly { - mstore(add(encoded, remainingLength), firstWord) - } - - if (length > REMAINING_LENGTH) { - length -= REMAINING_LENGTH; - for (uint256 i; i < ceil(length, WORD_LENGTH); i++) { - assembly { - let offset := add(mul(i, wordLength), remainingLength) - let slotIndex := add(i, 1) - mstore( - add(add(encoded, wordLength), offset), - sload(add(location.slot, slotIndex)) - ) - } - } - } - return encoded; - } - - /** - * @dev Fast memory copy of bytes using assembly. - * @param src The source memory address - * @param dest The destination memory address - * @param len The length of bytes to copy - */ - function copyBytes(uint256 src, uint256 dest, uint256 len) internal pure { - if (len == 0) { - return; - } - - // Copy word-length chunks while possible - for (; len > WORD_LENGTH; len -= WORD_LENGTH) { - assembly { - mstore(dest, mload(src)) - } - dest += WORD_LENGTH; - src += WORD_LENGTH; - } - - // Copy remaining bytes - uint256 mask = 256 ** (WORD_LENGTH - len) - 1; - assembly { - let srcpart := and(mload(src), not(mask)) - let destpart := and(mload(dest), mask) - mstore(dest, or(destpart, srcpart)) - } - } - - /** - * @dev Use assembly to get memory address. - * @param r The in-memory bytes array - * @return The memory address of `r` - */ - function getMemoryAddress(bytes memory r) internal pure returns (uint256) { - uint256 addr; - assembly { - addr := r - } - return addr; - } - - /** - * @dev Implement Math function of ceil - * @param a The denominator - * @param m The numerator - * @return r The result of ceil(a/m) - */ - function ceil(uint256 a, uint256 m) internal pure returns (uint256 r) { - return (a + m - 1) / m; - } - - // Decoders - /** - * This section of code `_decode_(u)int(32|64)`, `_decode_enum` and `_decode_bool` - * is to decode ProtoBuf native integers, - * using the `varint` encoding. - */ - - /** - * @dev Decode integers - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded integer - * @return The length of `bs` used to get decoded - */ - function _decode_uint32( - uint256 p, - bytes memory bs - ) internal pure returns (uint32, uint256) { - (uint256 varint, uint256 sz) = _decode_varint(p, bs); - return (uint32(varint), sz); - } - - /** - * @dev Decode integers - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded integer - * @return The length of `bs` used to get decoded - */ - function _decode_uint64( - uint256 p, - bytes memory bs - ) internal pure returns (uint64, uint256) { - (uint256 varint, uint256 sz) = _decode_varint(p, bs); - return (uint64(varint), sz); - } - - /** - * @dev Decode integers - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded integer - * @return The length of `bs` used to get decoded - */ - function _decode_int32( - uint256 p, - bytes memory bs - ) internal pure returns (int32, uint256) { - (uint256 varint, uint256 sz) = _decode_varint(p, bs); - int32 r; - assembly { - r := varint - } - return (r, sz); - } - - /** - * @dev Decode integers - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded integer - * @return The length of `bs` used to get decoded - */ - function _decode_int64( - uint256 p, - bytes memory bs - ) internal pure returns (int64, uint256) { - (uint256 varint, uint256 sz) = _decode_varint(p, bs); - int64 r; - assembly { - r := varint - } - return (r, sz); - } - - /** - * @dev Decode enum - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded enum's integer - * @return The length of `bs` used to get decoded - */ - function _decode_enum( - uint256 p, - bytes memory bs - ) internal pure returns (int64, uint256) { - return _decode_int64(p, bs); - } - - /** - * @dev Decode enum - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded boolean - * @return The length of `bs` used to get decoded - */ - function _decode_bool( - uint256 p, - bytes memory bs - ) internal pure returns (bool, uint256) { - (uint256 varint, uint256 sz) = _decode_varint(p, bs); - if (varint == 0) { - return (false, sz); - } - return (true, sz); - } - - /** - * This section of code `_decode_sint(32|64)` - * is to decode ProtoBuf native signed integers, - * using the `zig-zag` encoding. - */ - - /** - * @dev Decode signed integers - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded integer - * @return The length of `bs` used to get decoded - */ - function _decode_sint32( - uint256 p, - bytes memory bs - ) internal pure returns (int32, uint256) { - (int256 varint, uint256 sz) = _decode_varints(p, bs); - return (int32(varint), sz); - } - - /** - * @dev Decode signed integers - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded integer - * @return The length of `bs` used to get decoded - */ - function _decode_sint64( - uint256 p, - bytes memory bs - ) internal pure returns (int64, uint256) { - (int256 varint, uint256 sz) = _decode_varints(p, bs); - return (int64(varint), sz); - } - - /** - * @dev Decode string - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded string - * @return The length of `bs` used to get decoded - */ - function _decode_string( - uint256 p, - bytes memory bs - ) internal pure returns (string memory, uint256) { - (bytes memory x, uint256 sz) = _decode_lendelim(p, bs); - return (string(x), sz); - } - - /** - * @dev Decode bytes array - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded bytes array - * @return The length of `bs` used to get decoded - */ - function _decode_bytes( - uint256 p, - bytes memory bs - ) internal pure returns (bytes memory, uint256) { - return _decode_lendelim(p, bs); - } - - /** - * @dev Decode ProtoBuf key - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded field ID - * @return The decoded WireType specified in ProtoBuf - * @return The length of `bs` used to get decoded - */ - function _decode_key( - uint256 p, - bytes memory bs - ) internal pure returns (uint256, WireType, uint256) { - (uint256 x, uint256 n) = _decode_varint(p, bs); - WireType typeId = WireType(x & 7); - uint256 fieldId = x / 8; - return (fieldId, typeId, n); - } - - /** - * @dev Decode ProtoBuf varint - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded unsigned integer - * @return The length of `bs` used to get decoded - */ - function _decode_varint( - uint256 p, - bytes memory bs - ) internal pure returns (uint256, uint256) { - /** - * Read a byte. - * Use the lower 7 bits and shift it to the left, - * until the most significant bit is 0. - * Refer to https://developers.google.com/protocol-buffers/docs/encoding - */ - uint256 x = 0; - uint256 sz = 0; - uint256 length = bs.length + WORD_LENGTH; - assembly { - let b := 0x80 - p := add(bs, p) - for {} eq(0x80, and(b, 0x80)) {} { - if eq(lt(sub(p, bs), length), 0) { - mstore( - 0, - 0x08c379a000000000000000000000000000000000000000000000000000000000 - ) //error function selector - mstore(4, 32) - mstore(36, 15) - mstore( - 68, - 0x6c656e677468206f766572666c6f770000000000000000000000000000000000 - ) // length overflow in hex - revert(0, 83) - } - let tmp := mload(p) - let pos := 0 - for {} and(eq(0x80, and(b, 0x80)), lt(pos, 32)) {} { - if eq(lt(sub(p, bs), length), 0) { - mstore( - 0, - 0x08c379a000000000000000000000000000000000000000000000000000000000 - ) //error function selector - mstore(4, 32) - mstore(36, 15) - mstore( - 68, - 0x6c656e677468206f766572666c6f770000000000000000000000000000000000 - ) // length overflow in hex - revert(0, 83) - } - b := byte(pos, tmp) - x := or(x, shl(mul(7, sz), and(0x7f, b))) - sz := add(sz, 1) - pos := add(pos, 1) - p := add(p, 0x01) - } - } - } - return (x, sz); - } - - /** - * @dev Decode ProtoBuf zig-zag encoding - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded signed integer - * @return The length of `bs` used to get decoded - */ - function _decode_varints( - uint256 p, - bytes memory bs - ) internal pure returns (int256, uint256) { - /** - * Refer to https://developers.google.com/protocol-buffers/docs/encoding - */ - (uint256 u, uint256 sz) = _decode_varint(p, bs); - int256 s; - assembly { - s := xor(shr(1, u), add(not(and(u, 1)), 1)) - } - return (s, sz); - } - - /** - * @dev Decode ProtoBuf fixed-length encoding - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded unsigned integer - * @return The length of `bs` used to get decoded - */ - function _decode_uintf( - uint256 p, - bytes memory bs, - uint256 sz - ) internal pure returns (uint256, uint256) { - /** - * Refer to https://developers.google.com/protocol-buffers/docs/encoding - */ - uint256 x = 0; - uint256 length = bs.length + WORD_LENGTH; - assert(p + sz <= length); - assembly { - let i := 0 - p := add(bs, p) - let tmp := mload(p) - for {} lt(i, sz) {} { - x := or(x, shl(mul(8, i), byte(i, tmp))) - p := add(p, 0x01) - i := add(i, 1) - } - } - return (x, sz); - } - - /** - * `_decode_(s)fixed(32|64)` is the concrete implementation of `_decode_uintf` - */ - function _decode_fixed32( - uint256 p, - bytes memory bs - ) internal pure returns (uint32, uint256) { - (uint256 x, uint256 sz) = _decode_uintf(p, bs, 4); - return (uint32(x), sz); - } - - function _decode_fixed64( - uint256 p, - bytes memory bs - ) internal pure returns (uint64, uint256) { - (uint256 x, uint256 sz) = _decode_uintf(p, bs, 8); - return (uint64(x), sz); - } - - function _decode_sfixed32( - uint256 p, - bytes memory bs - ) internal pure returns (int32, uint256) { - (uint256 x, uint256 sz) = _decode_uintf(p, bs, 4); - int256 r; - assembly { - r := x - } - return (int32(r), sz); - } - - function _decode_sfixed64( - uint256 p, - bytes memory bs - ) internal pure returns (int64, uint256) { - (uint256 x, uint256 sz) = _decode_uintf(p, bs, 8); - int256 r; - assembly { - r := x - } - return (int64(r), sz); - } - - /** - * @dev Decode bytes array - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The decoded bytes array - * @return The length of `bs` used to get decoded - */ - function _decode_lendelim( - uint256 p, - bytes memory bs - ) internal pure returns (bytes memory, uint256) { - /** - * First read the size encoded in `varint`, then use the size to read bytes. - */ - (uint256 len, uint256 sz) = _decode_varint(p, bs); - bytes memory b = new bytes(len); - uint256 length = bs.length + WORD_LENGTH; - assert(p + sz + len <= length); - uint256 sourcePtr; - uint256 destPtr; - assembly { - destPtr := add(b, 32) - sourcePtr := add(add(bs, p), sz) - } - copyBytes(sourcePtr, destPtr, len); - return (b, sz + len); - } - - /** - * @dev Skip the decoding of a single field - * @param wt The WireType of the field - * @param p The memory offset of `bs` - * @param bs The bytes array to be decoded - * @return The length of `bs` to skipped - */ - function _skip_field_decode( - WireType wt, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - if (wt == ProtoBufRuntime.WireType.Fixed64) { - return 8; - } else if (wt == ProtoBufRuntime.WireType.Fixed32) { - return 4; - } else if (wt == ProtoBufRuntime.WireType.Varint) { - (, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - return size; - } else { - require(wt == ProtoBufRuntime.WireType.LengthDelim); - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - return size + len; - } - } - - // Encoders - /** - * @dev Encode ProtoBuf key - * @param x The field ID - * @param wt The WireType specified in ProtoBuf - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The length of encoded bytes - */ - function _encode_key( - uint256 x, - WireType wt, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint256 i; - assembly { - i := or(mul(x, 8), mod(wt, 8)) - } - return _encode_varint(i, p, bs); - } - - /** - * @dev Encode ProtoBuf varint - * @param x The unsigned integer to be encoded - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The length of encoded bytes - */ - function _encode_varint( - uint256 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - /** - * Refer to https://developers.google.com/protocol-buffers/docs/encoding - */ - uint256 sz = 0; - assembly { - let bsptr := add(bs, p) - let byt := and(x, 0x7f) - for {} gt(shr(7, x), 0) {} { - mstore8(bsptr, or(0x80, byt)) - bsptr := add(bsptr, 1) - sz := add(sz, 1) - x := shr(7, x) - byt := and(x, 0x7f) - } - mstore8(bsptr, byt) - sz := add(sz, 1) - } - return sz; - } - - /** - * @dev Encode ProtoBuf zig-zag encoding - * @param x The signed integer to be encoded - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The length of encoded bytes - */ - function _encode_varints( - int256 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - /** - * Refer to https://developers.google.com/protocol-buffers/docs/encoding - */ - uint256 encodedInt = _encode_zigzag(x); - return _encode_varint(encodedInt, p, bs); - } - - /** - * @dev Encode ProtoBuf bytes - * @param xs The bytes array to be encoded - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The length of encoded bytes - */ - function _encode_bytes( - bytes memory xs, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint256 xsLength = xs.length; - uint256 sz = _encode_varint(xsLength, p, bs); - uint256 count = 0; - assembly { - let bsptr := add(bs, add(p, sz)) - let xsptr := add(xs, 32) - for {} lt(count, xsLength) {} { - mstore8(bsptr, byte(0, mload(xsptr))) - bsptr := add(bsptr, 1) - xsptr := add(xsptr, 1) - count := add(count, 1) - } - } - return sz + count; - } - - /** - * @dev Encode ProtoBuf string - * @param xs The string to be encoded - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The length of encoded bytes - */ - function _encode_string( - string memory xs, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_bytes(bytes(xs), p, bs); - } - - /** - * `_encode_(u)int(32|64)`, `_encode_enum` and `_encode_bool` - * are concrete implementation of `_encode_varint` - */ - function _encode_uint32( - uint32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_varint(x, p, bs); - } - - function _encode_uint64( - uint64 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_varint(x, p, bs); - } - - function _encode_int32( - int32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint64 twosComplement; - assembly { - twosComplement := x - } - return _encode_varint(twosComplement, p, bs); - } - - function _encode_int64( - int64 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint64 twosComplement; - assembly { - twosComplement := x - } - return _encode_varint(twosComplement, p, bs); - } - - function _encode_enum( - int32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_int32(x, p, bs); - } - - function _encode_bool( - bool x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - if (x) { - return _encode_varint(1, p, bs); - } else { - return _encode_varint(0, p, bs); - } - } - - /** - * `_encode_sint(32|64)`, `_encode_enum` and `_encode_bool` - * are the concrete implementation of `_encode_varints` - */ - function _encode_sint32( - int32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_varints(x, p, bs); - } - - function _encode_sint64( - int64 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_varints(x, p, bs); - } - - /** - * `_encode_(s)fixed(32|64)` is the concrete implementation of `_encode_uintf` - */ - function _encode_fixed32( - uint32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_uintf(x, p, bs, 4); - } - - function _encode_fixed64( - uint64 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_uintf(x, p, bs, 8); - } - - function _encode_sfixed32( - int32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint32 twosComplement; - assembly { - twosComplement := x - } - return _encode_uintf(twosComplement, p, bs, 4); - } - - function _encode_sfixed64( - int64 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint64 twosComplement; - assembly { - twosComplement := x - } - return _encode_uintf(twosComplement, p, bs, 8); - } - - /** - * @dev Encode ProtoBuf fixed-length integer - * @param x The unsigned integer to be encoded - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The length of encoded bytes - */ - function _encode_uintf( - uint256 x, - uint256 p, - bytes memory bs, - uint256 sz - ) internal pure returns (uint256) { - assembly { - let bsptr := add(sz, add(bs, p)) - let count := sz - for {} gt(count, 0) {} { - bsptr := sub(bsptr, 1) - mstore8(bsptr, byte(sub(32, count), x)) - count := sub(count, 1) - } - } - return sz; - } - - /** - * @dev Encode ProtoBuf zig-zag signed integer - * @param i The unsigned integer to be encoded - * @return The encoded unsigned integer - */ - function _encode_zigzag(int256 i) internal pure returns (uint256) { - if (i >= 0) { - return uint256(i) * 2; - } else { - return uint256(i * -2) - 1; - } - } - - // Estimators - /** - * @dev Estimate the length of encoded LengthDelim - * @param i The length of LengthDelim - * @return The estimated encoded length - */ - function _sz_lendelim(uint256 i) internal pure returns (uint256) { - return i + _sz_varint(i); - } - - /** - * @dev Estimate the length of encoded ProtoBuf field ID - * @param i The field ID - * @return The estimated encoded length - */ - function _sz_key(uint256 i) internal pure returns (uint256) { - if (i < 16) { - return 1; - } else if (i < 2048) { - return 2; - } else if (i < 262144) { - return 3; - } else { - revert("not supported"); - } - } - - /** - * @dev Estimate the length of encoded ProtoBuf varint - * @param i The unsigned integer - * @return The estimated encoded length - */ - function _sz_varint(uint256 i) internal pure returns (uint256) { - uint256 count = 1; - assembly { - i := shr(7, i) - for {} gt(i, 0) {} { - i := shr(7, i) - count := add(count, 1) - } - } - return count; - } - - /** - * `_sz_(u)int(32|64)` and `_sz_enum` are the concrete implementation of `_sz_varint` - */ - function _sz_uint32(uint32 i) internal pure returns (uint256) { - return _sz_varint(i); - } - - function _sz_uint64(uint64 i) internal pure returns (uint256) { - return _sz_varint(i); - } - - function _sz_int32(int32 i) internal pure returns (uint256) { - if (i < 0) { - return 10; - } else { - return _sz_varint(uint32(i)); - } - } - - function _sz_int64(int64 i) internal pure returns (uint256) { - if (i < 0) { - return 10; - } else { - return _sz_varint(uint64(i)); - } - } - - function _sz_enum(int64 i) internal pure returns (uint256) { - if (i < 0) { - return 10; - } else { - return _sz_varint(uint64(i)); - } - } - - /** - * `_sz_sint(32|64)` and `_sz_enum` are the concrete implementation of zig-zag encoding - */ - function _sz_sint32(int32 i) internal pure returns (uint256) { - return _sz_varint(_encode_zigzag(i)); - } - - function _sz_sint64(int64 i) internal pure returns (uint256) { - return _sz_varint(_encode_zigzag(i)); - } - - /** - * `_estimate_packed_repeated_(uint32|uint64|int32|int64|sint32|sint64)` - */ - function _estimate_packed_repeated_uint32(uint32[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += _sz_uint32(a[i]); - } - return e; - } - - function _estimate_packed_repeated_uint64(uint64[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += _sz_uint64(a[i]); - } - return e; - } - - function _estimate_packed_repeated_int32(int32[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += _sz_int32(a[i]); - } - return e; - } - - function _estimate_packed_repeated_int64(int64[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += _sz_int64(a[i]); - } - return e; - } - - function _estimate_packed_repeated_sint32(int32[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += _sz_sint32(a[i]); - } - return e; - } - - function _estimate_packed_repeated_sint64(int64[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += _sz_sint64(a[i]); - } - return e; - } - - // Element counters for packed repeated fields - function _count_packed_repeated_varint( - uint256 p, - uint256 len, - bytes memory bs - ) internal pure returns (uint256) { - uint256 count = 0; - uint256 end = p + len; - while (p < end) { - uint256 sz; - (, sz) = _decode_varint(p, bs); - p += sz; - count += 1; - } - return count; - } - - // Soltype extensions - /** - * @dev Decode Solidity integer and/or fixed-size bytes array, filling from lowest bit. - * @param n The maximum number of bytes to read - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The bytes32 representation - * @return The number of bytes used to decode - */ - function _decode_sol_bytesN_lower( - uint8 n, - uint256 p, - bytes memory bs - ) internal pure returns (bytes32, uint256) { - uint256 r; - (uint256 len, uint256 sz) = _decode_varint(p, bs); - if (len + sz > n + 3) { - revert(OVERFLOW_MESSAGE); - } - p += 3; - assert(p < bs.length + WORD_LENGTH); - assembly { - r := mload(add(p, bs)) - } - for (uint256 i = len - 2; i < WORD_LENGTH; i++) { - r /= 256; - } - return (bytes32(r), len + sz); - } - - /** - * @dev Decode Solidity integer and/or fixed-size bytes array, filling from highest bit. - * @param n The maximum number of bytes to read - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The bytes32 representation - * @return The number of bytes used to decode - */ - function _decode_sol_bytesN( - uint8 n, - uint256 p, - bytes memory bs - ) internal pure returns (bytes32, uint256) { - (uint256 len, uint256 sz) = _decode_varint(p, bs); - uint256 wordLength = WORD_LENGTH; - uint256 byteSize = BYTE_SIZE; - if (len + sz > n + 3) { - revert(OVERFLOW_MESSAGE); - } - p += 3; - bytes32 acc; - assert(p < bs.length + WORD_LENGTH); - assembly { - acc := mload(add(p, bs)) - let difference := sub(wordLength, sub(len, 2)) - let bits := mul(byteSize, difference) - acc := shl(bits, shr(bits, acc)) - } - return (acc, len + sz); - } - - /* - * `_decode_sol*` are the concrete implementation of decoding Solidity types - */ - function _decode_sol_address( - uint256 p, - bytes memory bs - ) internal pure returns (address, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytesN(20, p, bs); - return (address(bytes20(r)), sz); - } - - function _decode_sol_bool( - uint256 p, - bytes memory bs - ) internal pure returns (bool, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(1, p, bs); - if (r == 0) { - return (false, sz); - } - return (true, sz); - } - - function _decode_sol_uint( - uint256 p, - bytes memory bs - ) internal pure returns (uint256, uint256) { - return _decode_sol_uint256(p, bs); - } - - function _decode_sol_uintN( - uint8 n, - uint256 p, - bytes memory bs - ) internal pure returns (uint256, uint256) { - (bytes32 u, uint256 sz) = _decode_sol_bytesN_lower(n, p, bs); - uint256 r; - assembly { - r := u - } - return (r, sz); - } - - function _decode_sol_uint8( - uint256 p, - bytes memory bs - ) internal pure returns (uint8, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(1, p, bs); - return (uint8(r), sz); - } - - function _decode_sol_uint16( - uint256 p, - bytes memory bs - ) internal pure returns (uint16, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(2, p, bs); - return (uint16(r), sz); - } - - function _decode_sol_uint24( - uint256 p, - bytes memory bs - ) internal pure returns (uint24, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(3, p, bs); - return (uint24(r), sz); - } - - function _decode_sol_uint32( - uint256 p, - bytes memory bs - ) internal pure returns (uint32, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(4, p, bs); - return (uint32(r), sz); - } - - function _decode_sol_uint40( - uint256 p, - bytes memory bs - ) internal pure returns (uint40, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(5, p, bs); - return (uint40(r), sz); - } - - function _decode_sol_uint48( - uint256 p, - bytes memory bs - ) internal pure returns (uint48, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(6, p, bs); - return (uint48(r), sz); - } - - function _decode_sol_uint56( - uint256 p, - bytes memory bs - ) internal pure returns (uint56, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(7, p, bs); - return (uint56(r), sz); - } - - function _decode_sol_uint64( - uint256 p, - bytes memory bs - ) internal pure returns (uint64, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(8, p, bs); - return (uint64(r), sz); - } - - function _decode_sol_uint72( - uint256 p, - bytes memory bs - ) internal pure returns (uint72, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(9, p, bs); - return (uint72(r), sz); - } - - function _decode_sol_uint80( - uint256 p, - bytes memory bs - ) internal pure returns (uint80, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(10, p, bs); - return (uint80(r), sz); - } - - function _decode_sol_uint88( - uint256 p, - bytes memory bs - ) internal pure returns (uint88, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(11, p, bs); - return (uint88(r), sz); - } - - function _decode_sol_uint96( - uint256 p, - bytes memory bs - ) internal pure returns (uint96, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(12, p, bs); - return (uint96(r), sz); - } - - function _decode_sol_uint104( - uint256 p, - bytes memory bs - ) internal pure returns (uint104, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(13, p, bs); - return (uint104(r), sz); - } - - function _decode_sol_uint112( - uint256 p, - bytes memory bs - ) internal pure returns (uint112, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(14, p, bs); - return (uint112(r), sz); - } - - function _decode_sol_uint120( - uint256 p, - bytes memory bs - ) internal pure returns (uint120, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(15, p, bs); - return (uint120(r), sz); - } - - function _decode_sol_uint128( - uint256 p, - bytes memory bs - ) internal pure returns (uint128, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(16, p, bs); - return (uint128(r), sz); - } - - function _decode_sol_uint136( - uint256 p, - bytes memory bs - ) internal pure returns (uint136, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(17, p, bs); - return (uint136(r), sz); - } - - function _decode_sol_uint144( - uint256 p, - bytes memory bs - ) internal pure returns (uint144, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(18, p, bs); - return (uint144(r), sz); - } - - function _decode_sol_uint152( - uint256 p, - bytes memory bs - ) internal pure returns (uint152, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(19, p, bs); - return (uint152(r), sz); - } - - function _decode_sol_uint160( - uint256 p, - bytes memory bs - ) internal pure returns (uint160, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(20, p, bs); - return (uint160(r), sz); - } - - function _decode_sol_uint168( - uint256 p, - bytes memory bs - ) internal pure returns (uint168, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(21, p, bs); - return (uint168(r), sz); - } - - function _decode_sol_uint176( - uint256 p, - bytes memory bs - ) internal pure returns (uint176, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(22, p, bs); - return (uint176(r), sz); - } - - function _decode_sol_uint184( - uint256 p, - bytes memory bs - ) internal pure returns (uint184, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(23, p, bs); - return (uint184(r), sz); - } - - function _decode_sol_uint192( - uint256 p, - bytes memory bs - ) internal pure returns (uint192, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(24, p, bs); - return (uint192(r), sz); - } - - function _decode_sol_uint200( - uint256 p, - bytes memory bs - ) internal pure returns (uint200, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(25, p, bs); - return (uint200(r), sz); - } - - function _decode_sol_uint208( - uint256 p, - bytes memory bs - ) internal pure returns (uint208, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(26, p, bs); - return (uint208(r), sz); - } - - function _decode_sol_uint216( - uint256 p, - bytes memory bs - ) internal pure returns (uint216, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(27, p, bs); - return (uint216(r), sz); - } - - function _decode_sol_uint224( - uint256 p, - bytes memory bs - ) internal pure returns (uint224, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(28, p, bs); - return (uint224(r), sz); - } - - function _decode_sol_uint232( - uint256 p, - bytes memory bs - ) internal pure returns (uint232, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(29, p, bs); - return (uint232(r), sz); - } - - function _decode_sol_uint240( - uint256 p, - bytes memory bs - ) internal pure returns (uint240, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(30, p, bs); - return (uint240(r), sz); - } - - function _decode_sol_uint248( - uint256 p, - bytes memory bs - ) internal pure returns (uint248, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(31, p, bs); - return (uint248(r), sz); - } - - function _decode_sol_uint256( - uint256 p, - bytes memory bs - ) internal pure returns (uint256, uint256) { - (uint256 r, uint256 sz) = _decode_sol_uintN(32, p, bs); - return (uint256(r), sz); - } - - function _decode_sol_int( - uint256 p, - bytes memory bs - ) internal pure returns (int256, uint256) { - return _decode_sol_int256(p, bs); - } - - function _decode_sol_intN( - uint8 n, - uint256 p, - bytes memory bs - ) internal pure returns (int256, uint256) { - (bytes32 u, uint256 sz) = _decode_sol_bytesN_lower(n, p, bs); - int256 r; - assembly { - r := u - r := signextend(sub(sz, 4), r) - } - return (r, sz); - } - - function _decode_sol_bytes( - uint8 n, - uint256 p, - bytes memory bs - ) internal pure returns (bytes32, uint256) { - (bytes32 u, uint256 sz) = _decode_sol_bytesN(n, p, bs); - return (u, sz); - } - - function _decode_sol_int8( - uint256 p, - bytes memory bs - ) internal pure returns (int8, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(1, p, bs); - return (int8(r), sz); - } - - function _decode_sol_int16( - uint256 p, - bytes memory bs - ) internal pure returns (int16, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(2, p, bs); - return (int16(r), sz); - } - - function _decode_sol_int24( - uint256 p, - bytes memory bs - ) internal pure returns (int24, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(3, p, bs); - return (int24(r), sz); - } - - function _decode_sol_int32( - uint256 p, - bytes memory bs - ) internal pure returns (int32, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(4, p, bs); - return (int32(r), sz); - } - - function _decode_sol_int40( - uint256 p, - bytes memory bs - ) internal pure returns (int40, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(5, p, bs); - return (int40(r), sz); - } - - function _decode_sol_int48( - uint256 p, - bytes memory bs - ) internal pure returns (int48, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(6, p, bs); - return (int48(r), sz); - } - - function _decode_sol_int56( - uint256 p, - bytes memory bs - ) internal pure returns (int56, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(7, p, bs); - return (int56(r), sz); - } - - function _decode_sol_int64( - uint256 p, - bytes memory bs - ) internal pure returns (int64, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(8, p, bs); - return (int64(r), sz); - } - - function _decode_sol_int72( - uint256 p, - bytes memory bs - ) internal pure returns (int72, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(9, p, bs); - return (int72(r), sz); - } - - function _decode_sol_int80( - uint256 p, - bytes memory bs - ) internal pure returns (int80, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(10, p, bs); - return (int80(r), sz); - } - - function _decode_sol_int88( - uint256 p, - bytes memory bs - ) internal pure returns (int88, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(11, p, bs); - return (int88(r), sz); - } - - function _decode_sol_int96( - uint256 p, - bytes memory bs - ) internal pure returns (int96, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(12, p, bs); - return (int96(r), sz); - } - - function _decode_sol_int104( - uint256 p, - bytes memory bs - ) internal pure returns (int104, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(13, p, bs); - return (int104(r), sz); - } - - function _decode_sol_int112( - uint256 p, - bytes memory bs - ) internal pure returns (int112, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(14, p, bs); - return (int112(r), sz); - } - - function _decode_sol_int120( - uint256 p, - bytes memory bs - ) internal pure returns (int120, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(15, p, bs); - return (int120(r), sz); - } - - function _decode_sol_int128( - uint256 p, - bytes memory bs - ) internal pure returns (int128, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(16, p, bs); - return (int128(r), sz); - } - - function _decode_sol_int136( - uint256 p, - bytes memory bs - ) internal pure returns (int136, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(17, p, bs); - return (int136(r), sz); - } - - function _decode_sol_int144( - uint256 p, - bytes memory bs - ) internal pure returns (int144, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(18, p, bs); - return (int144(r), sz); - } - - function _decode_sol_int152( - uint256 p, - bytes memory bs - ) internal pure returns (int152, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(19, p, bs); - return (int152(r), sz); - } - - function _decode_sol_int160( - uint256 p, - bytes memory bs - ) internal pure returns (int160, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(20, p, bs); - return (int160(r), sz); - } - - function _decode_sol_int168( - uint256 p, - bytes memory bs - ) internal pure returns (int168, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(21, p, bs); - return (int168(r), sz); - } - - function _decode_sol_int176( - uint256 p, - bytes memory bs - ) internal pure returns (int176, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(22, p, bs); - return (int176(r), sz); - } - - function _decode_sol_int184( - uint256 p, - bytes memory bs - ) internal pure returns (int184, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(23, p, bs); - return (int184(r), sz); - } - - function _decode_sol_int192( - uint256 p, - bytes memory bs - ) internal pure returns (int192, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(24, p, bs); - return (int192(r), sz); - } - - function _decode_sol_int200( - uint256 p, - bytes memory bs - ) internal pure returns (int200, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(25, p, bs); - return (int200(r), sz); - } - - function _decode_sol_int208( - uint256 p, - bytes memory bs - ) internal pure returns (int208, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(26, p, bs); - return (int208(r), sz); - } - - function _decode_sol_int216( - uint256 p, - bytes memory bs - ) internal pure returns (int216, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(27, p, bs); - return (int216(r), sz); - } - - function _decode_sol_int224( - uint256 p, - bytes memory bs - ) internal pure returns (int224, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(28, p, bs); - return (int224(r), sz); - } - - function _decode_sol_int232( - uint256 p, - bytes memory bs - ) internal pure returns (int232, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(29, p, bs); - return (int232(r), sz); - } - - function _decode_sol_int240( - uint256 p, - bytes memory bs - ) internal pure returns (int240, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(30, p, bs); - return (int240(r), sz); - } - - function _decode_sol_int248( - uint256 p, - bytes memory bs - ) internal pure returns (int248, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(31, p, bs); - return (int248(r), sz); - } - - function _decode_sol_int256( - uint256 p, - bytes memory bs - ) internal pure returns (int256, uint256) { - (int256 r, uint256 sz) = _decode_sol_intN(32, p, bs); - return (int256(r), sz); - } - - function _decode_sol_bytes1( - uint256 p, - bytes memory bs - ) internal pure returns (bytes1, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(1, p, bs); - return (bytes1(r), sz); - } - - function _decode_sol_bytes2( - uint256 p, - bytes memory bs - ) internal pure returns (bytes2, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(2, p, bs); - return (bytes2(r), sz); - } - - function _decode_sol_bytes3( - uint256 p, - bytes memory bs - ) internal pure returns (bytes3, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(3, p, bs); - return (bytes3(r), sz); - } - - function _decode_sol_bytes4( - uint256 p, - bytes memory bs - ) internal pure returns (bytes4, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(4, p, bs); - return (bytes4(r), sz); - } - - function _decode_sol_bytes5( - uint256 p, - bytes memory bs - ) internal pure returns (bytes5, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(5, p, bs); - return (bytes5(r), sz); - } - - function _decode_sol_bytes6( - uint256 p, - bytes memory bs - ) internal pure returns (bytes6, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(6, p, bs); - return (bytes6(r), sz); - } - - function _decode_sol_bytes7( - uint256 p, - bytes memory bs - ) internal pure returns (bytes7, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(7, p, bs); - return (bytes7(r), sz); - } - - function _decode_sol_bytes8( - uint256 p, - bytes memory bs - ) internal pure returns (bytes8, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(8, p, bs); - return (bytes8(r), sz); - } - - function _decode_sol_bytes9( - uint256 p, - bytes memory bs - ) internal pure returns (bytes9, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(9, p, bs); - return (bytes9(r), sz); - } - - function _decode_sol_bytes10( - uint256 p, - bytes memory bs - ) internal pure returns (bytes10, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(10, p, bs); - return (bytes10(r), sz); - } - - function _decode_sol_bytes11( - uint256 p, - bytes memory bs - ) internal pure returns (bytes11, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(11, p, bs); - return (bytes11(r), sz); - } - - function _decode_sol_bytes12( - uint256 p, - bytes memory bs - ) internal pure returns (bytes12, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(12, p, bs); - return (bytes12(r), sz); - } - - function _decode_sol_bytes13( - uint256 p, - bytes memory bs - ) internal pure returns (bytes13, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(13, p, bs); - return (bytes13(r), sz); - } - - function _decode_sol_bytes14( - uint256 p, - bytes memory bs - ) internal pure returns (bytes14, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(14, p, bs); - return (bytes14(r), sz); - } - - function _decode_sol_bytes15( - uint256 p, - bytes memory bs - ) internal pure returns (bytes15, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(15, p, bs); - return (bytes15(r), sz); - } - - function _decode_sol_bytes16( - uint256 p, - bytes memory bs - ) internal pure returns (bytes16, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(16, p, bs); - return (bytes16(r), sz); - } - - function _decode_sol_bytes17( - uint256 p, - bytes memory bs - ) internal pure returns (bytes17, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(17, p, bs); - return (bytes17(r), sz); - } - - function _decode_sol_bytes18( - uint256 p, - bytes memory bs - ) internal pure returns (bytes18, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(18, p, bs); - return (bytes18(r), sz); - } - - function _decode_sol_bytes19( - uint256 p, - bytes memory bs - ) internal pure returns (bytes19, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(19, p, bs); - return (bytes19(r), sz); - } - - function _decode_sol_bytes20( - uint256 p, - bytes memory bs - ) internal pure returns (bytes20, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(20, p, bs); - return (bytes20(r), sz); - } - - function _decode_sol_bytes21( - uint256 p, - bytes memory bs - ) internal pure returns (bytes21, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(21, p, bs); - return (bytes21(r), sz); - } - - function _decode_sol_bytes22( - uint256 p, - bytes memory bs - ) internal pure returns (bytes22, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(22, p, bs); - return (bytes22(r), sz); - } - - function _decode_sol_bytes23( - uint256 p, - bytes memory bs - ) internal pure returns (bytes23, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(23, p, bs); - return (bytes23(r), sz); - } - - function _decode_sol_bytes24( - uint256 p, - bytes memory bs - ) internal pure returns (bytes24, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(24, p, bs); - return (bytes24(r), sz); - } - - function _decode_sol_bytes25( - uint256 p, - bytes memory bs - ) internal pure returns (bytes25, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(25, p, bs); - return (bytes25(r), sz); - } - - function _decode_sol_bytes26( - uint256 p, - bytes memory bs - ) internal pure returns (bytes26, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(26, p, bs); - return (bytes26(r), sz); - } - - function _decode_sol_bytes27( - uint256 p, - bytes memory bs - ) internal pure returns (bytes27, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(27, p, bs); - return (bytes27(r), sz); - } - - function _decode_sol_bytes28( - uint256 p, - bytes memory bs - ) internal pure returns (bytes28, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(28, p, bs); - return (bytes28(r), sz); - } - - function _decode_sol_bytes29( - uint256 p, - bytes memory bs - ) internal pure returns (bytes29, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(29, p, bs); - return (bytes29(r), sz); - } - - function _decode_sol_bytes30( - uint256 p, - bytes memory bs - ) internal pure returns (bytes30, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(30, p, bs); - return (bytes30(r), sz); - } - - function _decode_sol_bytes31( - uint256 p, - bytes memory bs - ) internal pure returns (bytes31, uint256) { - (bytes32 r, uint256 sz) = _decode_sol_bytes(31, p, bs); - return (bytes31(r), sz); - } - - function _decode_sol_bytes32( - uint256 p, - bytes memory bs - ) internal pure returns (bytes32, uint256) { - return _decode_sol_bytes(32, p, bs); - } - - /* - * `_encode_sol*` are the concrete implementation of encoding Solidity types - */ - function _encode_sol_address( - address x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(uint160(x)), 20, p, bs); - } - - function _encode_sol_uint( - uint256 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 32, p, bs); - } - - function _encode_sol_uint8( - uint8 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 1, p, bs); - } - - function _encode_sol_uint16( - uint16 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 2, p, bs); - } - - function _encode_sol_uint24( - uint24 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 3, p, bs); - } - - function _encode_sol_uint32( - uint32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 4, p, bs); - } - - function _encode_sol_uint40( - uint40 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 5, p, bs); - } - - function _encode_sol_uint48( - uint48 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 6, p, bs); - } - - function _encode_sol_uint56( - uint56 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 7, p, bs); - } - - function _encode_sol_uint64( - uint64 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 8, p, bs); - } - - function _encode_sol_uint72( - uint72 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 9, p, bs); - } - - function _encode_sol_uint80( - uint80 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 10, p, bs); - } - - function _encode_sol_uint88( - uint88 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 11, p, bs); - } - - function _encode_sol_uint96( - uint96 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 12, p, bs); - } - - function _encode_sol_uint104( - uint104 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 13, p, bs); - } - - function _encode_sol_uint112( - uint112 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 14, p, bs); - } - - function _encode_sol_uint120( - uint120 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 15, p, bs); - } - - function _encode_sol_uint128( - uint128 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 16, p, bs); - } - - function _encode_sol_uint136( - uint136 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 17, p, bs); - } - - function _encode_sol_uint144( - uint144 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 18, p, bs); - } - - function _encode_sol_uint152( - uint152 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 19, p, bs); - } - - function _encode_sol_uint160( - uint160 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 20, p, bs); - } - - function _encode_sol_uint168( - uint168 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 21, p, bs); - } - - function _encode_sol_uint176( - uint176 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 22, p, bs); - } - - function _encode_sol_uint184( - uint184 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 23, p, bs); - } - - function _encode_sol_uint192( - uint192 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 24, p, bs); - } - - function _encode_sol_uint200( - uint200 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 25, p, bs); - } - - function _encode_sol_uint208( - uint208 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 26, p, bs); - } - - function _encode_sol_uint216( - uint216 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 27, p, bs); - } - - function _encode_sol_uint224( - uint224 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 28, p, bs); - } - - function _encode_sol_uint232( - uint232 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 29, p, bs); - } - - function _encode_sol_uint240( - uint240 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 30, p, bs); - } - - function _encode_sol_uint248( - uint248 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 31, p, bs); - } - - function _encode_sol_uint256( - uint256 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(uint256(x), 32, p, bs); - } - - function _encode_sol_int( - int256 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(x, 32, p, bs); - } - - function _encode_sol_int8( - int8 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 1, p, bs); - } - - function _encode_sol_int16( - int16 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 2, p, bs); - } - - function _encode_sol_int24( - int24 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 3, p, bs); - } - - function _encode_sol_int32( - int32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 4, p, bs); - } - - function _encode_sol_int40( - int40 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 5, p, bs); - } - - function _encode_sol_int48( - int48 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 6, p, bs); - } - - function _encode_sol_int56( - int56 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 7, p, bs); - } - - function _encode_sol_int64( - int64 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 8, p, bs); - } - - function _encode_sol_int72( - int72 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 9, p, bs); - } - - function _encode_sol_int80( - int80 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 10, p, bs); - } - - function _encode_sol_int88( - int88 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 11, p, bs); - } - - function _encode_sol_int96( - int96 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 12, p, bs); - } - - function _encode_sol_int104( - int104 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 13, p, bs); - } - - function _encode_sol_int112( - int112 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 14, p, bs); - } - - function _encode_sol_int120( - int120 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 15, p, bs); - } - - function _encode_sol_int128( - int128 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 16, p, bs); - } - - function _encode_sol_int136( - int136 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 17, p, bs); - } - - function _encode_sol_int144( - int144 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 18, p, bs); - } - - function _encode_sol_int152( - int152 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 19, p, bs); - } - - function _encode_sol_int160( - int160 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 20, p, bs); - } - - function _encode_sol_int168( - int168 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 21, p, bs); - } - - function _encode_sol_int176( - int176 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 22, p, bs); - } - - function _encode_sol_int184( - int184 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 23, p, bs); - } - - function _encode_sol_int192( - int192 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 24, p, bs); - } - - function _encode_sol_int200( - int200 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 25, p, bs); - } - - function _encode_sol_int208( - int208 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 26, p, bs); - } - - function _encode_sol_int216( - int216 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 27, p, bs); - } - - function _encode_sol_int224( - int224 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 28, p, bs); - } - - function _encode_sol_int232( - int232 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 29, p, bs); - } - - function _encode_sol_int240( - int240 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 30, p, bs); - } - - function _encode_sol_int248( - int248 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(int256(x), 31, p, bs); - } - - function _encode_sol_int256( - int256 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol(x, 32, p, bs); - } - - function _encode_sol_bytes1( - bytes1 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 1, p, bs); - } - - function _encode_sol_bytes2( - bytes2 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 2, p, bs); - } - - function _encode_sol_bytes3( - bytes3 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 3, p, bs); - } - - function _encode_sol_bytes4( - bytes4 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 4, p, bs); - } - - function _encode_sol_bytes5( - bytes5 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 5, p, bs); - } - - function _encode_sol_bytes6( - bytes6 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 6, p, bs); - } - - function _encode_sol_bytes7( - bytes7 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 7, p, bs); - } - - function _encode_sol_bytes8( - bytes8 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 8, p, bs); - } - - function _encode_sol_bytes9( - bytes9 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 9, p, bs); - } - - function _encode_sol_bytes10( - bytes10 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 10, p, bs); - } - - function _encode_sol_bytes11( - bytes11 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 11, p, bs); - } - - function _encode_sol_bytes12( - bytes12 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 12, p, bs); - } - - function _encode_sol_bytes13( - bytes13 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 13, p, bs); - } - - function _encode_sol_bytes14( - bytes14 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 14, p, bs); - } - - function _encode_sol_bytes15( - bytes15 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 15, p, bs); - } - - function _encode_sol_bytes16( - bytes16 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 16, p, bs); - } - - function _encode_sol_bytes17( - bytes17 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 17, p, bs); - } - - function _encode_sol_bytes18( - bytes18 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 18, p, bs); - } - - function _encode_sol_bytes19( - bytes19 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 19, p, bs); - } - - function _encode_sol_bytes20( - bytes20 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 20, p, bs); - } - - function _encode_sol_bytes21( - bytes21 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 21, p, bs); - } - - function _encode_sol_bytes22( - bytes22 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 22, p, bs); - } - - function _encode_sol_bytes23( - bytes23 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 23, p, bs); - } - - function _encode_sol_bytes24( - bytes24 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 24, p, bs); - } - - function _encode_sol_bytes25( - bytes25 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 25, p, bs); - } - - function _encode_sol_bytes26( - bytes26 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 26, p, bs); - } - - function _encode_sol_bytes27( - bytes27 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 27, p, bs); - } - - function _encode_sol_bytes28( - bytes28 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 28, p, bs); - } - - function _encode_sol_bytes29( - bytes29 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 29, p, bs); - } - - function _encode_sol_bytes30( - bytes30 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 30, p, bs); - } - - function _encode_sol_bytes31( - bytes31 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(bytes32(x), 31, p, bs); - } - - function _encode_sol_bytes32( - bytes32 x, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - return _encode_sol_bytes(x, 32, p, bs); - } - - /** - * @dev Encode the key of Solidity integer and/or fixed-size bytes array. - * @param sz The number of bytes used to encode Solidity types - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The number of bytes used to encode - */ - function _encode_sol_header( - uint256 sz, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint256 offset = p; - p += _encode_varint(sz + 2, p, bs); - p += _encode_key(1, WireType.LengthDelim, p, bs); - p += _encode_varint(sz, p, bs); - return p - offset; - } - - /** - * @dev Encode Solidity type - * @param x The unsinged integer to be encoded - * @param sz The number of bytes used to encode Solidity types - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The number of bytes used to encode - */ - function _encode_sol( - uint256 x, - uint256 sz, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint256 offset = p; - uint256 size; - p += 3; - size = _encode_sol_raw_other(x, p, bs, sz); - p += size; - _encode_sol_header(size, offset, bs); - return p - offset; - } - - /** - * @dev Encode Solidity type - * @param x The signed integer to be encoded - * @param sz The number of bytes used to encode Solidity types - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The number of bytes used to encode - */ - function _encode_sol( - int256 x, - uint256 sz, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint256 offset = p; - uint256 size; - p += 3; - size = _encode_sol_raw_other(x, p, bs, sz); - p += size; - _encode_sol_header(size, offset, bs); - return p - offset; - } - - /** - * @dev Encode Solidity type - * @param x The fixed-size byte array to be encoded - * @param sz The number of bytes used to encode Solidity types - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The number of bytes used to encode - */ - function _encode_sol_bytes( - bytes32 x, - uint256 sz, - uint256 p, - bytes memory bs - ) internal pure returns (uint256) { - uint256 offset = p; - uint256 size; - p += 3; - size = _encode_sol_raw_bytes_array(x, p, bs, sz); - p += size; - _encode_sol_header(size, offset, bs); - return p - offset; - } - - /** - * @dev Get the actual size needed to encoding an unsigned integer - * @param x The unsigned integer to be encoded - * @param sz The maximum number of bytes used to encode Solidity types - * @return The number of bytes needed for encoding `x` - */ - function _get_real_size( - uint256 x, - uint256 sz - ) internal pure returns (uint256) { - uint256 base = 0xff; - uint256 realSize = sz; - while ( - x & (base << (realSize * BYTE_SIZE - BYTE_SIZE)) == 0 - && realSize > 0 - ) { - realSize -= 1; - } - if (realSize == 0) { - realSize = 1; - } - return realSize; - } - - /** - * @dev Get the actual size needed to encoding an signed integer - * @param x The signed integer to be encoded - * @param sz The maximum number of bytes used to encode Solidity types - * @return The number of bytes needed for encoding `x` - */ - function _get_real_size( - int256 x, - uint256 sz - ) internal pure returns (uint256) { - int256 base = 0xff; - if (x >= 0) { - uint256 tmp = _get_real_size(uint256(x), sz); - int256 remainder = (x & (base << (tmp * BYTE_SIZE - BYTE_SIZE))) - >> (tmp * BYTE_SIZE - BYTE_SIZE); - if (remainder >= 128) { - tmp += 1; - } - return tmp; - } - - uint256 realSize = sz; - while ( - x & (base << (realSize * BYTE_SIZE - BYTE_SIZE)) - == (base << (realSize * BYTE_SIZE - BYTE_SIZE)) && realSize > 0 - ) { - realSize -= 1; - } - { - int256 remainder = ( - x & (base << (realSize * BYTE_SIZE - BYTE_SIZE)) - ) >> (realSize * BYTE_SIZE - BYTE_SIZE); - if (remainder < 128) { - realSize += 1; - } - } - return realSize; - } - - /** - * @dev Encode the fixed-bytes array - * @param x The fixed-size byte array to be encoded - * @param sz The maximum number of bytes used to encode Solidity types - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The number of bytes needed for encoding `x` - */ - function _encode_sol_raw_bytes_array( - bytes32 x, - uint256 p, - bytes memory bs, - uint256 sz - ) internal pure returns (uint256) { - /** - * The idea is to not encode the leading bytes of zero. - */ - uint256 actualSize = sz; - for (uint256 i; i < sz; i++) { - uint8 current = uint8(x[sz - 1 - i]); - if (current == 0 && actualSize > 1) { - actualSize--; - } else { - break; - } - } - assembly { - let bsptr := add(bs, p) - let count := actualSize - for {} gt(count, 0) {} { - mstore8(bsptr, byte(sub(actualSize, count), x)) - bsptr := add(bsptr, 1) - count := sub(count, 1) - } - } - return actualSize; - } - - /** - * @dev Encode the signed integer - * @param x The signed integer to be encoded - * @param sz The maximum number of bytes used to encode Solidity types - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The number of bytes needed for encoding `x` - */ - function _encode_sol_raw_other( - int256 x, - uint256 p, - bytes memory bs, - uint256 sz - ) internal pure returns (uint256) { - /** - * The idea is to not encode the leading bytes of zero.or one, - * depending on whether it is positive. - */ - uint256 realSize = _get_real_size(x, sz); - assembly { - let bsptr := add(bs, p) - let count := realSize - for {} gt(count, 0) {} { - mstore8(bsptr, byte(sub(32, count), x)) - bsptr := add(bsptr, 1) - count := sub(count, 1) - } - } - return realSize; - } - - /** - * @dev Encode the unsigned integer - * @param x The unsigned integer to be encoded - * @param sz The maximum number of bytes used to encode Solidity types - * @param p The offset of bytes array `bs` - * @param bs The bytes array to encode - * @return The number of bytes needed for encoding `x` - */ - function _encode_sol_raw_other( - uint256 x, - uint256 p, - bytes memory bs, - uint256 sz - ) internal pure returns (uint256) { - uint256 realSize = _get_real_size(x, sz); - assembly { - let bsptr := add(bs, p) - let count := realSize - for {} gt(count, 0) {} { - mstore8(bsptr, byte(sub(32, count), x)) - bsptr := add(bsptr, 1) - count := sub(count, 1) - } - } - return realSize; - } -} diff --git a/evm/contracts/proto/cosmos/auth/v1beta1/auth.sol b/evm/contracts/proto/cosmos/auth/v1beta1/auth.sol deleted file mode 100644 index 8c4817afb3..0000000000 --- a/evm/contracts/proto/cosmos/auth/v1beta1/auth.sol +++ /dev/null @@ -1,1356 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../ProtoBufRuntime.sol"; -import "../../../GoogleProtobufAny.sol"; -import "../../../cosmos_proto/cosmos.sol"; - -library CosmosAuthV1beta1BaseAccount { - //struct definition - struct Data { - string address_; - GoogleProtobufAny.Data pub_key; - uint64 account_number; - uint64 sequence; - } - - // 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_address(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_pub_key(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_account_number(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_sequence(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_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.address_ = 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_pub_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufAny.Data memory x, uint256 sz) = - _decode_GoogleProtobufAny(p, bs); - r.pub_key = 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_account_number( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.account_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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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.address_).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.address_, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufAny._encode_nested(r.pub_key, pointer, bs); - - if (r.account_number != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.account_number, pointer, bs); - } - if (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, 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.address_).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(GoogleProtobufAny._estimate(r.pub_key)); - e += 1 + ProtoBufRuntime._sz_uint64(r.account_number); - e += 1 + ProtoBufRuntime._sz_uint64(r.sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.address_).length != 0) { - return false; - } - - if (r.account_number != 0) { - return false; - } - - if (r.sequence != 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.address_ = input.address_; - GoogleProtobufAny.store(input.pub_key, output.pub_key); - output.account_number = input.account_number; - output.sequence = input.sequence; - } - - //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 CosmosAuthV1beta1BaseAccount - -library CosmosAuthV1beta1ModuleAccount { - //struct definition - struct Data { - CosmosAuthV1beta1BaseAccount.Data base_account; - string name; - string[] permissions; - } - - // 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[4] 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_base_account(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_name(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_permissions( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[3] > 0) { - require(r.permissions.length == 0); - r.permissions = new string[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 3) { - pointer += _read_unpacked_repeated_permissions( - 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_base_account( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosAuthV1beta1BaseAccount.Data memory x, uint256 sz) = - _decode_CosmosAuthV1beta1BaseAccount(p, bs); - r.base_account = 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_name( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.name = 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_permissions( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.permissions[r.permissions.length - counters[3]] = x; - counters[3] -= 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_CosmosAuthV1beta1BaseAccount( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosAuthV1beta1BaseAccount.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosAuthV1beta1BaseAccount.Data memory r,) = - CosmosAuthV1beta1BaseAccount._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 += CosmosAuthV1beta1BaseAccount._encode_nested( - r.base_account, pointer, bs - ); - - if (bytes(r.name).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.name, pointer, bs); - } - if (r.permissions.length != 0) { - for (i = 0; i < r.permissions.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.permissions[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( - CosmosAuthV1beta1BaseAccount._estimate(r.base_account) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.name).length); - for (i = 0; i < r.permissions.length; i++) { - e += - 1 + ProtoBufRuntime._sz_lendelim(bytes(r.permissions[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.name).length != 0) { - return false; - } - - if (r.permissions.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 { - CosmosAuthV1beta1BaseAccount.store( - input.base_account, output.base_account - ); - output.name = input.name; - output.permissions = input.permissions; - } - - //array helpers for Permissions - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPermissions( - Data memory self, - string memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.permissions.length + 1); - for (uint256 i; i < self.permissions.length; i++) { - tmp[i] = self.permissions[i]; - } - tmp[self.permissions.length] = value; - self.permissions = 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 CosmosAuthV1beta1ModuleAccount - -library CosmosAuthV1beta1ModuleCredential { - //struct definition - struct Data { - string module_name; - bytes[] derivation_keys; - } - - // 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_module_name(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_derivation_keys( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[2] > 0) { - require(r.derivation_keys.length == 0); - r.derivation_keys = new bytes[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 2) { - pointer += _read_unpacked_repeated_derivation_keys( - 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_module_name( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.module_name = 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_derivation_keys( - 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. - */ - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.derivation_keys[r.derivation_keys.length - counters[2]] = x; - counters[2] -= 1; - } - 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; - uint256 i; - if (bytes(r.module_name).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.module_name, pointer, bs); - } - if (r.derivation_keys.length != 0) { - for (i = 0; i < r.derivation_keys.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.derivation_keys[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.module_name).length); - for (i = 0; i < r.derivation_keys.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(r.derivation_keys[i].length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.module_name).length != 0) { - return false; - } - - if (r.derivation_keys.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.module_name = input.module_name; - output.derivation_keys = input.derivation_keys; - } - - //array helpers for DerivationKeys - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addDerivationKeys( - Data memory self, - bytes memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - bytes[] memory tmp = new bytes[](self.derivation_keys.length + 1); - for (uint256 i; i < self.derivation_keys.length; i++) { - tmp[i] = self.derivation_keys[i]; - } - tmp[self.derivation_keys.length] = value; - self.derivation_keys = 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 CosmosAuthV1beta1ModuleCredential - -library CosmosAuthV1beta1Params { - //struct definition - struct Data { - uint64 max_memo_characters; - uint64 tx_sig_limit; - uint64 tx_size_cost_per_byte; - uint64 sig_verify_cost_ed25519; - uint64 sig_verify_cost_secp256k1; - } - - // 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_max_memo_characters(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_tx_sig_limit(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_tx_size_cost_per_byte(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_sig_verify_cost_ed25519(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_sig_verify_cost_secp256k1(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_max_memo_characters( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.max_memo_characters = 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_tx_sig_limit( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.tx_sig_limit = 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_tx_size_cost_per_byte( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.tx_size_cost_per_byte = 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_sig_verify_cost_ed25519( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sig_verify_cost_ed25519 = 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_sig_verify_cost_secp256k1( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sig_verify_cost_secp256k1 = 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.max_memo_characters != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.max_memo_characters, pointer, bs - ); - } - if (r.tx_sig_limit != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.tx_sig_limit, pointer, bs); - } - if (r.tx_size_cost_per_byte != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.tx_size_cost_per_byte, pointer, bs - ); - } - if (r.sig_verify_cost_ed25519 != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.sig_verify_cost_ed25519, pointer, bs - ); - } - if (r.sig_verify_cost_secp256k1 != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.sig_verify_cost_secp256k1, 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.max_memo_characters); - e += 1 + ProtoBufRuntime._sz_uint64(r.tx_sig_limit); - e += 1 + ProtoBufRuntime._sz_uint64(r.tx_size_cost_per_byte); - e += 1 + ProtoBufRuntime._sz_uint64(r.sig_verify_cost_ed25519); - e += 1 + ProtoBufRuntime._sz_uint64(r.sig_verify_cost_secp256k1); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.max_memo_characters != 0) { - return false; - } - - if (r.tx_sig_limit != 0) { - return false; - } - - if (r.tx_size_cost_per_byte != 0) { - return false; - } - - if (r.sig_verify_cost_ed25519 != 0) { - return false; - } - - if (r.sig_verify_cost_secp256k1 != 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.max_memo_characters = input.max_memo_characters; - output.tx_sig_limit = input.tx_sig_limit; - output.tx_size_cost_per_byte = input.tx_size_cost_per_byte; - output.sig_verify_cost_ed25519 = input.sig_verify_cost_ed25519; - output.sig_verify_cost_secp256k1 = input.sig_verify_cost_secp256k1; - } - - //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 CosmosAuthV1beta1Params diff --git a/evm/contracts/proto/cosmos/base/query/v1beta1/pagination.sol b/evm/contracts/proto/cosmos/base/query/v1beta1/pagination.sol deleted file mode 100644 index 0f3bb19e2c..0000000000 --- a/evm/contracts/proto/cosmos/base/query/v1beta1/pagination.sol +++ /dev/null @@ -1,589 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library CosmosBaseQueryV1beta1PageRequest { - //struct definition - struct Data { - bytes key; - uint64 offset; - uint64 limit; - bool count_total; - bool reverse; - } - - // 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_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_offset(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_limit(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_count_total(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_reverse(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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key = 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_offset( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.offset = 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_limit( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.limit = 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_count_total( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.count_total = 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_reverse( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.reverse = 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.key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key, pointer, bs); - } - if (r.offset != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.offset, pointer, bs); - } - if (r.limit != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.limit, pointer, bs); - } - if (r.count_total != false) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool(r.count_total, pointer, bs); - } - if (r.reverse != false) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool(r.reverse, 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.key.length); - e += 1 + ProtoBufRuntime._sz_uint64(r.offset); - e += 1 + ProtoBufRuntime._sz_uint64(r.limit); - e += 1 + 1; - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key.length != 0) { - return false; - } - - if (r.offset != 0) { - return false; - } - - if (r.limit != 0) { - return false; - } - - if (r.count_total != false) { - return false; - } - - if (r.reverse != false) { - 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.key = input.key; - output.offset = input.offset; - output.limit = input.limit; - output.count_total = input.count_total; - output.reverse = input.reverse; - } - - //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 CosmosBaseQueryV1beta1PageRequest - -library CosmosBaseQueryV1beta1PageResponse { - //struct definition - struct Data { - bytes next_key; - uint64 total; - } - - // 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_next_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_total(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_next_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.next_key = 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_total( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.total = 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.next_key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.next_key, pointer, bs); - } - if (r.total != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.total, 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.next_key.length); - e += 1 + ProtoBufRuntime._sz_uint64(r.total); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.next_key.length != 0) { - return false; - } - - if (r.total != 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.next_key = input.next_key; - output.total = input.total; - } - - //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 CosmosBaseQueryV1beta1PageResponse diff --git a/evm/contracts/proto/cosmos/base/v1beta1/coin.sol b/evm/contracts/proto/cosmos/base/v1beta1/coin.sol deleted file mode 100644 index 4829e919a5..0000000000 --- a/evm/contracts/proto/cosmos/base/v1beta1/coin.sol +++ /dev/null @@ -1,921 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../ProtoBufRuntime.sol"; -import "../../../GoogleProtobufAny.sol"; - -import "../../../cosmos_proto/cosmos.sol"; - -library CosmosBaseV1beta1Coin { - //struct definition - struct Data { - string denom; - string amount; - } - - // 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_denom(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_amount(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_denom( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.denom = 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_amount( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.amount = 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 (bytes(r.denom).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.denom, pointer, bs); - } - if (bytes(r.amount).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.amount, 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.denom).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.amount).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.denom).length != 0) { - return false; - } - - if (bytes(r.amount).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.denom = input.denom; - output.amount = input.amount; - } - - //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 CosmosBaseV1beta1Coin - -library CosmosBaseV1beta1DecCoin { - //struct definition - struct Data { - string denom; - string amount; - } - - // 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_denom(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_amount(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_denom( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.denom = 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_amount( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.amount = 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 (bytes(r.denom).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.denom, pointer, bs); - } - if (bytes(r.amount).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.amount, 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.denom).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.amount).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.denom).length != 0) { - return false; - } - - if (bytes(r.amount).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.denom = input.denom; - output.amount = input.amount; - } - - //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 CosmosBaseV1beta1DecCoin - -library CosmosBaseV1beta1IntProto { - //struct definition - struct Data { - string int_; - } - - // 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_int(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_int( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.int_ = 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 (bytes(r.int_).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.int_, 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.int_).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.int_).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.int_ = input.int_; - } - - //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 CosmosBaseV1beta1IntProto - -library CosmosBaseV1beta1DecProto { - //struct definition - struct Data { - string dec; - } - - // 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_dec(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_dec( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.dec = 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 (bytes(r.dec).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.dec, 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.dec).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.dec).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.dec = input.dec; - } - - //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 CosmosBaseV1beta1DecProto diff --git a/evm/contracts/proto/cosmos/ics23/v1/proofs.sol b/evm/contracts/proto/cosmos/ics23/v1/proofs.sol deleted file mode 100644 index 8af3f213ef..0000000000 --- a/evm/contracts/proto/cosmos/ics23/v1/proofs.sol +++ /dev/null @@ -1,4833 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../../ProtoBufRuntime.sol"; -import "../../../GoogleProtobufAny.sol"; - -library CosmosIcs23V1ExistenceProof { - //struct definition - struct Data { - bytes key; - bytes value; - CosmosIcs23V1LeafOp.Data leaf; - CosmosIcs23V1InnerOp.Data[] path; - } - - // 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[5] 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_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_value(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_leaf(pointer, bs, r); - } else if (fieldId == 4) { - pointer += - _read_unpacked_repeated_path(pointer, bs, nil(), counters); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[4] > 0) { - require(r.path.length == 0); - r.path = new CosmosIcs23V1InnerOp.Data[](counters[4]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 4) { - pointer += - _read_unpacked_repeated_path(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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key = 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_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; - } - - /** - * @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_leaf( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1LeafOp.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1LeafOp(p, bs); - r.leaf = 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_path( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosIcs23V1InnerOp.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1InnerOp(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.path[r.path.length - counters[4]] = x; - counters[4] -= 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_CosmosIcs23V1LeafOp( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1LeafOp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1LeafOp.Data memory r,) = - CosmosIcs23V1LeafOp._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_CosmosIcs23V1InnerOp( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1InnerOp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1InnerOp.Data memory r,) = - CosmosIcs23V1InnerOp._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.key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key, pointer, bs); - } - if (r.value.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.value, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1LeafOp._encode_nested(r.leaf, pointer, bs); - - if (r.path.length != 0) { - for (i = 0; i < r.path.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - CosmosIcs23V1InnerOp._encode_nested(r.path[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.key.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.value.length); - e += 1 - + ProtoBufRuntime._sz_lendelim(CosmosIcs23V1LeafOp._estimate(r.leaf)); - for (i = 0; i < r.path.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1InnerOp._estimate(r.path[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key.length != 0) { - return false; - } - - if (r.value.length != 0) { - return false; - } - - if (r.path.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.key = input.key; - output.value = input.value; - CosmosIcs23V1LeafOp.store(input.leaf, output.leaf); - - for (uint256 i4 = 0; i4 < input.path.length; i4++) { - output.path.push(input.path[i4]); - } - } - - //array helpers for Path - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPath( - Data memory self, - CosmosIcs23V1InnerOp.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosIcs23V1InnerOp.Data[] memory tmp = - new CosmosIcs23V1InnerOp.Data[](self.path.length + 1); - for (uint256 i; i < self.path.length; i++) { - tmp[i] = self.path[i]; - } - tmp[self.path.length] = value; - self.path = 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 CosmosIcs23V1ExistenceProof - -library CosmosIcs23V1NonExistenceProof { - //struct definition - struct Data { - bytes key; - CosmosIcs23V1ExistenceProof.Data left; - CosmosIcs23V1ExistenceProof.Data right; - } - - // 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_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_left(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_right(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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key = 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_left( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1ExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1ExistenceProof(p, bs); - r.left = 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_right( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1ExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1ExistenceProof(p, bs); - r.right = 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_CosmosIcs23V1ExistenceProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1ExistenceProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1ExistenceProof.Data memory r,) = - CosmosIcs23V1ExistenceProof._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 (r.key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - CosmosIcs23V1ExistenceProof._encode_nested(r.left, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - CosmosIcs23V1ExistenceProof._encode_nested(r.right, 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.key.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1ExistenceProof._estimate(r.left) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1ExistenceProof._estimate(r.right) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key.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.key = input.key; - CosmosIcs23V1ExistenceProof.store(input.left, output.left); - CosmosIcs23V1ExistenceProof.store(input.right, output.right); - } - - //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 CosmosIcs23V1NonExistenceProof - -library CosmosIcs23V1CommitmentProof { - //struct definition - struct Data { - CosmosIcs23V1ExistenceProof.Data exist; - CosmosIcs23V1NonExistenceProof.Data nonexist; - CosmosIcs23V1BatchProof.Data batch; - CosmosIcs23V1CompressedBatchProof.Data compressed; - } - - // 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_exist(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_nonexist(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_batch(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_compressed(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_exist( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1ExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1ExistenceProof(p, bs); - r.exist = 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_nonexist( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1NonExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1NonExistenceProof(p, bs); - r.nonexist = 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_batch( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1BatchProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1BatchProof(p, bs); - r.batch = 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_compressed( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1CompressedBatchProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1CompressedBatchProof(p, bs); - r.compressed = 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_CosmosIcs23V1ExistenceProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1ExistenceProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1ExistenceProof.Data memory r,) = - CosmosIcs23V1ExistenceProof._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_CosmosIcs23V1NonExistenceProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1NonExistenceProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1NonExistenceProof.Data memory r,) = - CosmosIcs23V1NonExistenceProof._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_CosmosIcs23V1BatchProof( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1BatchProof.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1BatchProof.Data memory r,) = - CosmosIcs23V1BatchProof._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_CosmosIcs23V1CompressedBatchProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1CompressedBatchProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1CompressedBatchProof.Data memory r,) = - CosmosIcs23V1CompressedBatchProof._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 += - CosmosIcs23V1ExistenceProof._encode_nested(r.exist, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1NonExistenceProof._encode_nested( - r.nonexist, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1BatchProof._encode_nested(r.batch, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1CompressedBatchProof._encode_nested( - r.compressed, 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( - CosmosIcs23V1ExistenceProof._estimate(r.exist) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1NonExistenceProof._estimate(r.nonexist) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1BatchProof._estimate(r.batch) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1CompressedBatchProof._estimate(r.compressed) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - CosmosIcs23V1ExistenceProof.store(input.exist, output.exist); - CosmosIcs23V1NonExistenceProof.store(input.nonexist, output.nonexist); - CosmosIcs23V1BatchProof.store(input.batch, output.batch); - CosmosIcs23V1CompressedBatchProof.store( - input.compressed, output.compressed - ); - } - - //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 CosmosIcs23V1CommitmentProof - -library CosmosIcs23V1LeafOp { - //struct definition - struct Data { - CosmosIcs23V1GlobalEnums.HashOp hash; - CosmosIcs23V1GlobalEnums.HashOp prehash_key; - CosmosIcs23V1GlobalEnums.HashOp prehash_value; - CosmosIcs23V1GlobalEnums.LengthOp length; - bytes prefix; - } - - // 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_hash(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_prehash_key(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_prehash_value(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_length(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_prefix(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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - CosmosIcs23V1GlobalEnums.HashOp x = - CosmosIcs23V1GlobalEnums.decode_HashOp(tmp); - r.hash = 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_prehash_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - CosmosIcs23V1GlobalEnums.HashOp x = - CosmosIcs23V1GlobalEnums.decode_HashOp(tmp); - r.prehash_key = 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_prehash_value( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - CosmosIcs23V1GlobalEnums.HashOp x = - CosmosIcs23V1GlobalEnums.decode_HashOp(tmp); - r.prehash_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 - * @return The number of bytes decoded - */ - function _read_length( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - CosmosIcs23V1GlobalEnums.LengthOp x = - CosmosIcs23V1GlobalEnums.decode_LengthOp(tmp); - r.length = 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_prefix( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.prefix = 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 (uint256(r.hash) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_hash = CosmosIcs23V1GlobalEnums.encode_HashOp(r.hash); - pointer += ProtoBufRuntime._encode_enum(_enum_hash, pointer, bs); - } - if (uint256(r.prehash_key) != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_prehash_key = - CosmosIcs23V1GlobalEnums.encode_HashOp(r.prehash_key); - pointer += - ProtoBufRuntime._encode_enum(_enum_prehash_key, pointer, bs); - } - if (uint256(r.prehash_value) != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_prehash_value = - CosmosIcs23V1GlobalEnums.encode_HashOp(r.prehash_value); - pointer += - ProtoBufRuntime._encode_enum(_enum_prehash_value, pointer, bs); - } - if (uint256(r.length) != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_length = - CosmosIcs23V1GlobalEnums.encode_LengthOp(r.length); - pointer += ProtoBufRuntime._encode_enum(_enum_length, pointer, bs); - } - if (r.prefix.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.prefix, 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( - CosmosIcs23V1GlobalEnums.encode_HashOp(r.hash) - ); - e += 1 - + ProtoBufRuntime._sz_enum( - CosmosIcs23V1GlobalEnums.encode_HashOp(r.prehash_key) - ); - e += 1 - + ProtoBufRuntime._sz_enum( - CosmosIcs23V1GlobalEnums.encode_HashOp(r.prehash_value) - ); - e += 1 - + ProtoBufRuntime._sz_enum( - CosmosIcs23V1GlobalEnums.encode_LengthOp(r.length) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.prefix.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.hash) != 0) { - return false; - } - - if (uint256(r.prehash_key) != 0) { - return false; - } - - if (uint256(r.prehash_value) != 0) { - return false; - } - - if (uint256(r.length) != 0) { - return false; - } - - if (r.prefix.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.hash = input.hash; - output.prehash_key = input.prehash_key; - output.prehash_value = input.prehash_value; - output.length = input.length; - output.prefix = input.prefix; - } - - //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 CosmosIcs23V1LeafOp - -library CosmosIcs23V1InnerOp { - //struct definition - struct Data { - CosmosIcs23V1GlobalEnums.HashOp hash; - bytes prefix; - bytes suffix; - } - - // 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_hash(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_prefix(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_suffix(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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - CosmosIcs23V1GlobalEnums.HashOp x = - CosmosIcs23V1GlobalEnums.decode_HashOp(tmp); - r.hash = 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_prefix( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.prefix = 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_suffix( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.suffix = 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 (uint256(r.hash) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_hash = CosmosIcs23V1GlobalEnums.encode_HashOp(r.hash); - pointer += ProtoBufRuntime._encode_enum(_enum_hash, pointer, bs); - } - if (r.prefix.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.prefix, pointer, bs); - } - if (r.suffix.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.suffix, 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( - CosmosIcs23V1GlobalEnums.encode_HashOp(r.hash) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.prefix.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.suffix.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.hash) != 0) { - return false; - } - - if (r.prefix.length != 0) { - return false; - } - - if (r.suffix.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.hash = input.hash; - output.prefix = input.prefix; - output.suffix = input.suffix; - } - - //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 CosmosIcs23V1InnerOp - -library CosmosIcs23V1ProofSpec { - //struct definition - struct Data { - CosmosIcs23V1LeafOp.Data leaf_spec; - CosmosIcs23V1InnerSpec.Data inner_spec; - int32 max_depth; - int32 min_depth; - } - - // 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_leaf_spec(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_inner_spec(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_max_depth(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_min_depth(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_leaf_spec( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1LeafOp.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1LeafOp(p, bs); - r.leaf_spec = 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_inner_spec( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1InnerSpec.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1InnerSpec(p, bs); - r.inner_spec = 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_max_depth( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.max_depth = 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_min_depth( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.min_depth = 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_CosmosIcs23V1LeafOp( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1LeafOp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1LeafOp.Data memory r,) = - CosmosIcs23V1LeafOp._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_CosmosIcs23V1InnerSpec( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1InnerSpec.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1InnerSpec.Data memory r,) = - CosmosIcs23V1InnerSpec._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 += CosmosIcs23V1LeafOp._encode_nested(r.leaf_spec, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - CosmosIcs23V1InnerSpec._encode_nested(r.inner_spec, pointer, bs); - - if (r.max_depth != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int32(r.max_depth, pointer, bs); - } - if (r.min_depth != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int32(r.min_depth, 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( - CosmosIcs23V1LeafOp._estimate(r.leaf_spec) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1InnerSpec._estimate(r.inner_spec) - ); - e += 1 + ProtoBufRuntime._sz_int32(r.max_depth); - e += 1 + ProtoBufRuntime._sz_int32(r.min_depth); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.max_depth != 0) { - return false; - } - - if (r.min_depth != 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 { - CosmosIcs23V1LeafOp.store(input.leaf_spec, output.leaf_spec); - CosmosIcs23V1InnerSpec.store(input.inner_spec, output.inner_spec); - output.max_depth = input.max_depth; - output.min_depth = input.min_depth; - } - - //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 CosmosIcs23V1ProofSpec - -library CosmosIcs23V1InnerSpec { - //struct definition - struct Data { - int32[] child_order; - int32 child_size; - int32 min_prefix_length; - int32 max_prefix_length; - bytes empty_child; - CosmosIcs23V1GlobalEnums.HashOp hash; - } - - // 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[7] 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) { - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - pointer += _read_packed_repeated_child_order(pointer, bs, r); - } else { - pointer += _read_unpacked_repeated_child_order( - pointer, bs, nil(), counters - ); - } - } else if (fieldId == 2) { - pointer += _read_child_size(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_min_prefix_length(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_max_prefix_length(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_empty_child(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_hash(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.child_order.length == 0); - r.child_order = new int32[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if ( - fieldId == 1 && wireType != ProtoBufRuntime.WireType.LengthDelim - ) { - pointer += _read_unpacked_repeated_child_order( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_child_order( - uint256 p, - bytes memory bs, - Data memory r, - uint256[7] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.child_order[r.child_order.length - counters[1]] = x; - counters[1] -= 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_packed_repeated_child_order( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - p += size; - uint256 count = - ProtoBufRuntime._count_packed_repeated_varint(p, len, bs); - r.child_order = new int32[](count); - for (uint256 i; i < count; i++) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - p += sz; - r.child_order[i] = x; - } - return size + len; - } - - /** - * @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_child_size( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.child_size = 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_min_prefix_length( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.min_prefix_length = 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_max_prefix_length( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.max_prefix_length = 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_empty_child( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.empty_child = 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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - CosmosIcs23V1GlobalEnums.HashOp x = - CosmosIcs23V1GlobalEnums.decode_HashOp(tmp); - r.hash = 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; - uint256 i; - if (r.child_order.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_varint( - ProtoBufRuntime._estimate_packed_repeated_int32(r.child_order), - pointer, - bs - ); - for (i = 0; i < r.child_order.length; i++) { - pointer += - ProtoBufRuntime._encode_int32(r.child_order[i], pointer, bs); - } - } - if (r.child_size != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int32(r.child_size, pointer, bs); - } - if (r.min_prefix_length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_int32(r.min_prefix_length, pointer, bs); - } - if (r.max_prefix_length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_int32(r.max_prefix_length, pointer, bs); - } - if (r.empty_child.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.empty_child, pointer, bs); - } - if (uint256(r.hash) != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_hash = CosmosIcs23V1GlobalEnums.encode_HashOp(r.hash); - pointer += ProtoBufRuntime._encode_enum(_enum_hash, 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( - ProtoBufRuntime._estimate_packed_repeated_int32(r.child_order) - ); - e += 1 + ProtoBufRuntime._sz_int32(r.child_size); - e += 1 + ProtoBufRuntime._sz_int32(r.min_prefix_length); - e += 1 + ProtoBufRuntime._sz_int32(r.max_prefix_length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.empty_child.length); - e += 1 - + ProtoBufRuntime._sz_enum( - CosmosIcs23V1GlobalEnums.encode_HashOp(r.hash) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.child_order.length != 0) { - return false; - } - - if (r.child_size != 0) { - return false; - } - - if (r.min_prefix_length != 0) { - return false; - } - - if (r.max_prefix_length != 0) { - return false; - } - - if (r.empty_child.length != 0) { - return false; - } - - if (uint256(r.hash) != 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.child_order = input.child_order; - output.child_size = input.child_size; - output.min_prefix_length = input.min_prefix_length; - output.max_prefix_length = input.max_prefix_length; - output.empty_child = input.empty_child; - output.hash = input.hash; - } - - //array helpers for ChildOrder - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addChildOrder(Data memory self, int32 value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - int32[] memory tmp = new int32[](self.child_order.length + 1); - for (uint256 i; i < self.child_order.length; i++) { - tmp[i] = self.child_order[i]; - } - tmp[self.child_order.length] = value; - self.child_order = 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 CosmosIcs23V1InnerSpec - -library CosmosIcs23V1BatchProof { - //struct definition - struct Data { - CosmosIcs23V1BatchEntry.Data[] entries; - } - - // 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[2] 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_unpacked_repeated_entries( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.entries.length == 0); - r.entries = new CosmosIcs23V1BatchEntry.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_entries(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_entries( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosIcs23V1BatchEntry.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1BatchEntry(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.entries[r.entries.length - counters[1]] = x; - counters[1] -= 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_CosmosIcs23V1BatchEntry( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1BatchEntry.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1BatchEntry.Data memory r,) = - CosmosIcs23V1BatchEntry._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.entries.length != 0) { - for (i = 0; i < r.entries.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1BatchEntry._encode_nested( - r.entries[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; - for (i = 0; i < r.entries.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1BatchEntry._estimate(r.entries[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.entries.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 { - for (uint256 i1 = 0; i1 < input.entries.length; i1++) { - output.entries.push(input.entries[i1]); - } - } - - //array helpers for Entries - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addEntries( - Data memory self, - CosmosIcs23V1BatchEntry.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosIcs23V1BatchEntry.Data[] memory tmp = - new CosmosIcs23V1BatchEntry.Data[](self.entries.length + 1); - for (uint256 i; i < self.entries.length; i++) { - tmp[i] = self.entries[i]; - } - tmp[self.entries.length] = value; - self.entries = 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 CosmosIcs23V1BatchProof - -library CosmosIcs23V1BatchEntry { - //struct definition - struct Data { - CosmosIcs23V1ExistenceProof.Data exist; - CosmosIcs23V1NonExistenceProof.Data nonexist; - } - - // 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_exist(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_nonexist(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_exist( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1ExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1ExistenceProof(p, bs); - r.exist = 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_nonexist( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1NonExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1NonExistenceProof(p, bs); - r.nonexist = 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_CosmosIcs23V1ExistenceProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1ExistenceProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1ExistenceProof.Data memory r,) = - CosmosIcs23V1ExistenceProof._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_CosmosIcs23V1NonExistenceProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1NonExistenceProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1NonExistenceProof.Data memory r,) = - CosmosIcs23V1NonExistenceProof._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 += - CosmosIcs23V1ExistenceProof._encode_nested(r.exist, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1NonExistenceProof._encode_nested( - r.nonexist, 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( - CosmosIcs23V1ExistenceProof._estimate(r.exist) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1NonExistenceProof._estimate(r.nonexist) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - CosmosIcs23V1ExistenceProof.store(input.exist, output.exist); - CosmosIcs23V1NonExistenceProof.store(input.nonexist, output.nonexist); - } - - //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 CosmosIcs23V1BatchEntry - -library CosmosIcs23V1CompressedBatchProof { - //struct definition - struct Data { - CosmosIcs23V1CompressedBatchEntry.Data[] entries; - CosmosIcs23V1InnerOp.Data[] lookup_inners; - } - - // 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_unpacked_repeated_entries( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_lookup_inners( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.entries.length == 0); - r.entries = - new CosmosIcs23V1CompressedBatchEntry.Data[](counters[1]); - } - if (counters[2] > 0) { - require(r.lookup_inners.length == 0); - r.lookup_inners = new CosmosIcs23V1InnerOp.Data[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_entries(pointer, bs, r, counters); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_lookup_inners( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_entries( - 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. - */ - (CosmosIcs23V1CompressedBatchEntry.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1CompressedBatchEntry(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.entries[r.entries.length - counters[1]] = x; - counters[1] -= 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_lookup_inners( - 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. - */ - (CosmosIcs23V1InnerOp.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1InnerOp(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.lookup_inners[r.lookup_inners.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_CosmosIcs23V1CompressedBatchEntry( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1CompressedBatchEntry.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1CompressedBatchEntry.Data memory r,) = - CosmosIcs23V1CompressedBatchEntry._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_CosmosIcs23V1InnerOp( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1InnerOp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1InnerOp.Data memory r,) = - CosmosIcs23V1InnerOp._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.entries.length != 0) { - for (i = 0; i < r.entries.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1CompressedBatchEntry._encode_nested( - r.entries[i], pointer, bs - ); - } - } - if (r.lookup_inners.length != 0) { - for (i = 0; i < r.lookup_inners.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1InnerOp._encode_nested( - r.lookup_inners[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; - for (i = 0; i < r.entries.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1CompressedBatchEntry._estimate(r.entries[i]) - ); - } - for (i = 0; i < r.lookup_inners.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1InnerOp._estimate(r.lookup_inners[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.entries.length != 0) { - return false; - } - - if (r.lookup_inners.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 { - for (uint256 i1 = 0; i1 < input.entries.length; i1++) { - output.entries.push(input.entries[i1]); - } - - for (uint256 i2 = 0; i2 < input.lookup_inners.length; i2++) { - output.lookup_inners.push(input.lookup_inners[i2]); - } - } - - //array helpers for Entries - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addEntries( - Data memory self, - CosmosIcs23V1CompressedBatchEntry.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosIcs23V1CompressedBatchEntry.Data[] memory tmp = new CosmosIcs23V1CompressedBatchEntry - .Data[](self.entries.length + 1); - for (uint256 i; i < self.entries.length; i++) { - tmp[i] = self.entries[i]; - } - tmp[self.entries.length] = value; - self.entries = tmp; - } - - //array helpers for LookupInners - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addLookupInners( - Data memory self, - CosmosIcs23V1InnerOp.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosIcs23V1InnerOp.Data[] memory tmp = - new CosmosIcs23V1InnerOp.Data[](self.lookup_inners.length + 1); - for (uint256 i; i < self.lookup_inners.length; i++) { - tmp[i] = self.lookup_inners[i]; - } - tmp[self.lookup_inners.length] = value; - self.lookup_inners = 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 CosmosIcs23V1CompressedBatchProof - -library CosmosIcs23V1CompressedBatchEntry { - //struct definition - struct Data { - CosmosIcs23V1CompressedExistenceProof.Data exist; - CosmosIcs23V1CompressedNonExistenceProof.Data nonexist; - } - - // 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_exist(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_nonexist(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_exist( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1CompressedExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1CompressedExistenceProof(p, bs); - r.exist = 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_nonexist( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1CompressedNonExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1CompressedNonExistenceProof(p, bs); - r.nonexist = 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_CosmosIcs23V1CompressedExistenceProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1CompressedExistenceProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1CompressedExistenceProof.Data memory r,) = - CosmosIcs23V1CompressedExistenceProof._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_CosmosIcs23V1CompressedNonExistenceProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1CompressedNonExistenceProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1CompressedNonExistenceProof.Data memory r,) = - CosmosIcs23V1CompressedNonExistenceProof._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 += CosmosIcs23V1CompressedExistenceProof._encode_nested( - r.exist, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1CompressedNonExistenceProof._encode_nested( - r.nonexist, 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( - CosmosIcs23V1CompressedExistenceProof._estimate(r.exist) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1CompressedNonExistenceProof._estimate(r.nonexist) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - CosmosIcs23V1CompressedExistenceProof.store(input.exist, output.exist); - CosmosIcs23V1CompressedNonExistenceProof.store( - input.nonexist, output.nonexist - ); - } - - //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 CosmosIcs23V1CompressedBatchEntry - -library CosmosIcs23V1CompressedExistenceProof { - //struct definition - struct Data { - bytes key; - bytes value; - CosmosIcs23V1LeafOp.Data leaf; - int32[] path; - } - - // 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[5] 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_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_value(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_leaf(pointer, bs, r); - } else if (fieldId == 4) { - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - pointer += _read_packed_repeated_path(pointer, bs, r); - } else { - pointer += _read_unpacked_repeated_path( - pointer, bs, nil(), counters - ); - } - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[4] > 0) { - require(r.path.length == 0); - r.path = new int32[](counters[4]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if ( - fieldId == 4 && wireType != ProtoBufRuntime.WireType.LengthDelim - ) { - pointer += - _read_unpacked_repeated_path(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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key = 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_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; - } - - /** - * @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_leaf( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1LeafOp.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1LeafOp(p, bs); - r.leaf = 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_path( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.path[r.path.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 - * @return The number of bytes decoded - */ - function _read_packed_repeated_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - p += size; - uint256 count = - ProtoBufRuntime._count_packed_repeated_varint(p, len, bs); - r.path = new int32[](count); - for (uint256 i; i < count; i++) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - p += sz; - r.path[i] = x; - } - return size + len; - } - - // 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_CosmosIcs23V1LeafOp( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1LeafOp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1LeafOp.Data memory r,) = - CosmosIcs23V1LeafOp._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.key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key, pointer, bs); - } - if (r.value.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.value, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1LeafOp._encode_nested(r.leaf, pointer, bs); - - if (r.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_varint( - ProtoBufRuntime._estimate_packed_repeated_int32(r.path), - pointer, - bs - ); - for (i = 0; i < r.path.length; i++) { - pointer += ProtoBufRuntime._encode_int32(r.path[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; - e += 1 + ProtoBufRuntime._sz_lendelim(r.key.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.value.length); - e += 1 - + ProtoBufRuntime._sz_lendelim(CosmosIcs23V1LeafOp._estimate(r.leaf)); - e += 1 - + ProtoBufRuntime._sz_lendelim( - ProtoBufRuntime._estimate_packed_repeated_int32(r.path) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key.length != 0) { - return false; - } - - if (r.value.length != 0) { - return false; - } - - if (r.path.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.key = input.key; - output.value = input.value; - CosmosIcs23V1LeafOp.store(input.leaf, output.leaf); - output.path = input.path; - } - - //array helpers for Path - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPath(Data memory self, int32 value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - int32[] memory tmp = new int32[](self.path.length + 1); - for (uint256 i; i < self.path.length; i++) { - tmp[i] = self.path[i]; - } - tmp[self.path.length] = value; - self.path = 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 CosmosIcs23V1CompressedExistenceProof - -library CosmosIcs23V1CompressedNonExistenceProof { - //struct definition - struct Data { - bytes key; - CosmosIcs23V1CompressedExistenceProof.Data left; - CosmosIcs23V1CompressedExistenceProof.Data right; - } - - // 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_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_left(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_right(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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key = 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_left( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1CompressedExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1CompressedExistenceProof(p, bs); - r.left = 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_right( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosIcs23V1CompressedExistenceProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1CompressedExistenceProof(p, bs); - r.right = 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_CosmosIcs23V1CompressedExistenceProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1CompressedExistenceProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1CompressedExistenceProof.Data memory r,) = - CosmosIcs23V1CompressedExistenceProof._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 (r.key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1CompressedExistenceProof._encode_nested( - r.left, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1CompressedExistenceProof._encode_nested( - r.right, 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.key.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1CompressedExistenceProof._estimate(r.left) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1CompressedExistenceProof._estimate(r.right) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key.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.key = input.key; - CosmosIcs23V1CompressedExistenceProof.store(input.left, output.left); - CosmosIcs23V1CompressedExistenceProof.store(input.right, output.right); - } - - //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 CosmosIcs23V1CompressedNonExistenceProof - -library CosmosIcs23V1GlobalEnums { - //enum definition - // Solidity enum definitions - enum HashOp { - NO_HASH, - SHA256, - SHA512, - KECCAK, - RIPEMD160, - BITCOIN, - SHA512_256 - } - - // Solidity enum encoder - function encode_HashOp(HashOp x) internal pure returns (int32) { - if (x == HashOp.NO_HASH) { - return 0; - } - - if (x == HashOp.SHA256) { - return 1; - } - - if (x == HashOp.SHA512) { - return 2; - } - - if (x == HashOp.KECCAK) { - return 3; - } - - if (x == HashOp.RIPEMD160) { - return 4; - } - - if (x == HashOp.BITCOIN) { - return 5; - } - - if (x == HashOp.SHA512_256) { - return 6; - } - revert(); - } - - // Solidity enum decoder - function decode_HashOp(int64 x) internal pure returns (HashOp) { - if (x == 0) { - return HashOp.NO_HASH; - } - - if (x == 1) { - return HashOp.SHA256; - } - - if (x == 2) { - return HashOp.SHA512; - } - - if (x == 3) { - return HashOp.KECCAK; - } - - if (x == 4) { - return HashOp.RIPEMD160; - } - - if (x == 5) { - return HashOp.BITCOIN; - } - - if (x == 6) { - return HashOp.SHA512_256; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_HashOp(HashOp[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_HashOp(a[i])); - } - return e; - } - - // Solidity enum definitions - enum LengthOp { - NO_PREFIX, - VAR_PROTO, - VAR_RLP, - FIXED32_BIG, - FIXED32_LITTLE, - FIXED64_BIG, - FIXED64_LITTLE, - REQUIRE_32_BYTES, - REQUIRE_64_BYTES - } - - // Solidity enum encoder - function encode_LengthOp(LengthOp x) internal pure returns (int32) { - if (x == LengthOp.NO_PREFIX) { - return 0; - } - - if (x == LengthOp.VAR_PROTO) { - return 1; - } - - if (x == LengthOp.VAR_RLP) { - return 2; - } - - if (x == LengthOp.FIXED32_BIG) { - return 3; - } - - if (x == LengthOp.FIXED32_LITTLE) { - return 4; - } - - if (x == LengthOp.FIXED64_BIG) { - return 5; - } - - if (x == LengthOp.FIXED64_LITTLE) { - return 6; - } - - if (x == LengthOp.REQUIRE_32_BYTES) { - return 7; - } - - if (x == LengthOp.REQUIRE_64_BYTES) { - return 8; - } - revert(); - } - - // Solidity enum decoder - function decode_LengthOp(int64 x) internal pure returns (LengthOp) { - if (x == 0) { - return LengthOp.NO_PREFIX; - } - - if (x == 1) { - return LengthOp.VAR_PROTO; - } - - if (x == 2) { - return LengthOp.VAR_RLP; - } - - if (x == 3) { - return LengthOp.FIXED32_BIG; - } - - if (x == 4) { - return LengthOp.FIXED32_LITTLE; - } - - if (x == 5) { - return LengthOp.FIXED64_BIG; - } - - if (x == 6) { - return LengthOp.FIXED64_LITTLE; - } - - if (x == 7) { - return LengthOp.REQUIRE_32_BYTES; - } - - if (x == 8) { - return LengthOp.REQUIRE_64_BYTES; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_LengthOp(LengthOp[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_LengthOp(a[i])); - } - return e; - } -} -//library CosmosIcs23V1GlobalEnums diff --git a/evm/contracts/proto/cosmos/upgrade/v1beta1/upgrade.sol b/evm/contracts/proto/cosmos/upgrade/v1beta1/upgrade.sol deleted file mode 100644 index 8d34b94fe6..0000000000 --- a/evm/contracts/proto/cosmos/upgrade/v1beta1/upgrade.sol +++ /dev/null @@ -1,1181 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../../ProtoBufRuntime.sol"; -import "../../../GoogleProtobufAny.sol"; -import "../../../cosmos_proto/cosmos.sol"; - -library CosmosUpgradeV1beta1Plan { - //struct definition - struct Data { - string name; - GoogleProtobufTimestamp.Data time; - int64 height; - string info; - GoogleProtobufAny.Data upgraded_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_name(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_time(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_height(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_info(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_upgraded_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_name( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.name = 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_time( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufTimestamp.Data memory x, uint256 sz) = - _decode_GoogleProtobufTimestamp(p, bs); - r.time = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(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_info( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.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_upgraded_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.upgraded_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_GoogleProtobufTimestamp( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufTimestamp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufTimestamp.Data memory r,) = - GoogleProtobufTimestamp._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; - - if (bytes(r.name).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.name, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufTimestamp._encode_nested(r.time, pointer, bs); - - if (r.height != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.height, pointer, bs); - } - if (bytes(r.info).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.info, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufAny._encode_nested( - r.upgraded_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.name).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufTimestamp._estimate(r.time) - ); - e += 1 + ProtoBufRuntime._sz_int64(r.height); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.info).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.upgraded_client_state) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.name).length != 0) { - return false; - } - - if (r.height != 0) { - return false; - } - - if (bytes(r.info).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.name = input.name; - GoogleProtobufTimestamp.store(input.time, output.time); - output.height = input.height; - output.info = input.info; - GoogleProtobufAny.store( - input.upgraded_client_state, output.upgraded_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 CosmosUpgradeV1beta1Plan - -library CosmosUpgradeV1beta1SoftwareUpgradeProposal { - //struct definition - struct Data { - string title; - string description; - CosmosUpgradeV1beta1Plan.Data plan; - } - - // 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_plan(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_plan( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosUpgradeV1beta1Plan.Data memory x, uint256 sz) = - _decode_CosmosUpgradeV1beta1Plan(p, bs); - r.plan = 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_CosmosUpgradeV1beta1Plan( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosUpgradeV1beta1Plan.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosUpgradeV1beta1Plan.Data memory r,) = - CosmosUpgradeV1beta1Plan._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); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosUpgradeV1beta1Plan._encode_nested(r.plan, 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( - CosmosUpgradeV1beta1Plan._estimate(r.plan) - ); - 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; - } - - 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; - CosmosUpgradeV1beta1Plan.store(input.plan, output.plan); - } - - //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 CosmosUpgradeV1beta1SoftwareUpgradeProposal - -library CosmosUpgradeV1beta1CancelSoftwareUpgradeProposal { - //struct definition - struct Data { - string title; - string description; - } - - // 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 { - 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; - } - - // 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); - } - 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); - 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; - } - - 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; - } - - //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 CosmosUpgradeV1beta1CancelSoftwareUpgradeProposal - -library CosmosUpgradeV1beta1ModuleVersion { - //struct definition - struct Data { - string name; - uint64 version; - } - - // 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_name(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_version(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_name( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.name = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.version = 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 (bytes(r.name).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.name, pointer, bs); - } - if (r.version != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.version, 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.name).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.version); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.name).length != 0) { - return false; - } - - if (r.version != 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.name = input.name; - output.version = input.version; - } - - //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 CosmosUpgradeV1beta1ModuleVersion diff --git a/evm/contracts/proto/cosmos_proto/cosmos.sol b/evm/contracts/proto/cosmos_proto/cosmos.sol deleted file mode 100644 index e3f1f1c62a..0000000000 --- a/evm/contracts/proto/cosmos_proto/cosmos.sol +++ /dev/null @@ -1,692 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../ProtoBufRuntime.sol"; -import "../GoogleProtobufAny.sol"; - -library Cosmos_protoInterfaceDescriptor { - //struct definition - struct Data { - string name; - string description; - } - - // 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_name(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_description(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_name( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.name = 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; - } - - // 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.name).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.name, 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); - } - 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.name).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.description).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.name).length != 0) { - return false; - } - - if (bytes(r.description).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.name = input.name; - output.description = input.description; - } - - //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 Cosmos_protoInterfaceDescriptor - -library Cosmos_protoScalarDescriptor { - //struct definition - struct Data { - string name; - string description; - CosmosProtoCosmosProtoGlobalEnums.ScalarType[] field_type; - } - - // 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[4] 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_name(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_description(pointer, bs, r); - } else if (fieldId == 3) { - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - pointer += _read_packed_repeated_field_type(pointer, bs, r); - } else { - pointer += _read_unpacked_repeated_field_type( - pointer, bs, nil(), counters - ); - } - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[3] > 0) { - require(r.field_type.length == 0); - r.field_type = - new CosmosProtoCosmosProtoGlobalEnums.ScalarType[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if ( - fieldId == 3 && wireType != ProtoBufRuntime.WireType.LengthDelim - ) { - pointer += - _read_unpacked_repeated_field_type(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_name( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.name = 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_field_type( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - CosmosProtoCosmosProtoGlobalEnums.ScalarType x = - CosmosProtoCosmosProtoGlobalEnums.decode_ScalarType(tmp); - if (isNil(r)) { - counters[3] += 1; - } else { - r.field_type[r.field_type.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_packed_repeated_field_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - p += size; - uint256 count = - ProtoBufRuntime._count_packed_repeated_varint(p, len, bs); - r.field_type = new CosmosProtoCosmosProtoGlobalEnums.ScalarType[](count); - for (uint256 i; i < count; i++) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - CosmosProtoCosmosProtoGlobalEnums.ScalarType x = - CosmosProtoCosmosProtoGlobalEnums.decode_ScalarType(tmp); - p += sz; - r.field_type[i] = x; - } - return size + len; - } - - // 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.name).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.name, 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 (r.field_type.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_varint( - CosmosProtoCosmosProtoGlobalEnums - .estimate_packed_repeated_ScalarType(r.field_type), - pointer, - bs - ); - for (i = 0; i < r.field_type.length; i++) { - int32 _enum_field_type = CosmosProtoCosmosProtoGlobalEnums - .encode_ScalarType(r.field_type[i]); - pointer += - ProtoBufRuntime._encode_enum(_enum_field_type, 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.name).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.description).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosProtoCosmosProtoGlobalEnums - .estimate_packed_repeated_ScalarType(r.field_type) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.name).length != 0) { - return false; - } - - if (bytes(r.description).length != 0) { - return false; - } - - if (r.field_type.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.name = input.name; - output.description = input.description; - output.field_type = input.field_type; - } - - //array helpers for FieldType - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addFieldType( - Data memory self, - CosmosProtoCosmosProtoGlobalEnums.ScalarType value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosProtoCosmosProtoGlobalEnums.ScalarType[] memory tmp = new CosmosProtoCosmosProtoGlobalEnums - .ScalarType[](self.field_type.length + 1); - for (uint256 i; i < self.field_type.length; i++) { - tmp[i] = self.field_type[i]; - } - tmp[self.field_type.length] = value; - self.field_type = 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 Cosmos_protoScalarDescriptor - -library CosmosProtoCosmosProtoGlobalEnums { - //enum definition - // Solidity enum definitions - enum ScalarType { - SCALAR_TYPE_UNSPECIFIED, - SCALAR_TYPE_STRING, - SCALAR_TYPE_BYTES - } - - // Solidity enum encoder - function encode_ScalarType(ScalarType x) internal pure returns (int32) { - if (x == ScalarType.SCALAR_TYPE_UNSPECIFIED) { - return 0; - } - - if (x == ScalarType.SCALAR_TYPE_STRING) { - return 1; - } - - if (x == ScalarType.SCALAR_TYPE_BYTES) { - return 2; - } - revert(); - } - - // Solidity enum decoder - function decode_ScalarType(int64 x) internal pure returns (ScalarType) { - if (x == 0) { - return ScalarType.SCALAR_TYPE_UNSPECIFIED; - } - - if (x == 1) { - return ScalarType.SCALAR_TYPE_STRING; - } - - if (x == 2) { - return ScalarType.SCALAR_TYPE_BYTES; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_ScalarType(ScalarType[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_ScalarType(a[i])); - } - return e; - } -} -//library CosmosProtoCosmosProtoGlobalEnums diff --git a/evm/contracts/proto/google/api/http.sol b/evm/contracts/proto/google/api/http.sol deleted file mode 100644 index 74f4bf0d34..0000000000 --- a/evm/contracts/proto/google/api/http.sol +++ /dev/null @@ -1,1195 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../ProtoBufRuntime.sol"; -import "../../GoogleProtobufAny.sol"; - -library GoogleApiHttp { - //struct definition - struct Data { - GoogleApiHttpRule.Data[] rules; - bool fully_decode_reserved_expansion; - } - - // 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_unpacked_repeated_rules(pointer, bs, nil(), counters); - } else if (fieldId == 2) { - pointer += _read_fully_decode_reserved_expansion(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.rules.length == 0); - r.rules = new GoogleApiHttpRule.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_rules(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_rules( - 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. - */ - (GoogleApiHttpRule.Data memory x, uint256 sz) = - _decode_GoogleApiHttpRule(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.rules[r.rules.length - counters[1]] = x; - counters[1] -= 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_fully_decode_reserved_expansion( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.fully_decode_reserved_expansion = 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_GoogleApiHttpRule( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleApiHttpRule.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleApiHttpRule.Data memory r,) = - GoogleApiHttpRule._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.rules.length != 0) { - for (i = 0; i < r.rules.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleApiHttpRule._encode_nested(r.rules[i], pointer, bs); - } - } - if (r.fully_decode_reserved_expansion != false) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool( - r.fully_decode_reserved_expansion, 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; - for (i = 0; i < r.rules.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleApiHttpRule._estimate(r.rules[i]) - ); - } - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.rules.length != 0) { - return false; - } - - if (r.fully_decode_reserved_expansion != false) { - 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 { - for (uint256 i1 = 0; i1 < input.rules.length; i1++) { - output.rules.push(input.rules[i1]); - } - - output.fully_decode_reserved_expansion = - input.fully_decode_reserved_expansion; - } - - //array helpers for Rules - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addRules( - Data memory self, - GoogleApiHttpRule.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - GoogleApiHttpRule.Data[] memory tmp = - new GoogleApiHttpRule.Data[](self.rules.length + 1); - for (uint256 i; i < self.rules.length; i++) { - tmp[i] = self.rules[i]; - } - tmp[self.rules.length] = value; - self.rules = 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 GoogleApiHttp - -library GoogleApiHttpRule { - //struct definition - struct Data { - string selector; - string get; - string put; - string post; - string delete_; - string patch; - GoogleApiCustomHttpPattern.Data custom; - string body; - string response_body; - GoogleApiHttpRule.Data[] additional_bindings; - } - - // 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[13] 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_selector(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_get(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_put(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_post(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_delete(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_patch(pointer, bs, r); - } else if (fieldId == 8) { - pointer += _read_custom(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_body(pointer, bs, r); - } else if (fieldId == 12) { - pointer += _read_response_body(pointer, bs, r); - } else if (fieldId == 11) { - pointer += _read_unpacked_repeated_additional_bindings( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[11] > 0) { - require(r.additional_bindings.length == 0); - r.additional_bindings = new GoogleApiHttpRule.Data[](counters[11]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 11) { - pointer += _read_unpacked_repeated_additional_bindings( - 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_selector( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.selector = 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_get( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.get = 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_put( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.put = 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_post( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.post = 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_delete( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.delete_ = 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_patch( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.patch = 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_custom( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleApiCustomHttpPattern.Data memory x, uint256 sz) = - _decode_GoogleApiCustomHttpPattern(p, bs); - r.custom = 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_body( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.body = 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_response_body( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.response_body = 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_additional_bindings( - uint256 p, - bytes memory bs, - Data memory r, - uint256[13] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (GoogleApiHttpRule.Data memory x, uint256 sz) = - _decode_GoogleApiHttpRule(p, bs); - if (isNil(r)) { - counters[11] += 1; - } else { - r.additional_bindings[r.additional_bindings.length - counters[11]] = - x; - counters[11] -= 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_GoogleApiCustomHttpPattern( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleApiCustomHttpPattern.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleApiCustomHttpPattern.Data memory r,) = - GoogleApiCustomHttpPattern._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_GoogleApiHttpRule( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleApiHttpRule.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleApiHttpRule.Data memory r,) = - GoogleApiHttpRule._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.selector).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.selector, pointer, bs); - } - if (bytes(r.get).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.get, pointer, bs); - } - if (bytes(r.put).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.put, pointer, bs); - } - if (bytes(r.post).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.post, pointer, bs); - } - if (bytes(r.delete_).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.delete_, pointer, bs); - } - if (bytes(r.patch).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.patch, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 8, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleApiCustomHttpPattern._encode_nested(r.custom, pointer, bs); - - if (bytes(r.body).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.body, pointer, bs); - } - if (bytes(r.response_body).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 12, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.response_body, pointer, bs); - } - if (r.additional_bindings.length != 0) { - for (i = 0; i < r.additional_bindings.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 11, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleApiHttpRule._encode_nested( - r.additional_bindings[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.selector).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.get).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.put).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.post).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.delete_).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.patch).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleApiCustomHttpPattern._estimate(r.custom) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.body).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.response_body).length); - for (i = 0; i < r.additional_bindings.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleApiHttpRule._estimate(r.additional_bindings[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.selector).length != 0) { - return false; - } - - if (bytes(r.get).length != 0) { - return false; - } - - if (bytes(r.put).length != 0) { - return false; - } - - if (bytes(r.post).length != 0) { - return false; - } - - if (bytes(r.delete_).length != 0) { - return false; - } - - if (bytes(r.patch).length != 0) { - return false; - } - - if (bytes(r.body).length != 0) { - return false; - } - - if (bytes(r.response_body).length != 0) { - return false; - } - - if (r.additional_bindings.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.selector = input.selector; - output.get = input.get; - output.put = input.put; - output.post = input.post; - output.delete_ = input.delete_; - output.patch = input.patch; - GoogleApiCustomHttpPattern.store(input.custom, output.custom); - output.body = input.body; - output.response_body = input.response_body; - - for (uint256 i11 = 0; i11 < input.additional_bindings.length; i11++) { - output.additional_bindings.push(input.additional_bindings[i11]); - } - } - - //array helpers for AdditionalBindings - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAdditionalBindings( - Data memory self, - GoogleApiHttpRule.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - GoogleApiHttpRule.Data[] memory tmp = - new GoogleApiHttpRule.Data[](self.additional_bindings.length + 1); - for (uint256 i; i < self.additional_bindings.length; i++) { - tmp[i] = self.additional_bindings[i]; - } - tmp[self.additional_bindings.length] = value; - self.additional_bindings = 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 GoogleApiHttpRule - -library GoogleApiCustomHttpPattern { - //struct definition - struct Data { - string kind; - string path; - } - - // 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_kind(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_path(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_kind( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.kind = 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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.path = 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 (bytes(r.kind).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.kind, pointer, bs); - } - if (bytes(r.path).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.path, 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.kind).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.path).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.kind).length != 0) { - return false; - } - - if (bytes(r.path).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.kind = input.kind; - output.path = input.path; - } - - //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 GoogleApiCustomHttpPattern diff --git a/evm/contracts/proto/ibc/applications/fee/v1/ack.sol b/evm/contracts/proto/ibc/applications/fee/v1/ack.sol deleted file mode 100644 index dfa5aa4b41..0000000000 --- a/evm/contracts/proto/ibc/applications/fee/v1/ack.sol +++ /dev/null @@ -1,287 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcApplicationsFeeV1IncentivizedAcknowledgement { - //struct definition - struct Data { - bytes app_acknowledgement; - string forward_relayer_address; - bool underlying_app_success; - } - - // 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_app_acknowledgement(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_forward_relayer_address(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_underlying_app_success(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_app_acknowledgement( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.app_acknowledgement = 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_forward_relayer_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.forward_relayer_address = 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_underlying_app_success( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.underlying_app_success = 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.app_acknowledgement.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.app_acknowledgement, pointer, bs - ); - } - if (bytes(r.forward_relayer_address).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.forward_relayer_address, pointer, bs - ); - } - if (r.underlying_app_success != false) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool( - r.underlying_app_success, 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.app_acknowledgement.length); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.forward_relayer_address).length); - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.app_acknowledgement.length != 0) { - return false; - } - - if (bytes(r.forward_relayer_address).length != 0) { - return false; - } - - if (r.underlying_app_success != false) { - 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.app_acknowledgement = input.app_acknowledgement; - output.forward_relayer_address = input.forward_relayer_address; - output.underlying_app_success = input.underlying_app_success; - } - - //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 IbcApplicationsFeeV1IncentivizedAcknowledgement diff --git a/evm/contracts/proto/ibc/applications/fee/v1/fee.sol b/evm/contracts/proto/ibc/applications/fee/v1/fee.sol deleted file mode 100644 index 38b9f50b9d..0000000000 --- a/evm/contracts/proto/ibc/applications/fee/v1/fee.sol +++ /dev/null @@ -1,1497 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../../cosmos/base/v1beta1/coin.sol"; - -import "../../../core/channel/v1/channel.sol"; - -library IbcApplicationsFeeV1Fee { - //struct definition - struct Data { - CosmosBaseV1beta1Coin.Data[] recv_fee; - CosmosBaseV1beta1Coin.Data[] ack_fee; - CosmosBaseV1beta1Coin.Data[] timeout_fee; - } - - // 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[4] 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_unpacked_repeated_recv_fee( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_ack_fee( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_timeout_fee( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.recv_fee.length == 0); - r.recv_fee = new CosmosBaseV1beta1Coin.Data[](counters[1]); - } - if (counters[2] > 0) { - require(r.ack_fee.length == 0); - r.ack_fee = new CosmosBaseV1beta1Coin.Data[](counters[2]); - } - if (counters[3] > 0) { - require(r.timeout_fee.length == 0); - r.timeout_fee = new CosmosBaseV1beta1Coin.Data[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_recv_fee(pointer, bs, r, counters); - } else if (fieldId == 2) { - pointer += - _read_unpacked_repeated_ack_fee(pointer, bs, r, counters); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_timeout_fee( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_recv_fee( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosBaseV1beta1Coin.Data memory x, uint256 sz) = - _decode_CosmosBaseV1beta1Coin(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.recv_fee[r.recv_fee.length - counters[1]] = x; - counters[1] -= 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_ack_fee( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosBaseV1beta1Coin.Data memory x, uint256 sz) = - _decode_CosmosBaseV1beta1Coin(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.ack_fee[r.ack_fee.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_timeout_fee( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosBaseV1beta1Coin.Data memory x, uint256 sz) = - _decode_CosmosBaseV1beta1Coin(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.timeout_fee[r.timeout_fee.length - counters[3]] = x; - counters[3] -= 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_CosmosBaseV1beta1Coin( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosBaseV1beta1Coin.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseV1beta1Coin.Data memory r,) = - CosmosBaseV1beta1Coin._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.recv_fee.length != 0) { - for (i = 0; i < r.recv_fee.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseV1beta1Coin._encode_nested( - r.recv_fee[i], pointer, bs - ); - } - } - if (r.ack_fee.length != 0) { - for (i = 0; i < r.ack_fee.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseV1beta1Coin._encode_nested( - r.ack_fee[i], pointer, bs - ); - } - } - if (r.timeout_fee.length != 0) { - for (i = 0; i < r.timeout_fee.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseV1beta1Coin._encode_nested( - r.timeout_fee[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; - for (i = 0; i < r.recv_fee.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseV1beta1Coin._estimate(r.recv_fee[i]) - ); - } - for (i = 0; i < r.ack_fee.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseV1beta1Coin._estimate(r.ack_fee[i]) - ); - } - for (i = 0; i < r.timeout_fee.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseV1beta1Coin._estimate(r.timeout_fee[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.recv_fee.length != 0) { - return false; - } - - if (r.ack_fee.length != 0) { - return false; - } - - if (r.timeout_fee.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 { - for (uint256 i1 = 0; i1 < input.recv_fee.length; i1++) { - output.recv_fee.push(input.recv_fee[i1]); - } - - for (uint256 i2 = 0; i2 < input.ack_fee.length; i2++) { - output.ack_fee.push(input.ack_fee[i2]); - } - - for (uint256 i3 = 0; i3 < input.timeout_fee.length; i3++) { - output.timeout_fee.push(input.timeout_fee[i3]); - } - } - - //array helpers for RecvFee - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addRecvFee( - Data memory self, - CosmosBaseV1beta1Coin.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosBaseV1beta1Coin.Data[] memory tmp = - new CosmosBaseV1beta1Coin.Data[](self.recv_fee.length + 1); - for (uint256 i; i < self.recv_fee.length; i++) { - tmp[i] = self.recv_fee[i]; - } - tmp[self.recv_fee.length] = value; - self.recv_fee = tmp; - } - - //array helpers for AckFee - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAckFee( - Data memory self, - CosmosBaseV1beta1Coin.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosBaseV1beta1Coin.Data[] memory tmp = - new CosmosBaseV1beta1Coin.Data[](self.ack_fee.length + 1); - for (uint256 i; i < self.ack_fee.length; i++) { - tmp[i] = self.ack_fee[i]; - } - tmp[self.ack_fee.length] = value; - self.ack_fee = tmp; - } - - //array helpers for TimeoutFee - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addTimeoutFee( - Data memory self, - CosmosBaseV1beta1Coin.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosBaseV1beta1Coin.Data[] memory tmp = - new CosmosBaseV1beta1Coin.Data[](self.timeout_fee.length + 1); - for (uint256 i; i < self.timeout_fee.length; i++) { - tmp[i] = self.timeout_fee[i]; - } - tmp[self.timeout_fee.length] = value; - self.timeout_fee = 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 IbcApplicationsFeeV1Fee - -library IbcApplicationsFeeV1PacketFee { - //struct definition - struct Data { - IbcApplicationsFeeV1Fee.Data fee; - string refund_address; - string[] relayers; - } - - // 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[4] 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_fee(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_refund_address(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_relayers( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[3] > 0) { - require(r.relayers.length == 0); - r.relayers = new string[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 3) { - pointer += - _read_unpacked_repeated_relayers(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_fee( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcApplicationsFeeV1Fee.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1Fee(p, bs); - r.fee = 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_refund_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.refund_address = 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_relayers( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.relayers[r.relayers.length - counters[3]] = x; - counters[3] -= 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_IbcApplicationsFeeV1Fee( - uint256 p, - bytes memory bs - ) internal pure returns (IbcApplicationsFeeV1Fee.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1Fee.Data memory r,) = - IbcApplicationsFeeV1Fee._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 += IbcApplicationsFeeV1Fee._encode_nested(r.fee, pointer, bs); - - if (bytes(r.refund_address).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.refund_address, pointer, bs); - } - if (r.relayers.length != 0) { - for (i = 0; i < r.relayers.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.relayers[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(IbcApplicationsFeeV1Fee._estimate(r.fee)); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.refund_address).length); - for (i = 0; i < r.relayers.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.relayers[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.refund_address).length != 0) { - return false; - } - - if (r.relayers.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 { - IbcApplicationsFeeV1Fee.store(input.fee, output.fee); - output.refund_address = input.refund_address; - output.relayers = input.relayers; - } - - //array helpers for Relayers - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addRelayers(Data memory self, string memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.relayers.length + 1); - for (uint256 i; i < self.relayers.length; i++) { - tmp[i] = self.relayers[i]; - } - tmp[self.relayers.length] = value; - self.relayers = 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 IbcApplicationsFeeV1PacketFee - -library IbcApplicationsFeeV1PacketFees { - //struct definition - struct Data { - IbcApplicationsFeeV1PacketFee.Data[] packet_fees; - } - - // 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[2] 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_unpacked_repeated_packet_fees( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.packet_fees.length == 0); - r.packet_fees = - new IbcApplicationsFeeV1PacketFee.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_packet_fees( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_packet_fees( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcApplicationsFeeV1PacketFee.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1PacketFee(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.packet_fees[r.packet_fees.length - counters[1]] = x; - counters[1] -= 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_IbcApplicationsFeeV1PacketFee( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1PacketFee.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1PacketFee.Data memory r,) = - IbcApplicationsFeeV1PacketFee._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.packet_fees.length != 0) { - for (i = 0; i < r.packet_fees.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1PacketFee._encode_nested( - r.packet_fees[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; - for (i = 0; i < r.packet_fees.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1PacketFee._estimate(r.packet_fees[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.packet_fees.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 { - for (uint256 i1 = 0; i1 < input.packet_fees.length; i1++) { - output.packet_fees.push(input.packet_fees[i1]); - } - } - - //array helpers for PacketFees - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPacketFees( - Data memory self, - IbcApplicationsFeeV1PacketFee.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1PacketFee.Data[] memory tmp = new IbcApplicationsFeeV1PacketFee - .Data[](self.packet_fees.length + 1); - for (uint256 i; i < self.packet_fees.length; i++) { - tmp[i] = self.packet_fees[i]; - } - tmp[self.packet_fees.length] = value; - self.packet_fees = 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 IbcApplicationsFeeV1PacketFees - -library IbcApplicationsFeeV1IdentifiedPacketFees { - //struct definition - struct Data { - IbcCoreChannelV1PacketId.Data packet_id; - IbcApplicationsFeeV1PacketFee.Data[] packet_fees; - } - - // 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_packet_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_packet_fees( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[2] > 0) { - require(r.packet_fees.length == 0); - r.packet_fees = - new IbcApplicationsFeeV1PacketFee.Data[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 2) { - pointer += _read_unpacked_repeated_packet_fees( - 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_packet_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1PacketId.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketId(p, bs); - r.packet_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_packet_fees( - 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. - */ - (IbcApplicationsFeeV1PacketFee.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1PacketFee(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.packet_fees[r.packet_fees.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_IbcCoreChannelV1PacketId( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1PacketId.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketId.Data memory r,) = - IbcCoreChannelV1PacketId._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_IbcApplicationsFeeV1PacketFee( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1PacketFee.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1PacketFee.Data memory r,) = - IbcApplicationsFeeV1PacketFee._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 += - IbcCoreChannelV1PacketId._encode_nested(r.packet_id, pointer, bs); - - if (r.packet_fees.length != 0) { - for (i = 0; i < r.packet_fees.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1PacketFee._encode_nested( - r.packet_fees[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( - IbcCoreChannelV1PacketId._estimate(r.packet_id) - ); - for (i = 0; i < r.packet_fees.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1PacketFee._estimate(r.packet_fees[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.packet_fees.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 { - IbcCoreChannelV1PacketId.store(input.packet_id, output.packet_id); - - for (uint256 i2 = 0; i2 < input.packet_fees.length; i2++) { - output.packet_fees.push(input.packet_fees[i2]); - } - } - - //array helpers for PacketFees - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPacketFees( - Data memory self, - IbcApplicationsFeeV1PacketFee.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1PacketFee.Data[] memory tmp = new IbcApplicationsFeeV1PacketFee - .Data[](self.packet_fees.length + 1); - for (uint256 i; i < self.packet_fees.length; i++) { - tmp[i] = self.packet_fees[i]; - } - tmp[self.packet_fees.length] = value; - self.packet_fees = 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 IbcApplicationsFeeV1IdentifiedPacketFees diff --git a/evm/contracts/proto/ibc/applications/fee/v1/genesis.sol b/evm/contracts/proto/ibc/applications/fee/v1/genesis.sol deleted file mode 100644 index 2f4487a9e4..0000000000 --- a/evm/contracts/proto/ibc/applications/fee/v1/genesis.sol +++ /dev/null @@ -1,1855 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "./fee.sol"; -import "../../../core/channel/v1/channel.sol"; - -library IbcApplicationsFeeV1GenesisState { - //struct definition - struct Data { - IbcApplicationsFeeV1IdentifiedPacketFees.Data[] identified_fees; - IbcApplicationsFeeV1FeeEnabledChannel.Data[] fee_enabled_channels; - IbcApplicationsFeeV1RegisteredPayee.Data[] registered_payees; - IbcApplicationsFeeV1RegisteredCounterpartyPayee.Data[] - registered_counterparty_payees; - IbcApplicationsFeeV1ForwardRelayerAddress.Data[] forward_relayers; - } - - // 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_unpacked_repeated_identified_fees( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_fee_enabled_channels( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_registered_payees( - pointer, bs, nil(), counters - ); - } else if (fieldId == 4) { - pointer += - _read_unpacked_repeated_registered_counterparty_payees( - pointer, bs, nil(), counters - ); - } else if (fieldId == 5) { - pointer += _read_unpacked_repeated_forward_relayers( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.identified_fees.length == 0); - r.identified_fees = - new IbcApplicationsFeeV1IdentifiedPacketFees.Data[](counters[1]); - } - if (counters[2] > 0) { - require(r.fee_enabled_channels.length == 0); - r.fee_enabled_channels = - new IbcApplicationsFeeV1FeeEnabledChannel.Data[](counters[2]); - } - if (counters[3] > 0) { - require(r.registered_payees.length == 0); - r.registered_payees = - new IbcApplicationsFeeV1RegisteredPayee.Data[](counters[3]); - } - if (counters[4] > 0) { - require(r.registered_counterparty_payees.length == 0); - r.registered_counterparty_payees = new IbcApplicationsFeeV1RegisteredCounterpartyPayee - .Data[](counters[4]); - } - if (counters[5] > 0) { - require(r.forward_relayers.length == 0); - r.forward_relayers = new IbcApplicationsFeeV1ForwardRelayerAddress - .Data[](counters[5]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_identified_fees( - pointer, bs, r, counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_fee_enabled_channels( - pointer, bs, r, counters - ); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_registered_payees( - pointer, bs, r, counters - ); - } else if (fieldId == 4) { - pointer += - _read_unpacked_repeated_registered_counterparty_payees( - pointer, bs, r, counters - ); - } else if (fieldId == 5) { - pointer += _read_unpacked_repeated_forward_relayers( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_identified_fees( - 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. - */ - (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1IdentifiedPacketFees(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.identified_fees[r.identified_fees.length - counters[1]] = x; - counters[1] -= 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_fee_enabled_channels( - 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. - */ - (IbcApplicationsFeeV1FeeEnabledChannel.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1FeeEnabledChannel(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.fee_enabled_channels[r.fee_enabled_channels.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_registered_payees( - 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. - */ - (IbcApplicationsFeeV1RegisteredPayee.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1RegisteredPayee(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.registered_payees[r.registered_payees.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_registered_counterparty_payees( - 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. - */ - ( - IbcApplicationsFeeV1RegisteredCounterpartyPayee.Data memory x, - uint256 sz - ) = _decode_IbcApplicationsFeeV1RegisteredCounterpartyPayee(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.registered_counterparty_payees[r - .registered_counterparty_payees - .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_forward_relayers( - 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. - */ - (IbcApplicationsFeeV1ForwardRelayerAddress.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1ForwardRelayerAddress(p, bs); - if (isNil(r)) { - counters[5] += 1; - } else { - r.forward_relayers[r.forward_relayers.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_IbcApplicationsFeeV1IdentifiedPacketFees( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory r,) = - IbcApplicationsFeeV1IdentifiedPacketFees._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_IbcApplicationsFeeV1FeeEnabledChannel( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1FeeEnabledChannel.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1FeeEnabledChannel.Data memory r,) = - IbcApplicationsFeeV1FeeEnabledChannel._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_IbcApplicationsFeeV1RegisteredPayee( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1RegisteredPayee.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1RegisteredPayee.Data memory r,) = - IbcApplicationsFeeV1RegisteredPayee._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_IbcApplicationsFeeV1RegisteredCounterpartyPayee( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsFeeV1RegisteredCounterpartyPayee.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1RegisteredCounterpartyPayee.Data memory r,) = - IbcApplicationsFeeV1RegisteredCounterpartyPayee._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_IbcApplicationsFeeV1ForwardRelayerAddress( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1ForwardRelayerAddress.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1ForwardRelayerAddress.Data memory r,) = - IbcApplicationsFeeV1ForwardRelayerAddress._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.identified_fees.length != 0) { - for (i = 0; i < r.identified_fees.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1IdentifiedPacketFees - ._encode_nested(r.identified_fees[i], pointer, bs); - } - } - if (r.fee_enabled_channels.length != 0) { - for (i = 0; i < r.fee_enabled_channels.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1FeeEnabledChannel._encode_nested( - r.fee_enabled_channels[i], pointer, bs - ); - } - } - if (r.registered_payees.length != 0) { - for (i = 0; i < r.registered_payees.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1RegisteredPayee._encode_nested( - r.registered_payees[i], pointer, bs - ); - } - } - if (r.registered_counterparty_payees.length != 0) { - for (i = 0; i < r.registered_counterparty_payees.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1RegisteredCounterpartyPayee - ._encode_nested( - r.registered_counterparty_payees[i], pointer, bs - ); - } - } - if (r.forward_relayers.length != 0) { - for (i = 0; i < r.forward_relayers.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1ForwardRelayerAddress - ._encode_nested(r.forward_relayers[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; - for (i = 0; i < r.identified_fees.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1IdentifiedPacketFees._estimate( - r.identified_fees[i] - ) - ); - } - for (i = 0; i < r.fee_enabled_channels.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1FeeEnabledChannel._estimate( - r.fee_enabled_channels[i] - ) - ); - } - for (i = 0; i < r.registered_payees.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1RegisteredPayee._estimate( - r.registered_payees[i] - ) - ); - } - for (i = 0; i < r.registered_counterparty_payees.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1RegisteredCounterpartyPayee._estimate( - r.registered_counterparty_payees[i] - ) - ); - } - for (i = 0; i < r.forward_relayers.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1ForwardRelayerAddress._estimate( - r.forward_relayers[i] - ) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.identified_fees.length != 0) { - return false; - } - - if (r.fee_enabled_channels.length != 0) { - return false; - } - - if (r.registered_payees.length != 0) { - return false; - } - - if (r.registered_counterparty_payees.length != 0) { - return false; - } - - if (r.forward_relayers.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 { - for (uint256 i1 = 0; i1 < input.identified_fees.length; i1++) { - output.identified_fees.push(input.identified_fees[i1]); - } - - for (uint256 i2 = 0; i2 < input.fee_enabled_channels.length; i2++) { - output.fee_enabled_channels.push(input.fee_enabled_channels[i2]); - } - - for (uint256 i3 = 0; i3 < input.registered_payees.length; i3++) { - output.registered_payees.push(input.registered_payees[i3]); - } - - for ( - uint256 i4 = 0; - i4 < input.registered_counterparty_payees.length; - i4++ - ) { - output.registered_counterparty_payees.push( - input.registered_counterparty_payees[i4] - ); - } - - for (uint256 i5 = 0; i5 < input.forward_relayers.length; i5++) { - output.forward_relayers.push(input.forward_relayers[i5]); - } - } - - //array helpers for IdentifiedFees - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addIdentifiedFees( - Data memory self, - IbcApplicationsFeeV1IdentifiedPacketFees.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1IdentifiedPacketFees.Data[] memory tmp = new IbcApplicationsFeeV1IdentifiedPacketFees - .Data[](self.identified_fees.length + 1); - for (uint256 i; i < self.identified_fees.length; i++) { - tmp[i] = self.identified_fees[i]; - } - tmp[self.identified_fees.length] = value; - self.identified_fees = tmp; - } - - //array helpers for FeeEnabledChannels - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addFeeEnabledChannels( - Data memory self, - IbcApplicationsFeeV1FeeEnabledChannel.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1FeeEnabledChannel.Data[] memory tmp = new IbcApplicationsFeeV1FeeEnabledChannel - .Data[](self.fee_enabled_channels.length + 1); - for (uint256 i; i < self.fee_enabled_channels.length; i++) { - tmp[i] = self.fee_enabled_channels[i]; - } - tmp[self.fee_enabled_channels.length] = value; - self.fee_enabled_channels = tmp; - } - - //array helpers for RegisteredPayees - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addRegisteredPayees( - Data memory self, - IbcApplicationsFeeV1RegisteredPayee.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1RegisteredPayee.Data[] memory tmp = new IbcApplicationsFeeV1RegisteredPayee - .Data[](self.registered_payees.length + 1); - for (uint256 i; i < self.registered_payees.length; i++) { - tmp[i] = self.registered_payees[i]; - } - tmp[self.registered_payees.length] = value; - self.registered_payees = tmp; - } - - //array helpers for RegisteredCounterpartyPayees - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addRegisteredCounterpartyPayees( - Data memory self, - IbcApplicationsFeeV1RegisteredCounterpartyPayee.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1RegisteredCounterpartyPayee.Data[] memory tmp = new IbcApplicationsFeeV1RegisteredCounterpartyPayee - .Data[](self.registered_counterparty_payees.length + 1); - for (uint256 i; i < self.registered_counterparty_payees.length; i++) { - tmp[i] = self.registered_counterparty_payees[i]; - } - tmp[self.registered_counterparty_payees.length] = value; - self.registered_counterparty_payees = tmp; - } - - //array helpers for ForwardRelayers - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addForwardRelayers( - Data memory self, - IbcApplicationsFeeV1ForwardRelayerAddress.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1ForwardRelayerAddress.Data[] memory tmp = new IbcApplicationsFeeV1ForwardRelayerAddress - .Data[](self.forward_relayers.length + 1); - for (uint256 i; i < self.forward_relayers.length; i++) { - tmp[i] = self.forward_relayers[i]; - } - tmp[self.forward_relayers.length] = value; - self.forward_relayers = 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 IbcApplicationsFeeV1GenesisState - -library IbcApplicationsFeeV1FeeEnabledChannel { - //struct definition - struct Data { - string port_id; - string channel_id; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - } - - //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 IbcApplicationsFeeV1FeeEnabledChannel - -library IbcApplicationsFeeV1RegisteredPayee { - //struct definition - struct Data { - string channel_id; - string relayer; - string payee; - } - - // 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_channel_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_relayer(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_payee(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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_relayer( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.relayer = 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_payee( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.payee = 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 (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (bytes(r.relayer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.relayer, pointer, bs); - } - if (bytes(r.payee).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.payee, 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.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.relayer).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.payee).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (bytes(r.relayer).length != 0) { - return false; - } - - if (bytes(r.payee).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.channel_id = input.channel_id; - output.relayer = input.relayer; - output.payee = input.payee; - } - - //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 IbcApplicationsFeeV1RegisteredPayee - -library IbcApplicationsFeeV1RegisteredCounterpartyPayee { - //struct definition - struct Data { - string channel_id; - string relayer; - string counterparty_payee; - } - - // 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_channel_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_relayer(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_counterparty_payee(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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_relayer( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.relayer = 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_counterparty_payee( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.counterparty_payee = 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 (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (bytes(r.relayer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.relayer, pointer, bs); - } - if (bytes(r.counterparty_payee).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.counterparty_payee, 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.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.relayer).length); - e += - 1 + ProtoBufRuntime._sz_lendelim(bytes(r.counterparty_payee).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (bytes(r.relayer).length != 0) { - return false; - } - - if (bytes(r.counterparty_payee).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.channel_id = input.channel_id; - output.relayer = input.relayer; - output.counterparty_payee = input.counterparty_payee; - } - - //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 IbcApplicationsFeeV1RegisteredCounterpartyPayee - -library IbcApplicationsFeeV1ForwardRelayerAddress { - //struct definition - struct Data { - string address_; - IbcCoreChannelV1PacketId.Data packet_id; - } - - // 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_address(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_packet_id(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_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.address_ = 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_packet_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1PacketId.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketId(p, bs); - r.packet_id = 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_IbcCoreChannelV1PacketId( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1PacketId.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketId.Data memory r,) = - IbcCoreChannelV1PacketId._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.address_).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.address_, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreChannelV1PacketId._encode_nested(r.packet_id, 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.address_).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketId._estimate(r.packet_id) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.address_).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.address_ = input.address_; - IbcCoreChannelV1PacketId.store(input.packet_id, output.packet_id); - } - - //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 IbcApplicationsFeeV1ForwardRelayerAddress diff --git a/evm/contracts/proto/ibc/applications/fee/v1/metadata.sol b/evm/contracts/proto/ibc/applications/fee/v1/metadata.sol deleted file mode 100644 index 890df1aac6..0000000000 --- a/evm/contracts/proto/ibc/applications/fee/v1/metadata.sol +++ /dev/null @@ -1,250 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcApplicationsFeeV1Metadata { - //struct definition - struct Data { - string fee_version; - string app_version; - } - - // 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_fee_version(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_app_version(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_fee_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.fee_version = 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_app_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.app_version = 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 (bytes(r.fee_version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.fee_version, pointer, bs); - } - if (bytes(r.app_version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.app_version, 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.fee_version).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.app_version).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.fee_version).length != 0) { - return false; - } - - if (bytes(r.app_version).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.fee_version = input.fee_version; - output.app_version = input.app_version; - } - - //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 IbcApplicationsFeeV1Metadata diff --git a/evm/contracts/proto/ibc/applications/fee/v1/query.sol b/evm/contracts/proto/ibc/applications/fee/v1/query.sol deleted file mode 100644 index 62647d1578..0000000000 --- a/evm/contracts/proto/ibc/applications/fee/v1/query.sol +++ /dev/null @@ -1,5310 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../../../cosmos/base/v1beta1/coin.sol"; -import "../../../../cosmos/base/query/v1beta1/pagination.sol"; -import "./fee.sol"; -import "./genesis.sol"; -import "../../../core/channel/v1/channel.sol"; - -library IbcApplicationsFeeV1QueryIncentivizedPacketsRequest { - //struct definition - struct Data { - CosmosBaseQueryV1beta1PageRequest.Data pagination; - uint64 query_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_pagination(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_query_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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_query_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.query_height = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, pointer, bs - ); - - if (r.query_height != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.query_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_lendelim( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.query_height); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.query_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 { - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - output.query_height = input.query_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 IbcApplicationsFeeV1QueryIncentivizedPacketsRequest - -library IbcApplicationsFeeV1QueryIncentivizedPacketsResponse { - //struct definition - struct Data { - IbcApplicationsFeeV1IdentifiedPacketFees.Data[] incentivized_packets; - } - - // 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[2] 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_unpacked_repeated_incentivized_packets( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.incentivized_packets.length == 0); - r.incentivized_packets = - new IbcApplicationsFeeV1IdentifiedPacketFees.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_incentivized_packets( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_incentivized_packets( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1IdentifiedPacketFees(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.incentivized_packets[r.incentivized_packets.length - counters[1]] - = x; - counters[1] -= 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_IbcApplicationsFeeV1IdentifiedPacketFees( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory r,) = - IbcApplicationsFeeV1IdentifiedPacketFees._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.incentivized_packets.length != 0) { - for (i = 0; i < r.incentivized_packets.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1IdentifiedPacketFees - ._encode_nested(r.incentivized_packets[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; - for (i = 0; i < r.incentivized_packets.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1IdentifiedPacketFees._estimate( - r.incentivized_packets[i] - ) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.incentivized_packets.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 { - for (uint256 i1 = 0; i1 < input.incentivized_packets.length; i1++) { - output.incentivized_packets.push(input.incentivized_packets[i1]); - } - } - - //array helpers for IncentivizedPackets - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addIncentivizedPackets( - Data memory self, - IbcApplicationsFeeV1IdentifiedPacketFees.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1IdentifiedPacketFees.Data[] memory tmp = new IbcApplicationsFeeV1IdentifiedPacketFees - .Data[](self.incentivized_packets.length + 1); - for (uint256 i; i < self.incentivized_packets.length; i++) { - tmp[i] = self.incentivized_packets[i]; - } - tmp[self.incentivized_packets.length] = value; - self.incentivized_packets = 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 IbcApplicationsFeeV1QueryIncentivizedPacketsResponse - -library IbcApplicationsFeeV1QueryIncentivizedPacketRequest { - //struct definition - struct Data { - IbcCoreChannelV1PacketId.Data packet_id; - uint64 query_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_packet_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_query_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_packet_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1PacketId.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketId(p, bs); - r.packet_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_query_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.query_height = 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_IbcCoreChannelV1PacketId( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1PacketId.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketId.Data memory r,) = - IbcCoreChannelV1PacketId._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 += - IbcCoreChannelV1PacketId._encode_nested(r.packet_id, pointer, bs); - - if (r.query_height != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.query_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_lendelim( - IbcCoreChannelV1PacketId._estimate(r.packet_id) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.query_height); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.query_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 { - IbcCoreChannelV1PacketId.store(input.packet_id, output.packet_id); - output.query_height = input.query_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 IbcApplicationsFeeV1QueryIncentivizedPacketRequest - -library IbcApplicationsFeeV1QueryIncentivizedPacketResponse { - //struct definition - struct Data { - IbcApplicationsFeeV1IdentifiedPacketFees.Data incentivized_packet; - } - - // 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_incentivized_packet(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_incentivized_packet( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1IdentifiedPacketFees(p, bs); - r.incentivized_packet = 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_IbcApplicationsFeeV1IdentifiedPacketFees( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory r,) = - IbcApplicationsFeeV1IdentifiedPacketFees._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 += IbcApplicationsFeeV1IdentifiedPacketFees._encode_nested( - r.incentivized_packet, 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( - IbcApplicationsFeeV1IdentifiedPacketFees._estimate( - r.incentivized_packet - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcApplicationsFeeV1IdentifiedPacketFees.store( - input.incentivized_packet, output.incentivized_packet - ); - } - - //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 IbcApplicationsFeeV1QueryIncentivizedPacketResponse - -library IbcApplicationsFeeV1QueryIncentivizedPacketsForChannelRequest { - //struct definition - struct Data { - CosmosBaseQueryV1beta1PageRequest.Data pagination; - string port_id; - string channel_id; - uint64 query_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_pagination(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_port_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_query_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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_query_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.query_height = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, pointer, bs - ); - - if (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.query_height != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.query_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_lendelim( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.query_height); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.query_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 { - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - output.port_id = input.port_id; - output.channel_id = input.channel_id; - output.query_height = input.query_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 IbcApplicationsFeeV1QueryIncentivizedPacketsForChannelRequest - -library IbcApplicationsFeeV1QueryIncentivizedPacketsForChannelResponse { - //struct definition - struct Data { - IbcApplicationsFeeV1IdentifiedPacketFees.Data[] incentivized_packets; - } - - // 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[2] 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_unpacked_repeated_incentivized_packets( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.incentivized_packets.length == 0); - r.incentivized_packets = - new IbcApplicationsFeeV1IdentifiedPacketFees.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_incentivized_packets( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_incentivized_packets( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1IdentifiedPacketFees(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.incentivized_packets[r.incentivized_packets.length - counters[1]] - = x; - counters[1] -= 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_IbcApplicationsFeeV1IdentifiedPacketFees( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1IdentifiedPacketFees.Data memory r,) = - IbcApplicationsFeeV1IdentifiedPacketFees._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.incentivized_packets.length != 0) { - for (i = 0; i < r.incentivized_packets.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1IdentifiedPacketFees - ._encode_nested(r.incentivized_packets[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; - for (i = 0; i < r.incentivized_packets.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1IdentifiedPacketFees._estimate( - r.incentivized_packets[i] - ) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.incentivized_packets.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 { - for (uint256 i1 = 0; i1 < input.incentivized_packets.length; i1++) { - output.incentivized_packets.push(input.incentivized_packets[i1]); - } - } - - //array helpers for IncentivizedPackets - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addIncentivizedPackets( - Data memory self, - IbcApplicationsFeeV1IdentifiedPacketFees.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1IdentifiedPacketFees.Data[] memory tmp = new IbcApplicationsFeeV1IdentifiedPacketFees - .Data[](self.incentivized_packets.length + 1); - for (uint256 i; i < self.incentivized_packets.length; i++) { - tmp[i] = self.incentivized_packets[i]; - } - tmp[self.incentivized_packets.length] = value; - self.incentivized_packets = 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 IbcApplicationsFeeV1QueryIncentivizedPacketsForChannelResponse - -library IbcApplicationsFeeV1QueryTotalRecvFeesRequest { - //struct definition - struct Data { - IbcCoreChannelV1PacketId.Data packet_id; - } - - // 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_packet_id(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_packet_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1PacketId.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketId(p, bs); - r.packet_id = 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_IbcCoreChannelV1PacketId( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1PacketId.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketId.Data memory r,) = - IbcCoreChannelV1PacketId._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 += - IbcCoreChannelV1PacketId._encode_nested(r.packet_id, 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( - IbcCoreChannelV1PacketId._estimate(r.packet_id) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcCoreChannelV1PacketId.store(input.packet_id, output.packet_id); - } - - //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 IbcApplicationsFeeV1QueryTotalRecvFeesRequest - -library IbcApplicationsFeeV1QueryTotalRecvFeesResponse { - //struct definition - struct Data { - CosmosBaseV1beta1Coin.Data[] recv_fees; - } - - // 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[2] 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_unpacked_repeated_recv_fees( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.recv_fees.length == 0); - r.recv_fees = new CosmosBaseV1beta1Coin.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_recv_fees(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_recv_fees( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosBaseV1beta1Coin.Data memory x, uint256 sz) = - _decode_CosmosBaseV1beta1Coin(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.recv_fees[r.recv_fees.length - counters[1]] = x; - counters[1] -= 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_CosmosBaseV1beta1Coin( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosBaseV1beta1Coin.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseV1beta1Coin.Data memory r,) = - CosmosBaseV1beta1Coin._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.recv_fees.length != 0) { - for (i = 0; i < r.recv_fees.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseV1beta1Coin._encode_nested( - r.recv_fees[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; - for (i = 0; i < r.recv_fees.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseV1beta1Coin._estimate(r.recv_fees[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.recv_fees.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 { - for (uint256 i1 = 0; i1 < input.recv_fees.length; i1++) { - output.recv_fees.push(input.recv_fees[i1]); - } - } - - //array helpers for RecvFees - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addRecvFees( - Data memory self, - CosmosBaseV1beta1Coin.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosBaseV1beta1Coin.Data[] memory tmp = - new CosmosBaseV1beta1Coin.Data[](self.recv_fees.length + 1); - for (uint256 i; i < self.recv_fees.length; i++) { - tmp[i] = self.recv_fees[i]; - } - tmp[self.recv_fees.length] = value; - self.recv_fees = 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 IbcApplicationsFeeV1QueryTotalRecvFeesResponse - -library IbcApplicationsFeeV1QueryTotalAckFeesRequest { - //struct definition - struct Data { - IbcCoreChannelV1PacketId.Data packet_id; - } - - // 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_packet_id(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_packet_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1PacketId.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketId(p, bs); - r.packet_id = 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_IbcCoreChannelV1PacketId( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1PacketId.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketId.Data memory r,) = - IbcCoreChannelV1PacketId._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 += - IbcCoreChannelV1PacketId._encode_nested(r.packet_id, 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( - IbcCoreChannelV1PacketId._estimate(r.packet_id) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcCoreChannelV1PacketId.store(input.packet_id, output.packet_id); - } - - //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 IbcApplicationsFeeV1QueryTotalAckFeesRequest - -library IbcApplicationsFeeV1QueryTotalAckFeesResponse { - //struct definition - struct Data { - CosmosBaseV1beta1Coin.Data[] ack_fees; - } - - // 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[2] 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_unpacked_repeated_ack_fees( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.ack_fees.length == 0); - r.ack_fees = new CosmosBaseV1beta1Coin.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_ack_fees(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_ack_fees( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosBaseV1beta1Coin.Data memory x, uint256 sz) = - _decode_CosmosBaseV1beta1Coin(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.ack_fees[r.ack_fees.length - counters[1]] = x; - counters[1] -= 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_CosmosBaseV1beta1Coin( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosBaseV1beta1Coin.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseV1beta1Coin.Data memory r,) = - CosmosBaseV1beta1Coin._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.ack_fees.length != 0) { - for (i = 0; i < r.ack_fees.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseV1beta1Coin._encode_nested( - r.ack_fees[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; - for (i = 0; i < r.ack_fees.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseV1beta1Coin._estimate(r.ack_fees[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.ack_fees.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 { - for (uint256 i1 = 0; i1 < input.ack_fees.length; i1++) { - output.ack_fees.push(input.ack_fees[i1]); - } - } - - //array helpers for AckFees - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAckFees( - Data memory self, - CosmosBaseV1beta1Coin.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosBaseV1beta1Coin.Data[] memory tmp = - new CosmosBaseV1beta1Coin.Data[](self.ack_fees.length + 1); - for (uint256 i; i < self.ack_fees.length; i++) { - tmp[i] = self.ack_fees[i]; - } - tmp[self.ack_fees.length] = value; - self.ack_fees = 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 IbcApplicationsFeeV1QueryTotalAckFeesResponse - -library IbcApplicationsFeeV1QueryTotalTimeoutFeesRequest { - //struct definition - struct Data { - IbcCoreChannelV1PacketId.Data packet_id; - } - - // 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_packet_id(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_packet_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1PacketId.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketId(p, bs); - r.packet_id = 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_IbcCoreChannelV1PacketId( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1PacketId.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketId.Data memory r,) = - IbcCoreChannelV1PacketId._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 += - IbcCoreChannelV1PacketId._encode_nested(r.packet_id, 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( - IbcCoreChannelV1PacketId._estimate(r.packet_id) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcCoreChannelV1PacketId.store(input.packet_id, output.packet_id); - } - - //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 IbcApplicationsFeeV1QueryTotalTimeoutFeesRequest - -library IbcApplicationsFeeV1QueryTotalTimeoutFeesResponse { - //struct definition - struct Data { - CosmosBaseV1beta1Coin.Data[] timeout_fees; - } - - // 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[2] 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_unpacked_repeated_timeout_fees( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.timeout_fees.length == 0); - r.timeout_fees = new CosmosBaseV1beta1Coin.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_timeout_fees( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_timeout_fees( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosBaseV1beta1Coin.Data memory x, uint256 sz) = - _decode_CosmosBaseV1beta1Coin(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.timeout_fees[r.timeout_fees.length - counters[1]] = x; - counters[1] -= 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_CosmosBaseV1beta1Coin( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosBaseV1beta1Coin.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseV1beta1Coin.Data memory r,) = - CosmosBaseV1beta1Coin._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.timeout_fees.length != 0) { - for (i = 0; i < r.timeout_fees.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseV1beta1Coin._encode_nested( - r.timeout_fees[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; - for (i = 0; i < r.timeout_fees.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseV1beta1Coin._estimate(r.timeout_fees[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.timeout_fees.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 { - for (uint256 i1 = 0; i1 < input.timeout_fees.length; i1++) { - output.timeout_fees.push(input.timeout_fees[i1]); - } - } - - //array helpers for TimeoutFees - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addTimeoutFees( - Data memory self, - CosmosBaseV1beta1Coin.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosBaseV1beta1Coin.Data[] memory tmp = - new CosmosBaseV1beta1Coin.Data[](self.timeout_fees.length + 1); - for (uint256 i; i < self.timeout_fees.length; i++) { - tmp[i] = self.timeout_fees[i]; - } - tmp[self.timeout_fees.length] = value; - self.timeout_fees = 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 IbcApplicationsFeeV1QueryTotalTimeoutFeesResponse - -library IbcApplicationsFeeV1QueryPayeeRequest { - //struct definition - struct Data { - string channel_id; - string relayer; - } - - // 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_channel_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_relayer(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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_relayer( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.relayer = 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 (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (bytes(r.relayer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.relayer, 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.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.relayer).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (bytes(r.relayer).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.channel_id = input.channel_id; - output.relayer = input.relayer; - } - - //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 IbcApplicationsFeeV1QueryPayeeRequest - -library IbcApplicationsFeeV1QueryPayeeResponse { - //struct definition - struct Data { - string payee_address; - } - - // 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_payee_address(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_payee_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.payee_address = 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 (bytes(r.payee_address).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.payee_address, 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.payee_address).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.payee_address).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.payee_address = input.payee_address; - } - - //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 IbcApplicationsFeeV1QueryPayeeResponse - -library IbcApplicationsFeeV1QueryCounterpartyPayeeRequest { - //struct definition - struct Data { - string channel_id; - string relayer; - } - - // 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_channel_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_relayer(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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_relayer( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.relayer = 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 (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (bytes(r.relayer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.relayer, 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.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.relayer).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (bytes(r.relayer).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.channel_id = input.channel_id; - output.relayer = input.relayer; - } - - //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 IbcApplicationsFeeV1QueryCounterpartyPayeeRequest - -library IbcApplicationsFeeV1QueryCounterpartyPayeeResponse { - //struct definition - struct Data { - string counterparty_payee; - } - - // 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_counterparty_payee(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_counterparty_payee( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.counterparty_payee = 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 (bytes(r.counterparty_payee).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.counterparty_payee, 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.counterparty_payee).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.counterparty_payee).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.counterparty_payee = input.counterparty_payee; - } - - //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 IbcApplicationsFeeV1QueryCounterpartyPayeeResponse - -library IbcApplicationsFeeV1QueryFeeEnabledChannelsRequest { - //struct definition - struct Data { - CosmosBaseQueryV1beta1PageRequest.Data pagination; - uint64 query_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_pagination(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_query_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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_query_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.query_height = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, pointer, bs - ); - - if (r.query_height != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.query_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_lendelim( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.query_height); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.query_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 { - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - output.query_height = input.query_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 IbcApplicationsFeeV1QueryFeeEnabledChannelsRequest - -library IbcApplicationsFeeV1QueryFeeEnabledChannelsResponse { - //struct definition - struct Data { - IbcApplicationsFeeV1FeeEnabledChannel.Data[] fee_enabled_channels; - } - - // 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[2] 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_unpacked_repeated_fee_enabled_channels( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.fee_enabled_channels.length == 0); - r.fee_enabled_channels = - new IbcApplicationsFeeV1FeeEnabledChannel.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_fee_enabled_channels( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_fee_enabled_channels( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcApplicationsFeeV1FeeEnabledChannel.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1FeeEnabledChannel(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.fee_enabled_channels[r.fee_enabled_channels.length - counters[1]] - = x; - counters[1] -= 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_IbcApplicationsFeeV1FeeEnabledChannel( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1FeeEnabledChannel.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1FeeEnabledChannel.Data memory r,) = - IbcApplicationsFeeV1FeeEnabledChannel._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.fee_enabled_channels.length != 0) { - for (i = 0; i < r.fee_enabled_channels.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1FeeEnabledChannel._encode_nested( - r.fee_enabled_channels[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; - for (i = 0; i < r.fee_enabled_channels.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1FeeEnabledChannel._estimate( - r.fee_enabled_channels[i] - ) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.fee_enabled_channels.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 { - for (uint256 i1 = 0; i1 < input.fee_enabled_channels.length; i1++) { - output.fee_enabled_channels.push(input.fee_enabled_channels[i1]); - } - } - - //array helpers for FeeEnabledChannels - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addFeeEnabledChannels( - Data memory self, - IbcApplicationsFeeV1FeeEnabledChannel.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsFeeV1FeeEnabledChannel.Data[] memory tmp = new IbcApplicationsFeeV1FeeEnabledChannel - .Data[](self.fee_enabled_channels.length + 1); - for (uint256 i; i < self.fee_enabled_channels.length; i++) { - tmp[i] = self.fee_enabled_channels[i]; - } - tmp[self.fee_enabled_channels.length] = value; - self.fee_enabled_channels = 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 IbcApplicationsFeeV1QueryFeeEnabledChannelsResponse - -library IbcApplicationsFeeV1QueryFeeEnabledChannelRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - } - - //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 IbcApplicationsFeeV1QueryFeeEnabledChannelRequest - -library IbcApplicationsFeeV1QueryFeeEnabledChannelResponse { - //struct definition - struct Data { - bool fee_enabled; - } - - // 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_fee_enabled(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_fee_enabled( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.fee_enabled = 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.fee_enabled != false) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool(r.fee_enabled, 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 - * @return The number of bytes encoded in estimation - */ - function _estimate(Data memory /* r */ ) internal pure returns (uint256) { - uint256 e; - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.fee_enabled != false) { - 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.fee_enabled = input.fee_enabled; - } - - //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 IbcApplicationsFeeV1QueryFeeEnabledChannelResponse diff --git a/evm/contracts/proto/ibc/applications/fee/v1/tx.sol b/evm/contracts/proto/ibc/applications/fee/v1/tx.sol deleted file mode 100644 index ab4a6e6d29..0000000000 --- a/evm/contracts/proto/ibc/applications/fee/v1/tx.sol +++ /dev/null @@ -1,2031 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "./fee.sol"; -import "../../../core/channel/v1/channel.sol"; - -library IbcApplicationsFeeV1MsgRegisterPayee { - //struct definition - struct Data { - string port_id; - string channel_id; - string relayer; - string payee; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_relayer(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_payee(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_relayer( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.relayer = 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_payee( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.payee = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (bytes(r.relayer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.relayer, pointer, bs); - } - if (bytes(r.payee).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.payee, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.relayer).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.payee).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (bytes(r.relayer).length != 0) { - return false; - } - - if (bytes(r.payee).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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.relayer = input.relayer; - output.payee = input.payee; - } - - //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 IbcApplicationsFeeV1MsgRegisterPayee - -library IbcApplicationsFeeV1MsgRegisterPayeeResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcApplicationsFeeV1MsgRegisterPayeeResponse - -library IbcApplicationsFeeV1MsgRegisterCounterpartyPayee { - //struct definition - struct Data { - string port_id; - string channel_id; - string relayer; - string counterparty_payee; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_relayer(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_counterparty_payee(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_relayer( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.relayer = 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_counterparty_payee( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.counterparty_payee = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (bytes(r.relayer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.relayer, pointer, bs); - } - if (bytes(r.counterparty_payee).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.counterparty_payee, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.relayer).length); - e += - 1 + ProtoBufRuntime._sz_lendelim(bytes(r.counterparty_payee).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (bytes(r.relayer).length != 0) { - return false; - } - - if (bytes(r.counterparty_payee).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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.relayer = input.relayer; - output.counterparty_payee = input.counterparty_payee; - } - - //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 IbcApplicationsFeeV1MsgRegisterCounterpartyPayee - -library IbcApplicationsFeeV1MsgRegisterCounterpartyPayeeResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcApplicationsFeeV1MsgRegisterCounterpartyPayeeResponse - -library IbcApplicationsFeeV1MsgPayPacketFee { - //struct definition - struct Data { - IbcApplicationsFeeV1Fee.Data fee; - string source_port_id; - string source_channel_id; - string signer; - string[] relayers; - } - - // 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_fee(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_source_port_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_source_channel_id(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_signer(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_unpacked_repeated_relayers( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[5] > 0) { - require(r.relayers.length == 0); - r.relayers = new string[](counters[5]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 5) { - pointer += - _read_unpacked_repeated_relayers(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_fee( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcApplicationsFeeV1Fee.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1Fee(p, bs); - r.fee = 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_source_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.source_port_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_source_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.source_channel_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_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; - } - - /** - * @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_relayers( - 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. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[5] += 1; - } else { - r.relayers[r.relayers.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_IbcApplicationsFeeV1Fee( - uint256 p, - bytes memory bs - ) internal pure returns (IbcApplicationsFeeV1Fee.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1Fee.Data memory r,) = - IbcApplicationsFeeV1Fee._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 += IbcApplicationsFeeV1Fee._encode_nested(r.fee, pointer, bs); - - if (bytes(r.source_port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.source_port_id, pointer, bs); - } - if (bytes(r.source_channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.source_channel_id, 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); - } - if (r.relayers.length != 0) { - for (i = 0; i < r.relayers.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.relayers[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(IbcApplicationsFeeV1Fee._estimate(r.fee)); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.source_port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.source_channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); - for (i = 0; i < r.relayers.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.relayers[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.source_port_id).length != 0) { - return false; - } - - if (bytes(r.source_channel_id).length != 0) { - return false; - } - - if (bytes(r.signer).length != 0) { - return false; - } - - if (r.relayers.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 { - IbcApplicationsFeeV1Fee.store(input.fee, output.fee); - output.source_port_id = input.source_port_id; - output.source_channel_id = input.source_channel_id; - output.signer = input.signer; - output.relayers = input.relayers; - } - - //array helpers for Relayers - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addRelayers(Data memory self, string memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.relayers.length + 1); - for (uint256 i; i < self.relayers.length; i++) { - tmp[i] = self.relayers[i]; - } - tmp[self.relayers.length] = value; - self.relayers = 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 IbcApplicationsFeeV1MsgPayPacketFee - -library IbcApplicationsFeeV1MsgPayPacketFeeResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcApplicationsFeeV1MsgPayPacketFeeResponse - -library IbcApplicationsFeeV1MsgPayPacketFeeAsync { - //struct definition - struct Data { - IbcCoreChannelV1PacketId.Data packet_id; - IbcApplicationsFeeV1PacketFee.Data packet_fee; - } - - // 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_packet_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_packet_fee(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_packet_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1PacketId.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketId(p, bs); - r.packet_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_packet_fee( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcApplicationsFeeV1PacketFee.Data memory x, uint256 sz) = - _decode_IbcApplicationsFeeV1PacketFee(p, bs); - r.packet_fee = 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_IbcCoreChannelV1PacketId( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1PacketId.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketId.Data memory r,) = - IbcCoreChannelV1PacketId._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_IbcApplicationsFeeV1PacketFee( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsFeeV1PacketFee.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsFeeV1PacketFee.Data memory r,) = - IbcApplicationsFeeV1PacketFee._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 += - IbcCoreChannelV1PacketId._encode_nested(r.packet_id, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsFeeV1PacketFee._encode_nested( - r.packet_fee, 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( - IbcCoreChannelV1PacketId._estimate(r.packet_id) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsFeeV1PacketFee._estimate(r.packet_fee) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcCoreChannelV1PacketId.store(input.packet_id, output.packet_id); - IbcApplicationsFeeV1PacketFee.store(input.packet_fee, output.packet_fee); - } - - //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 IbcApplicationsFeeV1MsgPayPacketFeeAsync - -library IbcApplicationsFeeV1MsgPayPacketFeeAsyncResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcApplicationsFeeV1MsgPayPacketFeeAsyncResponse diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/controller.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/controller.sol deleted file mode 100644 index e236c433c6..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/controller.sol +++ /dev/null @@ -1,216 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../../ProtoBufRuntime.sol"; -import "../../../../../GoogleProtobufAny.sol"; - -library IbcApplicationsInterchain_accountsControllerV1Params { - //struct definition - struct Data { - bool controller_enabled; - } - - // 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_controller_enabled(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_controller_enabled( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.controller_enabled = 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.controller_enabled != false) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bool(r.controller_enabled, 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 - * @return The number of bytes encoded in estimation - */ - function _estimate(Data memory /* r */ ) internal pure returns (uint256) { - uint256 e; - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.controller_enabled != false) { - 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.controller_enabled = input.controller_enabled; - } - - //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 IbcApplicationsInterchain_accountsControllerV1Params diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/query.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/query.sol deleted file mode 100644 index f667c3963f..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/query.sol +++ /dev/null @@ -1,888 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../../ProtoBufRuntime.sol"; -import "../../../../../GoogleProtobufAny.sol"; -import "./controller.sol"; - -library - IbcApplicationsInterchain_accountsControllerV1QueryInterchainAccountRequest { - //struct definition - struct Data { - string owner; - string connection_id; - } - - // 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_owner(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_connection_id(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_owner( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.owner = 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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_id = 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 (bytes(r.owner).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.owner, pointer, bs); - } - if (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, 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.owner).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.connection_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.owner).length != 0) { - return false; - } - - if (bytes(r.connection_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.owner = input.owner; - output.connection_id = input.connection_id; - } - - //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 IbcApplicationsInterchain_accountsControllerV1QueryInterchainAccountRequest - -library - IbcApplicationsInterchain_accountsControllerV1QueryInterchainAccountResponse { - //struct definition - struct Data { - string address_; - } - - // 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_address(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_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.address_ = 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 (bytes(r.address_).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.address_, 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.address_).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.address_).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.address_ = input.address_; - } - - //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 IbcApplicationsInterchain_accountsControllerV1QueryInterchainAccountResponse - -library IbcApplicationsInterchain_accountsControllerV1QueryParamsRequest { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcApplicationsInterchain_accountsControllerV1QueryParamsRequest - -library IbcApplicationsInterchain_accountsControllerV1QueryParamsResponse { - //struct definition - struct Data { - IbcApplicationsInterchain_accountsControllerV1Params.Data params; - } - - // 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_params(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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - ( - IbcApplicationsInterchain_accountsControllerV1Params.Data memory x, - uint256 sz - ) = _decode_IbcApplicationsInterchain_accountsControllerV1Params(p, bs); - r.params = 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_IbcApplicationsInterchain_accountsControllerV1Params( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsControllerV1Params.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsInterchain_accountsControllerV1Params.Data memory r,) = - IbcApplicationsInterchain_accountsControllerV1Params._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 += IbcApplicationsInterchain_accountsControllerV1Params - ._encode_nested(r.params, 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( - IbcApplicationsInterchain_accountsControllerV1Params._estimate( - r.params - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcApplicationsInterchain_accountsControllerV1Params.store( - input.params, output.params - ); - } - - //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 IbcApplicationsInterchain_accountsControllerV1QueryParamsResponse diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/tx.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/tx.sol deleted file mode 100644 index 6d9a55e542..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/controller/v1/tx.sol +++ /dev/null @@ -1,1066 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../../ProtoBufRuntime.sol"; -import "../../../../../GoogleProtobufAny.sol"; - -import "../../v1/packet.sol"; - -library - IbcApplicationsInterchain_accountsControllerV1MsgRegisterInterchainAccount { - //struct definition - struct Data { - string owner; - string connection_id; - string version; - } - - // 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_owner(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_connection_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_version(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_owner( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.owner = 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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_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_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.version = 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 (bytes(r.owner).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.owner, pointer, bs); - } - if (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, pointer, bs); - } - if (bytes(r.version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.version, 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.owner).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.connection_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.version).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.owner).length != 0) { - return false; - } - - if (bytes(r.connection_id).length != 0) { - return false; - } - - if (bytes(r.version).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.owner = input.owner; - output.connection_id = input.connection_id; - output.version = input.version; - } - - //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 IbcApplicationsInterchain_accountsControllerV1MsgRegisterInterchainAccount - -library - IbcApplicationsInterchain_accountsControllerV1MsgRegisterInterchainAccountResponse -{ - //struct definition - struct Data { - string channel_id; - } - - // 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_channel_id(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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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 (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.channel_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.channel_id = input.channel_id; - } - - //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 IbcApplicationsInterchain_accountsControllerV1MsgRegisterInterchainAccountResponse - -library IbcApplicationsInterchain_accountsControllerV1MsgSendTx { - //struct definition - struct Data { - string owner; - string connection_id; - IbcApplicationsInterchain_accountsV1InterchainAccountPacketData.Data - packet_data; - uint64 relative_timeout; - } - - // 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_owner(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_connection_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_packet_data(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_relative_timeout(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_owner( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.owner = 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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_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_packet_data( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - ( - IbcApplicationsInterchain_accountsV1InterchainAccountPacketData.Data - memory x, - uint256 sz - ) = - _decode_IbcApplicationsInterchain_accountsV1InterchainAccountPacketData( - p, bs - ); - r.packet_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 - * @return The number of bytes decoded - */ - function _read_relative_timeout( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.relative_timeout = 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_IbcApplicationsInterchain_accountsV1InterchainAccountPacketData( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsV1InterchainAccountPacketData.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - ( - IbcApplicationsInterchain_accountsV1InterchainAccountPacketData.Data - memory r, - ) = IbcApplicationsInterchain_accountsV1InterchainAccountPacketData - ._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.owner).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.owner, pointer, bs); - } - if (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcApplicationsInterchain_accountsV1InterchainAccountPacketData - ._encode_nested(r.packet_data, pointer, bs); - - if (r.relative_timeout != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.relative_timeout, 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.owner).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.connection_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsInterchain_accountsV1InterchainAccountPacketData - ._estimate(r.packet_data) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.relative_timeout); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.owner).length != 0) { - return false; - } - - if (bytes(r.connection_id).length != 0) { - return false; - } - - if (r.relative_timeout != 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.owner = input.owner; - output.connection_id = input.connection_id; - IbcApplicationsInterchain_accountsV1InterchainAccountPacketData.store( - input.packet_data, output.packet_data - ); - output.relative_timeout = input.relative_timeout; - } - - //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 IbcApplicationsInterchain_accountsControllerV1MsgSendTx - -library IbcApplicationsInterchain_accountsControllerV1MsgSendTxResponse { - //struct definition - struct Data { - uint64 sequence; - } - - // 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_sequence(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, 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.sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequence != 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.sequence = input.sequence; - } - - //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 IbcApplicationsInterchain_accountsControllerV1MsgSendTxResponse diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/genesis/v1/genesis.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/genesis/v1/genesis.sol deleted file mode 100644 index 472b2b1750..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/genesis/v1/genesis.sol +++ /dev/null @@ -1,2071 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../../ProtoBufRuntime.sol"; -import "../../../../../GoogleProtobufAny.sol"; - -import "../../controller/v1/controller.sol"; -import "../../host/v1/host.sol"; - -library IbcApplicationsInterchain_accountsGenesisV1GenesisState { - //struct definition - struct Data { - IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState.Data - controller_genesis_state; - IbcApplicationsInterchain_accountsGenesisV1HostGenesisState.Data - host_genesis_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_controller_genesis_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_host_genesis_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_controller_genesis_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - ( - IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState - .Data memory x, - uint256 sz - ) = - _decode_IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState( - p, bs - ); - r.controller_genesis_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_host_genesis_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - ( - IbcApplicationsInterchain_accountsGenesisV1HostGenesisState.Data - memory x, - uint256 sz - ) = _decode_IbcApplicationsInterchain_accountsGenesisV1HostGenesisState( - p, bs - ); - r.host_genesis_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_IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState.Data - memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - ( - IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState - .Data memory r, - ) = IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState - ._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_IbcApplicationsInterchain_accountsGenesisV1HostGenesisState( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsGenesisV1HostGenesisState.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - ( - IbcApplicationsInterchain_accountsGenesisV1HostGenesisState.Data - memory r, - ) = IbcApplicationsInterchain_accountsGenesisV1HostGenesisState._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 += - IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState - ._encode_nested(r.controller_genesis_state, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsInterchain_accountsGenesisV1HostGenesisState - ._encode_nested(r.host_genesis_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( - IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState - ._estimate(r.controller_genesis_state) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsInterchain_accountsGenesisV1HostGenesisState - ._estimate(r.host_genesis_state) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState.store( - input.controller_genesis_state, output.controller_genesis_state - ); - IbcApplicationsInterchain_accountsGenesisV1HostGenesisState.store( - input.host_genesis_state, output.host_genesis_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 IbcApplicationsInterchain_accountsGenesisV1GenesisState - -library IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState { - //struct definition - struct Data { - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data[] - active_channels; - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data[] interchain_accounts; - string[] ports; - IbcApplicationsInterchain_accountsControllerV1Params.Data params; - } - - // 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[5] 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_unpacked_repeated_active_channels( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_interchain_accounts( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += - _read_unpacked_repeated_ports(pointer, bs, nil(), counters); - } else if (fieldId == 4) { - pointer += _read_params(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.active_channels.length == 0); - r.active_channels = new IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - .Data[](counters[1]); - } - if (counters[2] > 0) { - require(r.interchain_accounts.length == 0); - r.interchain_accounts = new IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data[](counters[2]); - } - if (counters[3] > 0) { - require(r.ports.length == 0); - r.ports = new string[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_active_channels( - pointer, bs, r, counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_interchain_accounts( - pointer, bs, r, counters - ); - } else if (fieldId == 3) { - pointer += - _read_unpacked_repeated_ports(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_active_channels( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - ( - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data memory - x, - uint256 sz - ) = _decode_IbcApplicationsInterchain_accountsGenesisV1ActiveChannel( - p, bs - ); - if (isNil(r)) { - counters[1] += 1; - } else { - r.active_channels[r.active_channels.length - counters[1]] = x; - counters[1] -= 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_interchain_accounts( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - ( - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data memory x, - uint256 sz - ) = - _decode_IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount( - p, bs - ); - if (isNil(r)) { - counters[2] += 1; - } else { - r.interchain_accounts[r.interchain_accounts.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_ports( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.ports[r.ports.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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - ( - IbcApplicationsInterchain_accountsControllerV1Params.Data memory x, - uint256 sz - ) = _decode_IbcApplicationsInterchain_accountsControllerV1Params(p, bs); - r.params = 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_IbcApplicationsInterchain_accountsGenesisV1ActiveChannel( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - ( - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data memory - r, - ) = IbcApplicationsInterchain_accountsGenesisV1ActiveChannel._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_IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount.Data - memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - ( - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data memory r, - ) = - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - ._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_IbcApplicationsInterchain_accountsControllerV1Params( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsControllerV1Params.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsInterchain_accountsControllerV1Params.Data memory r,) = - IbcApplicationsInterchain_accountsControllerV1Params._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.active_channels.length != 0) { - for (i = 0; i < r.active_channels.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - ._encode_nested(r.active_channels[i], pointer, bs); - } - } - if (r.interchain_accounts.length != 0) { - for (i = 0; i < r.interchain_accounts.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - ._encode_nested(r.interchain_accounts[i], pointer, bs); - } - } - if (r.ports.length != 0) { - for (i = 0; i < r.ports.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.ports[i], pointer, bs); - } - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsInterchain_accountsControllerV1Params - ._encode_nested(r.params, 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; - for (i = 0; i < r.active_channels.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - ._estimate(r.active_channels[i]) - ); - } - for (i = 0; i < r.interchain_accounts.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - ._estimate(r.interchain_accounts[i]) - ); - } - for (i = 0; i < r.ports.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.ports[i]).length); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsInterchain_accountsControllerV1Params._estimate( - r.params - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.active_channels.length != 0) { - return false; - } - - if (r.interchain_accounts.length != 0) { - return false; - } - - if (r.ports.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 { - for (uint256 i1 = 0; i1 < input.active_channels.length; i1++) { - output.active_channels.push(input.active_channels[i1]); - } - - for (uint256 i2 = 0; i2 < input.interchain_accounts.length; i2++) { - output.interchain_accounts.push(input.interchain_accounts[i2]); - } - - output.ports = input.ports; - IbcApplicationsInterchain_accountsControllerV1Params.store( - input.params, output.params - ); - } - - //array helpers for ActiveChannels - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addActiveChannels( - Data memory self, - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data memory - value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data[] memory - tmp = new IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - .Data[](self.active_channels.length + 1); - for (uint256 i; i < self.active_channels.length; i++) { - tmp[i] = self.active_channels[i]; - } - tmp[self.active_channels.length] = value; - self.active_channels = tmp; - } - - //array helpers for InterchainAccounts - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addInterchainAccounts( - Data memory self, - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data[] memory tmp = new IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data[](self.interchain_accounts.length + 1); - for (uint256 i; i < self.interchain_accounts.length; i++) { - tmp[i] = self.interchain_accounts[i]; - } - tmp[self.interchain_accounts.length] = value; - self.interchain_accounts = tmp; - } - - //array helpers for Ports - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPorts(Data memory self, string memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.ports.length + 1); - for (uint256 i; i < self.ports.length; i++) { - tmp[i] = self.ports[i]; - } - tmp[self.ports.length] = value; - self.ports = 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 IbcApplicationsInterchain_accountsGenesisV1ControllerGenesisState - -library IbcApplicationsInterchain_accountsGenesisV1HostGenesisState { - //struct definition - struct Data { - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data[] - active_channels; - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data[] interchain_accounts; - string port; - IbcApplicationsInterchain_accountsHostV1Params.Data params; - } - - // 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[5] 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_unpacked_repeated_active_channels( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_interchain_accounts( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += _read_port(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_params(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.active_channels.length == 0); - r.active_channels = new IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - .Data[](counters[1]); - } - if (counters[2] > 0) { - require(r.interchain_accounts.length == 0); - r.interchain_accounts = new IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_active_channels( - pointer, bs, r, counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_interchain_accounts( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_active_channels( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - ( - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data memory - x, - uint256 sz - ) = _decode_IbcApplicationsInterchain_accountsGenesisV1ActiveChannel( - p, bs - ); - if (isNil(r)) { - counters[1] += 1; - } else { - r.active_channels[r.active_channels.length - counters[1]] = x; - counters[1] -= 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_interchain_accounts( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - ( - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data memory x, - uint256 sz - ) = - _decode_IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount( - p, bs - ); - if (isNil(r)) { - counters[2] += 1; - } else { - r.interchain_accounts[r.interchain_accounts.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_port( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port = 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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - ( - IbcApplicationsInterchain_accountsHostV1Params.Data memory x, - uint256 sz - ) = _decode_IbcApplicationsInterchain_accountsHostV1Params(p, bs); - r.params = 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_IbcApplicationsInterchain_accountsGenesisV1ActiveChannel( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - ( - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data memory - r, - ) = IbcApplicationsInterchain_accountsGenesisV1ActiveChannel._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_IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount.Data - memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - ( - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data memory r, - ) = - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - ._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_IbcApplicationsInterchain_accountsHostV1Params( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsHostV1Params.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsInterchain_accountsHostV1Params.Data memory r,) = - IbcApplicationsInterchain_accountsHostV1Params._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.active_channels.length != 0) { - for (i = 0; i < r.active_channels.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - ._encode_nested(r.active_channels[i], pointer, bs); - } - } - if (r.interchain_accounts.length != 0) { - for (i = 0; i < r.interchain_accounts.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - ._encode_nested(r.interchain_accounts[i], pointer, bs); - } - } - if (bytes(r.port).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsInterchain_accountsHostV1Params._encode_nested( - r.params, 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; - for (i = 0; i < r.active_channels.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - ._estimate(r.active_channels[i]) - ); - } - for (i = 0; i < r.interchain_accounts.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - ._estimate(r.interchain_accounts[i]) - ); - } - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.port).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsInterchain_accountsHostV1Params._estimate(r.params) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.active_channels.length != 0) { - return false; - } - - if (r.interchain_accounts.length != 0) { - return false; - } - - if (bytes(r.port).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 { - for (uint256 i1 = 0; i1 < input.active_channels.length; i1++) { - output.active_channels.push(input.active_channels[i1]); - } - - for (uint256 i2 = 0; i2 < input.interchain_accounts.length; i2++) { - output.interchain_accounts.push(input.interchain_accounts[i2]); - } - - output.port = input.port; - IbcApplicationsInterchain_accountsHostV1Params.store( - input.params, output.params - ); - } - - //array helpers for ActiveChannels - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addActiveChannels( - Data memory self, - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data memory - value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsInterchain_accountsGenesisV1ActiveChannel.Data[] memory - tmp = new IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - .Data[](self.active_channels.length + 1); - for (uint256 i; i < self.active_channels.length; i++) { - tmp[i] = self.active_channels[i]; - } - tmp[self.active_channels.length] = value; - self.active_channels = tmp; - } - - //array helpers for InterchainAccounts - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addInterchainAccounts( - Data memory self, - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data[] memory tmp = new IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount - .Data[](self.interchain_accounts.length + 1); - for (uint256 i; i < self.interchain_accounts.length; i++) { - tmp[i] = self.interchain_accounts[i]; - } - tmp[self.interchain_accounts.length] = value; - self.interchain_accounts = 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 IbcApplicationsInterchain_accountsGenesisV1HostGenesisState - -library IbcApplicationsInterchain_accountsGenesisV1ActiveChannel { - //struct definition - struct Data { - string connection_id; - string port_id; - string channel_id; - bool is_middleware_enabled; - } - - // 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_connection_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_port_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_is_middleware_enabled(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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_is_middleware_enabled( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.is_middleware_enabled = 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 (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, pointer, bs); - } - if (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.is_middleware_enabled != false) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool( - r.is_middleware_enabled, 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.connection_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.connection_id).length != 0) { - return false; - } - - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.is_middleware_enabled != false) { - 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.connection_id = input.connection_id; - output.port_id = input.port_id; - output.channel_id = input.channel_id; - output.is_middleware_enabled = input.is_middleware_enabled; - } - - //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 IbcApplicationsInterchain_accountsGenesisV1ActiveChannel - -library IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount { - //struct definition - struct Data { - string connection_id; - string port_id; - string account_address; - } - - // 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_connection_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_port_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_account_address(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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_account_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.account_address = 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 (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, pointer, bs); - } - if (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.account_address).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.account_address, 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.connection_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.account_address).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.connection_id).length != 0) { - return false; - } - - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.account_address).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.connection_id = input.connection_id; - output.port_id = input.port_id; - output.account_address = input.account_address; - } - - //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 IbcApplicationsInterchain_accountsGenesisV1RegisteredInterchainAccount diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/host/v1/host.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/host/v1/host.sol deleted file mode 100644 index dd05685fc6..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/host/v1/host.sol +++ /dev/null @@ -1,309 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../../ProtoBufRuntime.sol"; -import "../../../../../GoogleProtobufAny.sol"; - -library IbcApplicationsInterchain_accountsHostV1Params { - //struct definition - struct Data { - bool host_enabled; - string[] allow_messages; - } - - // 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_host_enabled(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_allow_messages( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[2] > 0) { - require(r.allow_messages.length == 0); - r.allow_messages = new string[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 2) { - pointer += _read_unpacked_repeated_allow_messages( - 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_host_enabled( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.host_enabled = 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_allow_messages( - 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. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.allow_messages[r.allow_messages.length - counters[2]] = x; - counters[2] -= 1; - } - 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; - uint256 i; - if (r.host_enabled != false) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool(r.host_enabled, pointer, bs); - } - if (r.allow_messages.length != 0) { - for (i = 0; i < r.allow_messages.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.allow_messages[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 + 1; - for (i = 0; i < r.allow_messages.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.allow_messages[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.host_enabled != false) { - return false; - } - - if (r.allow_messages.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.host_enabled = input.host_enabled; - output.allow_messages = input.allow_messages; - } - - //array helpers for AllowMessages - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAllowMessages( - Data memory self, - string memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.allow_messages.length + 1); - for (uint256 i; i < self.allow_messages.length; i++) { - tmp[i] = self.allow_messages[i]; - } - tmp[self.allow_messages.length] = value; - self.allow_messages = 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 IbcApplicationsInterchain_accountsHostV1Params diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/host/v1/query.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/host/v1/query.sol deleted file mode 100644 index d19b8328a1..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/host/v1/query.sol +++ /dev/null @@ -1,425 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../../ProtoBufRuntime.sol"; -import "../../../../../GoogleProtobufAny.sol"; - -import "./host.sol"; - -library IbcApplicationsInterchain_accountsHostV1QueryParamsRequest { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcApplicationsInterchain_accountsHostV1QueryParamsRequest - -library IbcApplicationsInterchain_accountsHostV1QueryParamsResponse { - //struct definition - struct Data { - IbcApplicationsInterchain_accountsHostV1Params.Data params; - } - - // 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_params(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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - ( - IbcApplicationsInterchain_accountsHostV1Params.Data memory x, - uint256 sz - ) = _decode_IbcApplicationsInterchain_accountsHostV1Params(p, bs); - r.params = 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_IbcApplicationsInterchain_accountsHostV1Params( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcApplicationsInterchain_accountsHostV1Params.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsInterchain_accountsHostV1Params.Data memory r,) = - IbcApplicationsInterchain_accountsHostV1Params._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 += IbcApplicationsInterchain_accountsHostV1Params._encode_nested( - r.params, 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( - IbcApplicationsInterchain_accountsHostV1Params._estimate(r.params) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcApplicationsInterchain_accountsHostV1Params.store( - input.params, output.params - ); - } - - //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 IbcApplicationsInterchain_accountsHostV1QueryParamsResponse diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/v1/account.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/v1/account.sol deleted file mode 100644 index 20120453b8..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/v1/account.sol +++ /dev/null @@ -1,280 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../../cosmos_proto/cosmos.sol"; - -import "../../../../cosmos/auth/v1beta1/auth.sol"; - -library IbcApplicationsInterchain_accountsV1InterchainAccount { - //struct definition - struct Data { - CosmosAuthV1beta1BaseAccount.Data base_account; - string account_owner; - } - - // 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_base_account(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_account_owner(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_base_account( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosAuthV1beta1BaseAccount.Data memory x, uint256 sz) = - _decode_CosmosAuthV1beta1BaseAccount(p, bs); - r.base_account = 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_account_owner( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.account_owner = 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_CosmosAuthV1beta1BaseAccount( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosAuthV1beta1BaseAccount.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosAuthV1beta1BaseAccount.Data memory r,) = - CosmosAuthV1beta1BaseAccount._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 += CosmosAuthV1beta1BaseAccount._encode_nested( - r.base_account, pointer, bs - ); - - if (bytes(r.account_owner).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.account_owner, 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( - CosmosAuthV1beta1BaseAccount._estimate(r.base_account) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.account_owner).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.account_owner).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 { - CosmosAuthV1beta1BaseAccount.store( - input.base_account, output.base_account - ); - output.account_owner = input.account_owner; - } - - //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 IbcApplicationsInterchain_accountsV1InterchainAccount diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/v1/metadata.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/v1/metadata.sol deleted file mode 100644 index 9e020b8e65..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/v1/metadata.sol +++ /dev/null @@ -1,382 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcApplicationsInterchain_accountsV1Metadata { - //struct definition - struct Data { - string version; - string controller_connection_id; - string host_connection_id; - string address_; - string encoding; - string tx_type; - } - - // 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(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_controller_connection_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_host_connection_id(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_address(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_encoding(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_tx_type(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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.version = 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_controller_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.controller_connection_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_host_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.host_connection_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_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.address_ = 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_encoding( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.encoding = 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_tx_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.tx_type = 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 (bytes(r.version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.version, pointer, bs); - } - if (bytes(r.controller_connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.controller_connection_id, pointer, bs - ); - } - if (bytes(r.host_connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.host_connection_id, pointer, bs - ); - } - if (bytes(r.address_).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.address_, pointer, bs); - } - if (bytes(r.encoding).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.encoding, pointer, bs); - } - if (bytes(r.tx_type).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.tx_type, 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.version).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.controller_connection_id).length); - e += - 1 + ProtoBufRuntime._sz_lendelim(bytes(r.host_connection_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.address_).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.encoding).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.tx_type).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.version).length != 0) { - return false; - } - - if (bytes(r.controller_connection_id).length != 0) { - return false; - } - - if (bytes(r.host_connection_id).length != 0) { - return false; - } - - if (bytes(r.address_).length != 0) { - return false; - } - - if (bytes(r.encoding).length != 0) { - return false; - } - - if (bytes(r.tx_type).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.version = input.version; - output.controller_connection_id = input.controller_connection_id; - output.host_connection_id = input.host_connection_id; - output.address_ = input.address_; - output.encoding = input.encoding; - output.tx_type = input.tx_type; - } - - //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 IbcApplicationsInterchain_accountsV1Metadata diff --git a/evm/contracts/proto/ibc/applications/interchain_accounts/v1/packet.sol b/evm/contracts/proto/ibc/applications/interchain_accounts/v1/packet.sol deleted file mode 100644 index c3f9e2aeac..0000000000 --- a/evm/contracts/proto/ibc/applications/interchain_accounts/v1/packet.sol +++ /dev/null @@ -1,641 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcApplicationsInterchain_accountsV1InterchainAccountPacketData { - //struct definition - struct Data { - IbcApplicationsInterchainAccountsV1PacketGlobalEnums.Type type_; - bytes data; - string memo; - } - - // 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_type(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_data(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_memo(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_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcApplicationsInterchainAccountsV1PacketGlobalEnums.Type x = - IbcApplicationsInterchainAccountsV1PacketGlobalEnums.decode_Type(tmp); - r.type_ = 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_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 - * @return The number of bytes decoded - */ - function _read_memo( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.memo = 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 (uint256(r.type_) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_type = - IbcApplicationsInterchainAccountsV1PacketGlobalEnums.encode_Type( - r.type_ - ); - pointer += ProtoBufRuntime._encode_enum(_enum_type, pointer, bs); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); - } - if (bytes(r.memo).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.memo, 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( - IbcApplicationsInterchainAccountsV1PacketGlobalEnums.encode_Type( - r.type_ - ) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.memo).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.type_) != 0) { - return false; - } - - if (r.data.length != 0) { - return false; - } - - if (bytes(r.memo).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.type_ = input.type_; - output.data = input.data; - output.memo = input.memo; - } - - //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 IbcApplicationsInterchain_accountsV1InterchainAccountPacketData - -library IbcApplicationsInterchain_accountsV1CosmosTx { - //struct definition - struct Data { - GoogleProtobufAny.Data[] messages; - } - - // 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[2] 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_unpacked_repeated_messages( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.messages.length == 0); - r.messages = new GoogleProtobufAny.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_messages(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_messages( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] 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[1] += 1; - } else { - r.messages[r.messages.length - counters[1]] = x; - counters[1] -= 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.messages.length != 0) { - for (i = 0; i < r.messages.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufAny._encode_nested(r.messages[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; - for (i = 0; i < r.messages.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.messages[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.messages.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 { - for (uint256 i1 = 0; i1 < input.messages.length; i1++) { - output.messages.push(input.messages[i1]); - } - } - - //array helpers for Messages - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addMessages( - 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.messages.length + 1); - for (uint256 i; i < self.messages.length; i++) { - tmp[i] = self.messages[i]; - } - tmp[self.messages.length] = value; - self.messages = 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 IbcApplicationsInterchain_accountsV1CosmosTx - -library IbcApplicationsInterchainAccountsV1PacketGlobalEnums { - //enum definition - // Solidity enum definitions - enum Type { - TYPE_UNSPECIFIED, - TYPE_EXECUTE_TX - } - - // Solidity enum encoder - function encode_Type(Type x) internal pure returns (int32) { - if (x == Type.TYPE_UNSPECIFIED) { - return 0; - } - - if (x == Type.TYPE_EXECUTE_TX) { - return 1; - } - revert(); - } - - // Solidity enum decoder - function decode_Type(int64 x) internal pure returns (Type) { - if (x == 0) { - return Type.TYPE_UNSPECIFIED; - } - - if (x == 1) { - return Type.TYPE_EXECUTE_TX; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_Type(Type[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_Type(a[i])); - } - return e; - } -} -//library IbcApplicationsInterchainAccountsV1PacketGlobalEnums diff --git a/evm/contracts/proto/ibc/applications/transfer/v1/authz.sol b/evm/contracts/proto/ibc/applications/transfer/v1/authz.sol deleted file mode 100644 index 622f2b29f1..0000000000 --- a/evm/contracts/proto/ibc/applications/transfer/v1/authz.sol +++ /dev/null @@ -1,758 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../../cosmos_proto/cosmos.sol"; - -import "../../../../cosmos/base/v1beta1/coin.sol"; - -library IbcApplicationsTransferV1Allocation { - //struct definition - struct Data { - string source_port; - string source_channel; - CosmosBaseV1beta1Coin.Data[] spend_limit; - string[] allow_list; - } - - // 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[5] 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_source_port(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_source_channel(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_spend_limit( - pointer, bs, nil(), counters - ); - } else if (fieldId == 4) { - pointer += _read_unpacked_repeated_allow_list( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[3] > 0) { - require(r.spend_limit.length == 0); - r.spend_limit = new CosmosBaseV1beta1Coin.Data[](counters[3]); - } - if (counters[4] > 0) { - require(r.allow_list.length == 0); - r.allow_list = new string[](counters[4]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 3) { - pointer += _read_unpacked_repeated_spend_limit( - pointer, bs, r, counters - ); - } else if (fieldId == 4) { - pointer += - _read_unpacked_repeated_allow_list(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_source_port( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.source_port = 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_source_channel( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.source_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_spend_limit( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosBaseV1beta1Coin.Data memory x, uint256 sz) = - _decode_CosmosBaseV1beta1Coin(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.spend_limit[r.spend_limit.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_allow_list( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.allow_list[r.allow_list.length - counters[4]] = x; - counters[4] -= 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_CosmosBaseV1beta1Coin( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosBaseV1beta1Coin.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseV1beta1Coin.Data memory r,) = - CosmosBaseV1beta1Coin._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.source_port).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.source_port, pointer, bs); - } - if (bytes(r.source_channel).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.source_channel, pointer, bs); - } - if (r.spend_limit.length != 0) { - for (i = 0; i < r.spend_limit.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseV1beta1Coin._encode_nested( - r.spend_limit[i], pointer, bs - ); - } - } - if (r.allow_list.length != 0) { - for (i = 0; i < r.allow_list.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.allow_list[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.source_port).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.source_channel).length); - for (i = 0; i < r.spend_limit.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseV1beta1Coin._estimate(r.spend_limit[i]) - ); - } - for (i = 0; i < r.allow_list.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.allow_list[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.source_port).length != 0) { - return false; - } - - if (bytes(r.source_channel).length != 0) { - return false; - } - - if (r.spend_limit.length != 0) { - return false; - } - - if (r.allow_list.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.source_port = input.source_port; - output.source_channel = input.source_channel; - - for (uint256 i3 = 0; i3 < input.spend_limit.length; i3++) { - output.spend_limit.push(input.spend_limit[i3]); - } - - output.allow_list = input.allow_list; - } - - //array helpers for SpendLimit - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addSpendLimit( - Data memory self, - CosmosBaseV1beta1Coin.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosBaseV1beta1Coin.Data[] memory tmp = - new CosmosBaseV1beta1Coin.Data[](self.spend_limit.length + 1); - for (uint256 i; i < self.spend_limit.length; i++) { - tmp[i] = self.spend_limit[i]; - } - tmp[self.spend_limit.length] = value; - self.spend_limit = tmp; - } - - //array helpers for AllowList - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAllowList( - Data memory self, - string memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.allow_list.length + 1); - for (uint256 i; i < self.allow_list.length; i++) { - tmp[i] = self.allow_list[i]; - } - tmp[self.allow_list.length] = value; - self.allow_list = 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 IbcApplicationsTransferV1Allocation - -library IbcApplicationsTransferV1TransferAuthorization { - //struct definition - struct Data { - IbcApplicationsTransferV1Allocation.Data[] allocations; - } - - // 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[2] 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_unpacked_repeated_allocations( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.allocations.length == 0); - r.allocations = - new IbcApplicationsTransferV1Allocation.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_allocations( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_allocations( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcApplicationsTransferV1Allocation.Data memory x, uint256 sz) = - _decode_IbcApplicationsTransferV1Allocation(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.allocations[r.allocations.length - counters[1]] = x; - counters[1] -= 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_IbcApplicationsTransferV1Allocation( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsTransferV1Allocation.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsTransferV1Allocation.Data memory r,) = - IbcApplicationsTransferV1Allocation._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.allocations.length != 0) { - for (i = 0; i < r.allocations.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsTransferV1Allocation._encode_nested( - r.allocations[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; - for (i = 0; i < r.allocations.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsTransferV1Allocation._estimate(r.allocations[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.allocations.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 { - for (uint256 i1 = 0; i1 < input.allocations.length; i1++) { - output.allocations.push(input.allocations[i1]); - } - } - - //array helpers for Allocations - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAllocations( - Data memory self, - IbcApplicationsTransferV1Allocation.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsTransferV1Allocation.Data[] memory tmp = new IbcApplicationsTransferV1Allocation - .Data[](self.allocations.length + 1); - for (uint256 i; i < self.allocations.length; i++) { - tmp[i] = self.allocations[i]; - } - tmp[self.allocations.length] = value; - self.allocations = 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 IbcApplicationsTransferV1TransferAuthorization diff --git a/evm/contracts/proto/ibc/applications/transfer/v1/genesis.sol b/evm/contracts/proto/ibc/applications/transfer/v1/genesis.sol deleted file mode 100644 index 564717c676..0000000000 --- a/evm/contracts/proto/ibc/applications/transfer/v1/genesis.sol +++ /dev/null @@ -1,402 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "./transfer.sol"; - -library IbcApplicationsTransferV1GenesisState { - //struct definition - struct Data { - string port_id; - IbcApplicationsTransferV1DenomTrace.Data[] denom_traces; - IbcApplicationsTransferV1Params.Data params; - } - - // 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[4] 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_denom_traces( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += _read_params(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[2] > 0) { - require(r.denom_traces.length == 0); - r.denom_traces = - new IbcApplicationsTransferV1DenomTrace.Data[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 2) { - pointer += _read_unpacked_repeated_denom_traces( - 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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_denom_traces( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcApplicationsTransferV1DenomTrace.Data memory x, uint256 sz) = - _decode_IbcApplicationsTransferV1DenomTrace(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.denom_traces[r.denom_traces.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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcApplicationsTransferV1Params.Data memory x, uint256 sz) = - _decode_IbcApplicationsTransferV1Params(p, bs); - r.params = 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_IbcApplicationsTransferV1DenomTrace( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsTransferV1DenomTrace.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsTransferV1DenomTrace.Data memory r,) = - IbcApplicationsTransferV1DenomTrace._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_IbcApplicationsTransferV1Params( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsTransferV1Params.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsTransferV1Params.Data memory r,) = - IbcApplicationsTransferV1Params._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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (r.denom_traces.length != 0) { - for (i = 0; i < r.denom_traces.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsTransferV1DenomTrace._encode_nested( - r.denom_traces[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsTransferV1Params._encode_nested( - r.params, 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.port_id).length); - for (i = 0; i < r.denom_traces.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsTransferV1DenomTrace._estimate(r.denom_traces[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsTransferV1Params._estimate(r.params) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (r.denom_traces.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.port_id = input.port_id; - - for (uint256 i2 = 0; i2 < input.denom_traces.length; i2++) { - output.denom_traces.push(input.denom_traces[i2]); - } - - IbcApplicationsTransferV1Params.store(input.params, output.params); - } - - //array helpers for DenomTraces - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addDenomTraces( - Data memory self, - IbcApplicationsTransferV1DenomTrace.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsTransferV1DenomTrace.Data[] memory tmp = new IbcApplicationsTransferV1DenomTrace - .Data[](self.denom_traces.length + 1); - for (uint256 i; i < self.denom_traces.length; i++) { - tmp[i] = self.denom_traces[i]; - } - tmp[self.denom_traces.length] = value; - self.denom_traces = 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 IbcApplicationsTransferV1GenesisState diff --git a/evm/contracts/proto/ibc/applications/transfer/v1/query.sol b/evm/contracts/proto/ibc/applications/transfer/v1/query.sol deleted file mode 100644 index 9a5bd935f1..0000000000 --- a/evm/contracts/proto/ibc/applications/transfer/v1/query.sol +++ /dev/null @@ -1,2366 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../../../cosmos/base/query/v1beta1/pagination.sol"; -import "./transfer.sol"; - -library IbcApplicationsTransferV1QueryDenomTraceRequest { - //struct definition - struct Data { - string hash; - } - - // 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_hash(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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.hash = 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 (bytes(r.hash).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.hash, 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.hash).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.hash).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.hash = input.hash; - } - - //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 IbcApplicationsTransferV1QueryDenomTraceRequest - -library IbcApplicationsTransferV1QueryDenomTraceResponse { - //struct definition - struct Data { - IbcApplicationsTransferV1DenomTrace.Data denom_trace; - } - - // 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_denom_trace(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_denom_trace( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcApplicationsTransferV1DenomTrace.Data memory x, uint256 sz) = - _decode_IbcApplicationsTransferV1DenomTrace(p, bs); - r.denom_trace = 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_IbcApplicationsTransferV1DenomTrace( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsTransferV1DenomTrace.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsTransferV1DenomTrace.Data memory r,) = - IbcApplicationsTransferV1DenomTrace._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 += IbcApplicationsTransferV1DenomTrace._encode_nested( - r.denom_trace, 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( - IbcApplicationsTransferV1DenomTrace._estimate(r.denom_trace) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcApplicationsTransferV1DenomTrace.store( - input.denom_trace, output.denom_trace - ); - } - - //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 IbcApplicationsTransferV1QueryDenomTraceResponse - -library IbcApplicationsTransferV1QueryDenomTracesRequest { - //struct definition - struct Data { - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_pagination(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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcApplicationsTransferV1QueryDenomTracesRequest - -library IbcApplicationsTransferV1QueryDenomTracesResponse { - //struct definition - struct Data { - IbcApplicationsTransferV1DenomTrace.Data[] denom_traces; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - } - - // 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_unpacked_repeated_denom_traces( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.denom_traces.length == 0); - r.denom_traces = - new IbcApplicationsTransferV1DenomTrace.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_denom_traces( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_denom_traces( - 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. - */ - (IbcApplicationsTransferV1DenomTrace.Data memory x, uint256 sz) = - _decode_IbcApplicationsTransferV1DenomTrace(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.denom_traces[r.denom_traces.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_IbcApplicationsTransferV1DenomTrace( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsTransferV1DenomTrace.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsTransferV1DenomTrace.Data memory r,) = - IbcApplicationsTransferV1DenomTrace._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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.denom_traces.length != 0) { - for (i = 0; i < r.denom_traces.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcApplicationsTransferV1DenomTrace._encode_nested( - r.denom_traces[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, 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; - for (i = 0; i < r.denom_traces.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcApplicationsTransferV1DenomTrace._estimate(r.denom_traces[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.denom_traces.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 { - for (uint256 i1 = 0; i1 < input.denom_traces.length; i1++) { - output.denom_traces.push(input.denom_traces[i1]); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - } - - //array helpers for DenomTraces - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addDenomTraces( - Data memory self, - IbcApplicationsTransferV1DenomTrace.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcApplicationsTransferV1DenomTrace.Data[] memory tmp = new IbcApplicationsTransferV1DenomTrace - .Data[](self.denom_traces.length + 1); - for (uint256 i; i < self.denom_traces.length; i++) { - tmp[i] = self.denom_traces[i]; - } - tmp[self.denom_traces.length] = value; - self.denom_traces = 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 IbcApplicationsTransferV1QueryDenomTracesResponse - -library IbcApplicationsTransferV1QueryParamsRequest { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcApplicationsTransferV1QueryParamsRequest - -library IbcApplicationsTransferV1QueryParamsResponse { - //struct definition - struct Data { - IbcApplicationsTransferV1Params.Data params; - } - - // 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_params(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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcApplicationsTransferV1Params.Data memory x, uint256 sz) = - _decode_IbcApplicationsTransferV1Params(p, bs); - r.params = 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_IbcApplicationsTransferV1Params( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcApplicationsTransferV1Params.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcApplicationsTransferV1Params.Data memory r,) = - IbcApplicationsTransferV1Params._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 += IbcApplicationsTransferV1Params._encode_nested( - r.params, 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( - IbcApplicationsTransferV1Params._estimate(r.params) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcApplicationsTransferV1Params.store(input.params, output.params); - } - - //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 IbcApplicationsTransferV1QueryParamsResponse - -library IbcApplicationsTransferV1QueryDenomHashRequest { - //struct definition - struct Data { - string trace; - } - - // 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_trace(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_trace( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.trace = 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 (bytes(r.trace).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.trace, 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.trace).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.trace).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.trace = input.trace; - } - - //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 IbcApplicationsTransferV1QueryDenomHashRequest - -library IbcApplicationsTransferV1QueryDenomHashResponse { - //struct definition - struct Data { - string hash; - } - - // 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_hash(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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.hash = 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 (bytes(r.hash).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.hash, 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.hash).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.hash).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.hash = input.hash; - } - - //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 IbcApplicationsTransferV1QueryDenomHashResponse - -library IbcApplicationsTransferV1QueryEscrowAddressRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - } - - //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 IbcApplicationsTransferV1QueryEscrowAddressRequest - -library IbcApplicationsTransferV1QueryEscrowAddressResponse { - //struct definition - struct Data { - string escrow_address; - } - - // 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_escrow_address(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_escrow_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.escrow_address = 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 (bytes(r.escrow_address).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.escrow_address, 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.escrow_address).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.escrow_address).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.escrow_address = input.escrow_address; - } - - //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 IbcApplicationsTransferV1QueryEscrowAddressResponse diff --git a/evm/contracts/proto/ibc/applications/transfer/v1/transfer.sol b/evm/contracts/proto/ibc/applications/transfer/v1/transfer.sol deleted file mode 100644 index 4006448d99..0000000000 --- a/evm/contracts/proto/ibc/applications/transfer/v1/transfer.sol +++ /dev/null @@ -1,493 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcApplicationsTransferV1DenomTrace { - //struct definition - struct Data { - string path; - string base_denom; - } - - // 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_path(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_base_denom(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.path = 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_base_denom( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.base_denom = 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 (bytes(r.path).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.path, pointer, bs); - } - if (bytes(r.base_denom).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.base_denom, 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.path).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.base_denom).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.path).length != 0) { - return false; - } - - if (bytes(r.base_denom).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.path = input.path; - output.base_denom = input.base_denom; - } - - //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 IbcApplicationsTransferV1DenomTrace - -library IbcApplicationsTransferV1Params { - //struct definition - struct Data { - bool send_enabled; - bool receive_enabled; - } - - // 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_send_enabled(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_receive_enabled(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_send_enabled( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.send_enabled = 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_receive_enabled( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.receive_enabled = 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.send_enabled != false) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool(r.send_enabled, pointer, bs); - } - if (r.receive_enabled != false) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bool(r.receive_enabled, 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 - * @return The number of bytes encoded in estimation - */ - function _estimate(Data memory /* r */ ) internal pure returns (uint256) { - uint256 e; - e += 1 + 1; - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.send_enabled != false) { - return false; - } - - if (r.receive_enabled != false) { - 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.send_enabled = input.send_enabled; - output.receive_enabled = input.receive_enabled; - } - - //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 IbcApplicationsTransferV1Params diff --git a/evm/contracts/proto/ibc/applications/transfer/v1/tx.sol b/evm/contracts/proto/ibc/applications/transfer/v1/tx.sol deleted file mode 100644 index d353f2347e..0000000000 --- a/evm/contracts/proto/ibc/applications/transfer/v1/tx.sol +++ /dev/null @@ -1,699 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../../../cosmos/base/v1beta1/coin.sol"; -import "../../../core/client/v1/client.sol"; - -library IbcApplicationsTransferV1MsgTransfer { - //struct definition - struct Data { - string source_port; - string source_channel; - CosmosBaseV1beta1Coin.Data token; - string sender; - string receiver; - IbcCoreClientV1Height.Data timeout_height; - uint64 timeout_timestamp; - string memo; - } - - // 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_source_port(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_source_channel(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_token(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_sender(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_receiver(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_timeout_height(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_timeout_timestamp(pointer, bs, r); - } else if (fieldId == 8) { - pointer += _read_memo(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_source_port( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.source_port = 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_source_channel( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.source_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_token( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseV1beta1Coin.Data memory x, uint256 sz) = - _decode_CosmosBaseV1beta1Coin(p, bs); - r.token = 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_sender( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.sender = 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_receiver( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.receiver = 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_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; - } - - /** - * @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_memo( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.memo = 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_CosmosBaseV1beta1Coin( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosBaseV1beta1Coin.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseV1beta1Coin.Data memory r,) = - CosmosBaseV1beta1Coin._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.source_port).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.source_port, pointer, bs); - } - if (bytes(r.source_channel).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.source_channel, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseV1beta1Coin._encode_nested(r.token, pointer, bs); - - if (bytes(r.sender).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.sender, pointer, bs); - } - if (bytes(r.receiver).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.receiver, 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); - } - if (bytes(r.memo).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 8, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.memo, 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.source_port).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.source_channel).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(CosmosBaseV1beta1Coin._estimate(r.token)); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.sender).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.receiver).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.timeout_height) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.timeout_timestamp); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.memo).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.source_port).length != 0) { - return false; - } - - if (bytes(r.source_channel).length != 0) { - return false; - } - - if (bytes(r.sender).length != 0) { - return false; - } - - if (bytes(r.receiver).length != 0) { - return false; - } - - if (r.timeout_timestamp != 0) { - return false; - } - - if (bytes(r.memo).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.source_port = input.source_port; - output.source_channel = input.source_channel; - CosmosBaseV1beta1Coin.store(input.token, output.token); - output.sender = input.sender; - output.receiver = input.receiver; - IbcCoreClientV1Height.store(input.timeout_height, output.timeout_height); - output.timeout_timestamp = input.timeout_timestamp; - output.memo = input.memo; - } - - //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 IbcApplicationsTransferV1MsgTransfer - -library IbcApplicationsTransferV1MsgTransferResponse { - //struct definition - struct Data { - uint64 sequence; - } - - // 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_sequence(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, 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.sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequence != 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.sequence = input.sequence; - } - - //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 IbcApplicationsTransferV1MsgTransferResponse diff --git a/evm/contracts/proto/ibc/applications/transfer/v2/packet.sol b/evm/contracts/proto/ibc/applications/transfer/v2/packet.sol deleted file mode 100644 index 5e98bce50c..0000000000 --- a/evm/contracts/proto/ibc/applications/transfer/v2/packet.sol +++ /dev/null @@ -1,344 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcApplicationsTransferV2FungibleTokenPacketData { - //struct definition - struct Data { - string denom; - string amount; - string sender; - string receiver; - string memo; - } - - // 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_denom(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_amount(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_sender(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_receiver(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_memo(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_denom( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.denom = 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_amount( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.amount = 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_sender( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.sender = 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_receiver( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.receiver = 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_memo( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.memo = 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 (bytes(r.denom).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.denom, pointer, bs); - } - if (bytes(r.amount).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.amount, pointer, bs); - } - if (bytes(r.sender).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.sender, pointer, bs); - } - if (bytes(r.receiver).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.receiver, pointer, bs); - } - if (bytes(r.memo).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.memo, 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.denom).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.amount).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.sender).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.receiver).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.memo).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.denom).length != 0) { - return false; - } - - if (bytes(r.amount).length != 0) { - return false; - } - - if (bytes(r.sender).length != 0) { - return false; - } - - if (bytes(r.receiver).length != 0) { - return false; - } - - if (bytes(r.memo).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.denom = input.denom; - output.amount = input.amount; - output.sender = input.sender; - output.receiver = input.receiver; - output.memo = input.memo; - } - - //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 IbcApplicationsTransferV2FungibleTokenPacketData diff --git a/evm/contracts/proto/ibc/core/channel/v1/channel.sol b/evm/contracts/proto/ibc/core/channel/v1/channel.sol deleted file mode 100644 index 512cba41e5..0000000000 --- a/evm/contracts/proto/ibc/core/channel/v1/channel.sol +++ /dev/null @@ -1,2634 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../client/v1/client.sol"; - -library IbcCoreChannelV1Channel { - //struct definition - struct Data { - IbcCoreChannelV1GlobalEnums.State state; - IbcCoreChannelV1GlobalEnums.Order ordering; - IbcCoreChannelV1Counterparty.Data counterparty; - string[] connection_hops; - string version; - } - - // 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_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_ordering(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_counterparty(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_unpacked_repeated_connection_hops( - pointer, bs, nil(), counters - ); - } else if (fieldId == 5) { - pointer += _read_version(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[4] > 0) { - require(r.connection_hops.length == 0); - r.connection_hops = new string[](counters[4]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 4) { - pointer += _read_unpacked_repeated_connection_hops( - 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_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreChannelV1GlobalEnums.State x = - IbcCoreChannelV1GlobalEnums.decode_State(tmp); - r.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_ordering( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreChannelV1GlobalEnums.Order x = - IbcCoreChannelV1GlobalEnums.decode_Order(tmp); - r.ordering = 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_counterparty( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Counterparty.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Counterparty(p, bs); - r.counterparty = 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_connection_hops( - 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. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.connection_hops[r.connection_hops.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 - * @return The number of bytes decoded - */ - function _read_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.version = 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_IbcCoreChannelV1Counterparty( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1Counterparty.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Counterparty.Data memory r,) = - IbcCoreChannelV1Counterparty._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 (uint256(r.state) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_state = - IbcCoreChannelV1GlobalEnums.encode_State(r.state); - pointer += ProtoBufRuntime._encode_enum(_enum_state, pointer, bs); - } - if (uint256(r.ordering) != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_ordering = - IbcCoreChannelV1GlobalEnums.encode_Order(r.ordering); - pointer += ProtoBufRuntime._encode_enum(_enum_ordering, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1Counterparty._encode_nested( - r.counterparty, pointer, bs - ); - - if (r.connection_hops.length != 0) { - for (i = 0; i < r.connection_hops.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.connection_hops[i], pointer, bs - ); - } - } - if (bytes(r.version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.version, 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_enum( - IbcCoreChannelV1GlobalEnums.encode_State(r.state) - ); - e += 1 - + ProtoBufRuntime._sz_enum( - IbcCoreChannelV1GlobalEnums.encode_Order(r.ordering) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1Counterparty._estimate(r.counterparty) - ); - for (i = 0; i < r.connection_hops.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.connection_hops[i]).length); - } - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.version).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.state) != 0) { - return false; - } - - if (uint256(r.ordering) != 0) { - return false; - } - - if (r.connection_hops.length != 0) { - return false; - } - - if (bytes(r.version).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.state = input.state; - output.ordering = input.ordering; - IbcCoreChannelV1Counterparty.store( - input.counterparty, output.counterparty - ); - output.connection_hops = input.connection_hops; - output.version = input.version; - } - - //array helpers for ConnectionHops - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addConnectionHops( - Data memory self, - string memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.connection_hops.length + 1); - for (uint256 i; i < self.connection_hops.length; i++) { - tmp[i] = self.connection_hops[i]; - } - tmp[self.connection_hops.length] = value; - self.connection_hops = 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 IbcCoreChannelV1Channel - -library IbcCoreChannelV1IdentifiedChannel { - //struct definition - struct Data { - IbcCoreChannelV1GlobalEnums.State state; - IbcCoreChannelV1GlobalEnums.Order ordering; - IbcCoreChannelV1Counterparty.Data counterparty; - string[] connection_hops; - string version; - string port_id; - string channel_id; - } - - // 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_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_ordering(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_counterparty(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_unpacked_repeated_connection_hops( - pointer, bs, nil(), counters - ); - } else if (fieldId == 5) { - pointer += _read_version(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_port_id(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_channel_id(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[4] > 0) { - require(r.connection_hops.length == 0); - r.connection_hops = new string[](counters[4]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 4) { - pointer += _read_unpacked_repeated_connection_hops( - 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_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreChannelV1GlobalEnums.State x = - IbcCoreChannelV1GlobalEnums.decode_State(tmp); - r.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_ordering( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreChannelV1GlobalEnums.Order x = - IbcCoreChannelV1GlobalEnums.decode_Order(tmp); - r.ordering = 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_counterparty( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Counterparty.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Counterparty(p, bs); - r.counterparty = 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_connection_hops( - 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. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.connection_hops[r.connection_hops.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 - * @return The number of bytes decoded - */ - function _read_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.version = 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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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_IbcCoreChannelV1Counterparty( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1Counterparty.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Counterparty.Data memory r,) = - IbcCoreChannelV1Counterparty._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 (uint256(r.state) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_state = - IbcCoreChannelV1GlobalEnums.encode_State(r.state); - pointer += ProtoBufRuntime._encode_enum(_enum_state, pointer, bs); - } - if (uint256(r.ordering) != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_ordering = - IbcCoreChannelV1GlobalEnums.encode_Order(r.ordering); - pointer += ProtoBufRuntime._encode_enum(_enum_ordering, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1Counterparty._encode_nested( - r.counterparty, pointer, bs - ); - - if (r.connection_hops.length != 0) { - for (i = 0; i < r.connection_hops.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.connection_hops[i], pointer, bs - ); - } - } - if (bytes(r.version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.version, pointer, bs); - } - if (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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_enum( - IbcCoreChannelV1GlobalEnums.encode_State(r.state) - ); - e += 1 - + ProtoBufRuntime._sz_enum( - IbcCoreChannelV1GlobalEnums.encode_Order(r.ordering) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1Counterparty._estimate(r.counterparty) - ); - for (i = 0; i < r.connection_hops.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.connection_hops[i]).length); - } - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.version).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.state) != 0) { - return false; - } - - if (uint256(r.ordering) != 0) { - return false; - } - - if (r.connection_hops.length != 0) { - return false; - } - - if (bytes(r.version).length != 0) { - return false; - } - - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.state = input.state; - output.ordering = input.ordering; - IbcCoreChannelV1Counterparty.store( - input.counterparty, output.counterparty - ); - output.connection_hops = input.connection_hops; - output.version = input.version; - output.port_id = input.port_id; - output.channel_id = input.channel_id; - } - - //array helpers for ConnectionHops - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addConnectionHops( - Data memory self, - string memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.connection_hops.length + 1); - for (uint256 i; i < self.connection_hops.length; i++) { - tmp[i] = self.connection_hops[i]; - } - tmp[self.connection_hops.length] = value; - self.connection_hops = 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 IbcCoreChannelV1IdentifiedChannel - -library IbcCoreChannelV1Counterparty { - //struct definition - struct Data { - string port_id; - string channel_id; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - } - - //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 IbcCoreChannelV1Counterparty - -library IbcCoreChannelV1Packet { - //struct definition - struct Data { - uint64 sequence; - string source_port; - string source_channel; - string destination_port; - string destination_channel; - bytes data; - 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 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_sequence(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_source_port(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_source_channel(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_destination_port(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_destination_channel(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_data(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_timeout_height(pointer, bs, r); - } else if (fieldId == 8) { - pointer += _read_timeout_timestamp(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_source_port( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.source_port = 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_source_channel( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.source_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_destination_port( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.destination_port = 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_destination_channel( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.destination_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_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 - * @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_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 (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - if (bytes(r.source_port).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.source_port, pointer, bs); - } - if (bytes(r.source_channel).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.source_channel, pointer, bs); - } - if (bytes(r.destination_port).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.destination_port, pointer, bs); - } - if (bytes(r.destination_channel).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.destination_channel, pointer, bs - ); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.timeout_height, pointer, bs); - - if (r.timeout_timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 8, 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; - e += 1 + ProtoBufRuntime._sz_uint64(r.sequence); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.source_port).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.source_channel).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.destination_port).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.destination_channel).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - 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.sequence != 0) { - return false; - } - - if (bytes(r.source_port).length != 0) { - return false; - } - - if (bytes(r.source_channel).length != 0) { - return false; - } - - if (bytes(r.destination_port).length != 0) { - return false; - } - - if (bytes(r.destination_channel).length != 0) { - return false; - } - - if (r.data.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.sequence = input.sequence; - output.source_port = input.source_port; - output.source_channel = input.source_channel; - output.destination_port = input.destination_port; - output.destination_channel = input.destination_channel; - output.data = input.data; - IbcCoreClientV1Height.store(input.timeout_height, output.timeout_height); - output.timeout_timestamp = input.timeout_timestamp; - } - - //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 IbcCoreChannelV1Packet - -library IbcCoreChannelV1PacketState { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64 sequence; - bytes data; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_sequence(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_data(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_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; - } - - // 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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.sequence); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.sequence != 0) { - return false; - } - - if (r.data.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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.sequence = input.sequence; - output.data = input.data; - } - - //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 IbcCoreChannelV1PacketState - -library IbcCoreChannelV1PacketId { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64 sequence; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_sequence(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.sequence != 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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.sequence = input.sequence; - } - - //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 IbcCoreChannelV1PacketId - -library IbcCoreChannelV1Acknowledgement { - //struct definition - struct Data { - bytes result; - string error; - } - - // 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 == 21) { - pointer += _read_result(pointer, bs, r); - } else if (fieldId == 22) { - pointer += _read_error(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_result( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.result = 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_error( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.error = 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.result.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 21, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.result, pointer, bs); - } - if (bytes(r.error).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 22, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.error, 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 += 2 + ProtoBufRuntime._sz_lendelim(r.result.length); - e += 2 + ProtoBufRuntime._sz_lendelim(bytes(r.error).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.result.length != 0) { - return false; - } - - if (bytes(r.error).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.result = input.result; - output.error = input.error; - } - - //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 IbcCoreChannelV1Acknowledgement - -library IbcCoreChannelV1GlobalEnums { - //enum definition - // Solidity enum definitions - enum State { - STATE_UNINITIALIZED_UNSPECIFIED, - STATE_INIT, - STATE_TRYOPEN, - STATE_OPEN, - STATE_CLOSED - } - - // Solidity enum encoder - function encode_State(State x) internal pure returns (int32) { - if (x == State.STATE_UNINITIALIZED_UNSPECIFIED) { - return 0; - } - - if (x == State.STATE_INIT) { - return 1; - } - - if (x == State.STATE_TRYOPEN) { - return 2; - } - - if (x == State.STATE_OPEN) { - return 3; - } - - if (x == State.STATE_CLOSED) { - return 4; - } - revert(); - } - - // Solidity enum decoder - function decode_State(int64 x) internal pure returns (State) { - if (x == 0) { - return State.STATE_UNINITIALIZED_UNSPECIFIED; - } - - if (x == 1) { - return State.STATE_INIT; - } - - if (x == 2) { - return State.STATE_TRYOPEN; - } - - if (x == 3) { - return State.STATE_OPEN; - } - - if (x == 4) { - return State.STATE_CLOSED; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_State(State[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_State(a[i])); - } - return e; - } - - // Solidity enum definitions - enum Order { - ORDER_NONE_UNSPECIFIED, - ORDER_UNORDERED, - ORDER_ORDERED - } - - // Solidity enum encoder - function encode_Order(Order x) internal pure returns (int32) { - if (x == Order.ORDER_NONE_UNSPECIFIED) { - return 0; - } - - if (x == Order.ORDER_UNORDERED) { - return 1; - } - - if (x == Order.ORDER_ORDERED) { - return 2; - } - revert(); - } - - // Solidity enum decoder - function decode_Order(int64 x) internal pure returns (Order) { - if (x == 0) { - return Order.ORDER_NONE_UNSPECIFIED; - } - - if (x == 1) { - return Order.ORDER_UNORDERED; - } - - if (x == 2) { - return Order.ORDER_ORDERED; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_Order(Order[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_Order(a[i])); - } - return e; - } -} -//library IbcCoreChannelV1GlobalEnums diff --git a/evm/contracts/proto/ibc/core/channel/v1/genesis.sol b/evm/contracts/proto/ibc/core/channel/v1/genesis.sol deleted file mode 100644 index 4e333fbb27..0000000000 --- a/evm/contracts/proto/ibc/core/channel/v1/genesis.sol +++ /dev/null @@ -1,1195 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "./channel.sol"; - -library IbcCoreChannelV1GenesisState { - //struct definition - struct Data { - IbcCoreChannelV1IdentifiedChannel.Data[] channels; - IbcCoreChannelV1PacketState.Data[] acknowledgements; - IbcCoreChannelV1PacketState.Data[] commitments; - IbcCoreChannelV1PacketState.Data[] receipts; - IbcCoreChannelV1PacketSequence.Data[] send_sequences; - IbcCoreChannelV1PacketSequence.Data[] recv_sequences; - IbcCoreChannelV1PacketSequence.Data[] ack_sequences; - uint64 next_channel_sequence; - } - - // 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[9] 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_unpacked_repeated_channels( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_acknowledgements( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_commitments( - pointer, bs, nil(), counters - ); - } else if (fieldId == 4) { - pointer += _read_unpacked_repeated_receipts( - pointer, bs, nil(), counters - ); - } else if (fieldId == 5) { - pointer += _read_unpacked_repeated_send_sequences( - pointer, bs, nil(), counters - ); - } else if (fieldId == 6) { - pointer += _read_unpacked_repeated_recv_sequences( - pointer, bs, nil(), counters - ); - } else if (fieldId == 7) { - pointer += _read_unpacked_repeated_ack_sequences( - pointer, bs, nil(), counters - ); - } else if (fieldId == 8) { - pointer += _read_next_channel_sequence(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.channels.length == 0); - r.channels = - new IbcCoreChannelV1IdentifiedChannel.Data[](counters[1]); - } - if (counters[2] > 0) { - require(r.acknowledgements.length == 0); - r.acknowledgements = - new IbcCoreChannelV1PacketState.Data[](counters[2]); - } - if (counters[3] > 0) { - require(r.commitments.length == 0); - r.commitments = new IbcCoreChannelV1PacketState.Data[](counters[3]); - } - if (counters[4] > 0) { - require(r.receipts.length == 0); - r.receipts = new IbcCoreChannelV1PacketState.Data[](counters[4]); - } - if (counters[5] > 0) { - require(r.send_sequences.length == 0); - r.send_sequences = - new IbcCoreChannelV1PacketSequence.Data[](counters[5]); - } - if (counters[6] > 0) { - require(r.recv_sequences.length == 0); - r.recv_sequences = - new IbcCoreChannelV1PacketSequence.Data[](counters[6]); - } - if (counters[7] > 0) { - require(r.ack_sequences.length == 0); - r.ack_sequences = - new IbcCoreChannelV1PacketSequence.Data[](counters[7]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_channels(pointer, bs, r, counters); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_acknowledgements( - pointer, bs, r, counters - ); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_commitments( - pointer, bs, r, counters - ); - } else if (fieldId == 4) { - pointer += - _read_unpacked_repeated_receipts(pointer, bs, r, counters); - } else if (fieldId == 5) { - pointer += _read_unpacked_repeated_send_sequences( - pointer, bs, r, counters - ); - } else if (fieldId == 6) { - pointer += _read_unpacked_repeated_recv_sequences( - pointer, bs, r, counters - ); - } else if (fieldId == 7) { - pointer += _read_unpacked_repeated_ack_sequences( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_channels( - uint256 p, - bytes memory bs, - Data memory r, - uint256[9] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1IdentifiedChannel.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1IdentifiedChannel(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.channels[r.channels.length - counters[1]] = x; - counters[1] -= 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_acknowledgements( - uint256 p, - bytes memory bs, - Data memory r, - uint256[9] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1PacketState.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketState(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.acknowledgements[r.acknowledgements.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_commitments( - uint256 p, - bytes memory bs, - Data memory r, - uint256[9] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1PacketState.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketState(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.commitments[r.commitments.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_receipts( - uint256 p, - bytes memory bs, - Data memory r, - uint256[9] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1PacketState.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketState(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.receipts[r.receipts.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_send_sequences( - uint256 p, - bytes memory bs, - Data memory r, - uint256[9] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1PacketSequence.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketSequence(p, bs); - if (isNil(r)) { - counters[5] += 1; - } else { - r.send_sequences[r.send_sequences.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_recv_sequences( - uint256 p, - bytes memory bs, - Data memory r, - uint256[9] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1PacketSequence.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketSequence(p, bs); - if (isNil(r)) { - counters[6] += 1; - } else { - r.recv_sequences[r.recv_sequences.length - counters[6]] = x; - counters[6] -= 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_ack_sequences( - uint256 p, - bytes memory bs, - Data memory r, - uint256[9] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1PacketSequence.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketSequence(p, bs); - if (isNil(r)) { - counters[7] += 1; - } else { - r.ack_sequences[r.ack_sequences.length - counters[7]] = x; - counters[7] -= 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_next_channel_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.next_channel_sequence = 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_IbcCoreChannelV1IdentifiedChannel( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1IdentifiedChannel.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1IdentifiedChannel.Data memory r,) = - IbcCoreChannelV1IdentifiedChannel._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_IbcCoreChannelV1PacketState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1PacketState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketState.Data memory r,) = - IbcCoreChannelV1PacketState._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_IbcCoreChannelV1PacketSequence( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1PacketSequence.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketSequence.Data memory r,) = - IbcCoreChannelV1PacketSequence._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.channels.length != 0) { - for (i = 0; i < r.channels.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1IdentifiedChannel._encode_nested( - r.channels[i], pointer, bs - ); - } - } - if (r.acknowledgements.length != 0) { - for (i = 0; i < r.acknowledgements.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1PacketState._encode_nested( - r.acknowledgements[i], pointer, bs - ); - } - } - if (r.commitments.length != 0) { - for (i = 0; i < r.commitments.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1PacketState._encode_nested( - r.commitments[i], pointer, bs - ); - } - } - if (r.receipts.length != 0) { - for (i = 0; i < r.receipts.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1PacketState._encode_nested( - r.receipts[i], pointer, bs - ); - } - } - if (r.send_sequences.length != 0) { - for (i = 0; i < r.send_sequences.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1PacketSequence._encode_nested( - r.send_sequences[i], pointer, bs - ); - } - } - if (r.recv_sequences.length != 0) { - for (i = 0; i < r.recv_sequences.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1PacketSequence._encode_nested( - r.recv_sequences[i], pointer, bs - ); - } - } - if (r.ack_sequences.length != 0) { - for (i = 0; i < r.ack_sequences.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1PacketSequence._encode_nested( - r.ack_sequences[i], pointer, bs - ); - } - } - if (r.next_channel_sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 8, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.next_channel_sequence, 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; - for (i = 0; i < r.channels.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1IdentifiedChannel._estimate(r.channels[i]) - ); - } - for (i = 0; i < r.acknowledgements.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketState._estimate(r.acknowledgements[i]) - ); - } - for (i = 0; i < r.commitments.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketState._estimate(r.commitments[i]) - ); - } - for (i = 0; i < r.receipts.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketState._estimate(r.receipts[i]) - ); - } - for (i = 0; i < r.send_sequences.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketSequence._estimate(r.send_sequences[i]) - ); - } - for (i = 0; i < r.recv_sequences.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketSequence._estimate(r.recv_sequences[i]) - ); - } - for (i = 0; i < r.ack_sequences.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketSequence._estimate(r.ack_sequences[i]) - ); - } - e += 1 + ProtoBufRuntime._sz_uint64(r.next_channel_sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.channels.length != 0) { - return false; - } - - if (r.acknowledgements.length != 0) { - return false; - } - - if (r.commitments.length != 0) { - return false; - } - - if (r.receipts.length != 0) { - return false; - } - - if (r.send_sequences.length != 0) { - return false; - } - - if (r.recv_sequences.length != 0) { - return false; - } - - if (r.ack_sequences.length != 0) { - return false; - } - - if (r.next_channel_sequence != 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 { - for (uint256 i1 = 0; i1 < input.channels.length; i1++) { - output.channels.push(input.channels[i1]); - } - - for (uint256 i2 = 0; i2 < input.acknowledgements.length; i2++) { - output.acknowledgements.push(input.acknowledgements[i2]); - } - - for (uint256 i3 = 0; i3 < input.commitments.length; i3++) { - output.commitments.push(input.commitments[i3]); - } - - for (uint256 i4 = 0; i4 < input.receipts.length; i4++) { - output.receipts.push(input.receipts[i4]); - } - - for (uint256 i5 = 0; i5 < input.send_sequences.length; i5++) { - output.send_sequences.push(input.send_sequences[i5]); - } - - for (uint256 i6 = 0; i6 < input.recv_sequences.length; i6++) { - output.recv_sequences.push(input.recv_sequences[i6]); - } - - for (uint256 i7 = 0; i7 < input.ack_sequences.length; i7++) { - output.ack_sequences.push(input.ack_sequences[i7]); - } - - output.next_channel_sequence = input.next_channel_sequence; - } - - //array helpers for Channels - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addChannels( - Data memory self, - IbcCoreChannelV1IdentifiedChannel.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1IdentifiedChannel.Data[] memory tmp = new IbcCoreChannelV1IdentifiedChannel - .Data[](self.channels.length + 1); - for (uint256 i; i < self.channels.length; i++) { - tmp[i] = self.channels[i]; - } - tmp[self.channels.length] = value; - self.channels = tmp; - } - - //array helpers for Acknowledgements - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAcknowledgements( - Data memory self, - IbcCoreChannelV1PacketState.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1PacketState.Data[] memory tmp = new IbcCoreChannelV1PacketState - .Data[](self.acknowledgements.length + 1); - for (uint256 i; i < self.acknowledgements.length; i++) { - tmp[i] = self.acknowledgements[i]; - } - tmp[self.acknowledgements.length] = value; - self.acknowledgements = tmp; - } - - //array helpers for Commitments - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addCommitments( - Data memory self, - IbcCoreChannelV1PacketState.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1PacketState.Data[] memory tmp = - new IbcCoreChannelV1PacketState.Data[](self.commitments.length + 1); - for (uint256 i; i < self.commitments.length; i++) { - tmp[i] = self.commitments[i]; - } - tmp[self.commitments.length] = value; - self.commitments = tmp; - } - - //array helpers for Receipts - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addReceipts( - Data memory self, - IbcCoreChannelV1PacketState.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1PacketState.Data[] memory tmp = - new IbcCoreChannelV1PacketState.Data[](self.receipts.length + 1); - for (uint256 i; i < self.receipts.length; i++) { - tmp[i] = self.receipts[i]; - } - tmp[self.receipts.length] = value; - self.receipts = tmp; - } - - //array helpers for SendSequences - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addSendSequences( - Data memory self, - IbcCoreChannelV1PacketSequence.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1PacketSequence.Data[] memory tmp = new IbcCoreChannelV1PacketSequence - .Data[](self.send_sequences.length + 1); - for (uint256 i; i < self.send_sequences.length; i++) { - tmp[i] = self.send_sequences[i]; - } - tmp[self.send_sequences.length] = value; - self.send_sequences = tmp; - } - - //array helpers for RecvSequences - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addRecvSequences( - Data memory self, - IbcCoreChannelV1PacketSequence.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1PacketSequence.Data[] memory tmp = new IbcCoreChannelV1PacketSequence - .Data[](self.recv_sequences.length + 1); - for (uint256 i; i < self.recv_sequences.length; i++) { - tmp[i] = self.recv_sequences[i]; - } - tmp[self.recv_sequences.length] = value; - self.recv_sequences = tmp; - } - - //array helpers for AckSequences - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAckSequences( - Data memory self, - IbcCoreChannelV1PacketSequence.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1PacketSequence.Data[] memory tmp = new IbcCoreChannelV1PacketSequence - .Data[](self.ack_sequences.length + 1); - for (uint256 i; i < self.ack_sequences.length; i++) { - tmp[i] = self.ack_sequences[i]; - } - tmp[self.ack_sequences.length] = value; - self.ack_sequences = 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 IbcCoreChannelV1GenesisState - -library IbcCoreChannelV1PacketSequence { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64 sequence; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_sequence(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.sequence != 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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.sequence = input.sequence; - } - - //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 IbcCoreChannelV1PacketSequence diff --git a/evm/contracts/proto/ibc/core/channel/v1/query.sol b/evm/contracts/proto/ibc/core/channel/v1/query.sol deleted file mode 100644 index b58729a133..0000000000 --- a/evm/contracts/proto/ibc/core/channel/v1/query.sol +++ /dev/null @@ -1,8489 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../client/v1/client.sol"; -import "../../../../cosmos/base/query/v1beta1/pagination.sol"; -import "./channel.sol"; - -library IbcCoreChannelV1QueryChannelRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - } - - //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 IbcCoreChannelV1QueryChannelRequest - -library IbcCoreChannelV1QueryChannelResponse { - //struct definition - struct Data { - IbcCoreChannelV1Channel.Data channel; - bytes proof; - IbcCoreClientV1Height.Data proof_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_channel(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_channel( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Channel.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Channel(p, bs); - r.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_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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_IbcCoreChannelV1Channel( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1Channel.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Channel.Data memory r,) = - IbcCoreChannelV1Channel._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreChannelV1Channel._encode_nested(r.channel, pointer, bs); - - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim( - IbcCoreChannelV1Channel._estimate(r.channel) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof.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 { - IbcCoreChannelV1Channel.store(input.channel, output.channel); - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreChannelV1QueryChannelResponse - -library IbcCoreChannelV1QueryChannelsRequest { - //struct definition - struct Data { - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_pagination(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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcCoreChannelV1QueryChannelsRequest - -library IbcCoreChannelV1QueryChannelsResponse { - //struct definition - struct Data { - IbcCoreChannelV1IdentifiedChannel.Data[] channels; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - IbcCoreClientV1Height.Data 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[4] 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_unpacked_repeated_channels( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_height(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.channels.length == 0); - r.channels = - new IbcCoreChannelV1IdentifiedChannel.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_channels(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_channels( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1IdentifiedChannel.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1IdentifiedChannel(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.channels[r.channels.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_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; - } - - // 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_IbcCoreChannelV1IdentifiedChannel( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1IdentifiedChannel.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1IdentifiedChannel.Data memory r,) = - IbcCoreChannelV1IdentifiedChannel._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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.channels.length != 0) { - for (i = 0; i < r.channels.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1IdentifiedChannel._encode_nested( - r.channels[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.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; - uint256 i; - for (i = 0; i < r.channels.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1IdentifiedChannel._estimate(r.channels[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.channels.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 { - for (uint256 i1 = 0; i1 < input.channels.length; i1++) { - output.channels.push(input.channels[i1]); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - IbcCoreClientV1Height.store(input.height, output.height); - } - - //array helpers for Channels - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addChannels( - Data memory self, - IbcCoreChannelV1IdentifiedChannel.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1IdentifiedChannel.Data[] memory tmp = new IbcCoreChannelV1IdentifiedChannel - .Data[](self.channels.length + 1); - for (uint256 i; i < self.channels.length; i++) { - tmp[i] = self.channels[i]; - } - tmp[self.channels.length] = value; - self.channels = 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 IbcCoreChannelV1QueryChannelsResponse - -library IbcCoreChannelV1QueryConnectionChannelsRequest { - //struct definition - struct Data { - string connection; - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_connection(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_pagination(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_connection( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection = 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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.connection).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.connection, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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.connection).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.connection).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.connection = input.connection; - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcCoreChannelV1QueryConnectionChannelsRequest - -library IbcCoreChannelV1QueryConnectionChannelsResponse { - //struct definition - struct Data { - IbcCoreChannelV1IdentifiedChannel.Data[] channels; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - IbcCoreClientV1Height.Data 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[4] 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_unpacked_repeated_channels( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_height(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.channels.length == 0); - r.channels = - new IbcCoreChannelV1IdentifiedChannel.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_channels(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_channels( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1IdentifiedChannel.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1IdentifiedChannel(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.channels[r.channels.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_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; - } - - // 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_IbcCoreChannelV1IdentifiedChannel( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1IdentifiedChannel.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1IdentifiedChannel.Data memory r,) = - IbcCoreChannelV1IdentifiedChannel._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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.channels.length != 0) { - for (i = 0; i < r.channels.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1IdentifiedChannel._encode_nested( - r.channels[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.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; - uint256 i; - for (i = 0; i < r.channels.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1IdentifiedChannel._estimate(r.channels[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.channels.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 { - for (uint256 i1 = 0; i1 < input.channels.length; i1++) { - output.channels.push(input.channels[i1]); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - IbcCoreClientV1Height.store(input.height, output.height); - } - - //array helpers for Channels - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addChannels( - Data memory self, - IbcCoreChannelV1IdentifiedChannel.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1IdentifiedChannel.Data[] memory tmp = new IbcCoreChannelV1IdentifiedChannel - .Data[](self.channels.length + 1); - for (uint256 i; i < self.channels.length; i++) { - tmp[i] = self.channels[i]; - } - tmp[self.channels.length] = value; - self.channels = 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 IbcCoreChannelV1QueryConnectionChannelsResponse - -library IbcCoreChannelV1QueryChannelClientStateRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - } - - //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 IbcCoreChannelV1QueryChannelClientStateRequest - -library IbcCoreChannelV1QueryChannelClientStateResponse { - //struct definition - struct Data { - IbcCoreClientV1IdentifiedClientState.Data identified_client_state; - bytes proof; - IbcCoreClientV1Height.Data proof_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_identified_client_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_identified_client_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1IdentifiedClientState.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1IdentifiedClientState(p, bs); - r.identified_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_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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_IbcCoreClientV1IdentifiedClientState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreClientV1IdentifiedClientState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1IdentifiedClientState.Data memory r,) = - IbcCoreClientV1IdentifiedClientState._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1IdentifiedClientState._encode_nested( - r.identified_client_state, pointer, bs - ); - - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim( - IbcCoreClientV1IdentifiedClientState._estimate( - r.identified_client_state - ) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof.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 { - IbcCoreClientV1IdentifiedClientState.store( - input.identified_client_state, output.identified_client_state - ); - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreChannelV1QueryChannelClientStateResponse - -library IbcCoreChannelV1QueryChannelConsensusStateRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64 revision_number; - uint64 revision_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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_revision_number(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_revision_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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_revision_number( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.revision_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_revision_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.revision_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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.revision_number != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.revision_number, pointer, bs); - } - if (r.revision_height != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.revision_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_lendelim(bytes(r.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.revision_number); - e += 1 + ProtoBufRuntime._sz_uint64(r.revision_height); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.revision_number != 0) { - return false; - } - - if (r.revision_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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.revision_number = input.revision_number; - output.revision_height = input.revision_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 IbcCoreChannelV1QueryChannelConsensusStateRequest - -library IbcCoreChannelV1QueryChannelConsensusStateResponse { - //struct definition - struct Data { - GoogleProtobufAny.Data consensus_state; - string client_id; - bytes proof; - IbcCoreClientV1Height.Data proof_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_consensus_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_client_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_proof_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_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_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_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufAny._encode_nested(r.consensus_state, pointer, bs); - - if (bytes(r.client_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); - } - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim( - GoogleProtobufAny._estimate(r.consensus_state) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - 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.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.consensus_state, output.consensus_state); - output.client_id = input.client_id; - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreChannelV1QueryChannelConsensusStateResponse - -library IbcCoreChannelV1QueryPacketCommitmentRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64 sequence; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_sequence(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.sequence != 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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.sequence = input.sequence; - } - - //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 IbcCoreChannelV1QueryPacketCommitmentRequest - -library IbcCoreChannelV1QueryPacketCommitmentResponse { - //struct definition - struct Data { - bytes commitment; - bytes proof; - IbcCoreClientV1Height.Data proof_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_commitment(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_commitment( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.commitment = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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); - } - - // 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.commitment.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.commitment, pointer, bs); - } - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim(r.commitment.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.commitment.length != 0) { - return false; - } - - if (r.proof.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.commitment = input.commitment; - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreChannelV1QueryPacketCommitmentResponse - -library IbcCoreChannelV1QueryPacketCommitmentsRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_pagination(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcCoreChannelV1QueryPacketCommitmentsRequest - -library IbcCoreChannelV1QueryPacketCommitmentsResponse { - //struct definition - struct Data { - IbcCoreChannelV1PacketState.Data[] commitments; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - IbcCoreClientV1Height.Data 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[4] 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_unpacked_repeated_commitments( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_height(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.commitments.length == 0); - r.commitments = new IbcCoreChannelV1PacketState.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_commitments( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_commitments( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1PacketState.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketState(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.commitments[r.commitments.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_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; - } - - // 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_IbcCoreChannelV1PacketState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1PacketState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketState.Data memory r,) = - IbcCoreChannelV1PacketState._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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.commitments.length != 0) { - for (i = 0; i < r.commitments.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1PacketState._encode_nested( - r.commitments[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.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; - uint256 i; - for (i = 0; i < r.commitments.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketState._estimate(r.commitments[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.commitments.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 { - for (uint256 i1 = 0; i1 < input.commitments.length; i1++) { - output.commitments.push(input.commitments[i1]); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - IbcCoreClientV1Height.store(input.height, output.height); - } - - //array helpers for Commitments - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addCommitments( - Data memory self, - IbcCoreChannelV1PacketState.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1PacketState.Data[] memory tmp = - new IbcCoreChannelV1PacketState.Data[](self.commitments.length + 1); - for (uint256 i; i < self.commitments.length; i++) { - tmp[i] = self.commitments[i]; - } - tmp[self.commitments.length] = value; - self.commitments = 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 IbcCoreChannelV1QueryPacketCommitmentsResponse - -library IbcCoreChannelV1QueryPacketReceiptRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64 sequence; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_sequence(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.sequence != 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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.sequence = input.sequence; - } - - //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 IbcCoreChannelV1QueryPacketReceiptRequest - -library IbcCoreChannelV1QueryPacketReceiptResponse { - //struct definition - struct Data { - bool received; - bytes proof; - IbcCoreClientV1Height.Data proof_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 == 2) { - pointer += _read_received(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_proof_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_received( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.received = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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); - } - - // 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.received != false) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool(r.received, pointer, bs); - } - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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 + 1; - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.received != false) { - return false; - } - - if (r.proof.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.received = input.received; - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreChannelV1QueryPacketReceiptResponse - -library IbcCoreChannelV1QueryPacketAcknowledgementRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64 sequence; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_sequence(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.sequence != 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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.sequence = input.sequence; - } - - //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 IbcCoreChannelV1QueryPacketAcknowledgementRequest - -library IbcCoreChannelV1QueryPacketAcknowledgementResponse { - //struct definition - struct Data { - bytes acknowledgement; - bytes proof; - IbcCoreClientV1Height.Data proof_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_acknowledgement(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_acknowledgement( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.acknowledgement = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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); - } - - // 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.acknowledgement.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.acknowledgement, pointer, bs); - } - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim(r.acknowledgement.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.acknowledgement.length != 0) { - return false; - } - - if (r.proof.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.acknowledgement = input.acknowledgement; - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreChannelV1QueryPacketAcknowledgementResponse - -library IbcCoreChannelV1QueryPacketAcknowledgementsRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - CosmosBaseQueryV1beta1PageRequest.Data pagination; - uint64[] packet_commitment_sequences; - } - - // 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[5] 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_pagination(pointer, bs, r); - } else if (fieldId == 4) { - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - pointer += _read_packed_repeated_packet_commitment_sequences( - pointer, bs, r - ); - } else { - pointer += - _read_unpacked_repeated_packet_commitment_sequences( - pointer, bs, nil(), counters - ); - } - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[4] > 0) { - require(r.packet_commitment_sequences.length == 0); - r.packet_commitment_sequences = new uint64[](counters[4]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if ( - fieldId == 4 && wireType != ProtoBufRuntime.WireType.LengthDelim - ) { - pointer += _read_unpacked_repeated_packet_commitment_sequences( - 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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_packet_commitment_sequences( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.packet_commitment_sequences[r.packet_commitment_sequences.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 - * @return The number of bytes decoded - */ - function _read_packed_repeated_packet_commitment_sequences( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - p += size; - uint256 count = - ProtoBufRuntime._count_packed_repeated_varint(p, len, bs); - r.packet_commitment_sequences = new uint64[](count); - for (uint256 i; i < count; i++) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - p += sz; - r.packet_commitment_sequences[i] = x; - } - return size + len; - } - - // 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, pointer, bs - ); - - if (r.packet_commitment_sequences.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_varint( - ProtoBufRuntime._estimate_packed_repeated_uint64( - r.packet_commitment_sequences - ), - pointer, - bs - ); - for (i = 0; i < r.packet_commitment_sequences.length; i++) { - pointer += ProtoBufRuntime._encode_uint64( - r.packet_commitment_sequences[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; - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - ProtoBufRuntime._estimate_packed_repeated_uint64( - r.packet_commitment_sequences - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.packet_commitment_sequences.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.port_id = input.port_id; - output.channel_id = input.channel_id; - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - output.packet_commitment_sequences = input.packet_commitment_sequences; - } - - //array helpers for PacketCommitmentSequences - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPacketCommitmentSequences( - Data memory self, - uint64 value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - uint64[] memory tmp = - new uint64[](self.packet_commitment_sequences.length + 1); - for (uint256 i; i < self.packet_commitment_sequences.length; i++) { - tmp[i] = self.packet_commitment_sequences[i]; - } - tmp[self.packet_commitment_sequences.length] = value; - self.packet_commitment_sequences = 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 IbcCoreChannelV1QueryPacketAcknowledgementsRequest - -library IbcCoreChannelV1QueryPacketAcknowledgementsResponse { - //struct definition - struct Data { - IbcCoreChannelV1PacketState.Data[] acknowledgements; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - IbcCoreClientV1Height.Data 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[4] 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_unpacked_repeated_acknowledgements( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_height(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.acknowledgements.length == 0); - r.acknowledgements = - new IbcCoreChannelV1PacketState.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_acknowledgements( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_acknowledgements( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreChannelV1PacketState.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1PacketState(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.acknowledgements[r.acknowledgements.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_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; - } - - // 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_IbcCoreChannelV1PacketState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1PacketState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1PacketState.Data memory r,) = - IbcCoreChannelV1PacketState._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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.acknowledgements.length != 0) { - for (i = 0; i < r.acknowledgements.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1PacketState._encode_nested( - r.acknowledgements[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.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; - uint256 i; - for (i = 0; i < r.acknowledgements.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1PacketState._estimate(r.acknowledgements[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.acknowledgements.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 { - for (uint256 i1 = 0; i1 < input.acknowledgements.length; i1++) { - output.acknowledgements.push(input.acknowledgements[i1]); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - IbcCoreClientV1Height.store(input.height, output.height); - } - - //array helpers for Acknowledgements - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAcknowledgements( - Data memory self, - IbcCoreChannelV1PacketState.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreChannelV1PacketState.Data[] memory tmp = new IbcCoreChannelV1PacketState - .Data[](self.acknowledgements.length + 1); - for (uint256 i; i < self.acknowledgements.length; i++) { - tmp[i] = self.acknowledgements[i]; - } - tmp[self.acknowledgements.length] = value; - self.acknowledgements = 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 IbcCoreChannelV1QueryPacketAcknowledgementsResponse - -library IbcCoreChannelV1QueryUnreceivedPacketsRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64[] packet_commitment_sequences; - } - - // 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[4] 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - pointer += _read_packed_repeated_packet_commitment_sequences( - pointer, bs, r - ); - } else { - pointer += - _read_unpacked_repeated_packet_commitment_sequences( - pointer, bs, nil(), counters - ); - } - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[3] > 0) { - require(r.packet_commitment_sequences.length == 0); - r.packet_commitment_sequences = new uint64[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if ( - fieldId == 3 && wireType != ProtoBufRuntime.WireType.LengthDelim - ) { - pointer += _read_unpacked_repeated_packet_commitment_sequences( - 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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_packet_commitment_sequences( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.packet_commitment_sequences[r.packet_commitment_sequences.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_packed_repeated_packet_commitment_sequences( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - p += size; - uint256 count = - ProtoBufRuntime._count_packed_repeated_varint(p, len, bs); - r.packet_commitment_sequences = new uint64[](count); - for (uint256 i; i < count; i++) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - p += sz; - r.packet_commitment_sequences[i] = x; - } - return size + len; - } - - // 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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.packet_commitment_sequences.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_varint( - ProtoBufRuntime._estimate_packed_repeated_uint64( - r.packet_commitment_sequences - ), - pointer, - bs - ); - for (i = 0; i < r.packet_commitment_sequences.length; i++) { - pointer += ProtoBufRuntime._encode_uint64( - r.packet_commitment_sequences[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; - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - ProtoBufRuntime._estimate_packed_repeated_uint64( - r.packet_commitment_sequences - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.packet_commitment_sequences.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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.packet_commitment_sequences = input.packet_commitment_sequences; - } - - //array helpers for PacketCommitmentSequences - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPacketCommitmentSequences( - Data memory self, - uint64 value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - uint64[] memory tmp = - new uint64[](self.packet_commitment_sequences.length + 1); - for (uint256 i; i < self.packet_commitment_sequences.length; i++) { - tmp[i] = self.packet_commitment_sequences[i]; - } - tmp[self.packet_commitment_sequences.length] = value; - self.packet_commitment_sequences = 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 IbcCoreChannelV1QueryUnreceivedPacketsRequest - -library IbcCoreChannelV1QueryUnreceivedPacketsResponse { - //struct definition - struct Data { - uint64[] sequences; - IbcCoreClientV1Height.Data 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[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) { - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - pointer += _read_packed_repeated_sequences(pointer, bs, r); - } else { - pointer += _read_unpacked_repeated_sequences( - pointer, bs, nil(), counters - ); - } - } else if (fieldId == 2) { - pointer += _read_height(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.sequences.length == 0); - r.sequences = new uint64[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if ( - fieldId == 1 && wireType != ProtoBufRuntime.WireType.LengthDelim - ) { - pointer += - _read_unpacked_repeated_sequences(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_sequences( - 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. - */ - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.sequences[r.sequences.length - counters[1]] = x; - counters[1] -= 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_packed_repeated_sequences( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - p += size; - uint256 count = - ProtoBufRuntime._count_packed_repeated_varint(p, len, bs); - r.sequences = new uint64[](count); - for (uint256 i; i < count; i++) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - p += sz; - r.sequences[i] = x; - } - return size + len; - } - - /** - * @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; - } - - // 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); - } - - // 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.sequences.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_varint( - ProtoBufRuntime._estimate_packed_repeated_uint64(r.sequences), - pointer, - bs - ); - for (i = 0; i < r.sequences.length; i++) { - pointer += - ProtoBufRuntime._encode_uint64(r.sequences[i], pointer, bs); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.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_lendelim( - ProtoBufRuntime._estimate_packed_repeated_uint64(r.sequences) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequences.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.sequences = input.sequences; - IbcCoreClientV1Height.store(input.height, output.height); - } - - //array helpers for Sequences - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addSequences(Data memory self, uint64 value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - uint64[] memory tmp = new uint64[](self.sequences.length + 1); - for (uint256 i; i < self.sequences.length; i++) { - tmp[i] = self.sequences[i]; - } - tmp[self.sequences.length] = value; - self.sequences = 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 IbcCoreChannelV1QueryUnreceivedPacketsResponse - -library IbcCoreChannelV1QueryUnreceivedAcksRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - uint64[] packet_ack_sequences; - } - - // 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[4] 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - pointer += _read_packed_repeated_packet_ack_sequences( - pointer, bs, r - ); - } else { - pointer += _read_unpacked_repeated_packet_ack_sequences( - pointer, bs, nil(), counters - ); - } - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[3] > 0) { - require(r.packet_ack_sequences.length == 0); - r.packet_ack_sequences = new uint64[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if ( - fieldId == 3 && wireType != ProtoBufRuntime.WireType.LengthDelim - ) { - pointer += _read_unpacked_repeated_packet_ack_sequences( - 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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_packet_ack_sequences( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.packet_ack_sequences[r.packet_ack_sequences.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_packed_repeated_packet_ack_sequences( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - p += size; - uint256 count = - ProtoBufRuntime._count_packed_repeated_varint(p, len, bs); - r.packet_ack_sequences = new uint64[](count); - for (uint256 i; i < count; i++) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - p += sz; - r.packet_ack_sequences[i] = x; - } - return size + len; - } - - // 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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.packet_ack_sequences.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_varint( - ProtoBufRuntime._estimate_packed_repeated_uint64( - r.packet_ack_sequences - ), - pointer, - bs - ); - for (i = 0; i < r.packet_ack_sequences.length; i++) { - pointer += ProtoBufRuntime._encode_uint64( - r.packet_ack_sequences[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; - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - ProtoBufRuntime._estimate_packed_repeated_uint64( - r.packet_ack_sequences - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.packet_ack_sequences.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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.packet_ack_sequences = input.packet_ack_sequences; - } - - //array helpers for PacketAckSequences - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPacketAckSequences( - Data memory self, - uint64 value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - uint64[] memory tmp = new uint64[](self.packet_ack_sequences.length + 1); - for (uint256 i; i < self.packet_ack_sequences.length; i++) { - tmp[i] = self.packet_ack_sequences[i]; - } - tmp[self.packet_ack_sequences.length] = value; - self.packet_ack_sequences = 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 IbcCoreChannelV1QueryUnreceivedAcksRequest - -library IbcCoreChannelV1QueryUnreceivedAcksResponse { - //struct definition - struct Data { - uint64[] sequences; - IbcCoreClientV1Height.Data 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[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) { - if (wireType == ProtoBufRuntime.WireType.LengthDelim) { - pointer += _read_packed_repeated_sequences(pointer, bs, r); - } else { - pointer += _read_unpacked_repeated_sequences( - pointer, bs, nil(), counters - ); - } - } else if (fieldId == 2) { - pointer += _read_height(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.sequences.length == 0); - r.sequences = new uint64[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if ( - fieldId == 1 && wireType != ProtoBufRuntime.WireType.LengthDelim - ) { - pointer += - _read_unpacked_repeated_sequences(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_sequences( - 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. - */ - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.sequences[r.sequences.length - counters[1]] = x; - counters[1] -= 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_packed_repeated_sequences( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint256 len, uint256 size) = ProtoBufRuntime._decode_varint(p, bs); - p += size; - uint256 count = - ProtoBufRuntime._count_packed_repeated_varint(p, len, bs); - r.sequences = new uint64[](count); - for (uint256 i; i < count; i++) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - p += sz; - r.sequences[i] = x; - } - return size + len; - } - - /** - * @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; - } - - // 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); - } - - // 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.sequences.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_varint( - ProtoBufRuntime._estimate_packed_repeated_uint64(r.sequences), - pointer, - bs - ); - for (i = 0; i < r.sequences.length; i++) { - pointer += - ProtoBufRuntime._encode_uint64(r.sequences[i], pointer, bs); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.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_lendelim( - ProtoBufRuntime._estimate_packed_repeated_uint64(r.sequences) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequences.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.sequences = input.sequences; - IbcCoreClientV1Height.store(input.height, output.height); - } - - //array helpers for Sequences - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addSequences(Data memory self, uint64 value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - uint64[] memory tmp = new uint64[](self.sequences.length + 1); - for (uint256 i; i < self.sequences.length; i++) { - tmp[i] = self.sequences[i]; - } - tmp[self.sequences.length] = value; - self.sequences = 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 IbcCoreChannelV1QueryUnreceivedAcksResponse - -library IbcCoreChannelV1QueryNextSequenceReceiveRequest { - //struct definition - struct Data { - string port_id; - string channel_id; - } - - // 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_id = 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 (bytes(r.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - } - - //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 IbcCoreChannelV1QueryNextSequenceReceiveRequest - -library IbcCoreChannelV1QueryNextSequenceReceiveResponse { - //struct definition - struct Data { - uint64 next_sequence_receive; - bytes proof; - IbcCoreClientV1Height.Data proof_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_next_sequence_receive(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_next_sequence_receive( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.next_sequence_receive = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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); - } - - // 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.next_sequence_receive != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.next_sequence_receive, pointer, bs - ); - } - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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.next_sequence_receive); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.next_sequence_receive != 0) { - return false; - } - - if (r.proof.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.next_sequence_receive = input.next_sequence_receive; - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreChannelV1QueryNextSequenceReceiveResponse diff --git a/evm/contracts/proto/ibc/core/channel/v1/tx.sol b/evm/contracts/proto/ibc/core/channel/v1/tx.sol deleted file mode 100644 index e2538026c7..0000000000 --- a/evm/contracts/proto/ibc/core/channel/v1/tx.sol +++ /dev/null @@ -1,5831 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../client/v1/client.sol"; -import "./channel.sol"; - -library IbcCoreChannelV1MsgChannelOpenInit { - //struct definition - struct Data { - string port_id; - IbcCoreChannelV1Channel.Data channel; - 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Channel.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Channel(p, bs); - r.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_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_IbcCoreChannelV1Channel( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1Channel.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Channel.Data memory r,) = - IbcCoreChannelV1Channel._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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreChannelV1Channel._encode_nested(r.channel, 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.port_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1Channel._estimate(r.channel) - ); - 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.port_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.port_id = input.port_id; - IbcCoreChannelV1Channel.store(input.channel, output.channel); - 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 IbcCoreChannelV1MsgChannelOpenInit - -library IbcCoreChannelV1MsgChannelOpenInitResponse { - //struct definition - struct Data { - string channel_id; - string version; - } - - // 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_channel_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_version(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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.version = 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 (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (bytes(r.version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.version, 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.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.version).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (bytes(r.version).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.channel_id = input.channel_id; - output.version = input.version; - } - - //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 IbcCoreChannelV1MsgChannelOpenInitResponse - -library IbcCoreChannelV1MsgChannelOpenTry { - //struct definition - struct Data { - string port_id; - string previous_channel_id; - IbcCoreChannelV1Channel.Data channel; - string counterparty_version; - bytes proof_init; - IbcCoreClientV1Height.Data proof_height; - 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_previous_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_channel(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_counterparty_version(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_proof_init(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_proof_height(pointer, bs, r); - } else if (fieldId == 7) { - 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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_previous_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.previous_channel_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_channel( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Channel.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Channel(p, bs); - r.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_counterparty_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.counterparty_version = 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_init( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_init = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_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_IbcCoreChannelV1Channel( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1Channel.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Channel.Data memory r,) = - IbcCoreChannelV1Channel._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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.previous_channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.previous_channel_id, pointer, bs - ); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreChannelV1Channel._encode_nested(r.channel, pointer, bs); - - if (bytes(r.counterparty_version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.counterparty_version, pointer, bs - ); - } - if (r.proof_init.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_init, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, pointer, bs); - - if (bytes(r.signer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, 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.port_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.previous_channel_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1Channel._estimate(r.channel) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.counterparty_version).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_init.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - 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.port_id).length != 0) { - return false; - } - - if (bytes(r.previous_channel_id).length != 0) { - return false; - } - - if (bytes(r.counterparty_version).length != 0) { - return false; - } - - if (r.proof_init.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.port_id = input.port_id; - output.previous_channel_id = input.previous_channel_id; - IbcCoreChannelV1Channel.store(input.channel, output.channel); - output.counterparty_version = input.counterparty_version; - output.proof_init = input.proof_init; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - 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 IbcCoreChannelV1MsgChannelOpenTry - -library IbcCoreChannelV1MsgChannelOpenTryResponse { - //struct definition - struct Data { - string version; - } - - // 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(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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.version = 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 (bytes(r.version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.version, 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.version).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.version).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.version = input.version; - } - - //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 IbcCoreChannelV1MsgChannelOpenTryResponse - -library IbcCoreChannelV1MsgChannelOpenAck { - //struct definition - struct Data { - string port_id; - string channel_id; - string counterparty_channel_id; - string counterparty_version; - bytes proof_try; - IbcCoreClientV1Height.Data proof_height; - 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_counterparty_channel_id(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_counterparty_version(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_proof_try(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_proof_height(pointer, bs, r); - } else if (fieldId == 7) { - 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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_counterparty_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.counterparty_channel_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_counterparty_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.counterparty_version = 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_try( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_try = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_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_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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (bytes(r.counterparty_channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.counterparty_channel_id, pointer, bs - ); - } - if (bytes(r.counterparty_version).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.counterparty_version, pointer, bs - ); - } - if (r.proof_try.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_try, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, pointer, bs); - - if (bytes(r.signer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.counterparty_channel_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.counterparty_version).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_try.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - 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.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (bytes(r.counterparty_channel_id).length != 0) { - return false; - } - - if (bytes(r.counterparty_version).length != 0) { - return false; - } - - if (r.proof_try.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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.counterparty_channel_id = input.counterparty_channel_id; - output.counterparty_version = input.counterparty_version; - output.proof_try = input.proof_try; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - 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 IbcCoreChannelV1MsgChannelOpenAck - -library IbcCoreChannelV1MsgChannelOpenAckResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreChannelV1MsgChannelOpenAckResponse - -library IbcCoreChannelV1MsgChannelOpenConfirm { - //struct definition - struct Data { - string port_id; - string channel_id; - bytes proof_ack; - IbcCoreClientV1Height.Data proof_height; - 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_ack(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_proof_height(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_proof_ack( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_ack = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_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_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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.proof_ack.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_ack, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_ack.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - 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.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.proof_ack.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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.proof_ack = input.proof_ack; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - 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 IbcCoreChannelV1MsgChannelOpenConfirm - -library IbcCoreChannelV1MsgChannelOpenConfirmResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreChannelV1MsgChannelOpenConfirmResponse - -library IbcCoreChannelV1MsgChannelCloseInit { - //struct definition - struct Data { - string port_id; - string channel_id; - 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_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; - } - - // 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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).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.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_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.port_id = input.port_id; - output.channel_id = input.channel_id; - 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 IbcCoreChannelV1MsgChannelCloseInit - -library IbcCoreChannelV1MsgChannelCloseInitResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreChannelV1MsgChannelCloseInitResponse - -library IbcCoreChannelV1MsgChannelCloseConfirm { - //struct definition - struct Data { - string port_id; - string channel_id; - bytes proof_init; - IbcCoreClientV1Height.Data proof_height; - 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_port_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_init(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_proof_height(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_port_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.port_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_channel_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.channel_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_proof_init( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_init = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_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_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.port_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.port_id, pointer, bs); - } - if (bytes(r.channel_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.channel_id, pointer, bs); - } - if (r.proof_init.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_init, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, 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.port_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.channel_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_init.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - 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.port_id).length != 0) { - return false; - } - - if (bytes(r.channel_id).length != 0) { - return false; - } - - if (r.proof_init.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.port_id = input.port_id; - output.channel_id = input.channel_id; - output.proof_init = input.proof_init; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - 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 IbcCoreChannelV1MsgChannelCloseConfirm - -library IbcCoreChannelV1MsgChannelCloseConfirmResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreChannelV1MsgChannelCloseConfirmResponse - -library IbcCoreChannelV1MsgRecvPacket { - //struct definition - struct Data { - IbcCoreChannelV1Packet.Data packet; - bytes proof_commitment; - IbcCoreClientV1Height.Data proof_height; - 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_packet(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof_commitment(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_height(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_packet( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Packet.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Packet(p, bs); - r.packet = 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_commitment( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_commitment = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_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_IbcCoreChannelV1Packet( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1Packet.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Packet.Data memory r,) = - IbcCoreChannelV1Packet._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1Packet._encode_nested(r.packet, pointer, bs); - - if (r.proof_commitment.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.proof_commitment, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, 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( - IbcCoreChannelV1Packet._estimate(r.packet) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_commitment.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof_commitment.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 { - IbcCoreChannelV1Packet.store(input.packet, output.packet); - output.proof_commitment = input.proof_commitment; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - 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 IbcCoreChannelV1MsgRecvPacket - -library IbcCoreChannelV1MsgRecvPacketResponse { - //struct definition - struct Data { - IbcCoreChannelV1TxGlobalEnums.ResponseResultType result; - } - - // 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_result(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_result( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreChannelV1TxGlobalEnums.ResponseResultType x = - IbcCoreChannelV1TxGlobalEnums.decode_ResponseResultType(tmp); - r.result = 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 (uint256(r.result) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_result = IbcCoreChannelV1TxGlobalEnums - .encode_ResponseResultType(r.result); - pointer += ProtoBufRuntime._encode_enum(_enum_result, 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( - IbcCoreChannelV1TxGlobalEnums.encode_ResponseResultType(r.result) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.result) != 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.result = input.result; - } - - //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 IbcCoreChannelV1MsgRecvPacketResponse - -library IbcCoreChannelV1MsgTimeout { - //struct definition - struct Data { - IbcCoreChannelV1Packet.Data packet; - bytes proof_unreceived; - IbcCoreClientV1Height.Data proof_height; - uint64 next_sequence_recv; - 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_packet(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof_unreceived(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_height(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_next_sequence_recv(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_packet( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Packet.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Packet(p, bs); - r.packet = 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_unreceived( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_unreceived = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_next_sequence_recv( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.next_sequence_recv = 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_IbcCoreChannelV1Packet( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1Packet.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Packet.Data memory r,) = - IbcCoreChannelV1Packet._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1Packet._encode_nested(r.packet, pointer, bs); - - if (r.proof_unreceived.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.proof_unreceived, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, pointer, bs); - - if (r.next_sequence_recv != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.next_sequence_recv, 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( - IbcCoreChannelV1Packet._estimate(r.packet) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_unreceived.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.next_sequence_recv); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof_unreceived.length != 0) { - return false; - } - - if (r.next_sequence_recv != 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 { - IbcCoreChannelV1Packet.store(input.packet, output.packet); - output.proof_unreceived = input.proof_unreceived; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - output.next_sequence_recv = input.next_sequence_recv; - 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 IbcCoreChannelV1MsgTimeout - -library IbcCoreChannelV1MsgTimeoutResponse { - //struct definition - struct Data { - IbcCoreChannelV1TxGlobalEnums.ResponseResultType result; - } - - // 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_result(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_result( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreChannelV1TxGlobalEnums.ResponseResultType x = - IbcCoreChannelV1TxGlobalEnums.decode_ResponseResultType(tmp); - r.result = 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 (uint256(r.result) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_result = IbcCoreChannelV1TxGlobalEnums - .encode_ResponseResultType(r.result); - pointer += ProtoBufRuntime._encode_enum(_enum_result, 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( - IbcCoreChannelV1TxGlobalEnums.encode_ResponseResultType(r.result) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.result) != 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.result = input.result; - } - - //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 IbcCoreChannelV1MsgTimeoutResponse - -library IbcCoreChannelV1MsgTimeoutOnClose { - //struct definition - struct Data { - IbcCoreChannelV1Packet.Data packet; - bytes proof_unreceived; - bytes proof_close; - IbcCoreClientV1Height.Data proof_height; - uint64 next_sequence_recv; - 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_packet(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof_unreceived(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_close(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_proof_height(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_next_sequence_recv(pointer, bs, r); - } else if (fieldId == 6) { - 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_packet( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Packet.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Packet(p, bs); - r.packet = 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_unreceived( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_unreceived = 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_close( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_close = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_next_sequence_recv( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.next_sequence_recv = 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_IbcCoreChannelV1Packet( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1Packet.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Packet.Data memory r,) = - IbcCoreChannelV1Packet._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1Packet._encode_nested(r.packet, pointer, bs); - - if (r.proof_unreceived.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.proof_unreceived, pointer, bs); - } - if (r.proof_close.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_close, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, pointer, bs); - - if (r.next_sequence_recv != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.next_sequence_recv, pointer, bs - ); - } - if (bytes(r.signer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, 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( - IbcCoreChannelV1Packet._estimate(r.packet) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_unreceived.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_close.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.next_sequence_recv); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof_unreceived.length != 0) { - return false; - } - - if (r.proof_close.length != 0) { - return false; - } - - if (r.next_sequence_recv != 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 { - IbcCoreChannelV1Packet.store(input.packet, output.packet); - output.proof_unreceived = input.proof_unreceived; - output.proof_close = input.proof_close; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - output.next_sequence_recv = input.next_sequence_recv; - 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 IbcCoreChannelV1MsgTimeoutOnClose - -library IbcCoreChannelV1MsgTimeoutOnCloseResponse { - //struct definition - struct Data { - IbcCoreChannelV1TxGlobalEnums.ResponseResultType result; - } - - // 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_result(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_result( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreChannelV1TxGlobalEnums.ResponseResultType x = - IbcCoreChannelV1TxGlobalEnums.decode_ResponseResultType(tmp); - r.result = 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 (uint256(r.result) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_result = IbcCoreChannelV1TxGlobalEnums - .encode_ResponseResultType(r.result); - pointer += ProtoBufRuntime._encode_enum(_enum_result, 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( - IbcCoreChannelV1TxGlobalEnums.encode_ResponseResultType(r.result) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.result) != 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.result = input.result; - } - - //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 IbcCoreChannelV1MsgTimeoutOnCloseResponse - -library IbcCoreChannelV1MsgAcknowledgement { - //struct definition - struct Data { - IbcCoreChannelV1Packet.Data packet; - bytes acknowledgement; - bytes proof_acked; - IbcCoreClientV1Height.Data proof_height; - 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_packet(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_acknowledgement(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_acked(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_proof_height(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_packet( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Packet.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Packet(p, bs); - r.packet = 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_acknowledgement( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.acknowledgement = 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_acked( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_acked = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_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_IbcCoreChannelV1Packet( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1Packet.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Packet.Data memory r,) = - IbcCoreChannelV1Packet._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1Packet._encode_nested(r.packet, pointer, bs); - - if (r.acknowledgement.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.acknowledgement, pointer, bs); - } - if (r.proof_acked.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_acked, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, 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( - IbcCoreChannelV1Packet._estimate(r.packet) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.acknowledgement.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_acked.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.acknowledgement.length != 0) { - return false; - } - - if (r.proof_acked.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 { - IbcCoreChannelV1Packet.store(input.packet, output.packet); - output.acknowledgement = input.acknowledgement; - output.proof_acked = input.proof_acked; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - 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 IbcCoreChannelV1MsgAcknowledgement - -library IbcCoreChannelV1MsgAcknowledgementResponse { - //struct definition - struct Data { - IbcCoreChannelV1TxGlobalEnums.ResponseResultType result; - } - - // 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_result(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_result( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreChannelV1TxGlobalEnums.ResponseResultType x = - IbcCoreChannelV1TxGlobalEnums.decode_ResponseResultType(tmp); - r.result = 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 (uint256(r.result) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_result = IbcCoreChannelV1TxGlobalEnums - .encode_ResponseResultType(r.result); - pointer += ProtoBufRuntime._encode_enum(_enum_result, 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( - IbcCoreChannelV1TxGlobalEnums.encode_ResponseResultType(r.result) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.result) != 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.result = input.result; - } - - //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 IbcCoreChannelV1MsgAcknowledgementResponse - -library IbcCoreChannelV1TxGlobalEnums { - //enum definition - // Solidity enum definitions - enum ResponseResultType { - RESPONSE_RESULT_TYPE_UNSPECIFIED, - RESPONSE_RESULT_TYPE_NOOP, - RESPONSE_RESULT_TYPE_SUCCESS - } - - // Solidity enum encoder - function encode_ResponseResultType(ResponseResultType x) - internal - pure - returns (int32) - { - if (x == ResponseResultType.RESPONSE_RESULT_TYPE_UNSPECIFIED) { - return 0; - } - - if (x == ResponseResultType.RESPONSE_RESULT_TYPE_NOOP) { - return 1; - } - - if (x == ResponseResultType.RESPONSE_RESULT_TYPE_SUCCESS) { - return 2; - } - revert(); - } - - // Solidity enum decoder - function decode_ResponseResultType(int64 x) - internal - pure - returns (ResponseResultType) - { - if (x == 0) { - return ResponseResultType.RESPONSE_RESULT_TYPE_UNSPECIFIED; - } - - if (x == 1) { - return ResponseResultType.RESPONSE_RESULT_TYPE_NOOP; - } - - if (x == 2) { - return ResponseResultType.RESPONSE_RESULT_TYPE_SUCCESS; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_ResponseResultType( - ResponseResultType[] memory a - ) internal pure returns (uint256) { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_ResponseResultType(a[i])); - } - return e; - } -} -//library IbcCoreChannelV1TxGlobalEnums diff --git a/evm/contracts/proto/ibc/core/client/v1/client.sol b/evm/contracts/proto/ibc/core/client/v1/client.sol deleted file mode 100644 index 44cefd0d6c..0000000000 --- a/evm/contracts/proto/ibc/core/client/v1/client.sol +++ /dev/null @@ -1,2086 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../../cosmos/upgrade/v1beta1/upgrade.sol"; -import "../../../../cosmos_proto/cosmos.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) 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; 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 subject_client_id; - string substitute_client_id; - } - - // 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_subject_client_id(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_substitute_client_id(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_subject_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.subject_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_substitute_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.substitute_client_id = 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 (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.subject_client_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.subject_client_id, pointer, bs); - } - if (bytes(r.substitute_client_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.substitute_client_id, 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.subject_client_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.substitute_client_id).length); - 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.subject_client_id).length != 0) { - return false; - } - - if (bytes(r.substitute_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.subject_client_id = input.subject_client_id; - output.substitute_client_id = input.substitute_client_id; - } - - //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 IbcCoreClientV1UpgradeProposal { - //struct definition - struct Data { - string title; - string description; - CosmosUpgradeV1beta1Plan.Data plan; - GoogleProtobufAny.Data upgraded_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_title(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_description(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_plan(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_upgraded_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_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_plan( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosUpgradeV1beta1Plan.Data memory x, uint256 sz) = - _decode_CosmosUpgradeV1beta1Plan(p, bs); - r.plan = 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_upgraded_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.upgraded_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_CosmosUpgradeV1beta1Plan( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosUpgradeV1beta1Plan.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosUpgradeV1beta1Plan.Data memory r,) = - CosmosUpgradeV1beta1Plan._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; - - 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); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosUpgradeV1beta1Plan._encode_nested(r.plan, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufAny._encode_nested( - r.upgraded_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.title).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.description).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosUpgradeV1beta1Plan._estimate(r.plan) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.upgraded_client_state) - ); - 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; - } - - 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; - CosmosUpgradeV1beta1Plan.store(input.plan, output.plan); - GoogleProtobufAny.store( - input.upgraded_client_state, output.upgraded_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 IbcCoreClientV1UpgradeProposal - -library IbcCoreClientV1Height { - //struct definition - struct Data { - uint64 revision_number; - uint64 revision_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_revision_number(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_revision_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_revision_number( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.revision_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_revision_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.revision_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.revision_number != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.revision_number, pointer, bs); - } - if (r.revision_height != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.revision_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.revision_number); - e += 1 + ProtoBufRuntime._sz_uint64(r.revision_height); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.revision_number != 0) { - return false; - } - - if (r.revision_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.revision_number = input.revision_number; - output.revision_height = input.revision_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 - -library IbcCoreClientV1Params { - //struct definition - struct Data { - string[] allowed_clients; - } - - // 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[2] 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_unpacked_repeated_allowed_clients( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.allowed_clients.length == 0); - r.allowed_clients = new string[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_allowed_clients( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_allowed_clients( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.allowed_clients[r.allowed_clients.length - counters[1]] = x; - counters[1] -= 1; - } - 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; - uint256 i; - if (r.allowed_clients.length != 0) { - for (i = 0; i < r.allowed_clients.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.allowed_clients[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; - for (i = 0; i < r.allowed_clients.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.allowed_clients[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.allowed_clients.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.allowed_clients = input.allowed_clients; - } - - //array helpers for AllowedClients - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAllowedClients( - Data memory self, - string memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.allowed_clients.length + 1); - for (uint256 i; i < self.allowed_clients.length; i++) { - tmp[i] = self.allowed_clients[i]; - } - tmp[self.allowed_clients.length] = value; - self.allowed_clients = 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 IbcCoreClientV1Params diff --git a/evm/contracts/proto/ibc/core/client/v1/genesis.sol b/evm/contracts/proto/ibc/core/client/v1/genesis.sol deleted file mode 100644 index 95b0079b06..0000000000 --- a/evm/contracts/proto/ibc/core/client/v1/genesis.sol +++ /dev/null @@ -1,1240 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "./client.sol"; - -library IbcCoreClientV1GenesisState { - //struct definition - struct Data { - IbcCoreClientV1IdentifiedClientState.Data[] clients; - IbcCoreClientV1ClientConsensusStates.Data[] clients_consensus; - IbcCoreClientV1IdentifiedGenesisMetadata.Data[] clients_metadata; - IbcCoreClientV1Params.Data params; - bool create_localhost; - uint64 next_client_sequence; - } - - // 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[7] 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_unpacked_repeated_clients( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_clients_consensus( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_clients_metadata( - pointer, bs, nil(), counters - ); - } else if (fieldId == 4) { - pointer += _read_params(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_create_localhost(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_next_client_sequence(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.clients.length == 0); - r.clients = - new IbcCoreClientV1IdentifiedClientState.Data[](counters[1]); - } - if (counters[2] > 0) { - require(r.clients_consensus.length == 0); - r.clients_consensus = - new IbcCoreClientV1ClientConsensusStates.Data[](counters[2]); - } - if (counters[3] > 0) { - require(r.clients_metadata.length == 0); - r.clients_metadata = - new IbcCoreClientV1IdentifiedGenesisMetadata.Data[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_clients(pointer, bs, r, counters); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_clients_consensus( - pointer, bs, r, counters - ); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_clients_metadata( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_clients( - uint256 p, - bytes memory bs, - Data memory r, - uint256[7] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreClientV1IdentifiedClientState.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1IdentifiedClientState(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.clients[r.clients.length - counters[1]] = x; - counters[1] -= 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_clients_consensus( - uint256 p, - bytes memory bs, - Data memory r, - uint256[7] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreClientV1ClientConsensusStates.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1ClientConsensusStates(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.clients_consensus[r.clients_consensus.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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_clients_metadata( - uint256 p, - bytes memory bs, - Data memory r, - uint256[7] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreClientV1IdentifiedGenesisMetadata.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1IdentifiedGenesisMetadata(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.clients_metadata[r.clients_metadata.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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Params.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Params(p, bs); - r.params = 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_create_localhost( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.create_localhost = 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_next_client_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.next_client_sequence = 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_IbcCoreClientV1IdentifiedClientState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreClientV1IdentifiedClientState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1IdentifiedClientState.Data memory r,) = - IbcCoreClientV1IdentifiedClientState._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_IbcCoreClientV1ClientConsensusStates( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreClientV1ClientConsensusStates.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1ClientConsensusStates.Data memory r,) = - IbcCoreClientV1ClientConsensusStates._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_IbcCoreClientV1IdentifiedGenesisMetadata( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreClientV1IdentifiedGenesisMetadata.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1IdentifiedGenesisMetadata.Data memory r,) = - IbcCoreClientV1IdentifiedGenesisMetadata._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_IbcCoreClientV1Params( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreClientV1Params.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1Params.Data memory r,) = - IbcCoreClientV1Params._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.clients.length != 0) { - for (i = 0; i < r.clients.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1IdentifiedClientState._encode_nested( - r.clients[i], pointer, bs - ); - } - } - if (r.clients_consensus.length != 0) { - for (i = 0; i < r.clients_consensus.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1ClientConsensusStates._encode_nested( - r.clients_consensus[i], pointer, bs - ); - } - } - if (r.clients_metadata.length != 0) { - for (i = 0; i < r.clients_metadata.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1IdentifiedGenesisMetadata - ._encode_nested(r.clients_metadata[i], pointer, bs); - } - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Params._encode_nested(r.params, pointer, bs); - - if (r.create_localhost != false) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bool(r.create_localhost, pointer, bs); - } - if (r.next_client_sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.next_client_sequence, 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; - for (i = 0; i < r.clients.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1IdentifiedClientState._estimate(r.clients[i]) - ); - } - for (i = 0; i < r.clients_consensus.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1ClientConsensusStates._estimate( - r.clients_consensus[i] - ) - ); - } - for (i = 0; i < r.clients_metadata.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1IdentifiedGenesisMetadata._estimate( - r.clients_metadata[i] - ) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Params._estimate(r.params) - ); - e += 1 + 1; - e += 1 + ProtoBufRuntime._sz_uint64(r.next_client_sequence); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.clients.length != 0) { - return false; - } - - if (r.clients_consensus.length != 0) { - return false; - } - - if (r.clients_metadata.length != 0) { - return false; - } - - if (r.create_localhost != false) { - return false; - } - - if (r.next_client_sequence != 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 { - for (uint256 i1 = 0; i1 < input.clients.length; i1++) { - output.clients.push(input.clients[i1]); - } - - for (uint256 i2 = 0; i2 < input.clients_consensus.length; i2++) { - output.clients_consensus.push(input.clients_consensus[i2]); - } - - for (uint256 i3 = 0; i3 < input.clients_metadata.length; i3++) { - output.clients_metadata.push(input.clients_metadata[i3]); - } - - IbcCoreClientV1Params.store(input.params, output.params); - output.create_localhost = input.create_localhost; - output.next_client_sequence = input.next_client_sequence; - } - - //array helpers for Clients - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addClients( - Data memory self, - IbcCoreClientV1IdentifiedClientState.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreClientV1IdentifiedClientState.Data[] memory tmp = new IbcCoreClientV1IdentifiedClientState - .Data[](self.clients.length + 1); - for (uint256 i; i < self.clients.length; i++) { - tmp[i] = self.clients[i]; - } - tmp[self.clients.length] = value; - self.clients = tmp; - } - - //array helpers for ClientsConsensus - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addClientsConsensus( - Data memory self, - IbcCoreClientV1ClientConsensusStates.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreClientV1ClientConsensusStates.Data[] memory tmp = new IbcCoreClientV1ClientConsensusStates - .Data[](self.clients_consensus.length + 1); - for (uint256 i; i < self.clients_consensus.length; i++) { - tmp[i] = self.clients_consensus[i]; - } - tmp[self.clients_consensus.length] = value; - self.clients_consensus = tmp; - } - - //array helpers for ClientsMetadata - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addClientsMetadata( - Data memory self, - IbcCoreClientV1IdentifiedGenesisMetadata.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreClientV1IdentifiedGenesisMetadata.Data[] memory tmp = new IbcCoreClientV1IdentifiedGenesisMetadata - .Data[](self.clients_metadata.length + 1); - for (uint256 i; i < self.clients_metadata.length; i++) { - tmp[i] = self.clients_metadata[i]; - } - tmp[self.clients_metadata.length] = value; - self.clients_metadata = 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 IbcCoreClientV1GenesisState - -library IbcCoreClientV1GenesisMetadata { - //struct definition - struct Data { - bytes key; - 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_key(pointer, bs, r); - } else if (fieldId == 2) { - 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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key = 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_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.key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key, pointer, bs); - } - if (r.value.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, 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.key.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.value.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key.length != 0) { - return false; - } - - 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.key = input.key; - 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 IbcCoreClientV1GenesisMetadata - -library IbcCoreClientV1IdentifiedGenesisMetadata { - //struct definition - struct Data { - string client_id; - IbcCoreClientV1GenesisMetadata.Data[] client_metadata; - } - - // 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_client_metadata( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[2] > 0) { - require(r.client_metadata.length == 0); - r.client_metadata = - new IbcCoreClientV1GenesisMetadata.Data[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 2) { - pointer += _read_unpacked_repeated_client_metadata( - 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_client_metadata( - 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. - */ - (IbcCoreClientV1GenesisMetadata.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1GenesisMetadata(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.client_metadata[r.client_metadata.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_IbcCoreClientV1GenesisMetadata( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreClientV1GenesisMetadata.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1GenesisMetadata.Data memory r,) = - IbcCoreClientV1GenesisMetadata._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.client_metadata.length != 0) { - for (i = 0; i < r.client_metadata.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1GenesisMetadata._encode_nested( - r.client_metadata[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.client_metadata.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1GenesisMetadata._estimate(r.client_metadata[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.client_metadata.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.client_metadata.length; i2++) { - output.client_metadata.push(input.client_metadata[i2]); - } - } - - //array helpers for ClientMetadata - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addClientMetadata( - Data memory self, - IbcCoreClientV1GenesisMetadata.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreClientV1GenesisMetadata.Data[] memory tmp = new IbcCoreClientV1GenesisMetadata - .Data[](self.client_metadata.length + 1); - for (uint256 i; i < self.client_metadata.length; i++) { - tmp[i] = self.client_metadata[i]; - } - tmp[self.client_metadata.length] = value; - self.client_metadata = 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 IbcCoreClientV1IdentifiedGenesisMetadata diff --git a/evm/contracts/proto/ibc/core/client/v1/query.sol b/evm/contracts/proto/ibc/core/client/v1/query.sol deleted file mode 100644 index 4f26ec7072..0000000000 --- a/evm/contracts/proto/ibc/core/client/v1/query.sol +++ /dev/null @@ -1,4715 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../../cosmos/base/query/v1beta1/pagination.sol"; -import "./client.sol"; - -library IbcCoreClientV1QueryClientStateRequest { - //struct definition - struct Data { - string client_id; - } - - // 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 { - 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; - } - - // 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); - } - 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); - 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; - } - - //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 IbcCoreClientV1QueryClientStateRequest - -library IbcCoreClientV1QueryClientStateResponse { - //struct definition - struct Data { - GoogleProtobufAny.Data client_state; - bytes proof; - IbcCoreClientV1Height.Data proof_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_client_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_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_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufAny._encode_nested(r.client_state, pointer, bs); - - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim( - GoogleProtobufAny._estimate(r.client_state) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof.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.client_state, output.client_state); - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreClientV1QueryClientStateResponse - -library IbcCoreClientV1QueryClientStatesRequest { - //struct definition - struct Data { - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_pagination(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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcCoreClientV1QueryClientStatesRequest - -library IbcCoreClientV1QueryClientStatesResponse { - //struct definition - struct Data { - IbcCoreClientV1IdentifiedClientState.Data[] client_states; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - } - - // 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_unpacked_repeated_client_states( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.client_states.length == 0); - r.client_states = - new IbcCoreClientV1IdentifiedClientState.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_client_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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_client_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. - */ - (IbcCoreClientV1IdentifiedClientState.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1IdentifiedClientState(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.client_states[r.client_states.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_IbcCoreClientV1IdentifiedClientState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreClientV1IdentifiedClientState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1IdentifiedClientState.Data memory r,) = - IbcCoreClientV1IdentifiedClientState._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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.client_states.length != 0) { - for (i = 0; i < r.client_states.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1IdentifiedClientState._encode_nested( - r.client_states[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, 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; - for (i = 0; i < r.client_states.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1IdentifiedClientState._estimate( - r.client_states[i] - ) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.client_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 { - for (uint256 i1 = 0; i1 < input.client_states.length; i1++) { - output.client_states.push(input.client_states[i1]); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - } - - //array helpers for ClientStates - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addClientStates( - Data memory self, - IbcCoreClientV1IdentifiedClientState.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreClientV1IdentifiedClientState.Data[] memory tmp = new IbcCoreClientV1IdentifiedClientState - .Data[](self.client_states.length + 1); - for (uint256 i; i < self.client_states.length; i++) { - tmp[i] = self.client_states[i]; - } - tmp[self.client_states.length] = value; - self.client_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 IbcCoreClientV1QueryClientStatesResponse - -library IbcCoreClientV1QueryConsensusStateRequest { - //struct definition - struct Data { - string client_id; - uint64 revision_number; - uint64 revision_height; - bool latest_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_client_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_revision_number(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_revision_height(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_latest_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_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_revision_number( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.revision_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_revision_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.revision_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_latest_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.latest_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 (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.revision_number != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.revision_number, pointer, bs); - } - if (r.revision_height != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.revision_height, pointer, bs); - } - if (r.latest_height != false) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bool(r.latest_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_lendelim(bytes(r.client_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.revision_number); - e += 1 + ProtoBufRuntime._sz_uint64(r.revision_height); - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.client_id).length != 0) { - return false; - } - - if (r.revision_number != 0) { - return false; - } - - if (r.revision_height != 0) { - return false; - } - - if (r.latest_height != false) { - 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; - output.revision_number = input.revision_number; - output.revision_height = input.revision_height; - output.latest_height = input.latest_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 IbcCoreClientV1QueryConsensusStateRequest - -library IbcCoreClientV1QueryConsensusStateResponse { - //struct definition - struct Data { - GoogleProtobufAny.Data consensus_state; - bytes proof; - IbcCoreClientV1Height.Data proof_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_consensus_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_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_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufAny._encode_nested(r.consensus_state, pointer, bs); - - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim( - GoogleProtobufAny._estimate(r.consensus_state) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof.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.consensus_state, output.consensus_state); - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreClientV1QueryConsensusStateResponse - -library IbcCoreClientV1QueryConsensusStatesRequest { - //struct definition - struct Data { - string client_id; - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_pagination(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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - 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; - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcCoreClientV1QueryConsensusStatesRequest - -library IbcCoreClientV1QueryConsensusStatesResponse { - //struct definition - struct Data { - IbcCoreClientV1ConsensusStateWithHeight.Data[] consensus_states; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - } - - // 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_unpacked_repeated_consensus_states( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.consensus_states.length == 0); - r.consensus_states = - new IbcCoreClientV1ConsensusStateWithHeight.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - 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 - * @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[1] += 1; - } else { - r.consensus_states[r.consensus_states.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_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); - } - - /** - * @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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.consensus_states.length != 0) { - for (i = 0; i < r.consensus_states.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1ConsensusStateWithHeight - ._encode_nested(r.consensus_states[i], pointer, bs); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, 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; - for (i = 0; i < r.consensus_states.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1ConsensusStateWithHeight._estimate( - r.consensus_states[i] - ) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - 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 { - for (uint256 i1 = 0; i1 < input.consensus_states.length; i1++) { - output.consensus_states.push(input.consensus_states[i1]); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - } - - //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; 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 IbcCoreClientV1QueryConsensusStatesResponse - -library IbcCoreClientV1QueryConsensusStateHeightsRequest { - //struct definition - struct Data { - string client_id; - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_pagination(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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - 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; - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcCoreClientV1QueryConsensusStateHeightsRequest - -library IbcCoreClientV1QueryConsensusStateHeightsResponse { - //struct definition - struct Data { - IbcCoreClientV1Height.Data[] consensus_state_heights; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - } - - // 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_unpacked_repeated_consensus_state_heights( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.consensus_state_heights.length == 0); - r.consensus_state_heights = - new IbcCoreClientV1Height.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_consensus_state_heights( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_consensus_state_heights( - 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. - */ - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.consensus_state_heights[r.consensus_state_heights.length - - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.consensus_state_heights.length != 0) { - for (i = 0; i < r.consensus_state_heights.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested( - r.consensus_state_heights[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, 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; - for (i = 0; i < r.consensus_state_heights.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.consensus_state_heights[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.consensus_state_heights.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 { - for (uint256 i1 = 0; i1 < input.consensus_state_heights.length; i1++) { - output.consensus_state_heights.push( - input.consensus_state_heights[i1] - ); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - } - - //array helpers for ConsensusStateHeights - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addConsensusStateHeights( - Data memory self, - IbcCoreClientV1Height.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreClientV1Height.Data[] memory tmp = new IbcCoreClientV1Height.Data[]( - self.consensus_state_heights.length + 1 - ); - for (uint256 i; i < self.consensus_state_heights.length; i++) { - tmp[i] = self.consensus_state_heights[i]; - } - tmp[self.consensus_state_heights.length] = value; - self.consensus_state_heights = 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 IbcCoreClientV1QueryConsensusStateHeightsResponse - -library IbcCoreClientV1QueryClientStatusRequest { - //struct definition - struct Data { - string client_id; - } - - // 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 { - 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; - } - - // 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); - } - 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); - 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; - } - - //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 IbcCoreClientV1QueryClientStatusRequest - -library IbcCoreClientV1QueryClientStatusResponse { - //struct definition - struct Data { - string 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_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_status( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - 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 (bytes(r.status).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.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(bytes(r.status).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.status).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.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 IbcCoreClientV1QueryClientStatusResponse - -library IbcCoreClientV1QueryClientParamsRequest { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreClientV1QueryClientParamsRequest - -library IbcCoreClientV1QueryClientParamsResponse { - //struct definition - struct Data { - IbcCoreClientV1Params.Data params; - } - - // 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_params(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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Params.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Params(p, bs); - r.params = 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_IbcCoreClientV1Params( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreClientV1Params.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1Params.Data memory r,) = - IbcCoreClientV1Params._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 += IbcCoreClientV1Params._encode_nested(r.params, 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( - IbcCoreClientV1Params._estimate(r.params) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcCoreClientV1Params.store(input.params, output.params); - } - - //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 IbcCoreClientV1QueryClientParamsResponse - -library IbcCoreClientV1QueryUpgradedClientStateRequest { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreClientV1QueryUpgradedClientStateRequest - -library IbcCoreClientV1QueryUpgradedClientStateResponse { - //struct definition - struct Data { - GoogleProtobufAny.Data upgraded_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_upgraded_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_upgraded_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.upgraded_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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufAny._encode_nested( - r.upgraded_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( - GoogleProtobufAny._estimate(r.upgraded_client_state) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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.upgraded_client_state, output.upgraded_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 IbcCoreClientV1QueryUpgradedClientStateResponse - -library IbcCoreClientV1QueryUpgradedConsensusStateRequest { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreClientV1QueryUpgradedConsensusStateRequest - -library IbcCoreClientV1QueryUpgradedConsensusStateResponse { - //struct definition - struct Data { - GoogleProtobufAny.Data upgraded_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_upgraded_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_upgraded_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.upgraded_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_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.upgraded_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( - GoogleProtobufAny._estimate(r.upgraded_consensus_state) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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.upgraded_consensus_state, output.upgraded_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 IbcCoreClientV1QueryUpgradedConsensusStateResponse diff --git a/evm/contracts/proto/ibc/core/client/v1/tx.sol b/evm/contracts/proto/ibc/core/client/v1/tx.sol deleted file mode 100644 index cb6d3165b5..0000000000 --- a/evm/contracts/proto/ibc/core/client/v1/tx.sol +++ /dev/null @@ -1,1993 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcCoreClientV1MsgCreateClient { - //struct definition - struct Data { - 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_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_consensus_state(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_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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufAny._encode_nested(r.client_state, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufAny._encode_nested(r.consensus_state, 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( - 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.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 { - 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 IbcCoreClientV1MsgCreateClientResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreClientV1MsgCreateClientResponse - -library IbcCoreClientV1MsgUpdateClient { - //struct definition - struct Data { - string client_id; - GoogleProtobufAny.Data client_message; - 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_message(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_client_message( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufAny.Data memory x, uint256 sz) = - _decode_GoogleProtobufAny(p, bs); - r.client_message = 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_message, 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.client_message) - ); - 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_message, output.client_message); - 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 IbcCoreClientV1MsgUpdateClientResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreClientV1MsgUpdateClientResponse - -library IbcCoreClientV1MsgUpgradeClient { - //struct definition - struct Data { - string client_id; - GoogleProtobufAny.Data client_state; - GoogleProtobufAny.Data consensus_state; - bytes proof_upgrade_client; - bytes proof_upgrade_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_proof_upgrade_client(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_proof_upgrade_consensus_state(pointer, bs, r); - } else if (fieldId == 6) { - 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_proof_upgrade_client( - 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_client = 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_consensus_state( - 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_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 (r.proof_upgrade_client.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.proof_upgrade_client, pointer, bs - ); - } - if (r.proof_upgrade_consensus_state.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.proof_upgrade_consensus_state, pointer, bs - ); - } - if (bytes(r.signer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, 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(r.proof_upgrade_client.length); - e += 1 - + ProtoBufRuntime._sz_lendelim(r.proof_upgrade_consensus_state.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_client.length != 0) { - return false; - } - - if (r.proof_upgrade_consensus_state.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.proof_upgrade_client = input.proof_upgrade_client; - output.proof_upgrade_consensus_state = - input.proof_upgrade_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 IbcCoreClientV1MsgUpgradeClient - -library IbcCoreClientV1MsgUpgradeClientResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreClientV1MsgUpgradeClientResponse - -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 IbcCoreClientV1MsgSubmitMisbehaviourResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreClientV1MsgSubmitMisbehaviourResponse diff --git a/evm/contracts/proto/ibc/core/commitment/v1/commitment.sol b/evm/contracts/proto/ibc/core/commitment/v1/commitment.sol deleted file mode 100644 index dbdfa6f6f6..0000000000 --- a/evm/contracts/proto/ibc/core/commitment/v1/commitment.sol +++ /dev/null @@ -1,1002 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../../cosmos/ics23/v1/proofs.sol"; - -library IbcCoreCommitmentV1MerkleRoot { - //struct definition - struct Data { - bytes hash; - } - - // 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_hash(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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.hash = 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.hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.hash, 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.hash.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.hash.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.hash = input.hash; - } - - //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 IbcCoreCommitmentV1MerkleRoot - -library IbcCoreCommitmentV1MerklePrefix { - //struct definition - struct Data { - bytes key_prefix; - } - - // 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_key_prefix(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_key_prefix( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key_prefix = 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.key_prefix.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key_prefix, 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.key_prefix.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key_prefix.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.key_prefix = input.key_prefix; - } - - //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 IbcCoreCommitmentV1MerklePrefix - -library IbcCoreCommitmentV1MerklePath { - //struct definition - struct Data { - string[] key_path; - } - - // 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[2] 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_unpacked_repeated_key_path( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.key_path.length == 0); - r.key_path = new string[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_key_path(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_key_path( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.key_path[r.key_path.length - counters[1]] = x; - counters[1] -= 1; - } - 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; - uint256 i; - if (r.key_path.length != 0) { - for (i = 0; i < r.key_path.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.key_path[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; - for (i = 0; i < r.key_path.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.key_path[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key_path.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.key_path = input.key_path; - } - - //array helpers for KeyPath - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addKeyPath(Data memory self, string memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.key_path.length + 1); - for (uint256 i; i < self.key_path.length; i++) { - tmp[i] = self.key_path[i]; - } - tmp[self.key_path.length] = value; - self.key_path = 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 IbcCoreCommitmentV1MerklePath - -library IbcCoreCommitmentV1MerkleProof { - //struct definition - struct Data { - CosmosIcs23V1CommitmentProof.Data[] proofs; - } - - // 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[2] 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_unpacked_repeated_proofs(pointer, bs, nil(), counters); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.proofs.length == 0); - r.proofs = new CosmosIcs23V1CommitmentProof.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_proofs(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_proofs( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosIcs23V1CommitmentProof.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1CommitmentProof(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.proofs[r.proofs.length - counters[1]] = x; - counters[1] -= 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_CosmosIcs23V1CommitmentProof( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosIcs23V1CommitmentProof.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1CommitmentProof.Data memory r,) = - CosmosIcs23V1CommitmentProof._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.proofs.length != 0) { - for (i = 0; i < r.proofs.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1CommitmentProof._encode_nested( - r.proofs[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; - for (i = 0; i < r.proofs.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1CommitmentProof._estimate(r.proofs[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proofs.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 { - for (uint256 i1 = 0; i1 < input.proofs.length; i1++) { - output.proofs.push(input.proofs[i1]); - } - } - - //array helpers for Proofs - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addProofs( - Data memory self, - CosmosIcs23V1CommitmentProof.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosIcs23V1CommitmentProof.Data[] memory tmp = - new CosmosIcs23V1CommitmentProof.Data[](self.proofs.length + 1); - for (uint256 i; i < self.proofs.length; i++) { - tmp[i] = self.proofs[i]; - } - tmp[self.proofs.length] = value; - self.proofs = 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 IbcCoreCommitmentV1MerkleProof diff --git a/evm/contracts/proto/ibc/core/connection/v1/connection.sol b/evm/contracts/proto/ibc/core/connection/v1/connection.sol deleted file mode 100644 index 40d91b4d05..0000000000 --- a/evm/contracts/proto/ibc/core/connection/v1/connection.sol +++ /dev/null @@ -1,2424 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../commitment/v1/commitment.sol"; - -library IbcCoreConnectionV1ConnectionEnd { - //struct definition - struct Data { - string client_id; - IbcCoreConnectionV1Version.Data[] versions; - IbcCoreConnectionV1GlobalEnums.State state; - IbcCoreConnectionV1Counterparty.Data counterparty; - uint64 delay_period; - } - - // 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_client_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_versions( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += _read_state(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_counterparty(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_delay_period(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[2] > 0) { - require(r.versions.length == 0); - r.versions = new IbcCoreConnectionV1Version.Data[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 2) { - pointer += - _read_unpacked_repeated_versions(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_versions( - 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. - */ - (IbcCoreConnectionV1Version.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Version(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.versions[r.versions.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_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreConnectionV1GlobalEnums.State x = - IbcCoreConnectionV1GlobalEnums.decode_State(tmp); - r.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_counterparty( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1Counterparty.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Counterparty(p, bs); - r.counterparty = 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_delay_period( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.delay_period = 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_IbcCoreConnectionV1Version( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreConnectionV1Version.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Version.Data memory r,) = - IbcCoreConnectionV1Version._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_IbcCoreConnectionV1Counterparty( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1Counterparty.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Counterparty.Data memory r,) = - IbcCoreConnectionV1Counterparty._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.versions.length != 0) { - for (i = 0; i < r.versions.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1Version._encode_nested( - r.versions[i], pointer, bs - ); - } - } - if (uint256(r.state) != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_state = - IbcCoreConnectionV1GlobalEnums.encode_State(r.state); - pointer += ProtoBufRuntime._encode_enum(_enum_state, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1Counterparty._encode_nested( - r.counterparty, pointer, bs - ); - - if (r.delay_period != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.delay_period, 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.versions.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Version._estimate(r.versions[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_enum( - IbcCoreConnectionV1GlobalEnums.encode_State(r.state) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Counterparty._estimate(r.counterparty) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.delay_period); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.client_id).length != 0) { - return false; - } - - if (r.versions.length != 0) { - return false; - } - - if (uint256(r.state) != 0) { - return false; - } - - if (r.delay_period != 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.versions.length; i2++) { - output.versions.push(input.versions[i2]); - } - - output.state = input.state; - IbcCoreConnectionV1Counterparty.store( - input.counterparty, output.counterparty - ); - output.delay_period = input.delay_period; - } - - //array helpers for Versions - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addVersions( - Data memory self, - IbcCoreConnectionV1Version.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreConnectionV1Version.Data[] memory tmp = - new IbcCoreConnectionV1Version.Data[](self.versions.length + 1); - for (uint256 i; i < self.versions.length; i++) { - tmp[i] = self.versions[i]; - } - tmp[self.versions.length] = value; - self.versions = 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 IbcCoreConnectionV1ConnectionEnd - -library IbcCoreConnectionV1IdentifiedConnection { - //struct definition - struct Data { - string id; - string client_id; - IbcCoreConnectionV1Version.Data[] versions; - IbcCoreConnectionV1GlobalEnums.State state; - IbcCoreConnectionV1Counterparty.Data counterparty; - uint64 delay_period; - } - - // 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[7] 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_client_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_unpacked_repeated_versions( - pointer, bs, nil(), counters - ); - } else if (fieldId == 4) { - pointer += _read_state(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_counterparty(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_delay_period(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[3] > 0) { - require(r.versions.length == 0); - r.versions = new IbcCoreConnectionV1Version.Data[](counters[3]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 3) { - pointer += - _read_unpacked_repeated_versions(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) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(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_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_versions( - uint256 p, - bytes memory bs, - Data memory r, - uint256[7] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreConnectionV1Version.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Version(p, bs); - if (isNil(r)) { - counters[3] += 1; - } else { - r.versions[r.versions.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_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcCoreConnectionV1GlobalEnums.State x = - IbcCoreConnectionV1GlobalEnums.decode_State(tmp); - r.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_counterparty( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1Counterparty.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Counterparty(p, bs); - r.counterparty = 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_delay_period( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.delay_period = 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_IbcCoreConnectionV1Version( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreConnectionV1Version.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Version.Data memory r,) = - IbcCoreConnectionV1Version._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_IbcCoreConnectionV1Counterparty( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1Counterparty.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Counterparty.Data memory r,) = - IbcCoreConnectionV1Counterparty._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.id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.id, pointer, bs); - } - if (bytes(r.client_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); - } - if (r.versions.length != 0) { - for (i = 0; i < r.versions.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1Version._encode_nested( - r.versions[i], pointer, bs - ); - } - } - if (uint256(r.state) != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_state = - IbcCoreConnectionV1GlobalEnums.encode_State(r.state); - pointer += ProtoBufRuntime._encode_enum(_enum_state, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1Counterparty._encode_nested( - r.counterparty, pointer, bs - ); - - if (r.delay_period != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.delay_period, 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.id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); - for (i = 0; i < r.versions.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Version._estimate(r.versions[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_enum( - IbcCoreConnectionV1GlobalEnums.encode_State(r.state) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Counterparty._estimate(r.counterparty) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.delay_period); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.id).length != 0) { - return false; - } - - if (bytes(r.client_id).length != 0) { - return false; - } - - if (r.versions.length != 0) { - return false; - } - - if (uint256(r.state) != 0) { - return false; - } - - if (r.delay_period != 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.client_id = input.client_id; - - for (uint256 i3 = 0; i3 < input.versions.length; i3++) { - output.versions.push(input.versions[i3]); - } - - output.state = input.state; - IbcCoreConnectionV1Counterparty.store( - input.counterparty, output.counterparty - ); - output.delay_period = input.delay_period; - } - - //array helpers for Versions - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addVersions( - Data memory self, - IbcCoreConnectionV1Version.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreConnectionV1Version.Data[] memory tmp = - new IbcCoreConnectionV1Version.Data[](self.versions.length + 1); - for (uint256 i; i < self.versions.length; i++) { - tmp[i] = self.versions[i]; - } - tmp[self.versions.length] = value; - self.versions = 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 IbcCoreConnectionV1IdentifiedConnection - -library IbcCoreConnectionV1Counterparty { - //struct definition - struct Data { - string client_id; - string connection_id; - IbcCoreCommitmentV1MerklePrefix.Data prefix; - } - - // 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_connection_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_prefix(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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_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_prefix( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreCommitmentV1MerklePrefix.Data memory x, uint256 sz) = - _decode_IbcCoreCommitmentV1MerklePrefix(p, bs); - r.prefix = 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_IbcCoreCommitmentV1MerklePrefix( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreCommitmentV1MerklePrefix.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreCommitmentV1MerklePrefix.Data memory r,) = - IbcCoreCommitmentV1MerklePrefix._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); - } - if (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreCommitmentV1MerklePrefix._encode_nested( - r.prefix, 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(bytes(r.connection_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreCommitmentV1MerklePrefix._estimate(r.prefix) - ); - 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.connection_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; - output.connection_id = input.connection_id; - IbcCoreCommitmentV1MerklePrefix.store(input.prefix, output.prefix); - } - - //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 IbcCoreConnectionV1Counterparty - -library IbcCoreConnectionV1ClientPaths { - //struct definition - struct Data { - string[] paths; - } - - // 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[2] 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_unpacked_repeated_paths(pointer, bs, nil(), counters); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.paths.length == 0); - r.paths = new string[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_paths(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_paths( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.paths[r.paths.length - counters[1]] = x; - counters[1] -= 1; - } - 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; - uint256 i; - if (r.paths.length != 0) { - for (i = 0; i < r.paths.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.paths[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; - for (i = 0; i < r.paths.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.paths[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.paths.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.paths = input.paths; - } - - //array helpers for Paths - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPaths(Data memory self, string memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.paths.length + 1); - for (uint256 i; i < self.paths.length; i++) { - tmp[i] = self.paths[i]; - } - tmp[self.paths.length] = value; - self.paths = 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 IbcCoreConnectionV1ClientPaths - -library IbcCoreConnectionV1ConnectionPaths { - //struct definition - struct Data { - string client_id; - string[] paths; - } - - // 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_paths(pointer, bs, nil(), counters); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[2] > 0) { - require(r.paths.length == 0); - r.paths = new string[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 2) { - pointer += - _read_unpacked_repeated_paths(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_paths( - 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. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.paths[r.paths.length - counters[2]] = x; - counters[2] -= 1; - } - 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; - 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.paths.length != 0) { - for (i = 0; i < r.paths.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.paths[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.paths.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.paths[i]).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.paths.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; - output.paths = input.paths; - } - - //array helpers for Paths - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addPaths(Data memory self, string memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.paths.length + 1); - for (uint256 i; i < self.paths.length; i++) { - tmp[i] = self.paths[i]; - } - tmp[self.paths.length] = value; - self.paths = 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 IbcCoreConnectionV1ConnectionPaths - -library IbcCoreConnectionV1Version { - //struct definition - struct Data { - string identifier; - string[] features; - } - - // 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_identifier(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_features( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[2] > 0) { - require(r.features.length == 0); - r.features = new string[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 2) { - pointer += - _read_unpacked_repeated_features(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_identifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.identifier = 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_features( - 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. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.features[r.features.length - counters[2]] = x; - counters[2] -= 1; - } - 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; - uint256 i; - if (bytes(r.identifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.identifier, pointer, bs); - } - if (r.features.length != 0) { - for (i = 0; i < r.features.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.features[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.identifier).length); - for (i = 0; i < r.features.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.features[i]).length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.identifier).length != 0) { - return false; - } - - if (r.features.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.identifier = input.identifier; - output.features = input.features; - } - - //array helpers for Features - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addFeatures(Data memory self, string memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.features.length + 1); - for (uint256 i; i < self.features.length; i++) { - tmp[i] = self.features[i]; - } - tmp[self.features.length] = value; - self.features = 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 IbcCoreConnectionV1Version - -library IbcCoreConnectionV1Params { - //struct definition - struct Data { - uint64 max_expected_time_per_block; - } - - // 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_max_expected_time_per_block(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_max_expected_time_per_block( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.max_expected_time_per_block = 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.max_expected_time_per_block != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.max_expected_time_per_block, 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.max_expected_time_per_block); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.max_expected_time_per_block != 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.max_expected_time_per_block = input.max_expected_time_per_block; - } - - //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 IbcCoreConnectionV1Params - -library IbcCoreConnectionV1GlobalEnums { - //enum definition - // Solidity enum definitions - enum State { - STATE_UNINITIALIZED_UNSPECIFIED, - STATE_INIT, - STATE_TRYOPEN, - STATE_OPEN - } - - // Solidity enum encoder - function encode_State(State x) internal pure returns (int32) { - if (x == State.STATE_UNINITIALIZED_UNSPECIFIED) { - return 0; - } - - if (x == State.STATE_INIT) { - return 1; - } - - if (x == State.STATE_TRYOPEN) { - return 2; - } - - if (x == State.STATE_OPEN) { - return 3; - } - revert(); - } - - // Solidity enum decoder - function decode_State(int64 x) internal pure returns (State) { - if (x == 0) { - return State.STATE_UNINITIALIZED_UNSPECIFIED; - } - - if (x == 1) { - return State.STATE_INIT; - } - - if (x == 2) { - return State.STATE_TRYOPEN; - } - - if (x == 3) { - return State.STATE_OPEN; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_State(State[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_State(a[i])); - } - return e; - } -} -//library IbcCoreConnectionV1GlobalEnums diff --git a/evm/contracts/proto/ibc/core/connection/v1/genesis.sol b/evm/contracts/proto/ibc/core/connection/v1/genesis.sol deleted file mode 100644 index a76e44e5e5..0000000000 --- a/evm/contracts/proto/ibc/core/connection/v1/genesis.sol +++ /dev/null @@ -1,517 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "./connection.sol"; - -library IbcCoreConnectionV1GenesisState { - //struct definition - struct Data { - IbcCoreConnectionV1IdentifiedConnection.Data[] connections; - IbcCoreConnectionV1ConnectionPaths.Data[] client_connection_paths; - uint64 next_connection_sequence; - IbcCoreConnectionV1Params.Data params; - } - - // 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[5] 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_unpacked_repeated_connections( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_client_connection_paths( - pointer, bs, nil(), counters - ); - } else if (fieldId == 3) { - pointer += _read_next_connection_sequence(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_params(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.connections.length == 0); - r.connections = - new IbcCoreConnectionV1IdentifiedConnection.Data[](counters[1]); - } - if (counters[2] > 0) { - require(r.client_connection_paths.length == 0); - r.client_connection_paths = - new IbcCoreConnectionV1ConnectionPaths.Data[](counters[2]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_connections( - pointer, bs, r, counters - ); - } else if (fieldId == 2) { - pointer += _read_unpacked_repeated_client_connection_paths( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_connections( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreConnectionV1IdentifiedConnection.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1IdentifiedConnection(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.connections[r.connections.length - counters[1]] = x; - counters[1] -= 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_client_connection_paths( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreConnectionV1ConnectionPaths.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1ConnectionPaths(p, bs); - if (isNil(r)) { - counters[2] += 1; - } else { - r.client_connection_paths[r.client_connection_paths.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_next_connection_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.next_connection_sequence = 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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1Params.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Params(p, bs); - r.params = 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_IbcCoreConnectionV1IdentifiedConnection( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1IdentifiedConnection.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1IdentifiedConnection.Data memory r,) = - IbcCoreConnectionV1IdentifiedConnection._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_IbcCoreConnectionV1ConnectionPaths( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1ConnectionPaths.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1ConnectionPaths.Data memory r,) = - IbcCoreConnectionV1ConnectionPaths._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_IbcCoreConnectionV1Params( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreConnectionV1Params.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Params.Data memory r,) = - IbcCoreConnectionV1Params._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.connections.length != 0) { - for (i = 0; i < r.connections.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1IdentifiedConnection - ._encode_nested(r.connections[i], pointer, bs); - } - } - if (r.client_connection_paths.length != 0) { - for (i = 0; i < r.client_connection_paths.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1ConnectionPaths._encode_nested( - r.client_connection_paths[i], pointer, bs - ); - } - } - if (r.next_connection_sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64( - r.next_connection_sequence, pointer, bs - ); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreConnectionV1Params._encode_nested(r.params, 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; - for (i = 0; i < r.connections.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1IdentifiedConnection._estimate( - r.connections[i] - ) - ); - } - for (i = 0; i < r.client_connection_paths.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1ConnectionPaths._estimate( - r.client_connection_paths[i] - ) - ); - } - e += 1 + ProtoBufRuntime._sz_uint64(r.next_connection_sequence); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Params._estimate(r.params) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.connections.length != 0) { - return false; - } - - if (r.client_connection_paths.length != 0) { - return false; - } - - if (r.next_connection_sequence != 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 { - for (uint256 i1 = 0; i1 < input.connections.length; i1++) { - output.connections.push(input.connections[i1]); - } - - for (uint256 i2 = 0; i2 < input.client_connection_paths.length; i2++) { - output.client_connection_paths.push( - input.client_connection_paths[i2] - ); - } - - output.next_connection_sequence = input.next_connection_sequence; - IbcCoreConnectionV1Params.store(input.params, output.params); - } - - //array helpers for Connections - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addConnections( - Data memory self, - IbcCoreConnectionV1IdentifiedConnection.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreConnectionV1IdentifiedConnection.Data[] memory tmp = new IbcCoreConnectionV1IdentifiedConnection - .Data[](self.connections.length + 1); - for (uint256 i; i < self.connections.length; i++) { - tmp[i] = self.connections[i]; - } - tmp[self.connections.length] = value; - self.connections = tmp; - } - - //array helpers for ClientConnectionPaths - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addClientConnectionPaths( - Data memory self, - IbcCoreConnectionV1ConnectionPaths.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreConnectionV1ConnectionPaths.Data[] memory tmp = new IbcCoreConnectionV1ConnectionPaths - .Data[](self.client_connection_paths.length + 1); - for (uint256 i; i < self.client_connection_paths.length; i++) { - tmp[i] = self.client_connection_paths[i]; - } - tmp[self.client_connection_paths.length] = value; - self.client_connection_paths = 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 IbcCoreConnectionV1GenesisState diff --git a/evm/contracts/proto/ibc/core/connection/v1/query.sol b/evm/contracts/proto/ibc/core/connection/v1/query.sol deleted file mode 100644 index a179e9da74..0000000000 --- a/evm/contracts/proto/ibc/core/connection/v1/query.sol +++ /dev/null @@ -1,3361 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../../../cosmos/base/query/v1beta1/pagination.sol"; -import "../../client/v1/client.sol"; -import "./connection.sol"; - -library IbcCoreConnectionV1QueryConnectionRequest { - //struct definition - struct Data { - string connection_id; - } - - // 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_connection_id(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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_id = 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 (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, 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.connection_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.connection_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.connection_id = input.connection_id; - } - - //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 IbcCoreConnectionV1QueryConnectionRequest - -library IbcCoreConnectionV1QueryConnectionResponse { - //struct definition - struct Data { - IbcCoreConnectionV1ConnectionEnd.Data connection; - bytes proof; - IbcCoreClientV1Height.Data proof_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_connection(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_connection( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1ConnectionEnd.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1ConnectionEnd(p, bs); - r.connection = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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_IbcCoreConnectionV1ConnectionEnd( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1ConnectionEnd.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1ConnectionEnd.Data memory r,) = - IbcCoreConnectionV1ConnectionEnd._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1ConnectionEnd._encode_nested( - r.connection, pointer, bs - ); - - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim( - IbcCoreConnectionV1ConnectionEnd._estimate(r.connection) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof.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 { - IbcCoreConnectionV1ConnectionEnd.store( - input.connection, output.connection - ); - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreConnectionV1QueryConnectionResponse - -library IbcCoreConnectionV1QueryConnectionsRequest { - //struct definition - struct Data { - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_pagination(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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcCoreConnectionV1QueryConnectionsRequest - -library IbcCoreConnectionV1QueryConnectionsResponse { - //struct definition - struct Data { - IbcCoreConnectionV1IdentifiedConnection.Data[] connections; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - IbcCoreClientV1Height.Data 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[4] 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_unpacked_repeated_connections( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_height(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.connections.length == 0); - r.connections = - new IbcCoreConnectionV1IdentifiedConnection.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_connections( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_connections( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreConnectionV1IdentifiedConnection.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1IdentifiedConnection(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.connections[r.connections.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_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; - } - - // 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_IbcCoreConnectionV1IdentifiedConnection( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1IdentifiedConnection.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1IdentifiedConnection.Data memory r,) = - IbcCoreConnectionV1IdentifiedConnection._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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.connections.length != 0) { - for (i = 0; i < r.connections.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1IdentifiedConnection - ._encode_nested(r.connections[i], pointer, bs); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.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; - uint256 i; - for (i = 0; i < r.connections.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1IdentifiedConnection._estimate( - r.connections[i] - ) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.connections.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 { - for (uint256 i1 = 0; i1 < input.connections.length; i1++) { - output.connections.push(input.connections[i1]); - } - - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - IbcCoreClientV1Height.store(input.height, output.height); - } - - //array helpers for Connections - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addConnections( - Data memory self, - IbcCoreConnectionV1IdentifiedConnection.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreConnectionV1IdentifiedConnection.Data[] memory tmp = new IbcCoreConnectionV1IdentifiedConnection - .Data[](self.connections.length + 1); - for (uint256 i; i < self.connections.length; i++) { - tmp[i] = self.connections[i]; - } - tmp[self.connections.length] = value; - self.connections = 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 IbcCoreConnectionV1QueryConnectionsResponse - -library IbcCoreConnectionV1QueryClientConnectionsRequest { - //struct definition - struct Data { - string client_id; - } - - // 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 { - 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; - } - - // 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); - } - 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); - 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; - } - - //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 IbcCoreConnectionV1QueryClientConnectionsRequest - -library IbcCoreConnectionV1QueryClientConnectionsResponse { - //struct definition - struct Data { - string[] connection_paths; - bytes proof; - IbcCoreClientV1Height.Data proof_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[4] 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_unpacked_repeated_connection_paths( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_height(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.connection_paths.length == 0); - r.connection_paths = new string[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_connection_paths( - 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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_connection_paths( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.connection_paths[r.connection_paths.length - counters[1]] = x; - counters[1] -= 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_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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); - } - - // 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.connection_paths.length != 0) { - for (i = 0; i < r.connection_paths.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.connection_paths[i], pointer, bs - ); - } - } - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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; - uint256 i; - for (i = 0; i < r.connection_paths.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.connection_paths[i]).length); - } - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.connection_paths.length != 0) { - return false; - } - - if (r.proof.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.connection_paths = input.connection_paths; - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - } - - //array helpers for ConnectionPaths - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addConnectionPaths( - Data memory self, - string memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.connection_paths.length + 1); - for (uint256 i; i < self.connection_paths.length; i++) { - tmp[i] = self.connection_paths[i]; - } - tmp[self.connection_paths.length] = value; - self.connection_paths = 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 IbcCoreConnectionV1QueryClientConnectionsResponse - -library IbcCoreConnectionV1QueryConnectionClientStateRequest { - //struct definition - struct Data { - string connection_id; - } - - // 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_connection_id(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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_id = 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 (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, 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.connection_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.connection_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.connection_id = input.connection_id; - } - - //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 IbcCoreConnectionV1QueryConnectionClientStateRequest - -library IbcCoreConnectionV1QueryConnectionClientStateResponse { - //struct definition - struct Data { - IbcCoreClientV1IdentifiedClientState.Data identified_client_state; - bytes proof; - IbcCoreClientV1Height.Data proof_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_identified_client_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_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_identified_client_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1IdentifiedClientState.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1IdentifiedClientState(p, bs); - r.identified_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_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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_IbcCoreClientV1IdentifiedClientState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreClientV1IdentifiedClientState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1IdentifiedClientState.Data memory r,) = - IbcCoreClientV1IdentifiedClientState._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1IdentifiedClientState._encode_nested( - r.identified_client_state, pointer, bs - ); - - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim( - IbcCoreClientV1IdentifiedClientState._estimate( - r.identified_client_state - ) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.proof.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 { - IbcCoreClientV1IdentifiedClientState.store( - input.identified_client_state, output.identified_client_state - ); - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreConnectionV1QueryConnectionClientStateResponse - -library IbcCoreConnectionV1QueryConnectionConsensusStateRequest { - //struct definition - struct Data { - string connection_id; - uint64 revision_number; - uint64 revision_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_connection_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_revision_number(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_revision_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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_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_revision_number( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.revision_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_revision_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.revision_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 (bytes(r.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, pointer, bs); - } - if (r.revision_number != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.revision_number, pointer, bs); - } - if (r.revision_height != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.revision_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_lendelim(bytes(r.connection_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.revision_number); - e += 1 + ProtoBufRuntime._sz_uint64(r.revision_height); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.connection_id).length != 0) { - return false; - } - - if (r.revision_number != 0) { - return false; - } - - if (r.revision_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.connection_id = input.connection_id; - output.revision_number = input.revision_number; - output.revision_height = input.revision_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 IbcCoreConnectionV1QueryConnectionConsensusStateRequest - -library IbcCoreConnectionV1QueryConnectionConsensusStateResponse { - //struct definition - struct Data { - GoogleProtobufAny.Data consensus_state; - string client_id; - bytes proof; - IbcCoreClientV1Height.Data proof_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_consensus_state(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_client_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_proof_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_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_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_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_height = 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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufAny._encode_nested(r.consensus_state, pointer, bs); - - if (bytes(r.client_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); - } - if (r.proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_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_lendelim( - GoogleProtobufAny._estimate(r.consensus_state) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - 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.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.consensus_state, output.consensus_state); - output.client_id = input.client_id; - output.proof = input.proof; - IbcCoreClientV1Height.store(input.proof_height, output.proof_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 IbcCoreConnectionV1QueryConnectionConsensusStateResponse - -library IbcCoreConnectionV1QueryConnectionParamsRequest { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreConnectionV1QueryConnectionParamsRequest - -library IbcCoreConnectionV1QueryConnectionParamsResponse { - //struct definition - struct Data { - IbcCoreConnectionV1Params.Data params; - } - - // 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_params(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_params( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1Params.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Params(p, bs); - r.params = 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_IbcCoreConnectionV1Params( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreConnectionV1Params.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Params.Data memory r,) = - IbcCoreConnectionV1Params._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 += - IbcCoreConnectionV1Params._encode_nested(r.params, 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( - IbcCoreConnectionV1Params._estimate(r.params) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcCoreConnectionV1Params.store(input.params, output.params); - } - - //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 IbcCoreConnectionV1QueryConnectionParamsResponse diff --git a/evm/contracts/proto/ibc/core/connection/v1/tx.sol b/evm/contracts/proto/ibc/core/connection/v1/tx.sol deleted file mode 100644 index 8c0edf356b..0000000000 --- a/evm/contracts/proto/ibc/core/connection/v1/tx.sol +++ /dev/null @@ -1,2804 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../client/v1/client.sol"; -import "./connection.sol"; - -library IbcCoreConnectionV1MsgConnectionOpenInit { - //struct definition - struct Data { - string client_id; - IbcCoreConnectionV1Counterparty.Data counterparty; - IbcCoreConnectionV1Version.Data version; - uint64 delay_period; - 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_counterparty(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_version(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_delay_period(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_counterparty( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1Counterparty.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Counterparty(p, bs); - r.counterparty = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1Version.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Version(p, bs); - r.version = 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_delay_period( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.delay_period = 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_IbcCoreConnectionV1Counterparty( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1Counterparty.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Counterparty.Data memory r,) = - IbcCoreConnectionV1Counterparty._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_IbcCoreConnectionV1Version( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreConnectionV1Version.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Version.Data memory r,) = - IbcCoreConnectionV1Version._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 += IbcCoreConnectionV1Counterparty._encode_nested( - r.counterparty, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreConnectionV1Version._encode_nested(r.version, pointer, bs); - - if (r.delay_period != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.delay_period, 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( - IbcCoreConnectionV1Counterparty._estimate(r.counterparty) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Version._estimate(r.version) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.delay_period); - 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.delay_period != 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; - IbcCoreConnectionV1Counterparty.store( - input.counterparty, output.counterparty - ); - IbcCoreConnectionV1Version.store(input.version, output.version); - output.delay_period = input.delay_period; - 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 IbcCoreConnectionV1MsgConnectionOpenInit - -library IbcCoreConnectionV1MsgConnectionOpenInitResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreConnectionV1MsgConnectionOpenInitResponse - -library IbcCoreConnectionV1MsgConnectionOpenTry { - //struct definition - struct Data { - string client_id; - string previous_connection_id; - GoogleProtobufAny.Data client_state; - IbcCoreConnectionV1Counterparty.Data counterparty; - uint64 delay_period; - IbcCoreConnectionV1Version.Data[] counterparty_versions; - IbcCoreClientV1Height.Data proof_height; - bytes proof_init; - bytes proof_client; - bytes proof_consensus; - IbcCoreClientV1Height.Data consensus_height; - string signer; - bytes host_consensus_state_proof; - } - - // 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[14] 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_previous_connection_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_client_state(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_counterparty(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_delay_period(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_unpacked_repeated_counterparty_versions( - pointer, bs, nil(), counters - ); - } else if (fieldId == 7) { - pointer += _read_proof_height(pointer, bs, r); - } else if (fieldId == 8) { - pointer += _read_proof_init(pointer, bs, r); - } else if (fieldId == 9) { - pointer += _read_proof_client(pointer, bs, r); - } else if (fieldId == 10) { - pointer += _read_proof_consensus(pointer, bs, r); - } else if (fieldId == 11) { - pointer += _read_consensus_height(pointer, bs, r); - } else if (fieldId == 12) { - pointer += _read_signer(pointer, bs, r); - } else if (fieldId == 13) { - pointer += _read_host_consensus_state_proof(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[6] > 0) { - require(r.counterparty_versions.length == 0); - r.counterparty_versions = - new IbcCoreConnectionV1Version.Data[](counters[6]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 6) { - pointer += _read_unpacked_repeated_counterparty_versions( - 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 - * @return The number of bytes decoded - */ - function _read_previous_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.previous_connection_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_counterparty( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1Counterparty.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Counterparty(p, bs); - r.counterparty = 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_delay_period( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.delay_period = 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_counterparty_versions( - uint256 p, - bytes memory bs, - Data memory r, - uint256[14] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcCoreConnectionV1Version.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Version(p, bs); - if (isNil(r)) { - counters[6] += 1; - } else { - r.counterparty_versions[r.counterparty_versions.length - counters[6]] - = x; - counters[6] -= 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_proof_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_init( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_init = 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_client( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_client = 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_consensus( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_consensus = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.consensus_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_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; - } - - /** - * @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_host_consensus_state_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.host_consensus_state_proof = 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_IbcCoreConnectionV1Counterparty( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1Counterparty.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Counterparty.Data memory r,) = - IbcCoreConnectionV1Counterparty._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_IbcCoreConnectionV1Version( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreConnectionV1Version.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Version.Data memory r,) = - IbcCoreConnectionV1Version._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.client_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs); - } - if (bytes(r.previous_connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.previous_connection_id, pointer, bs - ); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufAny._encode_nested(r.client_state, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1Counterparty._encode_nested( - r.counterparty, pointer, bs - ); - - if (r.delay_period != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.delay_period, pointer, bs); - } - if (r.counterparty_versions.length != 0) { - for (i = 0; i < r.counterparty_versions.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1Version._encode_nested( - r.counterparty_versions[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, pointer, bs); - - if (r.proof_init.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 8, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_init, pointer, bs); - } - if (r.proof_client.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 9, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.proof_client, pointer, bs); - } - if (r.proof_consensus.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 10, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.proof_consensus, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 11, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested( - r.consensus_height, pointer, bs - ); - - if (bytes(r.signer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 12, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.signer, pointer, bs); - } - if (r.host_consensus_state_proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 13, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.host_consensus_state_proof, 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); - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.previous_connection_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.client_state) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Counterparty._estimate(r.counterparty) - ); - e += 1 + ProtoBufRuntime._sz_uint64(r.delay_period); - for (i = 0; i < r.counterparty_versions.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Version._estimate(r.counterparty_versions[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_init.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_client.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_consensus.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.consensus_height) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(r.host_consensus_state_proof.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.previous_connection_id).length != 0) { - return false; - } - - if (r.delay_period != 0) { - return false; - } - - if (r.counterparty_versions.length != 0) { - return false; - } - - if (r.proof_init.length != 0) { - return false; - } - - if (r.proof_client.length != 0) { - return false; - } - - if (r.proof_consensus.length != 0) { - return false; - } - - if (bytes(r.signer).length != 0) { - return false; - } - - if (r.host_consensus_state_proof.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; - output.previous_connection_id = input.previous_connection_id; - GoogleProtobufAny.store(input.client_state, output.client_state); - IbcCoreConnectionV1Counterparty.store( - input.counterparty, output.counterparty - ); - output.delay_period = input.delay_period; - - for (uint256 i6 = 0; i6 < input.counterparty_versions.length; i6++) { - output.counterparty_versions.push(input.counterparty_versions[i6]); - } - - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - output.proof_init = input.proof_init; - output.proof_client = input.proof_client; - output.proof_consensus = input.proof_consensus; - IbcCoreClientV1Height.store( - input.consensus_height, output.consensus_height - ); - output.signer = input.signer; - output.host_consensus_state_proof = input.host_consensus_state_proof; - } - - //array helpers for CounterpartyVersions - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addCounterpartyVersions( - Data memory self, - IbcCoreConnectionV1Version.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcCoreConnectionV1Version.Data[] memory tmp = new IbcCoreConnectionV1Version - .Data[](self.counterparty_versions.length + 1); - for (uint256 i; i < self.counterparty_versions.length; i++) { - tmp[i] = self.counterparty_versions[i]; - } - tmp[self.counterparty_versions.length] = value; - self.counterparty_versions = 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 IbcCoreConnectionV1MsgConnectionOpenTry - -library IbcCoreConnectionV1MsgConnectionOpenTryResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreConnectionV1MsgConnectionOpenTryResponse - -library IbcCoreConnectionV1MsgConnectionOpenAck { - //struct definition - struct Data { - string connection_id; - string counterparty_connection_id; - IbcCoreConnectionV1Version.Data version; - GoogleProtobufAny.Data client_state; - IbcCoreClientV1Height.Data proof_height; - bytes proof_try; - bytes proof_client; - bytes proof_consensus; - IbcCoreClientV1Height.Data consensus_height; - string signer; - bytes host_consensus_state_proof; - } - - // 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_connection_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_counterparty_connection_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_version(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_client_state(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_proof_height(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_proof_try(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_proof_client(pointer, bs, r); - } else if (fieldId == 8) { - pointer += _read_proof_consensus(pointer, bs, r); - } else if (fieldId == 9) { - pointer += _read_consensus_height(pointer, bs, r); - } else if (fieldId == 10) { - pointer += _read_signer(pointer, bs, r); - } else if (fieldId == 11) { - pointer += _read_host_consensus_state_proof(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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_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_counterparty_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.counterparty_connection_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_version( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1Version.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1Version(p, bs); - r.version = 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_proof_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_try( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_try = 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_client( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_client = 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_consensus( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_consensus = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.consensus_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_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; - } - - /** - * @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_host_consensus_state_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.host_consensus_state_proof = 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_IbcCoreConnectionV1Version( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreConnectionV1Version.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1Version.Data memory r,) = - IbcCoreConnectionV1Version._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); - } - - /** - * @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.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, pointer, bs); - } - if (bytes(r.counterparty_connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.counterparty_connection_id, pointer, bs - ); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreConnectionV1Version._encode_nested(r.version, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufAny._encode_nested(r.client_state, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, pointer, bs); - - if (r.proof_try.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_try, pointer, bs); - } - if (r.proof_client.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.proof_client, pointer, bs); - } - if (r.proof_consensus.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 8, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.proof_consensus, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 9, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested( - r.consensus_height, pointer, bs - ); - - if (bytes(r.signer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 10, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.signer, pointer, bs); - } - if (r.host_consensus_state_proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 11, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.host_consensus_state_proof, 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.connection_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - bytes(r.counterparty_connection_id).length - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1Version._estimate(r.version) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.client_state) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_try.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_client.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_consensus.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.consensus_height) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.signer).length); - e += 1 - + ProtoBufRuntime._sz_lendelim(r.host_consensus_state_proof.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.connection_id).length != 0) { - return false; - } - - if (bytes(r.counterparty_connection_id).length != 0) { - return false; - } - - if (r.proof_try.length != 0) { - return false; - } - - if (r.proof_client.length != 0) { - return false; - } - - if (r.proof_consensus.length != 0) { - return false; - } - - if (bytes(r.signer).length != 0) { - return false; - } - - if (r.host_consensus_state_proof.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.connection_id = input.connection_id; - output.counterparty_connection_id = input.counterparty_connection_id; - IbcCoreConnectionV1Version.store(input.version, output.version); - GoogleProtobufAny.store(input.client_state, output.client_state); - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - output.proof_try = input.proof_try; - output.proof_client = input.proof_client; - output.proof_consensus = input.proof_consensus; - IbcCoreClientV1Height.store( - input.consensus_height, output.consensus_height - ); - output.signer = input.signer; - output.host_consensus_state_proof = input.host_consensus_state_proof; - } - - //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 IbcCoreConnectionV1MsgConnectionOpenAck - -library IbcCoreConnectionV1MsgConnectionOpenAckResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreConnectionV1MsgConnectionOpenAckResponse - -library IbcCoreConnectionV1MsgConnectionOpenConfirm { - //struct definition - struct Data { - string connection_id; - bytes proof_ack; - IbcCoreClientV1Height.Data proof_height; - 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_connection_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof_ack(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof_height(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_connection_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.connection_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_proof_ack( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proof_ack = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.proof_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_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_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.connection_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.connection_id, pointer, bs); - } - if (r.proof_ack.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.proof_ack, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.proof_height, 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.connection_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proof_ack.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.proof_height) - ); - 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.connection_id).length != 0) { - return false; - } - - if (r.proof_ack.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.connection_id = input.connection_id; - output.proof_ack = input.proof_ack; - IbcCoreClientV1Height.store(input.proof_height, output.proof_height); - 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 IbcCoreConnectionV1MsgConnectionOpenConfirm - -library IbcCoreConnectionV1MsgConnectionOpenConfirmResponse { - //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 p The offset of bytes array to start decode - * @return The number of bytes encoded - */ - function _encode( - Data memory, - uint256 p, - bytes memory - ) 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) 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 IbcCoreConnectionV1MsgConnectionOpenConfirmResponse diff --git a/evm/contracts/proto/ibc/core/types/v1/genesis.sol b/evm/contracts/proto/ibc/core/types/v1/genesis.sol deleted file mode 100644 index 105e9368ee..0000000000 --- a/evm/contracts/proto/ibc/core/types/v1/genesis.sol +++ /dev/null @@ -1,366 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -import "../../client/v1/genesis.sol"; -import "../../connection/v1/genesis.sol"; -import "../../channel/v1/genesis.sol"; - -library IbcCoreTypesV1GenesisState { - //struct definition - struct Data { - IbcCoreClientV1GenesisState.Data client_genesis; - IbcCoreConnectionV1GenesisState.Data connection_genesis; - IbcCoreChannelV1GenesisState.Data channel_genesis; - } - - // 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_genesis(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_connection_genesis(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_channel_genesis(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_genesis( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1GenesisState.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1GenesisState(p, bs); - r.client_genesis = 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_connection_genesis( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1GenesisState.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1GenesisState(p, bs); - r.connection_genesis = 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_channel_genesis( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1GenesisState.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1GenesisState(p, bs); - r.channel_genesis = 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_IbcCoreClientV1GenesisState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreClientV1GenesisState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreClientV1GenesisState.Data memory r,) = - IbcCoreClientV1GenesisState._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_IbcCoreConnectionV1GenesisState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1GenesisState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1GenesisState.Data memory r,) = - IbcCoreConnectionV1GenesisState._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_IbcCoreChannelV1GenesisState( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreChannelV1GenesisState.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1GenesisState.Data memory r,) = - IbcCoreChannelV1GenesisState._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 += IbcCoreClientV1GenesisState._encode_nested( - r.client_genesis, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1GenesisState._encode_nested( - r.connection_genesis, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreChannelV1GenesisState._encode_nested( - r.channel_genesis, 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( - IbcCoreClientV1GenesisState._estimate(r.client_genesis) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1GenesisState._estimate(r.connection_genesis) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1GenesisState._estimate(r.channel_genesis) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - IbcCoreClientV1GenesisState.store( - input.client_genesis, output.client_genesis - ); - IbcCoreConnectionV1GenesisState.store( - input.connection_genesis, output.connection_genesis - ); - IbcCoreChannelV1GenesisState.store( - input.channel_genesis, output.channel_genesis - ); - } - - //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 IbcCoreTypesV1GenesisState diff --git a/evm/contracts/proto/ibc/lightclients/solomachine/v2/solomachine.sol b/evm/contracts/proto/ibc/lightclients/solomachine/v2/solomachine.sol deleted file mode 100644 index e6b3c83c14..0000000000 --- a/evm/contracts/proto/ibc/lightclients/solomachine/v2/solomachine.sol +++ /dev/null @@ -1,4694 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../core/connection/v1/connection.sol"; -import "../../../core/channel/v1/channel.sol"; - -library IbcLightclientsSolomachineV2ClientState { - //struct definition - struct Data { - uint64 sequence; - bool is_frozen; - IbcLightclientsSolomachineV2ConsensusState.Data consensus_state; - bool allow_update_after_proposal; - } - - // 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_sequence(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_is_frozen(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_consensus_state(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_allow_update_after_proposal(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_is_frozen( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.is_frozen = 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) { - (IbcLightclientsSolomachineV2ConsensusState.Data memory x, uint256 sz) = - _decode_IbcLightclientsSolomachineV2ConsensusState(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_allow_update_after_proposal( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.allow_update_after_proposal = 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_IbcLightclientsSolomachineV2ConsensusState( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcLightclientsSolomachineV2ConsensusState.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcLightclientsSolomachineV2ConsensusState.Data memory r,) = - IbcLightclientsSolomachineV2ConsensusState._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 (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - if (r.is_frozen != false) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool(r.is_frozen, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsSolomachineV2ConsensusState._encode_nested( - r.consensus_state, pointer, bs - ); - - if (r.allow_update_after_proposal != false) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool( - r.allow_update_after_proposal, 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.sequence); - e += 1 + 1; - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcLightclientsSolomachineV2ConsensusState._estimate( - r.consensus_state - ) - ); - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequence != 0) { - return false; - } - - if (r.is_frozen != false) { - return false; - } - - if (r.allow_update_after_proposal != false) { - 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.sequence = input.sequence; - output.is_frozen = input.is_frozen; - IbcLightclientsSolomachineV2ConsensusState.store( - input.consensus_state, output.consensus_state - ); - output.allow_update_after_proposal = input.allow_update_after_proposal; - } - - //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 IbcLightclientsSolomachineV2ClientState - -library IbcLightclientsSolomachineV2ConsensusState { - //struct definition - struct Data { - GoogleProtobufAny.Data public_key; - string diversifier; - uint64 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 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_public_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_diversifier(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_timestamp(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_public_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufAny.Data memory x, uint256 sz) = - _decode_GoogleProtobufAny(p, bs); - r.public_key = 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_diversifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.diversifier = 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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.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_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.public_key, pointer, bs); - - if (bytes(r.diversifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.diversifier, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.public_key) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.diversifier).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.diversifier).length != 0) { - return false; - } - - if (r.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 { - GoogleProtobufAny.store(input.public_key, output.public_key); - output.diversifier = input.diversifier; - output.timestamp = input.timestamp; - } - - //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 IbcLightclientsSolomachineV2ConsensusState - -library IbcLightclientsSolomachineV2Header { - //struct definition - struct Data { - uint64 sequence; - uint64 timestamp; - bytes signature; - GoogleProtobufAny.Data new_public_key; - string new_diversifier; - } - - // 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_sequence(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_timestamp(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_signature(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_new_public_key(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_new_diversifier(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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_signature( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature = 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_new_public_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufAny.Data memory x, uint256 sz) = - _decode_GoogleProtobufAny(p, bs); - r.new_public_key = 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_new_diversifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.new_diversifier = 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 (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.timestamp, pointer, bs); - } - if (r.signature.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.signature, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufAny._encode_nested(r.new_public_key, pointer, bs); - - if (bytes(r.new_diversifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.new_diversifier, 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.sequence); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.new_public_key) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.new_diversifier).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequence != 0) { - return false; - } - - if (r.timestamp != 0) { - return false; - } - - if (r.signature.length != 0) { - return false; - } - - if (bytes(r.new_diversifier).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.sequence = input.sequence; - output.timestamp = input.timestamp; - output.signature = input.signature; - GoogleProtobufAny.store(input.new_public_key, output.new_public_key); - output.new_diversifier = input.new_diversifier; - } - - //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 IbcLightclientsSolomachineV2Header - -library IbcLightclientsSolomachineV2Misbehaviour { - //struct definition - struct Data { - string client_id; - uint64 sequence; - IbcLightclientsSolomachineV2SignatureAndData.Data signature_one; - IbcLightclientsSolomachineV2SignatureAndData.Data signature_two; - } - - // 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_sequence(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_signature_one(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_signature_two(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_signature_one( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcLightclientsSolomachineV2SignatureAndData.Data memory x, uint256 sz) - = _decode_IbcLightclientsSolomachineV2SignatureAndData(p, bs); - r.signature_one = 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_signature_two( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcLightclientsSolomachineV2SignatureAndData.Data memory x, uint256 sz) - = _decode_IbcLightclientsSolomachineV2SignatureAndData(p, bs); - r.signature_two = 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_IbcLightclientsSolomachineV2SignatureAndData( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcLightclientsSolomachineV2SignatureAndData.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcLightclientsSolomachineV2SignatureAndData.Data memory r,) = - IbcLightclientsSolomachineV2SignatureAndData._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); - } - if (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsSolomachineV2SignatureAndData._encode_nested( - r.signature_one, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsSolomachineV2SignatureAndData._encode_nested( - r.signature_two, 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_uint64(r.sequence); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcLightclientsSolomachineV2SignatureAndData._estimate( - r.signature_one - ) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcLightclientsSolomachineV2SignatureAndData._estimate( - r.signature_two - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.client_id).length != 0) { - return false; - } - - if (r.sequence != 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; - output.sequence = input.sequence; - IbcLightclientsSolomachineV2SignatureAndData.store( - input.signature_one, output.signature_one - ); - IbcLightclientsSolomachineV2SignatureAndData.store( - input.signature_two, output.signature_two - ); - } - - //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 IbcLightclientsSolomachineV2Misbehaviour - -library IbcLightclientsSolomachineV2SignatureAndData { - //struct definition - struct Data { - bytes signature; - IbcLightClientsSolomachineV2SolomachineGlobalEnums.DataType data_type; - bytes data; - uint64 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 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_signature(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_data_type(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_data(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_timestamp(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_signature( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature = 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_data_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcLightClientsSolomachineV2SolomachineGlobalEnums.DataType x = - IbcLightClientsSolomachineV2SolomachineGlobalEnums.decode_DataType(tmp); - r.data_type = 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_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 - * @return The number of bytes decoded - */ - function _read_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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.signature.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.signature, pointer, bs); - } - if (uint256(r.data_type) != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_data_type = - IbcLightClientsSolomachineV2SolomachineGlobalEnums.encode_DataType( - r.data_type - ); - pointer += - ProtoBufRuntime._encode_enum(_enum_data_type, pointer, bs); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature.length); - e += 1 - + ProtoBufRuntime._sz_enum( - IbcLightClientsSolomachineV2SolomachineGlobalEnums.encode_DataType( - r.data_type - ) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.signature.length != 0) { - return false; - } - - if (uint256(r.data_type) != 0) { - return false; - } - - if (r.data.length != 0) { - return false; - } - - if (r.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.signature = input.signature; - output.data_type = input.data_type; - output.data = input.data; - output.timestamp = input.timestamp; - } - - //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 IbcLightclientsSolomachineV2SignatureAndData - -library IbcLightclientsSolomachineV2TimestampedSignatureData { - //struct definition - struct Data { - bytes signature_data; - uint64 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 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_signature_data(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_timestamp(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_signature_data( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature_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 - * @return The number of bytes decoded - */ - function _read_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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.signature_data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.signature_data, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature_data.length); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.signature_data.length != 0) { - return false; - } - - if (r.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.signature_data = input.signature_data; - output.timestamp = input.timestamp; - } - - //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 IbcLightclientsSolomachineV2TimestampedSignatureData - -library IbcLightclientsSolomachineV2SignBytes { - //struct definition - struct Data { - uint64 sequence; - uint64 timestamp; - string diversifier; - IbcLightClientsSolomachineV2SolomachineGlobalEnums.DataType data_type; - bytes data; - } - - // 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_sequence(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_timestamp(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_diversifier(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_data_type(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_data(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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_diversifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.diversifier = 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_data_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - IbcLightClientsSolomachineV2SolomachineGlobalEnums.DataType x = - IbcLightClientsSolomachineV2SolomachineGlobalEnums.decode_DataType(tmp); - r.data_type = 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_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; - } - - // 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.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.timestamp, pointer, bs); - } - if (bytes(r.diversifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.diversifier, pointer, bs); - } - if (uint256(r.data_type) != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_data_type = - IbcLightClientsSolomachineV2SolomachineGlobalEnums.encode_DataType( - r.data_type - ); - pointer += - ProtoBufRuntime._encode_enum(_enum_data_type, pointer, bs); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, 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.sequence); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.diversifier).length); - e += 1 - + ProtoBufRuntime._sz_enum( - IbcLightClientsSolomachineV2SolomachineGlobalEnums.encode_DataType( - r.data_type - ) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequence != 0) { - return false; - } - - if (r.timestamp != 0) { - return false; - } - - if (bytes(r.diversifier).length != 0) { - return false; - } - - if (uint256(r.data_type) != 0) { - return false; - } - - if (r.data.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.sequence = input.sequence; - output.timestamp = input.timestamp; - output.diversifier = input.diversifier; - output.data_type = input.data_type; - output.data = input.data; - } - - //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 IbcLightclientsSolomachineV2SignBytes - -library IbcLightclientsSolomachineV2HeaderData { - //struct definition - struct Data { - GoogleProtobufAny.Data new_pub_key; - string new_diversifier; - } - - // 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_new_pub_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_new_diversifier(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_new_pub_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufAny.Data memory x, uint256 sz) = - _decode_GoogleProtobufAny(p, bs); - r.new_pub_key = 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_new_diversifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.new_diversifier = 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.new_pub_key, pointer, bs); - - if (bytes(r.new_diversifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.new_diversifier, 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.new_pub_key) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.new_diversifier).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.new_diversifier).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.new_pub_key, output.new_pub_key); - output.new_diversifier = input.new_diversifier; - } - - //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 IbcLightclientsSolomachineV2HeaderData - -library IbcLightclientsSolomachineV2ClientStateData { - //struct definition - struct Data { - bytes path; - 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_path(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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 (r.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, 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(r.path.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 (r.path.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.path = input.path; - 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 IbcLightclientsSolomachineV2ClientStateData - -library IbcLightclientsSolomachineV2ConsensusStateData { - //struct definition - struct Data { - bytes path; - 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_path(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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_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 (r.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, 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(r.path.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.consensus_state) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.path.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.path = input.path; - 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 IbcLightclientsSolomachineV2ConsensusStateData - -library IbcLightclientsSolomachineV2ConnectionStateData { - //struct definition - struct Data { - bytes path; - IbcCoreConnectionV1ConnectionEnd.Data connection; - } - - // 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_path(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_connection(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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_connection( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreConnectionV1ConnectionEnd.Data memory x, uint256 sz) = - _decode_IbcCoreConnectionV1ConnectionEnd(p, bs); - r.connection = 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_IbcCoreConnectionV1ConnectionEnd( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreConnectionV1ConnectionEnd.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreConnectionV1ConnectionEnd.Data memory r,) = - IbcCoreConnectionV1ConnectionEnd._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 (r.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreConnectionV1ConnectionEnd._encode_nested( - r.connection, 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.path.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreConnectionV1ConnectionEnd._estimate(r.connection) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.path.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.path = input.path; - IbcCoreConnectionV1ConnectionEnd.store( - input.connection, output.connection - ); - } - - //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 IbcLightclientsSolomachineV2ConnectionStateData - -library IbcLightclientsSolomachineV2ChannelStateData { - //struct definition - struct Data { - bytes path; - IbcCoreChannelV1Channel.Data channel; - } - - // 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_path(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_channel(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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_channel( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreChannelV1Channel.Data memory x, uint256 sz) = - _decode_IbcCoreChannelV1Channel(p, bs); - r.channel = 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_IbcCoreChannelV1Channel( - uint256 p, - bytes memory bs - ) internal pure returns (IbcCoreChannelV1Channel.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreChannelV1Channel.Data memory r,) = - IbcCoreChannelV1Channel._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 (r.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreChannelV1Channel._encode_nested(r.channel, 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.path.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreChannelV1Channel._estimate(r.channel) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.path.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.path = input.path; - IbcCoreChannelV1Channel.store(input.channel, output.channel); - } - - //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 IbcLightclientsSolomachineV2ChannelStateData - -library IbcLightclientsSolomachineV2PacketCommitmentData { - //struct definition - struct Data { - bytes path; - bytes commitment; - } - - // 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_path(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_commitment(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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_commitment( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.commitment = 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.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, pointer, bs); - } - if (r.commitment.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.commitment, 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.path.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.commitment.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.path.length != 0) { - return false; - } - - if (r.commitment.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.path = input.path; - output.commitment = input.commitment; - } - - //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 IbcLightclientsSolomachineV2PacketCommitmentData - -library IbcLightclientsSolomachineV2PacketAcknowledgementData { - //struct definition - struct Data { - bytes path; - bytes acknowledgement; - } - - // 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_path(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_acknowledgement(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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_acknowledgement( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.acknowledgement = 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.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, pointer, bs); - } - if (r.acknowledgement.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.acknowledgement, 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.path.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.acknowledgement.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.path.length != 0) { - return false; - } - - if (r.acknowledgement.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.path = input.path; - output.acknowledgement = input.acknowledgement; - } - - //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 IbcLightclientsSolomachineV2PacketAcknowledgementData - -library IbcLightclientsSolomachineV2PacketReceiptAbsenceData { - //struct definition - struct Data { - bytes path; - } - - // 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_path(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, 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.path.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.path.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.path = input.path; - } - - //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 IbcLightclientsSolomachineV2PacketReceiptAbsenceData - -library IbcLightclientsSolomachineV2NextSequenceRecvData { - //struct definition - struct Data { - bytes path; - uint64 next_seq_recv; - } - - // 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_path(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_next_seq_recv(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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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_next_seq_recv( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.next_seq_recv = 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.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, pointer, bs); - } - if (r.next_seq_recv != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.next_seq_recv, 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.path.length); - e += 1 + ProtoBufRuntime._sz_uint64(r.next_seq_recv); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.path.length != 0) { - return false; - } - - if (r.next_seq_recv != 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.path = input.path; - output.next_seq_recv = input.next_seq_recv; - } - - //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 IbcLightclientsSolomachineV2NextSequenceRecvData - -library IbcLightClientsSolomachineV2SolomachineGlobalEnums { - //enum definition - // Solidity enum definitions - enum DataType { - DATA_TYPE_UNINITIALIZED_UNSPECIFIED, - DATA_TYPE_CLIENT_STATE, - DATA_TYPE_CONSENSUS_STATE, - DATA_TYPE_CONNECTION_STATE, - DATA_TYPE_CHANNEL_STATE, - DATA_TYPE_PACKET_COMMITMENT, - DATA_TYPE_PACKET_ACKNOWLEDGEMENT, - DATA_TYPE_PACKET_RECEIPT_ABSENCE, - DATA_TYPE_NEXT_SEQUENCE_RECV, - DATA_TYPE_HEADER - } - - // Solidity enum encoder - function encode_DataType(DataType x) internal pure returns (int32) { - if (x == DataType.DATA_TYPE_UNINITIALIZED_UNSPECIFIED) { - return 0; - } - - if (x == DataType.DATA_TYPE_CLIENT_STATE) { - return 1; - } - - if (x == DataType.DATA_TYPE_CONSENSUS_STATE) { - return 2; - } - - if (x == DataType.DATA_TYPE_CONNECTION_STATE) { - return 3; - } - - if (x == DataType.DATA_TYPE_CHANNEL_STATE) { - return 4; - } - - if (x == DataType.DATA_TYPE_PACKET_COMMITMENT) { - return 5; - } - - if (x == DataType.DATA_TYPE_PACKET_ACKNOWLEDGEMENT) { - return 6; - } - - if (x == DataType.DATA_TYPE_PACKET_RECEIPT_ABSENCE) { - return 7; - } - - if (x == DataType.DATA_TYPE_NEXT_SEQUENCE_RECV) { - return 8; - } - - if (x == DataType.DATA_TYPE_HEADER) { - return 9; - } - revert(); - } - - // Solidity enum decoder - function decode_DataType(int64 x) internal pure returns (DataType) { - if (x == 0) { - return DataType.DATA_TYPE_UNINITIALIZED_UNSPECIFIED; - } - - if (x == 1) { - return DataType.DATA_TYPE_CLIENT_STATE; - } - - if (x == 2) { - return DataType.DATA_TYPE_CONSENSUS_STATE; - } - - if (x == 3) { - return DataType.DATA_TYPE_CONNECTION_STATE; - } - - if (x == 4) { - return DataType.DATA_TYPE_CHANNEL_STATE; - } - - if (x == 5) { - return DataType.DATA_TYPE_PACKET_COMMITMENT; - } - - if (x == 6) { - return DataType.DATA_TYPE_PACKET_ACKNOWLEDGEMENT; - } - - if (x == 7) { - return DataType.DATA_TYPE_PACKET_RECEIPT_ABSENCE; - } - - if (x == 8) { - return DataType.DATA_TYPE_NEXT_SEQUENCE_RECV; - } - - if (x == 9) { - return DataType.DATA_TYPE_HEADER; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_DataType(DataType[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_DataType(a[i])); - } - return e; - } -} -//library IbcLightClientsSolomachineV2SolomachineGlobalEnums diff --git a/evm/contracts/proto/ibc/lightclients/solomachine/v3/solomachine.sol b/evm/contracts/proto/ibc/lightclients/solomachine/v3/solomachine.sol deleted file mode 100644 index 302c86123e..0000000000 --- a/evm/contracts/proto/ibc/lightclients/solomachine/v3/solomachine.sol +++ /dev/null @@ -1,2423 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcLightclientsSolomachineV3ClientState { - //struct definition - struct Data { - uint64 sequence; - bool is_frozen; - IbcLightclientsSolomachineV3ConsensusState.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_sequence(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_is_frozen(pointer, bs, r); - } else if (fieldId == 3) { - 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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_is_frozen( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.is_frozen = 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) { - (IbcLightclientsSolomachineV3ConsensusState.Data memory x, uint256 sz) = - _decode_IbcLightclientsSolomachineV3ConsensusState(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_IbcLightclientsSolomachineV3ConsensusState( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcLightclientsSolomachineV3ConsensusState.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcLightclientsSolomachineV3ConsensusState.Data memory r,) = - IbcLightclientsSolomachineV3ConsensusState._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 (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - if (r.is_frozen != false) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool(r.is_frozen, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsSolomachineV3ConsensusState._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_uint64(r.sequence); - e += 1 + 1; - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcLightclientsSolomachineV3ConsensusState._estimate( - r.consensus_state - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequence != 0) { - return false; - } - - if (r.is_frozen != false) { - 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.sequence = input.sequence; - output.is_frozen = input.is_frozen; - IbcLightclientsSolomachineV3ConsensusState.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 IbcLightclientsSolomachineV3ClientState - -library IbcLightclientsSolomachineV3ConsensusState { - //struct definition - struct Data { - GoogleProtobufAny.Data public_key; - string diversifier; - uint64 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 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_public_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_diversifier(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_timestamp(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_public_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufAny.Data memory x, uint256 sz) = - _decode_GoogleProtobufAny(p, bs); - r.public_key = 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_diversifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.diversifier = 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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.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_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.public_key, pointer, bs); - - if (bytes(r.diversifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.diversifier, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.public_key) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.diversifier).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.diversifier).length != 0) { - return false; - } - - if (r.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 { - GoogleProtobufAny.store(input.public_key, output.public_key); - output.diversifier = input.diversifier; - output.timestamp = input.timestamp; - } - - //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 IbcLightclientsSolomachineV3ConsensusState - -library IbcLightclientsSolomachineV3Header { - //struct definition - struct Data { - uint64 timestamp; - bytes signature; - GoogleProtobufAny.Data new_public_key; - string new_diversifier; - } - - // 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_timestamp(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_signature(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_new_public_key(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_new_diversifier(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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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_signature( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature = 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_new_public_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufAny.Data memory x, uint256 sz) = - _decode_GoogleProtobufAny(p, bs); - r.new_public_key = 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_new_diversifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.new_diversifier = 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 (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.timestamp, pointer, bs); - } - if (r.signature.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.signature, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufAny._encode_nested(r.new_public_key, pointer, bs); - - if (bytes(r.new_diversifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.new_diversifier, 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.timestamp); - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufAny._estimate(r.new_public_key) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.new_diversifier).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.timestamp != 0) { - return false; - } - - if (r.signature.length != 0) { - return false; - } - - if (bytes(r.new_diversifier).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.timestamp = input.timestamp; - output.signature = input.signature; - GoogleProtobufAny.store(input.new_public_key, output.new_public_key); - output.new_diversifier = input.new_diversifier; - } - - //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 IbcLightclientsSolomachineV3Header - -library IbcLightclientsSolomachineV3Misbehaviour { - //struct definition - struct Data { - uint64 sequence; - IbcLightclientsSolomachineV3SignatureAndData.Data signature_one; - IbcLightclientsSolomachineV3SignatureAndData.Data signature_two; - } - - // 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_sequence(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_signature_one(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_signature_two(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_signature_one( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcLightclientsSolomachineV3SignatureAndData.Data memory x, uint256 sz) - = _decode_IbcLightclientsSolomachineV3SignatureAndData(p, bs); - r.signature_one = 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_signature_two( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcLightclientsSolomachineV3SignatureAndData.Data memory x, uint256 sz) - = _decode_IbcLightclientsSolomachineV3SignatureAndData(p, bs); - r.signature_two = 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_IbcLightclientsSolomachineV3SignatureAndData( - uint256 p, - bytes memory bs - ) - internal - pure - returns ( - IbcLightclientsSolomachineV3SignatureAndData.Data memory, - uint256 - ) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcLightclientsSolomachineV3SignatureAndData.Data memory r,) = - IbcLightclientsSolomachineV3SignatureAndData._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 (r.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsSolomachineV3SignatureAndData._encode_nested( - r.signature_one, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsSolomachineV3SignatureAndData._encode_nested( - r.signature_two, 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.sequence); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcLightclientsSolomachineV3SignatureAndData._estimate( - r.signature_one - ) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcLightclientsSolomachineV3SignatureAndData._estimate( - r.signature_two - ) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequence != 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.sequence = input.sequence; - IbcLightclientsSolomachineV3SignatureAndData.store( - input.signature_one, output.signature_one - ); - IbcLightclientsSolomachineV3SignatureAndData.store( - input.signature_two, output.signature_two - ); - } - - //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 IbcLightclientsSolomachineV3Misbehaviour - -library IbcLightclientsSolomachineV3SignatureAndData { - //struct definition - struct Data { - bytes signature; - bytes path; - bytes data; - uint64 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 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_signature(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_path(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_data(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_timestamp(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_signature( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature = 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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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_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 - * @return The number of bytes decoded - */ - function _read_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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.signature.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.signature, pointer, bs); - } - if (r.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, pointer, bs); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.path.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.signature.length != 0) { - return false; - } - - if (r.path.length != 0) { - return false; - } - - if (r.data.length != 0) { - return false; - } - - if (r.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.signature = input.signature; - output.path = input.path; - output.data = input.data; - output.timestamp = input.timestamp; - } - - //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 IbcLightclientsSolomachineV3SignatureAndData - -library IbcLightclientsSolomachineV3TimestampedSignatureData { - //struct definition - struct Data { - bytes signature_data; - uint64 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 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_signature_data(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_timestamp(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_signature_data( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature_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 - * @return The number of bytes decoded - */ - function _read_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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.signature_data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.signature_data, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature_data.length); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.signature_data.length != 0) { - return false; - } - - if (r.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.signature_data = input.signature_data; - output.timestamp = input.timestamp; - } - - //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 IbcLightclientsSolomachineV3TimestampedSignatureData - -library IbcLightclientsSolomachineV3SignBytes { - //struct definition - struct Data { - uint64 sequence; - uint64 timestamp; - string diversifier; - bytes path; - bytes data; - } - - // 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_sequence(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_timestamp(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_diversifier(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_path(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_data(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_sequence( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.sequence = 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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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_diversifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.diversifier = 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_path( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.path = 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_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; - } - - // 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.sequence != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.sequence, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.timestamp, pointer, bs); - } - if (bytes(r.diversifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.diversifier, pointer, bs); - } - if (r.path.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.path, pointer, bs); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, 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.sequence); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.diversifier).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.path.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.sequence != 0) { - return false; - } - - if (r.timestamp != 0) { - return false; - } - - if (bytes(r.diversifier).length != 0) { - return false; - } - - if (r.path.length != 0) { - return false; - } - - if (r.data.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.sequence = input.sequence; - output.timestamp = input.timestamp; - output.diversifier = input.diversifier; - output.path = input.path; - output.data = input.data; - } - - //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 IbcLightclientsSolomachineV3SignBytes - -library IbcLightclientsSolomachineV3HeaderData { - //struct definition - struct Data { - GoogleProtobufAny.Data new_pub_key; - string new_diversifier; - } - - // 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_new_pub_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_new_diversifier(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_new_pub_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufAny.Data memory x, uint256 sz) = - _decode_GoogleProtobufAny(p, bs); - r.new_pub_key = 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_new_diversifier( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.new_diversifier = 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.new_pub_key, pointer, bs); - - if (bytes(r.new_diversifier).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.new_diversifier, 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.new_pub_key) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.new_diversifier).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.new_diversifier).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.new_pub_key, output.new_pub_key); - output.new_diversifier = input.new_diversifier; - } - - //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 IbcLightclientsSolomachineV3HeaderData diff --git a/evm/contracts/proto/ibc/lightclients/tendermint/v1/tendermint.sol b/evm/contracts/proto/ibc/lightclients/tendermint/v1/tendermint.sol deleted file mode 100644 index abb65e1244..0000000000 --- a/evm/contracts/proto/ibc/lightclients/tendermint/v1/tendermint.sol +++ /dev/null @@ -1,2024 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../../tendermint/types/validator.sol"; -import "../../../../tendermint/types/types.sol"; -import "../../../../cosmos/ics23/v1/proofs.sol"; -import "../../../core/client/v1/client.sol"; -import "../../../core/commitment/v1/commitment.sol"; - -library IbcLightclientsTendermintV1ClientState { - //struct definition - struct Data { - string chain_id; - IbcLightclientsTendermintV1Fraction.Data trust_level; - GoogleProtobufDuration.Data trusting_period; - GoogleProtobufDuration.Data unbonding_period; - GoogleProtobufDuration.Data max_clock_drift; - IbcCoreClientV1Height.Data frozen_height; - IbcCoreClientV1Height.Data latest_height; - CosmosIcs23V1ProofSpec.Data[] proof_specs; - string[] upgrade_path; - bool allow_update_after_expiry; - bool allow_update_after_misbehaviour; - } - - // 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[12] 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_trust_level(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_trusting_period(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_unbonding_period(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_max_clock_drift(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_frozen_height(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_latest_height(pointer, bs, r); - } else if (fieldId == 8) { - pointer += _read_unpacked_repeated_proof_specs( - pointer, bs, nil(), counters - ); - } else if (fieldId == 9) { - pointer += _read_unpacked_repeated_upgrade_path( - pointer, bs, nil(), counters - ); - } else if (fieldId == 10) { - pointer += _read_allow_update_after_expiry(pointer, bs, r); - } else if (fieldId == 11) { - pointer += _read_allow_update_after_misbehaviour(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[8] > 0) { - require(r.proof_specs.length == 0); - r.proof_specs = new CosmosIcs23V1ProofSpec.Data[](counters[8]); - } - if (counters[9] > 0) { - require(r.upgrade_path.length == 0); - r.upgrade_path = new string[](counters[9]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 8) { - pointer += _read_unpacked_repeated_proof_specs( - pointer, bs, r, counters - ); - } else if (fieldId == 9) { - pointer += _read_unpacked_repeated_upgrade_path( - 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_trust_level( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcLightclientsTendermintV1Fraction.Data memory x, uint256 sz) = - _decode_IbcLightclientsTendermintV1Fraction(p, bs); - r.trust_level = 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_trusting_period( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufDuration.Data memory x, uint256 sz) = - _decode_GoogleProtobufDuration(p, bs); - r.trusting_period = 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_unbonding_period( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufDuration.Data memory x, uint256 sz) = - _decode_GoogleProtobufDuration(p, bs); - r.unbonding_period = 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_max_clock_drift( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufDuration.Data memory x, uint256 sz) = - _decode_GoogleProtobufDuration(p, bs); - r.max_clock_drift = 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_frozen_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.frozen_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_latest_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.latest_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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_proof_specs( - uint256 p, - bytes memory bs, - Data memory r, - uint256[12] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (CosmosIcs23V1ProofSpec.Data memory x, uint256 sz) = - _decode_CosmosIcs23V1ProofSpec(p, bs); - if (isNil(r)) { - counters[8] += 1; - } else { - r.proof_specs[r.proof_specs.length - counters[8]] = x; - counters[8] -= 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_upgrade_path( - uint256 p, - bytes memory bs, - Data memory r, - uint256[12] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[9] += 1; - } else { - r.upgrade_path[r.upgrade_path.length - counters[9]] = x; - counters[9] -= 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_allow_update_after_expiry( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.allow_update_after_expiry = 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_allow_update_after_misbehaviour( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bool x, uint256 sz) = ProtoBufRuntime._decode_bool(p, bs); - r.allow_update_after_misbehaviour = 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_IbcLightclientsTendermintV1Fraction( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcLightclientsTendermintV1Fraction.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcLightclientsTendermintV1Fraction.Data memory r,) = - IbcLightclientsTendermintV1Fraction._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_GoogleProtobufDuration( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufDuration.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufDuration.Data memory r,) = - GoogleProtobufDuration._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); - } - - /** - * @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_CosmosIcs23V1ProofSpec( - uint256 p, - bytes memory bs - ) internal pure returns (CosmosIcs23V1ProofSpec.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosIcs23V1ProofSpec.Data memory r,) = - CosmosIcs23V1ProofSpec._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); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsTendermintV1Fraction._encode_nested( - r.trust_level, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufDuration._encode_nested( - r.trusting_period, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufDuration._encode_nested( - r.unbonding_period, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufDuration._encode_nested( - r.max_clock_drift, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.frozen_height, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.latest_height, pointer, bs); - - if (r.proof_specs.length != 0) { - for (i = 0; i < r.proof_specs.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 8, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosIcs23V1ProofSpec._encode_nested( - r.proof_specs[i], pointer, bs - ); - } - } - if (r.upgrade_path.length != 0) { - for (i = 0; i < r.upgrade_path.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 9, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string( - r.upgrade_path[i], pointer, bs - ); - } - } - if (r.allow_update_after_expiry != false) { - pointer += ProtoBufRuntime._encode_key( - 10, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool( - r.allow_update_after_expiry, pointer, bs - ); - } - if (r.allow_update_after_misbehaviour != false) { - pointer += ProtoBufRuntime._encode_key( - 11, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bool( - r.allow_update_after_misbehaviour, 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_lendelim( - IbcLightclientsTendermintV1Fraction._estimate(r.trust_level) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufDuration._estimate(r.trusting_period) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufDuration._estimate(r.unbonding_period) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufDuration._estimate(r.max_clock_drift) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.frozen_height) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.latest_height) - ); - for (i = 0; i < r.proof_specs.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosIcs23V1ProofSpec._estimate(r.proof_specs[i]) - ); - } - for (i = 0; i < r.upgrade_path.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim(bytes(r.upgrade_path[i]).length); - } - e += 1 + 1; - e += 1 + 1; - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.chain_id).length != 0) { - return false; - } - - if (r.proof_specs.length != 0) { - return false; - } - - if (r.upgrade_path.length != 0) { - return false; - } - - if (r.allow_update_after_expiry != false) { - return false; - } - - if (r.allow_update_after_misbehaviour != false) { - 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; - IbcLightclientsTendermintV1Fraction.store( - input.trust_level, output.trust_level - ); - GoogleProtobufDuration.store( - input.trusting_period, output.trusting_period - ); - GoogleProtobufDuration.store( - input.unbonding_period, output.unbonding_period - ); - GoogleProtobufDuration.store( - input.max_clock_drift, output.max_clock_drift - ); - IbcCoreClientV1Height.store(input.frozen_height, output.frozen_height); - IbcCoreClientV1Height.store(input.latest_height, output.latest_height); - - for (uint256 i8 = 0; i8 < input.proof_specs.length; i8++) { - output.proof_specs.push(input.proof_specs[i8]); - } - - output.upgrade_path = input.upgrade_path; - output.allow_update_after_expiry = input.allow_update_after_expiry; - output.allow_update_after_misbehaviour = - input.allow_update_after_misbehaviour; - } - - //array helpers for ProofSpecs - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addProofSpecs( - Data memory self, - CosmosIcs23V1ProofSpec.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - CosmosIcs23V1ProofSpec.Data[] memory tmp = - new CosmosIcs23V1ProofSpec.Data[](self.proof_specs.length + 1); - for (uint256 i; i < self.proof_specs.length; i++) { - tmp[i] = self.proof_specs[i]; - } - tmp[self.proof_specs.length] = value; - self.proof_specs = tmp; - } - - //array helpers for UpgradePath - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addUpgradePath( - Data memory self, - string memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.upgrade_path.length + 1); - for (uint256 i; i < self.upgrade_path.length; i++) { - tmp[i] = self.upgrade_path[i]; - } - tmp[self.upgrade_path.length] = value; - self.upgrade_path = 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 IbcLightclientsTendermintV1ClientState - -library IbcLightclientsTendermintV1ConsensusState { - //struct definition - struct Data { - GoogleProtobufTimestamp.Data timestamp; - IbcCoreCommitmentV1MerkleRoot.Data root; - bytes next_validators_hash; - } - - // 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_timestamp(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_root(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_next_validators_hash(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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufTimestamp.Data memory x, uint256 sz) = - _decode_GoogleProtobufTimestamp(p, bs); - r.timestamp = 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_root( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreCommitmentV1MerkleRoot.Data memory x, uint256 sz) = - _decode_IbcCoreCommitmentV1MerkleRoot(p, bs); - r.root = 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_next_validators_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.next_validators_hash = 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_GoogleProtobufTimestamp( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufTimestamp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufTimestamp.Data memory r,) = - GoogleProtobufTimestamp._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_IbcCoreCommitmentV1MerkleRoot( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreCommitmentV1MerkleRoot.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreCommitmentV1MerkleRoot.Data memory r,) = - IbcCoreCommitmentV1MerkleRoot._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 += - GoogleProtobufTimestamp._encode_nested(r.timestamp, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreCommitmentV1MerkleRoot._encode_nested(r.root, pointer, bs); - - if (r.next_validators_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.next_validators_hash, 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( - GoogleProtobufTimestamp._estimate(r.timestamp) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreCommitmentV1MerkleRoot._estimate(r.root) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.next_validators_hash.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.next_validators_hash.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 { - GoogleProtobufTimestamp.store(input.timestamp, output.timestamp); - IbcCoreCommitmentV1MerkleRoot.store(input.root, output.root); - output.next_validators_hash = input.next_validators_hash; - } - - //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 IbcLightclientsTendermintV1ConsensusState - -library IbcLightclientsTendermintV1Misbehaviour { - //struct definition - struct Data { - string client_id; - IbcLightclientsTendermintV1Header.Data header_1; - IbcLightclientsTendermintV1Header.Data header_2; - } - - // 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_1(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_header_2(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_1( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcLightclientsTendermintV1Header.Data memory x, uint256 sz) = - _decode_IbcLightclientsTendermintV1Header(p, bs); - r.header_1 = 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_2( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcLightclientsTendermintV1Header.Data memory x, uint256 sz) = - _decode_IbcLightclientsTendermintV1Header(p, bs); - r.header_2 = 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_IbcLightclientsTendermintV1Header( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcLightclientsTendermintV1Header.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcLightclientsTendermintV1Header.Data memory r,) = - IbcLightclientsTendermintV1Header._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 += IbcLightclientsTendermintV1Header._encode_nested( - r.header_1, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsTendermintV1Header._encode_nested( - r.header_2, 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( - IbcLightclientsTendermintV1Header._estimate(r.header_1) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcLightclientsTendermintV1Header._estimate(r.header_2) - ); - 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; - IbcLightclientsTendermintV1Header.store(input.header_1, output.header_1); - IbcLightclientsTendermintV1Header.store(input.header_2, output.header_2); - } - - //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 IbcLightclientsTendermintV1Misbehaviour - -library IbcLightclientsTendermintV1Header { - //struct definition - struct Data { - TendermintTypesSignedHeader.Data signed_header; - TendermintTypesValidatorSet.Data validator_set; - IbcCoreClientV1Height.Data trusted_height; - TendermintTypesValidatorSet.Data trusted_validators; - } - - // 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_signed_header(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_validator_set(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_trusted_height(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_trusted_validators(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_signed_header( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesSignedHeader.Data memory x, uint256 sz) = - _decode_TendermintTypesSignedHeader(p, bs); - r.signed_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_validator_set( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesValidatorSet.Data memory x, uint256 sz) = - _decode_TendermintTypesValidatorSet(p, bs); - r.validator_set = 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_trusted_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.trusted_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_trusted_validators( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesValidatorSet.Data memory x, uint256 sz) = - _decode_TendermintTypesValidatorSet(p, bs); - r.trusted_validators = 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_TendermintTypesSignedHeader( - uint256 p, - bytes memory bs - ) - internal - pure - returns (TendermintTypesSignedHeader.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesSignedHeader.Data memory r,) = - TendermintTypesSignedHeader._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_TendermintTypesValidatorSet( - uint256 p, - bytes memory bs - ) - internal - pure - returns (TendermintTypesValidatorSet.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesValidatorSet.Data memory r,) = - TendermintTypesValidatorSet._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesSignedHeader._encode_nested( - r.signed_header, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesValidatorSet._encode_nested( - r.validator_set, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.trusted_height, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesValidatorSet._encode_nested( - r.trusted_validators, 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( - TendermintTypesSignedHeader._estimate(r.signed_header) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesValidatorSet._estimate(r.validator_set) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.trusted_height) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesValidatorSet._estimate(r.trusted_validators) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - TendermintTypesSignedHeader.store( - input.signed_header, output.signed_header - ); - TendermintTypesValidatorSet.store( - input.validator_set, output.validator_set - ); - IbcCoreClientV1Height.store(input.trusted_height, output.trusted_height); - TendermintTypesValidatorSet.store( - input.trusted_validators, output.trusted_validators - ); - } - - //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 IbcLightclientsTendermintV1Header - -library IbcLightclientsTendermintV1Fraction { - //struct definition - struct Data { - uint64 numerator; - uint64 denominator; - } - - // 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_numerator(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_denominator(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_numerator( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.numerator = 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_denominator( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.denominator = 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.numerator != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.numerator, pointer, bs); - } - if (r.denominator != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.denominator, 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.numerator); - e += 1 + ProtoBufRuntime._sz_uint64(r.denominator); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.numerator != 0) { - return false; - } - - if (r.denominator != 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.numerator = input.numerator; - output.denominator = input.denominator; - } - - //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 IbcLightclientsTendermintV1Fraction diff --git a/evm/contracts/proto/ibc/lightclients/wasm/v1/genesis.sol b/evm/contracts/proto/ibc/lightclients/wasm/v1/genesis.sol deleted file mode 100644 index 8e995a9966..0000000000 --- a/evm/contracts/proto/ibc/lightclients/wasm/v1/genesis.sol +++ /dev/null @@ -1,554 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcLightclientsWasmV1GenesisState { - //struct definition - struct Data { - IbcLightclientsWasmV1GenesisContract.Data[] contracts; - } - - // 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[2] 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_unpacked_repeated_contracts( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.contracts.length == 0); - r.contracts = - new IbcLightclientsWasmV1GenesisContract.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_contracts(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_contracts( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (IbcLightclientsWasmV1GenesisContract.Data memory x, uint256 sz) = - _decode_IbcLightclientsWasmV1GenesisContract(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.contracts[r.contracts.length - counters[1]] = x; - counters[1] -= 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_IbcLightclientsWasmV1GenesisContract( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcLightclientsWasmV1GenesisContract.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcLightclientsWasmV1GenesisContract.Data memory r,) = - IbcLightclientsWasmV1GenesisContract._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.contracts.length != 0) { - for (i = 0; i < r.contracts.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcLightclientsWasmV1GenesisContract._encode_nested( - r.contracts[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; - for (i = 0; i < r.contracts.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcLightclientsWasmV1GenesisContract._estimate(r.contracts[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.contracts.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 { - for (uint256 i1 = 0; i1 < input.contracts.length; i1++) { - output.contracts.push(input.contracts[i1]); - } - } - - //array helpers for Contracts - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addContracts( - Data memory self, - IbcLightclientsWasmV1GenesisContract.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - IbcLightclientsWasmV1GenesisContract.Data[] memory tmp = new IbcLightclientsWasmV1GenesisContract - .Data[](self.contracts.length + 1); - for (uint256 i; i < self.contracts.length; i++) { - tmp[i] = self.contracts[i]; - } - tmp[self.contracts.length] = value; - self.contracts = 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 IbcLightclientsWasmV1GenesisState - -library IbcLightclientsWasmV1GenesisContract { - //struct definition - struct Data { - bytes code_id_key; - bytes contract_code; - } - - // 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_code_id_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_contract_code(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_code_id_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.code_id_key = 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_contract_code( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.contract_code = 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.code_id_key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.code_id_key, pointer, bs); - } - if (r.contract_code.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.contract_code, 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.code_id_key.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.contract_code.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.code_id_key.length != 0) { - return false; - } - - if (r.contract_code.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.code_id_key = input.code_id_key; - output.contract_code = input.contract_code; - } - - //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 IbcLightclientsWasmV1GenesisContract diff --git a/evm/contracts/proto/ibc/lightclients/wasm/v1/query.sol b/evm/contracts/proto/ibc/lightclients/wasm/v1/query.sol deleted file mode 100644 index 3e99362508..0000000000 --- a/evm/contracts/proto/ibc/lightclients/wasm/v1/query.sol +++ /dev/null @@ -1,1000 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../../cosmos/base/query/v1beta1/pagination.sol"; - -library IbcLightclientsWasmV1QueryCodeIdsRequest { - //struct definition - struct Data { - CosmosBaseQueryV1beta1PageRequest.Data pagination; - } - - // 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_pagination(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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageRequest.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageRequest(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageRequest( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageRequest.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageRequest.Data memory r,) = - CosmosBaseQueryV1beta1PageRequest._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 += CosmosBaseQueryV1beta1PageRequest._encode_nested( - r.pagination, 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( - CosmosBaseQueryV1beta1PageRequest._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - CosmosBaseQueryV1beta1PageRequest.store( - input.pagination, output.pagination - ); - } - - //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 IbcLightclientsWasmV1QueryCodeIdsRequest - -library IbcLightclientsWasmV1QueryCodeIdsResponse { - //struct definition - struct Data { - string[] code_ids; - CosmosBaseQueryV1beta1PageResponse.Data pagination; - } - - // 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_unpacked_repeated_code_ids( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_pagination(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.code_ids.length == 0); - r.code_ids = new string[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_code_ids(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_code_ids( - 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. - */ - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.code_ids[r.code_ids.length - counters[1]] = x; - counters[1] -= 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_pagination( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (CosmosBaseQueryV1beta1PageResponse.Data memory x, uint256 sz) = - _decode_CosmosBaseQueryV1beta1PageResponse(p, bs); - r.pagination = 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_CosmosBaseQueryV1beta1PageResponse( - uint256 p, - bytes memory bs - ) - internal - pure - returns (CosmosBaseQueryV1beta1PageResponse.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (CosmosBaseQueryV1beta1PageResponse.Data memory r,) = - CosmosBaseQueryV1beta1PageResponse._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.code_ids.length != 0) { - for (i = 0; i < r.code_ids.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.code_ids[i], pointer, bs); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += CosmosBaseQueryV1beta1PageResponse._encode_nested( - r.pagination, 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; - for (i = 0; i < r.code_ids.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.code_ids[i]).length); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - CosmosBaseQueryV1beta1PageResponse._estimate(r.pagination) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.code_ids.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.code_ids = input.code_ids; - CosmosBaseQueryV1beta1PageResponse.store( - input.pagination, output.pagination - ); - } - - //array helpers for CodeIds - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addCodeIds(Data memory self, string memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - string[] memory tmp = new string[](self.code_ids.length + 1); - for (uint256 i; i < self.code_ids.length; i++) { - tmp[i] = self.code_ids[i]; - } - tmp[self.code_ids.length] = value; - self.code_ids = 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 IbcLightclientsWasmV1QueryCodeIdsResponse - -library IbcLightclientsWasmV1QueryCodeRequest { - //struct definition - struct Data { - string code_id; - } - - // 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_code_id(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_code_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.code_id = 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 (bytes(r.code_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.code_id, 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.code_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.code_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.code_id = input.code_id; - } - - //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 IbcLightclientsWasmV1QueryCodeRequest - -library IbcLightclientsWasmV1QueryCodeResponse { - //struct definition - struct Data { - bytes code; - } - - // 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_code(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_code( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.code = 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.code.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.code, 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.code.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.code.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.code = input.code; - } - - //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 IbcLightclientsWasmV1QueryCodeResponse diff --git a/evm/contracts/proto/ibc/lightclients/wasm/v1/tx.sol b/evm/contracts/proto/ibc/lightclients/wasm/v1/tx.sol deleted file mode 100644 index e3783a0843..0000000000 --- a/evm/contracts/proto/ibc/lightclients/wasm/v1/tx.sol +++ /dev/null @@ -1,461 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; - -library IbcLightclientsWasmV1MsgStoreCode { - //struct definition - struct Data { - string signer; - bytes code; - } - - // 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_signer(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_code(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_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; - } - - /** - * @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_code( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.code = 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 (bytes(r.signer).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.signer, pointer, bs); - } - if (r.code.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.code, 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.signer).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.code.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.signer).length != 0) { - return false; - } - - if (r.code.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.signer = input.signer; - output.code = input.code; - } - - //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 IbcLightclientsWasmV1MsgStoreCode - -library IbcLightclientsWasmV1MsgStoreCodeResponse { - //struct definition - struct Data { - bytes code_id; - } - - // 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_code_id(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_code_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.code_id = 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.code_id.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.code_id, 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.code_id.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.code_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.code_id = input.code_id; - } - - //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 IbcLightclientsWasmV1MsgStoreCodeResponse diff --git a/evm/contracts/proto/ibc/lightclients/wasm/v1/wasm.sol b/evm/contracts/proto/ibc/lightclients/wasm/v1/wasm.sol deleted file mode 100644 index f0ac876c3c..0000000000 --- a/evm/contracts/proto/ibc/lightclients/wasm/v1/wasm.sol +++ /dev/null @@ -1,1027 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../../../ProtoBufRuntime.sol"; -import "../../../../GoogleProtobufAny.sol"; -import "../../../core/client/v1/client.sol"; - -library IbcLightclientsWasmV1ClientState { - //struct definition - struct Data { - bytes data; - bytes code_id; - IbcCoreClientV1Height.Data latest_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_data(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_code_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_latest_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_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 - * @return The number of bytes decoded - */ - function _read_code_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.code_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_latest_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.latest_height = 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); - } - - // 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.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); - } - if (r.code_id.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.code_id, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.latest_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_lendelim(r.data.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.code_id.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.latest_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.data.length != 0) { - return false; - } - - if (r.code_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.data = input.data; - output.code_id = input.code_id; - IbcCoreClientV1Height.store(input.latest_height, output.latest_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 IbcLightclientsWasmV1ClientState - -library IbcLightclientsWasmV1ConsensusState { - //struct definition - struct Data { - bytes data; - uint64 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 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_timestamp(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_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 - * @return The number of bytes decoded - */ - function _read_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); - } - if (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.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; - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - e += 1 + ProtoBufRuntime._sz_uint64(r.timestamp); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.data.length != 0) { - return false; - } - - if (r.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.data = input.data; - output.timestamp = input.timestamp; - } - - //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 IbcLightclientsWasmV1ConsensusState - -library IbcLightclientsWasmV1Header { - //struct definition - struct Data { - bytes data; - IbcCoreClientV1Height.Data 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_data(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_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_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 - * @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; - } - - // 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); - } - - // 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.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreClientV1Height._encode_nested(r.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_lendelim(r.data.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.data.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; - IbcCoreClientV1Height.store(input.height, output.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 IbcLightclientsWasmV1Header - -library IbcLightclientsWasmV1Misbehaviour { - //struct definition - struct Data { - bytes data; - } - - // 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_data(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_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; - } - - // 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.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, 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.data.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.data.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; - } - - //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 IbcLightclientsWasmV1Misbehaviour diff --git a/evm/contracts/proto/tendermint/crypto/keys.sol b/evm/contracts/proto/tendermint/crypto/keys.sol deleted file mode 100644 index 9481694152..0000000000 --- a/evm/contracts/proto/tendermint/crypto/keys.sol +++ /dev/null @@ -1,281 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../ProtoBufRuntime.sol"; -import "../../GoogleProtobufAny.sol"; - -library TendermintCryptoPublicKey { - //struct definition - struct Data { - bytes ed25519; - bytes secp256k1; - bytes bn254; - } - - // 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_ed25519(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_secp256k1(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_bn254(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_ed25519( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.ed25519 = 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_secp256k1( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.secp256k1 = 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_bn254( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.bn254 = 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.ed25519.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.ed25519, pointer, bs); - } - if (r.secp256k1.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.secp256k1, pointer, bs); - } - if (r.bn254.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.bn254, 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.ed25519.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.secp256k1.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.bn254.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.ed25519.length != 0) { - return false; - } - - if (r.secp256k1.length != 0) { - return false; - } - - if (r.bn254.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.ed25519 = input.ed25519; - output.secp256k1 = input.secp256k1; - output.bn254 = input.bn254; - } - - //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 TendermintCryptoPublicKey diff --git a/evm/contracts/proto/tendermint/crypto/proof.sol b/evm/contracts/proto/tendermint/crypto/proof.sol deleted file mode 100644 index 0707f9da2c..0000000000 --- a/evm/contracts/proto/tendermint/crypto/proof.sol +++ /dev/null @@ -1,1483 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../ProtoBufRuntime.sol"; -import "../../GoogleProtobufAny.sol"; - -library TendermintCryptoProof { - //struct definition - struct Data { - int64 total; - int64 index; - bytes leaf_hash; - bytes[] aunts; - } - - // 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[5] 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_total(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_index(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_leaf_hash(pointer, bs, r); - } else if (fieldId == 4) { - pointer += - _read_unpacked_repeated_aunts(pointer, bs, nil(), counters); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[4] > 0) { - require(r.aunts.length == 0); - r.aunts = new bytes[](counters[4]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 4) { - pointer += - _read_unpacked_repeated_aunts(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_total( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.total = 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_index( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.index = 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_leaf_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.leaf_hash = 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_aunts( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.aunts[r.aunts.length - counters[4]] = x; - counters[4] -= 1; - } - 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; - uint256 i; - if (r.total != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.total, pointer, bs); - } - if (r.index != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.index, pointer, bs); - } - if (r.leaf_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.leaf_hash, pointer, bs); - } - if (r.aunts.length != 0) { - for (i = 0; i < r.aunts.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.aunts[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_int64(r.total); - e += 1 + ProtoBufRuntime._sz_int64(r.index); - e += 1 + ProtoBufRuntime._sz_lendelim(r.leaf_hash.length); - for (i = 0; i < r.aunts.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(r.aunts[i].length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.total != 0) { - return false; - } - - if (r.index != 0) { - return false; - } - - if (r.leaf_hash.length != 0) { - return false; - } - - if (r.aunts.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.total = input.total; - output.index = input.index; - output.leaf_hash = input.leaf_hash; - output.aunts = input.aunts; - } - - //array helpers for Aunts - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addAunts(Data memory self, bytes memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - bytes[] memory tmp = new bytes[](self.aunts.length + 1); - for (uint256 i; i < self.aunts.length; i++) { - tmp[i] = self.aunts[i]; - } - tmp[self.aunts.length] = value; - self.aunts = 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 TendermintCryptoProof - -library TendermintCryptoValueOp { - //struct definition - struct Data { - bytes key; - TendermintCryptoProof.Data proof; - } - - // 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_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_proof(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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintCryptoProof.Data memory x, uint256 sz) = - _decode_TendermintCryptoProof(p, bs); - r.proof = 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_TendermintCryptoProof( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintCryptoProof.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintCryptoProof.Data memory r,) = - TendermintCryptoProof._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 (r.key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintCryptoProof._encode_nested(r.proof, 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.key.length); - e += 1 - + ProtoBufRuntime._sz_lendelim(TendermintCryptoProof._estimate(r.proof)); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.key.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.key = input.key; - TendermintCryptoProof.store(input.proof, output.proof); - } - - //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 TendermintCryptoValueOp - -library TendermintCryptoDominoOp { - //struct definition - struct Data { - string key; - string input; - string output; - } - - // 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_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_input(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_output(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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.key = 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_input( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.input = 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_output( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.output = 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 (bytes(r.key).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.key, pointer, bs); - } - if (bytes(r.input).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.input, pointer, bs); - } - if (bytes(r.output).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.output, 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.key).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.input).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.output).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.key).length != 0) { - return false; - } - - if (bytes(r.input).length != 0) { - return false; - } - - if (bytes(r.output).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.key = input.key; - output.input = input.input; - output.output = input.output; - } - - //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 TendermintCryptoDominoOp - -library TendermintCryptoProofOp { - //struct definition - struct Data { - string ty; - bytes key; - bytes data; - } - - // 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_type(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_key(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_data(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_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.ty = 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_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.key = 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_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; - } - - // 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.ty).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.ty, pointer, bs); - } - if (r.key.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.key, pointer, bs); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, 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.ty).length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.key.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.ty).length != 0) { - return false; - } - - if (r.key.length != 0) { - return false; - } - - if (r.data.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.ty = input.ty; - output.key = input.key; - output.data = input.data; - } - - //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 TendermintCryptoProofOp - -library TendermintCryptoProofOps { - //struct definition - struct Data { - TendermintCryptoProofOp.Data[] ops; - } - - // 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[2] 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_unpacked_repeated_ops(pointer, bs, nil(), counters); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.ops.length == 0); - r.ops = new TendermintCryptoProofOp.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_ops(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_ops( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (TendermintCryptoProofOp.Data memory x, uint256 sz) = - _decode_TendermintCryptoProofOp(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.ops[r.ops.length - counters[1]] = x; - counters[1] -= 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_TendermintCryptoProofOp( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintCryptoProofOp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintCryptoProofOp.Data memory r,) = - TendermintCryptoProofOp._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.ops.length != 0) { - for (i = 0; i < r.ops.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintCryptoProofOp._encode_nested( - r.ops[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; - for (i = 0; i < r.ops.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintCryptoProofOp._estimate(r.ops[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.ops.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 { - for (uint256 i1 = 0; i1 < input.ops.length; i1++) { - output.ops.push(input.ops[i1]); - } - } - - //array helpers for Ops - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addOps( - Data memory self, - TendermintCryptoProofOp.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - TendermintCryptoProofOp.Data[] memory tmp = - new TendermintCryptoProofOp.Data[](self.ops.length + 1); - for (uint256 i; i < self.ops.length; i++) { - tmp[i] = self.ops[i]; - } - tmp[self.ops.length] = value; - self.ops = 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 TendermintCryptoProofOps diff --git a/evm/contracts/proto/tendermint/types/canonical.sol b/evm/contracts/proto/tendermint/types/canonical.sol deleted file mode 100644 index 429380f6ef..0000000000 --- a/evm/contracts/proto/tendermint/types/canonical.sol +++ /dev/null @@ -1,1357 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../ProtoBufRuntime.sol"; -import "../../GoogleProtobufAny.sol"; -import "./types.sol"; - -library TendermintTypesCanonicalBlockID { - //struct definition - struct Data { - bytes hash; - TendermintTypesCanonicalPartSetHeader.Data part_set_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_hash(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_part_set_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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.hash = 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_part_set_header( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesCanonicalPartSetHeader.Data memory x, uint256 sz) = - _decode_TendermintTypesCanonicalPartSetHeader(p, bs); - r.part_set_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_TendermintTypesCanonicalPartSetHeader( - uint256 p, - bytes memory bs - ) - internal - pure - returns (TendermintTypesCanonicalPartSetHeader.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesCanonicalPartSetHeader.Data memory r,) = - TendermintTypesCanonicalPartSetHeader._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 (r.hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.hash, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesCanonicalPartSetHeader._encode_nested( - r.part_set_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(r.hash.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesCanonicalPartSetHeader._estimate(r.part_set_header) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.hash.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.hash = input.hash; - TendermintTypesCanonicalPartSetHeader.store( - input.part_set_header, output.part_set_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 TendermintTypesCanonicalBlockID - -library TendermintTypesCanonicalPartSetHeader { - //struct definition - struct Data { - uint32 total; - bytes hash; - } - - // 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_total(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_hash(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_total( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint32 x, uint256 sz) = ProtoBufRuntime._decode_uint32(p, bs); - r.total = 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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.hash = 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.total != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint32(r.total, pointer, bs); - } - if (r.hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.hash, 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.total); - e += 1 + ProtoBufRuntime._sz_lendelim(r.hash.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.total != 0) { - return false; - } - - if (r.hash.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.total = input.total; - output.hash = input.hash; - } - - //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 TendermintTypesCanonicalPartSetHeader - -library TendermintTypesCanonicalProposal { - //struct definition - struct Data { - TendermintTypesTypesGlobalEnums.SignedMsgType type_; - int64 height; - int64 round; - int64 pol_round; - TendermintTypesCanonicalBlockID.Data block_id; - GoogleProtobufTimestamp.Data timestamp; - string chain_id; - } - - // 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_type(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_height(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_round(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_pol_round(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_block_id(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_timestamp(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_chain_id(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_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - TendermintTypesTypesGlobalEnums.SignedMsgType x = - TendermintTypesTypesGlobalEnums.decode_SignedMsgType(tmp); - r.type_ = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_sfixed64(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_round( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_sfixed64(p, bs); - r.round = 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_pol_round( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.pol_round = 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_block_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesCanonicalBlockID.Data memory x, uint256 sz) = - _decode_TendermintTypesCanonicalBlockID(p, bs); - r.block_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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufTimestamp.Data memory x, uint256 sz) = - _decode_GoogleProtobufTimestamp(p, bs); - r.timestamp = 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_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; - } - - // 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_TendermintTypesCanonicalBlockID( - uint256 p, - bytes memory bs - ) - internal - pure - returns (TendermintTypesCanonicalBlockID.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesCanonicalBlockID.Data memory r,) = - TendermintTypesCanonicalBlockID._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_GoogleProtobufTimestamp( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufTimestamp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufTimestamp.Data memory r,) = - GoogleProtobufTimestamp._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.type_) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_type = - TendermintTypesTypesGlobalEnums.encode_SignedMsgType(r.type_); - pointer += ProtoBufRuntime._encode_enum(_enum_type, pointer, bs); - } - if (r.height != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Fixed64, pointer, bs - ); - pointer += ProtoBufRuntime._encode_sfixed64(r.height, pointer, bs); - } - if (r.round != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Fixed64, pointer, bs - ); - pointer += ProtoBufRuntime._encode_sfixed64(r.round, pointer, bs); - } - if (r.pol_round != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.pol_round, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesCanonicalBlockID._encode_nested( - r.block_id, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufTimestamp._encode_nested(r.timestamp, pointer, bs); - - if (bytes(r.chain_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.chain_id, 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( - TendermintTypesTypesGlobalEnums.encode_SignedMsgType(r.type_) - ); - e += 1 + 8; - e += 1 + 8; - e += 1 + ProtoBufRuntime._sz_int64(r.pol_round); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesCanonicalBlockID._estimate(r.block_id) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufTimestamp._estimate(r.timestamp) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.chain_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.type_) != 0) { - return false; - } - - if (r.height != 0) { - return false; - } - - if (r.round != 0) { - return false; - } - - if (r.pol_round != 0) { - return false; - } - - if (bytes(r.chain_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.type_ = input.type_; - output.height = input.height; - output.round = input.round; - output.pol_round = input.pol_round; - TendermintTypesCanonicalBlockID.store(input.block_id, output.block_id); - GoogleProtobufTimestamp.store(input.timestamp, output.timestamp); - output.chain_id = input.chain_id; - } - - //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 TendermintTypesCanonicalProposal - -library TendermintTypesCanonicalVote { - //struct definition - struct Data { - TendermintTypesTypesGlobalEnums.SignedMsgType type_; - int64 height; - int64 round; - TendermintTypesCanonicalBlockID.Data block_id; - string chain_id; - } - - // 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_type(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_height(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_round(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_block_id(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_chain_id(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_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - TendermintTypesTypesGlobalEnums.SignedMsgType x = - TendermintTypesTypesGlobalEnums.decode_SignedMsgType(tmp); - r.type_ = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_sfixed64(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_round( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_sfixed64(p, bs); - r.round = 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_block_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesCanonicalBlockID.Data memory x, uint256 sz) = - _decode_TendermintTypesCanonicalBlockID(p, bs); - r.block_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_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; - } - - // 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_TendermintTypesCanonicalBlockID( - uint256 p, - bytes memory bs - ) - internal - pure - returns (TendermintTypesCanonicalBlockID.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesCanonicalBlockID.Data memory r,) = - TendermintTypesCanonicalBlockID._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.type_) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_type = - TendermintTypesTypesGlobalEnums.encode_SignedMsgType(r.type_); - pointer += ProtoBufRuntime._encode_enum(_enum_type, pointer, bs); - } - if (r.height != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Fixed64, pointer, bs - ); - pointer += ProtoBufRuntime._encode_sfixed64(r.height, pointer, bs); - } - if (r.round != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Fixed64, pointer, bs - ); - pointer += ProtoBufRuntime._encode_sfixed64(r.round, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesCanonicalBlockID._encode_nested( - r.block_id, pointer, bs - ); - - if (bytes(r.chain_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.chain_id, 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( - TendermintTypesTypesGlobalEnums.encode_SignedMsgType(r.type_) - ); - e += 1 + 8; - e += 1 + 8; - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesCanonicalBlockID._estimate(r.block_id) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.chain_id).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.type_) != 0) { - return false; - } - - if (r.height != 0) { - return false; - } - - if (r.round != 0) { - return false; - } - - if (bytes(r.chain_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.type_ = input.type_; - output.height = input.height; - output.round = input.round; - TendermintTypesCanonicalBlockID.store(input.block_id, output.block_id); - output.chain_id = input.chain_id; - } - - //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 TendermintTypesCanonicalVote diff --git a/evm/contracts/proto/tendermint/types/types.sol b/evm/contracts/proto/tendermint/types/types.sol deleted file mode 100644 index 08909a6585..0000000000 --- a/evm/contracts/proto/tendermint/types/types.sol +++ /dev/null @@ -1,4856 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../ProtoBufRuntime.sol"; -import "../../GoogleProtobufAny.sol"; -import "../crypto/proof.sol"; -import "../version/types.sol"; -import "./validator.sol"; - -library TendermintTypesPartSetHeader { - //struct definition - struct Data { - uint32 total; - bytes hash; - } - - // 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_total(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_hash(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_total( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint32 x, uint256 sz) = ProtoBufRuntime._decode_uint32(p, bs); - r.total = 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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.hash = 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.total != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint32(r.total, pointer, bs); - } - if (r.hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.hash, 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.total); - e += 1 + ProtoBufRuntime._sz_lendelim(r.hash.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.total != 0) { - return false; - } - - if (r.hash.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.total = input.total; - output.hash = input.hash; - } - - //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 TendermintTypesPartSetHeader - -library TendermintTypesPart { - //struct definition - struct Data { - uint32 index; - bytes bz; - TendermintCryptoProof.Data proof; - } - - // 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_index(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_bytes(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof(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_index( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint32 x, uint256 sz) = ProtoBufRuntime._decode_uint32(p, bs); - r.index = 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_bytes( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.bz = 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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintCryptoProof.Data memory x, uint256 sz) = - _decode_TendermintCryptoProof(p, bs); - r.proof = 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_TendermintCryptoProof( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintCryptoProof.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintCryptoProof.Data memory r,) = - TendermintCryptoProof._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 (r.index != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint32(r.index, pointer, bs); - } - if (r.bz.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.bz, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintCryptoProof._encode_nested(r.proof, 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.index); - e += 1 + ProtoBufRuntime._sz_lendelim(r.bz.length); - e += 1 - + ProtoBufRuntime._sz_lendelim(TendermintCryptoProof._estimate(r.proof)); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.index != 0) { - return false; - } - - if (r.bz.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.index = input.index; - output.bz = input.bz; - TendermintCryptoProof.store(input.proof, output.proof); - } - - //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 TendermintTypesPart - -library TendermintTypesBlockID { - //struct definition - struct Data { - bytes hash; - TendermintTypesPartSetHeader.Data part_set_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_hash(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_part_set_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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.hash = 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_part_set_header( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesPartSetHeader.Data memory x, uint256 sz) = - _decode_TendermintTypesPartSetHeader(p, bs); - r.part_set_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_TendermintTypesPartSetHeader( - uint256 p, - bytes memory bs - ) - internal - pure - returns (TendermintTypesPartSetHeader.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesPartSetHeader.Data memory r,) = - TendermintTypesPartSetHeader._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 (r.hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.hash, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesPartSetHeader._encode_nested( - r.part_set_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(r.hash.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesPartSetHeader._estimate(r.part_set_header) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.hash.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.hash = input.hash; - TendermintTypesPartSetHeader.store( - input.part_set_header, output.part_set_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 TendermintTypesBlockID - -library TendermintTypesHeader { - //struct definition - struct Data { - TendermintVersionConsensus.Data version; - string chain_id; - int64 height; - GoogleProtobufTimestamp.Data time; - TendermintTypesBlockID.Data last_block_id; - bytes last_commit_hash; - bytes data_hash; - bytes validators_hash; - bytes next_validators_hash; - bytes consensus_hash; - bytes app_hash; - bytes last_results_hash; - bytes evidence_hash; - bytes proposer_address; - } - - // 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(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_chain_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_height(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_time(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_last_block_id(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_last_commit_hash(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_data_hash(pointer, bs, r); - } else if (fieldId == 8) { - pointer += _read_validators_hash(pointer, bs, r); - } else if (fieldId == 9) { - pointer += _read_next_validators_hash(pointer, bs, r); - } else if (fieldId == 10) { - pointer += _read_consensus_hash(pointer, bs, r); - } else if (fieldId == 11) { - pointer += _read_app_hash(pointer, bs, r); - } else if (fieldId == 12) { - pointer += _read_last_results_hash(pointer, bs, r); - } else if (fieldId == 13) { - pointer += _read_evidence_hash(pointer, bs, r); - } else if (fieldId == 14) { - pointer += _read_proposer_address(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( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintVersionConsensus.Data memory x, uint256 sz) = - _decode_TendermintVersionConsensus(p, bs); - r.version = 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_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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(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_time( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufTimestamp.Data memory x, uint256 sz) = - _decode_GoogleProtobufTimestamp(p, bs); - r.time = 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_last_block_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesBlockID.Data memory x, uint256 sz) = - _decode_TendermintTypesBlockID(p, bs); - r.last_block_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_last_commit_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.last_commit_hash = 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_data_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.data_hash = 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_validators_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.validators_hash = 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_next_validators_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.next_validators_hash = 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_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.consensus_hash = 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_app_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.app_hash = 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_last_results_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.last_results_hash = 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_evidence_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.evidence_hash = 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_proposer_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.proposer_address = 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_TendermintVersionConsensus( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintVersionConsensus.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintVersionConsensus.Data memory r,) = - TendermintVersionConsensus._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_GoogleProtobufTimestamp( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufTimestamp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufTimestamp.Data memory r,) = - GoogleProtobufTimestamp._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_TendermintTypesBlockID( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesBlockID.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesBlockID.Data memory r,) = - TendermintTypesBlockID._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 += - TendermintVersionConsensus._encode_nested(r.version, pointer, bs); - - if (bytes(r.chain_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.chain_id, pointer, bs); - } - if (r.height != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.height, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufTimestamp._encode_nested(r.time, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - TendermintTypesBlockID._encode_nested(r.last_block_id, pointer, bs); - - if (r.last_commit_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.last_commit_hash, pointer, bs); - } - if (r.data_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data_hash, pointer, bs); - } - if (r.validators_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 8, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.validators_hash, pointer, bs); - } - if (r.next_validators_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 9, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.next_validators_hash, pointer, bs - ); - } - if (r.consensus_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 10, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.consensus_hash, pointer, bs); - } - if (r.app_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 11, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.app_hash, pointer, bs); - } - if (r.last_results_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 12, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.last_results_hash, pointer, bs); - } - if (r.evidence_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 13, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.evidence_hash, pointer, bs); - } - if (r.proposer_address.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 14, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.proposer_address, 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( - TendermintVersionConsensus._estimate(r.version) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.chain_id).length); - e += 1 + ProtoBufRuntime._sz_int64(r.height); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufTimestamp._estimate(r.time) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesBlockID._estimate(r.last_block_id) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.last_commit_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.validators_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.next_validators_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.consensus_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.app_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.last_results_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.evidence_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.proposer_address.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.chain_id).length != 0) { - return false; - } - - if (r.height != 0) { - return false; - } - - if (r.last_commit_hash.length != 0) { - return false; - } - - if (r.data_hash.length != 0) { - return false; - } - - if (r.validators_hash.length != 0) { - return false; - } - - if (r.next_validators_hash.length != 0) { - return false; - } - - if (r.consensus_hash.length != 0) { - return false; - } - - if (r.app_hash.length != 0) { - return false; - } - - if (r.last_results_hash.length != 0) { - return false; - } - - if (r.evidence_hash.length != 0) { - return false; - } - - if (r.proposer_address.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 { - TendermintVersionConsensus.store(input.version, output.version); - output.chain_id = input.chain_id; - output.height = input.height; - GoogleProtobufTimestamp.store(input.time, output.time); - TendermintTypesBlockID.store(input.last_block_id, output.last_block_id); - output.last_commit_hash = input.last_commit_hash; - output.data_hash = input.data_hash; - output.validators_hash = input.validators_hash; - output.next_validators_hash = input.next_validators_hash; - output.consensus_hash = input.consensus_hash; - output.app_hash = input.app_hash; - output.last_results_hash = input.last_results_hash; - output.evidence_hash = input.evidence_hash; - output.proposer_address = input.proposer_address; - } - - //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 TendermintTypesHeader - -library TendermintTypesData { - //struct definition - struct Data { - bytes[] txs; - } - - // 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[2] 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_unpacked_repeated_txs(pointer, bs, nil(), counters); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.txs.length == 0); - r.txs = new bytes[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += _read_unpacked_repeated_txs(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_txs( - uint256 p, - bytes memory bs, - Data memory r, - uint256[2] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.txs[r.txs.length - counters[1]] = x; - counters[1] -= 1; - } - 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; - uint256 i; - if (r.txs.length != 0) { - for (i = 0; i < r.txs.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.txs[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; - for (i = 0; i < r.txs.length; i++) { - e += 1 + ProtoBufRuntime._sz_lendelim(r.txs[i].length); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.txs.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.txs = input.txs; - } - - //array helpers for Txs - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addTxs(Data memory self, bytes memory value) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - bytes[] memory tmp = new bytes[](self.txs.length + 1); - for (uint256 i; i < self.txs.length; i++) { - tmp[i] = self.txs[i]; - } - tmp[self.txs.length] = value; - self.txs = 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 TendermintTypesData - -library TendermintTypesVote { - //struct definition - struct Data { - TendermintTypesTypesGlobalEnums.SignedMsgType ty; - int64 height; - int32 round; - TendermintTypesBlockID.Data block_id; - GoogleProtobufTimestamp.Data timestamp; - bytes validator_address; - int32 validator_index; - bytes signature; - } - - // 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_type(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_height(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_round(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_block_id(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_timestamp(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_validator_address(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_validator_index(pointer, bs, r); - } else if (fieldId == 8) { - pointer += _read_signature(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_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - TendermintTypesTypesGlobalEnums.SignedMsgType x = - TendermintTypesTypesGlobalEnums.decode_SignedMsgType(tmp); - r.ty = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(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_round( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.round = 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_block_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesBlockID.Data memory x, uint256 sz) = - _decode_TendermintTypesBlockID(p, bs); - r.block_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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufTimestamp.Data memory x, uint256 sz) = - _decode_GoogleProtobufTimestamp(p, bs); - r.timestamp = 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_validator_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.validator_address = 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_validator_index( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.validator_index = 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_signature( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature = 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_TendermintTypesBlockID( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesBlockID.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesBlockID.Data memory r,) = - TendermintTypesBlockID._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_GoogleProtobufTimestamp( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufTimestamp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufTimestamp.Data memory r,) = - GoogleProtobufTimestamp._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.ty) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_type = - TendermintTypesTypesGlobalEnums.encode_SignedMsgType(r.ty); - pointer += ProtoBufRuntime._encode_enum(_enum_type, pointer, bs); - } - if (r.height != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.height, pointer, bs); - } - if (r.round != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int32(r.round, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - TendermintTypesBlockID._encode_nested(r.block_id, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufTimestamp._encode_nested(r.timestamp, pointer, bs); - - if (r.validator_address.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.validator_address, pointer, bs); - } - if (r.validator_index != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_int32(r.validator_index, pointer, bs); - } - if (r.signature.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 8, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.signature, 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( - TendermintTypesTypesGlobalEnums.encode_SignedMsgType(r.ty) - ); - e += 1 + ProtoBufRuntime._sz_int64(r.height); - e += 1 + ProtoBufRuntime._sz_int32(r.round); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesBlockID._estimate(r.block_id) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufTimestamp._estimate(r.timestamp) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.validator_address.length); - e += 1 + ProtoBufRuntime._sz_int32(r.validator_index); - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.ty) != 0) { - return false; - } - - if (r.height != 0) { - return false; - } - - if (r.round != 0) { - return false; - } - - if (r.validator_address.length != 0) { - return false; - } - - if (r.validator_index != 0) { - return false; - } - - if (r.signature.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.ty = input.ty; - output.height = input.height; - output.round = input.round; - TendermintTypesBlockID.store(input.block_id, output.block_id); - GoogleProtobufTimestamp.store(input.timestamp, output.timestamp); - output.validator_address = input.validator_address; - output.validator_index = input.validator_index; - output.signature = input.signature; - } - - //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 TendermintTypesVote - -library TendermintTypesCommit { - //struct definition - struct Data { - int64 height; - int32 round; - TendermintTypesBlockID.Data block_id; - TendermintTypesCommitSig.Data[] signatures; - } - - // 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[5] 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_height(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_round(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_block_id(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_unpacked_repeated_signatures( - pointer, bs, nil(), counters - ); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[4] > 0) { - require(r.signatures.length == 0); - r.signatures = new TendermintTypesCommitSig.Data[](counters[4]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 4) { - pointer += - _read_unpacked_repeated_signatures(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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(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_round( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.round = 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_block_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesBlockID.Data memory x, uint256 sz) = - _decode_TendermintTypesBlockID(p, bs); - r.block_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_signatures( - uint256 p, - bytes memory bs, - Data memory r, - uint256[5] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (TendermintTypesCommitSig.Data memory x, uint256 sz) = - _decode_TendermintTypesCommitSig(p, bs); - if (isNil(r)) { - counters[4] += 1; - } else { - r.signatures[r.signatures.length - counters[4]] = x; - counters[4] -= 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_TendermintTypesBlockID( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesBlockID.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesBlockID.Data memory r,) = - TendermintTypesBlockID._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_TendermintTypesCommitSig( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesCommitSig.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesCommitSig.Data memory r,) = - TendermintTypesCommitSig._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.height != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.height, pointer, bs); - } - if (r.round != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int32(r.round, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - TendermintTypesBlockID._encode_nested(r.block_id, pointer, bs); - - if (r.signatures.length != 0) { - for (i = 0; i < r.signatures.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesCommitSig._encode_nested( - r.signatures[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_int64(r.height); - e += 1 + ProtoBufRuntime._sz_int32(r.round); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesBlockID._estimate(r.block_id) - ); - for (i = 0; i < r.signatures.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesCommitSig._estimate(r.signatures[i]) - ); - } - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.height != 0) { - return false; - } - - if (r.round != 0) { - return false; - } - - if (r.signatures.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.height = input.height; - output.round = input.round; - TendermintTypesBlockID.store(input.block_id, output.block_id); - - for (uint256 i4 = 0; i4 < input.signatures.length; i4++) { - output.signatures.push(input.signatures[i4]); - } - } - - //array helpers for Signatures - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addSignatures( - Data memory self, - TendermintTypesCommitSig.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - TendermintTypesCommitSig.Data[] memory tmp = - new TendermintTypesCommitSig.Data[](self.signatures.length + 1); - for (uint256 i; i < self.signatures.length; i++) { - tmp[i] = self.signatures[i]; - } - tmp[self.signatures.length] = value; - self.signatures = 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 TendermintTypesCommit - -library TendermintTypesCommitSig { - //struct definition - struct Data { - TendermintTypesTypesGlobalEnums.BlockIDFlag block_id_flag; - bytes validator_address; - GoogleProtobufTimestamp.Data timestamp; - bytes signature; - } - - // 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_block_id_flag(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_validator_address(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_timestamp(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_signature(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_block_id_flag( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - TendermintTypesTypesGlobalEnums.BlockIDFlag x = - TendermintTypesTypesGlobalEnums.decode_BlockIDFlag(tmp); - r.block_id_flag = 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_validator_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.validator_address = 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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufTimestamp.Data memory x, uint256 sz) = - _decode_GoogleProtobufTimestamp(p, bs); - r.timestamp = 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_signature( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature = 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_GoogleProtobufTimestamp( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufTimestamp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufTimestamp.Data memory r,) = - GoogleProtobufTimestamp._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.block_id_flag) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_block_id_flag = TendermintTypesTypesGlobalEnums - .encode_BlockIDFlag(r.block_id_flag); - pointer += - ProtoBufRuntime._encode_enum(_enum_block_id_flag, pointer, bs); - } - if (r.validator_address.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.validator_address, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufTimestamp._encode_nested(r.timestamp, pointer, bs); - - if (r.signature.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.signature, 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( - TendermintTypesTypesGlobalEnums.encode_BlockIDFlag(r.block_id_flag) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.validator_address.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufTimestamp._estimate(r.timestamp) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.block_id_flag) != 0) { - return false; - } - - if (r.validator_address.length != 0) { - return false; - } - - if (r.signature.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.block_id_flag = input.block_id_flag; - output.validator_address = input.validator_address; - GoogleProtobufTimestamp.store(input.timestamp, output.timestamp); - output.signature = input.signature; - } - - //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 TendermintTypesCommitSig - -library TendermintTypesProposal { - //struct definition - struct Data { - TendermintTypesTypesGlobalEnums.SignedMsgType ty; - int64 height; - int32 round; - int32 pol_round; - TendermintTypesBlockID.Data block_id; - GoogleProtobufTimestamp.Data timestamp; - bytes signature; - } - - // 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_type(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_height(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_round(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_pol_round(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_block_id(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_timestamp(pointer, bs, r); - } else if (fieldId == 7) { - pointer += _read_signature(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_type( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 tmp, uint256 sz) = ProtoBufRuntime._decode_enum(p, bs); - TendermintTypesTypesGlobalEnums.SignedMsgType x = - TendermintTypesTypesGlobalEnums.decode_SignedMsgType(tmp); - r.ty = 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_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(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_round( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.round = 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_pol_round( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int32 x, uint256 sz) = ProtoBufRuntime._decode_int32(p, bs); - r.pol_round = 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_block_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesBlockID.Data memory x, uint256 sz) = - _decode_TendermintTypesBlockID(p, bs); - r.block_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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufTimestamp.Data memory x, uint256 sz) = - _decode_GoogleProtobufTimestamp(p, bs); - r.timestamp = 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_signature( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.signature = 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_TendermintTypesBlockID( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesBlockID.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesBlockID.Data memory r,) = - TendermintTypesBlockID._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_GoogleProtobufTimestamp( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufTimestamp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufTimestamp.Data memory r,) = - GoogleProtobufTimestamp._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.ty) != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - int32 _enum_type = - TendermintTypesTypesGlobalEnums.encode_SignedMsgType(r.ty); - pointer += ProtoBufRuntime._encode_enum(_enum_type, pointer, bs); - } - if (r.height != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.height, pointer, bs); - } - if (r.round != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int32(r.round, pointer, bs); - } - if (r.pol_round != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int32(r.pol_round, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - TendermintTypesBlockID._encode_nested(r.block_id, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - GoogleProtobufTimestamp._encode_nested(r.timestamp, pointer, bs); - - if (r.signature.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 7, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.signature, 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( - TendermintTypesTypesGlobalEnums.encode_SignedMsgType(r.ty) - ); - e += 1 + ProtoBufRuntime._sz_int64(r.height); - e += 1 + ProtoBufRuntime._sz_int32(r.round); - e += 1 + ProtoBufRuntime._sz_int32(r.pol_round); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesBlockID._estimate(r.block_id) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufTimestamp._estimate(r.timestamp) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.signature.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (uint256(r.ty) != 0) { - return false; - } - - if (r.height != 0) { - return false; - } - - if (r.round != 0) { - return false; - } - - if (r.pol_round != 0) { - return false; - } - - if (r.signature.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.ty = input.ty; - output.height = input.height; - output.round = input.round; - output.pol_round = input.pol_round; - TendermintTypesBlockID.store(input.block_id, output.block_id); - GoogleProtobufTimestamp.store(input.timestamp, output.timestamp); - output.signature = input.signature; - } - - //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 TendermintTypesProposal - -library TendermintTypesSignedHeader { - //struct definition - struct Data { - TendermintTypesHeader.Data header; - TendermintTypesCommit.Data commit; - } - - // 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_header(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_commit(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_header( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesHeader.Data memory x, uint256 sz) = - _decode_TendermintTypesHeader(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_commit( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesCommit.Data memory x, uint256 sz) = - _decode_TendermintTypesCommit(p, bs); - r.commit = 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_TendermintTypesHeader( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesHeader.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesHeader.Data memory r,) = - TendermintTypesHeader._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_TendermintTypesCommit( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesCommit.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesCommit.Data memory r,) = - TendermintTypesCommit._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 += TendermintTypesHeader._encode_nested(r.header, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesCommit._encode_nested(r.commit, 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( - TendermintTypesHeader._estimate(r.header) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesCommit._estimate(r.commit) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - TendermintTypesHeader.store(input.header, output.header); - TendermintTypesCommit.store(input.commit, output.commit); - } - - //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 TendermintTypesSignedHeader - -library TendermintTypesLightBlock { - //struct definition - struct Data { - TendermintTypesSignedHeader.Data signed_header; - TendermintTypesValidatorSet.Data validator_set; - } - - // 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_signed_header(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_validator_set(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_signed_header( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesSignedHeader.Data memory x, uint256 sz) = - _decode_TendermintTypesSignedHeader(p, bs); - r.signed_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_validator_set( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesValidatorSet.Data memory x, uint256 sz) = - _decode_TendermintTypesValidatorSet(p, bs); - r.validator_set = 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_TendermintTypesSignedHeader( - uint256 p, - bytes memory bs - ) - internal - pure - returns (TendermintTypesSignedHeader.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesSignedHeader.Data memory r,) = - TendermintTypesSignedHeader._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_TendermintTypesValidatorSet( - uint256 p, - bytes memory bs - ) - internal - pure - returns (TendermintTypesValidatorSet.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesValidatorSet.Data memory r,) = - TendermintTypesValidatorSet._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 += TendermintTypesSignedHeader._encode_nested( - r.signed_header, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesValidatorSet._encode_nested( - r.validator_set, 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( - TendermintTypesSignedHeader._estimate(r.signed_header) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesValidatorSet._estimate(r.validator_set) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - TendermintTypesSignedHeader.store( - input.signed_header, output.signed_header - ); - TendermintTypesValidatorSet.store( - input.validator_set, output.validator_set - ); - } - - //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 TendermintTypesLightBlock - -library TendermintTypesBlockMeta { - //struct definition - struct Data { - TendermintTypesBlockID.Data block_id; - int64 block_size; - TendermintTypesHeader.Data header; - int64 num_txs; - } - - // 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_block_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_block_size(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_header(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_num_txs(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_block_id( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesBlockID.Data memory x, uint256 sz) = - _decode_TendermintTypesBlockID(p, bs); - r.block_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_block_size( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.block_size = 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) { - (TendermintTypesHeader.Data memory x, uint256 sz) = - _decode_TendermintTypesHeader(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_num_txs( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.num_txs = 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_TendermintTypesBlockID( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesBlockID.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesBlockID.Data memory r,) = - TendermintTypesBlockID._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_TendermintTypesHeader( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesHeader.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesHeader.Data memory r,) = - TendermintTypesHeader._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 += - TendermintTypesBlockID._encode_nested(r.block_id, pointer, bs); - - if (r.block_size != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.block_size, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesHeader._encode_nested(r.header, pointer, bs); - - if (r.num_txs != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.num_txs, 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( - TendermintTypesBlockID._estimate(r.block_id) - ); - e += 1 + ProtoBufRuntime._sz_int64(r.block_size); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesHeader._estimate(r.header) - ); - e += 1 + ProtoBufRuntime._sz_int64(r.num_txs); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.block_size != 0) { - return false; - } - - if (r.num_txs != 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 { - TendermintTypesBlockID.store(input.block_id, output.block_id); - output.block_size = input.block_size; - TendermintTypesHeader.store(input.header, output.header); - output.num_txs = input.num_txs; - } - - //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 TendermintTypesBlockMeta - -library TendermintTypesTxProof { - //struct definition - struct Data { - bytes root_hash; - bytes data; - TendermintCryptoProof.Data proof; - } - - // 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_root_hash(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_data(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_proof(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_root_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.root_hash = 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_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 - * @return The number of bytes decoded - */ - function _read_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintCryptoProof.Data memory x, uint256 sz) = - _decode_TendermintCryptoProof(p, bs); - r.proof = 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_TendermintCryptoProof( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintCryptoProof.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintCryptoProof.Data memory r,) = - TendermintCryptoProof._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 (r.root_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.root_hash, pointer, bs); - } - if (r.data.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.data, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintCryptoProof._encode_nested(r.proof, 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.root_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.data.length); - e += 1 - + ProtoBufRuntime._sz_lendelim(TendermintCryptoProof._estimate(r.proof)); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.root_hash.length != 0) { - return false; - } - - if (r.data.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.root_hash = input.root_hash; - output.data = input.data; - TendermintCryptoProof.store(input.proof, output.proof); - } - - //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 TendermintTypesTxProof - -library TendermintTypesTypesGlobalEnums { - //enum definition - // Solidity enum definitions - enum BlockIDFlag { - BLOCK_ID_FLAG_UNKNOWN, - BLOCK_ID_FLAG_ABSENT, - BLOCK_ID_FLAG_COMMIT, - BLOCK_ID_FLAG_NIL - } - - // Solidity enum encoder - function encode_BlockIDFlag(BlockIDFlag x) internal pure returns (int32) { - if (x == BlockIDFlag.BLOCK_ID_FLAG_UNKNOWN) { - return 0; - } - - if (x == BlockIDFlag.BLOCK_ID_FLAG_ABSENT) { - return 1; - } - - if (x == BlockIDFlag.BLOCK_ID_FLAG_COMMIT) { - return 2; - } - - if (x == BlockIDFlag.BLOCK_ID_FLAG_NIL) { - return 3; - } - revert(); - } - - // Solidity enum decoder - function decode_BlockIDFlag(int64 x) internal pure returns (BlockIDFlag) { - if (x == 0) { - return BlockIDFlag.BLOCK_ID_FLAG_UNKNOWN; - } - - if (x == 1) { - return BlockIDFlag.BLOCK_ID_FLAG_ABSENT; - } - - if (x == 2) { - return BlockIDFlag.BLOCK_ID_FLAG_COMMIT; - } - - if (x == 3) { - return BlockIDFlag.BLOCK_ID_FLAG_NIL; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_BlockIDFlag(BlockIDFlag[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_BlockIDFlag(a[i])); - } - return e; - } - - // Solidity enum definitions - enum SignedMsgType { - SIGNED_MSG_TYPE_UNKNOWN, - SIGNED_MSG_TYPE_PREVOTE, - SIGNED_MSG_TYPE_PRECOMMIT, - SIGNED_MSG_TYPE_PROPOSAL - } - - // Solidity enum encoder - function encode_SignedMsgType(SignedMsgType x) - internal - pure - returns (int32) - { - if (x == SignedMsgType.SIGNED_MSG_TYPE_UNKNOWN) { - return 0; - } - - if (x == SignedMsgType.SIGNED_MSG_TYPE_PREVOTE) { - return 1; - } - - if (x == SignedMsgType.SIGNED_MSG_TYPE_PRECOMMIT) { - return 2; - } - - if (x == SignedMsgType.SIGNED_MSG_TYPE_PROPOSAL) { - return 32; - } - revert(); - } - - // Solidity enum decoder - function decode_SignedMsgType(int64 x) - internal - pure - returns (SignedMsgType) - { - if (x == 0) { - return SignedMsgType.SIGNED_MSG_TYPE_UNKNOWN; - } - - if (x == 1) { - return SignedMsgType.SIGNED_MSG_TYPE_PREVOTE; - } - - if (x == 2) { - return SignedMsgType.SIGNED_MSG_TYPE_PRECOMMIT; - } - - if (x == 32) { - return SignedMsgType.SIGNED_MSG_TYPE_PROPOSAL; - } - revert(); - } - - /** - * @dev The estimator for an packed enum array - * @return The number of bytes encoded - */ - function estimate_packed_repeated_SignedMsgType(SignedMsgType[] memory a) - internal - pure - returns (uint256) - { - uint256 e = 0; - for (uint256 i; i < a.length; i++) { - e += ProtoBufRuntime._sz_enum(encode_SignedMsgType(a[i])); - } - return e; - } -} -//library TendermintTypesTypesGlobalEnums diff --git a/evm/contracts/proto/tendermint/types/validator.sol b/evm/contracts/proto/tendermint/types/validator.sol deleted file mode 100644 index 387a08630b..0000000000 --- a/evm/contracts/proto/tendermint/types/validator.sol +++ /dev/null @@ -1,972 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../ProtoBufRuntime.sol"; -import "../../GoogleProtobufAny.sol"; -import "../crypto/keys.sol"; - -library TendermintTypesValidatorSet { - //struct definition - struct Data { - TendermintTypesValidator.Data[] validators; - TendermintTypesValidator.Data proposer; - int64 total_voting_power; - } - - // 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[4] 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_unpacked_repeated_validators( - pointer, bs, nil(), counters - ); - } else if (fieldId == 2) { - pointer += _read_proposer(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_total_voting_power(pointer, bs, r); - } else { - pointer += - ProtoBufRuntime._skip_field_decode(wireType, pointer, bs); - } - } - pointer = offset; - if (counters[1] > 0) { - require(r.validators.length == 0); - r.validators = new TendermintTypesValidator.Data[](counters[1]); - } - - while (pointer < offset + sz) { - (fieldId, wireType, bytesRead) = - ProtoBufRuntime._decode_key(pointer, bs); - pointer += bytesRead; - if (fieldId == 1) { - pointer += - _read_unpacked_repeated_validators(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 - * @param counters The counters for repeated fields - * @return The number of bytes decoded - */ - function _read_unpacked_repeated_validators( - uint256 p, - bytes memory bs, - Data memory r, - uint256[4] memory counters - ) internal pure returns (uint256) { - /** - * if `r` is NULL, then only counting the number of fields. - */ - (TendermintTypesValidator.Data memory x, uint256 sz) = - _decode_TendermintTypesValidator(p, bs); - if (isNil(r)) { - counters[1] += 1; - } else { - r.validators[r.validators.length - counters[1]] = x; - counters[1] -= 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_proposer( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintTypesValidator.Data memory x, uint256 sz) = - _decode_TendermintTypesValidator(p, bs); - r.proposer = 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_total_voting_power( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.total_voting_power = 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_TendermintTypesValidator( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintTypesValidator.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintTypesValidator.Data memory r,) = - TendermintTypesValidator._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.validators.length != 0) { - for (i = 0; i < r.validators.length; i++) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += TendermintTypesValidator._encode_nested( - r.validators[i], pointer, bs - ); - } - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - TendermintTypesValidator._encode_nested(r.proposer, pointer, bs); - - if (r.total_voting_power != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_int64(r.total_voting_power, 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; - for (i = 0; i < r.validators.length; i++) { - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesValidator._estimate(r.validators[i]) - ); - } - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintTypesValidator._estimate(r.proposer) - ); - e += 1 + ProtoBufRuntime._sz_int64(r.total_voting_power); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.validators.length != 0) { - return false; - } - - if (r.total_voting_power != 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 { - for (uint256 i1 = 0; i1 < input.validators.length; i1++) { - output.validators.push(input.validators[i1]); - } - - TendermintTypesValidator.store(input.proposer, output.proposer); - output.total_voting_power = input.total_voting_power; - } - - //array helpers for Validators - /** - * @dev Add value to an array - * @param self The in-memory struct - * @param value The value to add - */ - function addValidators( - Data memory self, - TendermintTypesValidator.Data memory value - ) internal pure { - /** - * First resize the array. Then add the new element to the end. - */ - TendermintTypesValidator.Data[] memory tmp = - new TendermintTypesValidator.Data[](self.validators.length + 1); - for (uint256 i; i < self.validators.length; i++) { - tmp[i] = self.validators[i]; - } - tmp[self.validators.length] = value; - self.validators = 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 TendermintTypesValidatorSet - -library TendermintTypesValidator { - //struct definition - struct Data { - bytes addr; - TendermintCryptoPublicKey.Data pub_key; - int64 voting_power; - int64 proposer_priority; - } - - // 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_address(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_pub_key(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_voting_power(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_proposer_priority(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_address( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.addr = 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_pub_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintCryptoPublicKey.Data memory x, uint256 sz) = - _decode_TendermintCryptoPublicKey(p, bs); - r.pub_key = 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_voting_power( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.voting_power = 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_proposer_priority( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.proposer_priority = 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_TendermintCryptoPublicKey( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintCryptoPublicKey.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintCryptoPublicKey.Data memory r,) = - TendermintCryptoPublicKey._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 (r.addr.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.addr, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - TendermintCryptoPublicKey._encode_nested(r.pub_key, pointer, bs); - - if (r.voting_power != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_int64(r.voting_power, pointer, bs); - } - if (r.proposer_priority != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_int64(r.proposer_priority, 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.addr.length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - TendermintCryptoPublicKey._estimate(r.pub_key) - ); - e += 1 + ProtoBufRuntime._sz_int64(r.voting_power); - e += 1 + ProtoBufRuntime._sz_int64(r.proposer_priority); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.addr.length != 0) { - return false; - } - - if (r.voting_power != 0) { - return false; - } - - if (r.proposer_priority != 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.addr = input.addr; - TendermintCryptoPublicKey.store(input.pub_key, output.pub_key); - output.voting_power = input.voting_power; - output.proposer_priority = input.proposer_priority; - } - - //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 TendermintTypesValidator - -library TendermintTypesSimpleValidator { - //struct definition - struct Data { - TendermintCryptoPublicKey.Data pub_key; - int64 voting_power; - } - - // 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_pub_key(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_voting_power(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_pub_key( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (TendermintCryptoPublicKey.Data memory x, uint256 sz) = - _decode_TendermintCryptoPublicKey(p, bs); - r.pub_key = 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_voting_power( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(p, bs); - r.voting_power = 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_TendermintCryptoPublicKey( - uint256 p, - bytes memory bs - ) internal pure returns (TendermintCryptoPublicKey.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (TendermintCryptoPublicKey.Data memory r,) = - TendermintCryptoPublicKey._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 += - TendermintCryptoPublicKey._encode_nested(r.pub_key, pointer, bs); - - if (r.voting_power != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_int64(r.voting_power, 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( - TendermintCryptoPublicKey._estimate(r.pub_key) - ); - e += 1 + ProtoBufRuntime._sz_int64(r.voting_power); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.voting_power != 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 { - TendermintCryptoPublicKey.store(input.pub_key, output.pub_key); - output.voting_power = input.voting_power; - } - - //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 TendermintTypesSimpleValidator diff --git a/evm/contracts/proto/tendermint/version/types.sol b/evm/contracts/proto/tendermint/version/types.sol deleted file mode 100644 index fd9e741428..0000000000 --- a/evm/contracts/proto/tendermint/version/types.sol +++ /dev/null @@ -1,494 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../ProtoBufRuntime.sol"; -import "../../GoogleProtobufAny.sol"; - -library TendermintVersionApp { - //struct definition - struct Data { - uint64 protocol; - string software; - } - - // 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_protocol(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_software(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_protocol( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.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 - * @return The number of bytes decoded - */ - function _read_software( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs); - r.software = 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.protocol != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.protocol, pointer, bs); - } - if (bytes(r.software).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_string(r.software, 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.protocol); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.software).length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.protocol != 0) { - return false; - } - - if (bytes(r.software).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.protocol = input.protocol; - output.software = input.software; - } - - //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 TendermintVersionApp - -library TendermintVersionConsensus { - //struct definition - struct Data { - uint64 block; - uint64 app; - } - - // 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_block(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_app(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_block( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.block = 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_app( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.app = 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.block != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.block, pointer, bs); - } - if (r.app != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.app, 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.block); - e += 1 + ProtoBufRuntime._sz_uint64(r.app); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.block != 0) { - return false; - } - - if (r.app != 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.block = input.block; - output.app = input.app; - } - - //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 TendermintVersionConsensus diff --git a/evm/contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol b/evm/contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol deleted file mode 100644 index eed1c7b967..0000000000 --- a/evm/contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol +++ /dev/null @@ -1,1679 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../../../../ProtoBufRuntime.sol"; -import "../../../../../GoogleProtobufAny.sol"; -import "../../../../../tendermint/types/types.sol"; -import "../../../../../ibc/core/client/v1/client.sol"; -import "../../../../../ibc/core/commitment/v1/commitment.sol"; - -library UnionIbcLightclientsCometblsV1ClientState { - //struct definition - struct Data { - string chain_id; - uint64 trusting_period; - uint64 unbonding_period; - uint64 max_clock_drift; - IbcCoreClientV1Height.Data frozen_height; - IbcCoreClientV1Height.Data latest_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_chain_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_trusting_period(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_unbonding_period(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_max_clock_drift(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_frozen_height(pointer, bs, r); - } else if (fieldId == 6) { - pointer += _read_latest_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_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_trusting_period( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.trusting_period = 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_unbonding_period( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.unbonding_period = 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_max_clock_drift( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.max_clock_drift = 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_frozen_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.frozen_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_latest_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.latest_height = 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); - } - - // 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.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.trusting_period != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.trusting_period, pointer, bs); - } - if (r.unbonding_period != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.unbonding_period, pointer, bs); - } - if (r.max_clock_drift != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_uint64(r.max_clock_drift, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.frozen_height, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 6, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.latest_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_lendelim(bytes(r.chain_id).length); - e += 1 + ProtoBufRuntime._sz_uint64(r.trusting_period); - e += 1 + ProtoBufRuntime._sz_uint64(r.unbonding_period); - e += 1 + ProtoBufRuntime._sz_uint64(r.max_clock_drift); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.frozen_height) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.latest_height) - ); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.chain_id).length != 0) { - return false; - } - - if (r.trusting_period != 0) { - return false; - } - - if (r.unbonding_period != 0) { - return false; - } - - if (r.max_clock_drift != 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.trusting_period = input.trusting_period; - output.unbonding_period = input.unbonding_period; - output.max_clock_drift = input.max_clock_drift; - IbcCoreClientV1Height.store(input.frozen_height, output.frozen_height); - IbcCoreClientV1Height.store(input.latest_height, output.latest_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 UnionIbcLightclientsCometblsV1ClientState - -library UnionIbcLightclientsCometblsV1ConsensusState { - //struct definition - struct Data { - uint64 timestamp; - IbcCoreCommitmentV1MerkleRoot.Data root; - bytes next_validators_hash; - } - - // 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_timestamp(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_root(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_next_validators_hash(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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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_root( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreCommitmentV1MerkleRoot.Data memory x, uint256 sz) = - _decode_IbcCoreCommitmentV1MerkleRoot(p, bs); - r.root = 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_next_validators_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.next_validators_hash = 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_IbcCoreCommitmentV1MerkleRoot( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreCommitmentV1MerkleRoot.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreCommitmentV1MerkleRoot.Data memory r,) = - IbcCoreCommitmentV1MerkleRoot._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 (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.timestamp, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreCommitmentV1MerkleRoot._encode_nested(r.root, pointer, bs); - - if (r.next_validators_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.next_validators_hash, 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.timestamp); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreCommitmentV1MerkleRoot._estimate(r.root) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.next_validators_hash.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.timestamp != 0) { - return false; - } - - if (r.next_validators_hash.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.timestamp = input.timestamp; - IbcCoreCommitmentV1MerkleRoot.store(input.root, output.root); - output.next_validators_hash = input.next_validators_hash; - } - - //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 UnionIbcLightclientsCometblsV1ConsensusState - -library UnionIbcLightclientsCometblsV1Misbehaviour { - //struct definition - struct Data { - UnionIbcLightclientsCometblsV1Header.Data header_1; - UnionIbcLightclientsCometblsV1Header.Data header_2; - } - - // 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_header_1(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_header_2(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_header_1( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (UnionIbcLightclientsCometblsV1Header.Data memory x, uint256 sz) = - _decode_UnionIbcLightclientsCometblsV1Header(p, bs); - r.header_1 = 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_2( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (UnionIbcLightclientsCometblsV1Header.Data memory x, uint256 sz) = - _decode_UnionIbcLightclientsCometblsV1Header(p, bs); - r.header_2 = 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_UnionIbcLightclientsCometblsV1Header( - uint256 p, - bytes memory bs - ) - internal - pure - returns (UnionIbcLightclientsCometblsV1Header.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (UnionIbcLightclientsCometblsV1Header.Data memory r,) = - UnionIbcLightclientsCometblsV1Header._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 += UnionIbcLightclientsCometblsV1Header._encode_nested( - r.header_1, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += UnionIbcLightclientsCometblsV1Header._encode_nested( - r.header_2, 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( - UnionIbcLightclientsCometblsV1Header._estimate(r.header_1) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - UnionIbcLightclientsCometblsV1Header._estimate(r.header_2) - ); - return e; - } - - // empty checker - - function _empty(Data memory) 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 { - UnionIbcLightclientsCometblsV1Header.store( - input.header_1, output.header_1 - ); - UnionIbcLightclientsCometblsV1Header.store( - input.header_2, output.header_2 - ); - } - - //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 UnionIbcLightclientsCometblsV1Misbehaviour - -library UnionIbcLightclientsCometblsV1LightHeader { - //struct definition - struct Data { - int64 height; - GoogleProtobufTimestamp.Data time; - bytes validators_hash; - bytes next_validators_hash; - bytes app_hash; - } - - // 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_time(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_validators_hash(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_next_validators_hash(pointer, bs, r); - } else if (fieldId == 5) { - pointer += _read_app_hash(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) { - (int64 x, uint256 sz) = ProtoBufRuntime._decode_int64(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_time( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (GoogleProtobufTimestamp.Data memory x, uint256 sz) = - _decode_GoogleProtobufTimestamp(p, bs); - r.time = 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_validators_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.validators_hash = 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_next_validators_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.next_validators_hash = 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_app_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.app_hash = 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_GoogleProtobufTimestamp( - uint256 p, - bytes memory bs - ) internal pure returns (GoogleProtobufTimestamp.Data memory, uint256) { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (GoogleProtobufTimestamp.Data memory r,) = - GoogleProtobufTimestamp._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 (r.height != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_int64(r.height, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += GoogleProtobufTimestamp._encode_nested(r.time, pointer, bs); - - if (r.validators_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.validators_hash, pointer, bs); - } - if (r.next_validators_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.next_validators_hash, pointer, bs - ); - } - if (r.app_hash.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 5, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes(r.app_hash, 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_int64(r.height); - e += 1 - + ProtoBufRuntime._sz_lendelim( - GoogleProtobufTimestamp._estimate(r.time) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.validators_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.next_validators_hash.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.app_hash.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.height != 0) { - return false; - } - - if (r.validators_hash.length != 0) { - return false; - } - - if (r.next_validators_hash.length != 0) { - return false; - } - - if (r.app_hash.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.height = input.height; - GoogleProtobufTimestamp.store(input.time, output.time); - output.validators_hash = input.validators_hash; - output.next_validators_hash = input.next_validators_hash; - output.app_hash = input.app_hash; - } - - //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 UnionIbcLightclientsCometblsV1LightHeader - -library UnionIbcLightclientsCometblsV1Header { - //struct definition - struct Data { - UnionIbcLightclientsCometblsV1LightHeader.Data signed_header; - IbcCoreClientV1Height.Data trusted_height; - bytes zero_knowledge_proof; - } - - // 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_signed_header(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_trusted_height(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_zero_knowledge_proof(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_signed_header( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (UnionIbcLightclientsCometblsV1LightHeader.Data memory x, uint256 sz) = - _decode_UnionIbcLightclientsCometblsV1LightHeader(p, bs); - r.signed_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_trusted_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.trusted_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_zero_knowledge_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.zero_knowledge_proof = 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_UnionIbcLightclientsCometblsV1LightHeader( - uint256 p, - bytes memory bs - ) - internal - pure - returns (UnionIbcLightclientsCometblsV1LightHeader.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (UnionIbcLightclientsCometblsV1LightHeader.Data memory r,) = - UnionIbcLightclientsCometblsV1LightHeader._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; - - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += UnionIbcLightclientsCometblsV1LightHeader._encode_nested( - r.signed_header, pointer, bs - ); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.trusted_height, pointer, bs); - - if (r.zero_knowledge_proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += ProtoBufRuntime._encode_bytes( - r.zero_knowledge_proof, 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( - UnionIbcLightclientsCometblsV1LightHeader._estimate(r.signed_header) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.trusted_height) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.zero_knowledge_proof.length); - return e; - } - - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.zero_knowledge_proof.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 { - UnionIbcLightclientsCometblsV1LightHeader.store( - input.signed_header, output.signed_header - ); - IbcCoreClientV1Height.store(input.trusted_height, output.trusted_height); - IbcCoreClientV1Height.store(input.trusted_height, output.trusted_height); - output.zero_knowledge_proof = input.zero_knowledge_proof; - } - - //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 UnionIbcLightclientsCometblsV1Header diff --git a/evm/contracts/proto/union/ibc/lightclients/cosmosincosmos/v1/cosmosincosmos.sol b/evm/contracts/proto/union/ibc/lightclients/cosmosincosmos/v1/cosmosincosmos.sol deleted file mode 100644 index febec06614..0000000000 --- a/evm/contracts/proto/union/ibc/lightclients/cosmosincosmos/v1/cosmosincosmos.sol +++ /dev/null @@ -1,927 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity ^0.8.23; - -import "../../../../../ProtoBufRuntime.sol"; -import "../../../../../GoogleProtobufAny.sol"; -import "../../../../../ibc/core/client/v1/client.sol"; -import "../../../../../ibc/core/commitment/v1/commitment.sol"; - -library UnionIbcLightclientsCosmosincosmosV1ClientState { - //struct definition - struct Data { - string l2_chain_id; - string l1_client_id; - string l2_client_id; - IbcCoreClientV1Height.Data latest_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_l2_chain_id(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_l1_client_id(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_l2_client_id(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_latest_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_l2_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.l2_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_l1_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.l1_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_l2_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.l2_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_latest_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.latest_height = 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); - } - - // 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.l2_chain_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.l2_chain_id, pointer, bs); - } - if (bytes(r.l1_client_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.l1_client_id, pointer, bs); - } - if (bytes(r.l2_client_id).length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_string(r.l2_client_id, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.latest_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_lendelim(bytes(r.l2_chain_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.l1_client_id).length); - e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.l2_client_id).length); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.latest_height) - ); - return e; - } - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (bytes(r.l2_chain_id).length != 0) { - return false; - } - - if (bytes(r.l1_client_id).length != 0) { - return false; - } - - if (bytes(r.l2_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.l2_chain_id = input.l2_chain_id; - output.l1_client_id = input.l1_client_id; - output.l2_client_id = input.l2_client_id; - IbcCoreClientV1Height.store(input.latest_height, output.latest_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 UnionIbcLightclientsCosmosincosmosV1ClientState - -library UnionIbcLightclientsCosmosincosmosV1ConsensusState { - //struct definition - struct Data { - uint64 timestamp; - IbcCoreCommitmentV1MerkleRoot.Data app_hash; - } - - // 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_timestamp(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_app_hash(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_timestamp( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (uint64 x, uint256 sz) = ProtoBufRuntime._decode_uint64(p, bs); - r.timestamp = 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_app_hash( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreCommitmentV1MerkleRoot.Data memory x, uint256 sz) = - _decode_IbcCoreCommitmentV1MerkleRoot(p, bs); - r.app_hash = 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_IbcCoreCommitmentV1MerkleRoot( - uint256 p, - bytes memory bs - ) - internal - pure - returns (IbcCoreCommitmentV1MerkleRoot.Data memory, uint256) - { - uint256 pointer = p; - (uint256 sz, uint256 bytesRead) = - ProtoBufRuntime._decode_varint(pointer, bs); - pointer += bytesRead; - (IbcCoreCommitmentV1MerkleRoot.Data memory r,) = - IbcCoreCommitmentV1MerkleRoot._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 (r.timestamp != 0) { - pointer += ProtoBufRuntime._encode_key( - 1, ProtoBufRuntime.WireType.Varint, pointer, bs - ); - pointer += ProtoBufRuntime._encode_uint64(r.timestamp, pointer, bs); - } - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += IbcCoreCommitmentV1MerkleRoot._encode_nested( - r.app_hash, 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.timestamp); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreCommitmentV1MerkleRoot._estimate(r.app_hash) - ); - return e; - } - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.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.timestamp = input.timestamp; - IbcCoreCommitmentV1MerkleRoot.store(input.app_hash, output.app_hash); - } - - //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 UnionIbcLightclientsCosmosincosmosV1ConsensusState - -library UnionIbcLightclientsCosmosincosmosV1Header { - //struct definition - struct Data { - IbcCoreClientV1Height.Data l1_height; - IbcCoreClientV1Height.Data l2_height; - bytes l2_inclusion_proof; - bytes l2_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_l1_height(pointer, bs, r); - } else if (fieldId == 2) { - pointer += _read_l2_height(pointer, bs, r); - } else if (fieldId == 3) { - pointer += _read_l2_inclusion_proof(pointer, bs, r); - } else if (fieldId == 4) { - pointer += _read_l2_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_l1_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.l1_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_l2_height( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (IbcCoreClientV1Height.Data memory x, uint256 sz) = - _decode_IbcCoreClientV1Height(p, bs); - r.l2_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_l2_inclusion_proof( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.l2_inclusion_proof = 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_l2_consensus_state( - uint256 p, - bytes memory bs, - Data memory r - ) internal pure returns (uint256) { - (bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs); - r.l2_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); - } - - // 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.l1_height, pointer, bs); - - pointer += ProtoBufRuntime._encode_key( - 2, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - IbcCoreClientV1Height._encode_nested(r.l2_height, pointer, bs); - - if (r.l2_inclusion_proof.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 3, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.l2_inclusion_proof, pointer, bs); - } - if (r.l2_consensus_state.length != 0) { - pointer += ProtoBufRuntime._encode_key( - 4, ProtoBufRuntime.WireType.LengthDelim, pointer, bs - ); - pointer += - ProtoBufRuntime._encode_bytes(r.l2_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.l1_height) - ); - e += 1 - + ProtoBufRuntime._sz_lendelim( - IbcCoreClientV1Height._estimate(r.l2_height) - ); - e += 1 + ProtoBufRuntime._sz_lendelim(r.l2_inclusion_proof.length); - e += 1 + ProtoBufRuntime._sz_lendelim(r.l2_consensus_state.length); - return e; - } - // empty checker - - function _empty(Data memory r) internal pure returns (bool) { - if (r.l2_inclusion_proof.length != 0) { - return false; - } - - if (r.l2_consensus_state.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 { - IbcCoreClientV1Height.store(input.l1_height, output.l1_height); - IbcCoreClientV1Height.store(input.l2_height, output.l2_height); - output.l2_inclusion_proof = input.l2_inclusion_proof; - output.l2_consensus_state = input.l2_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 UnionIbcLightclientsCosmosincosmosV1Header diff --git a/evm/evm.nix b/evm/evm.nix index 04c93aebcb..8e189de3ef 100644 --- a/evm/evm.nix +++ b/evm/evm.nix @@ -32,8 +32,8 @@ _: { forge-std = pkgs.fetchFromGitHub { owner = "foundry-rs"; repo = "forge-std"; - rev = "v1.8.1"; - hash = "sha256-s/J7odpWysj4U93knIRA28aZqXworZH6IVIjIXD78Yc="; + rev = "v1.9.3"; + hash = "sha256-v9aFV4TQqbYPNBSRt4QLZMD85fIXTtBQ8rGYPRw2qmE="; fetchSubmodules = true; }; openzeppelin = pkgs.fetchFromGitHub { @@ -137,25 +137,35 @@ _: { }; # Foundry FS permissions must be explicitly set in the config file foundryConfig = pkgs.writeTextDir "/foundry.toml" '' + [profile.default.optimizer_details] + cse = true + constantOptimizer = true + yul = true + [profile.default] fs_permissions = [{ access = "read", path = "./"}] libs = ["libs"] gas_reports = ["*"] via_ir = true ast = true + optimizer = true + optimizer_runs = 1_000 [profile.script] src = "scripts" bytecode_hash = "none" cbor_metadata = false sparse_mode = false - optimizer = true - optimizer_runs = 10_000_000 [profile.test] test = "tests/src" - optimizer = false ''; + compilers = pkgs.linkFarm "evm-libraries" [ + { + name = ".svm/${pkgs.solc.version}/solc-${pkgs.solc.version}"; + path = "${pkgs.solc}/bin/solc"; + } + ]; wrappedForge = pkgs.symlinkJoin { name = "forge"; paths = [ pkgs.foundry-bin ]; @@ -163,7 +173,7 @@ _: { postBuild = '' wrapProgram $out/bin/forge \ --append-flags "--offline --no-auto-detect" \ - --set PATH ${pkgs.lib.makeBinPath [ pkgs.solc ]} \ + --set HOME ${compilers} \ --set SSL_CERT_FILE "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" \ --set FOUNDRY_CONFIG "${foundryConfig}/foundry.toml" ''; @@ -419,7 +429,10 @@ _: { pkgs.stdenv.mkDerivation { name = "evm-contracts"; src = evmSources; - buildInputs = [ wrappedForge ]; + buildInputs = [ + wrappedForge + pkgs.solc + ]; buildPhase = '' forge --version FOUNDRY_PROFILE=script forge build --sizes @@ -451,7 +464,6 @@ _: { # '${evmSources}/contracts/core/DevnetIBCHandlerInit.sol' \ # '${evmSources}/contracts/core/DevnetOwnableIBCHandler.sol' \ # '${evmSources}/contracts/core/OwnableIBCHandler.sol' \ - # '${evmSources}/contracts/core/25-handler/IBCQuerier.sol' \ # '${evmSources}/contracts/core/24-host/IBCCommitment.sol' \ # '${evmSources}/tests/*' # genhtml lcov.info.pruned -o $out --branch-coverage @@ -483,7 +495,7 @@ _: { ${contracts}/out/IBCPacket.sol/IBCPacket.json \ ${contracts}/out/IBCConnection.sol/IBCConnection.json \ ${contracts}/out/OwnableIBCHandler.sol/OwnableIBCHandler.json \ - ${contracts}/out/IBCChannelHandshake.sol/IBCChannelHandshake.json > ibc-handler.json + ${contracts}/out/IBCChannel.sol/IBCChannelHandshake.json > ibc-handler.json jq --compact-output --slurp 'map(.abi) | add' \ ${contracts}/out/Relay.sol/IRelay.json \ diff --git a/evm/scripts/Deploy.s.sol b/evm/scripts/Deploy.s.sol index d734034392..57253cc93e 100644 --- a/evm/scripts/Deploy.s.sol +++ b/evm/scripts/Deploy.s.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.8.23; +pragma solidity ^0.8.27; import "forge-std/Vm.sol"; import "forge-std/Script.sol"; @@ -7,15 +7,11 @@ import "@openzeppelin-foundry-upgradeable/Upgrades.sol"; import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol"; import "@openzeppelin/access/Ownable.sol"; -import "../contracts/Glue.sol"; import "../contracts/Multicall.sol"; -import "../contracts/core/02-client/IBCClient.sol"; -import "../contracts/core/03-connection/IBCConnection.sol"; -import "../contracts/core/04-channel/IBCChannelHandshake.sol"; -import "../contracts/core/04-channel/IBCPacket.sol"; import "../contracts/core/OwnableIBCHandler.sol"; -import "../contracts/clients/CometblsClientV2.sol"; -import "../contracts/clients/CosmosInCosmosClient.sol"; +import "../contracts/clients/CometblsClient.sol"; +import {CosmosInCosmosClient} from + "../contracts/clients/CosmosInCosmosClient.sol"; import "../contracts/apps/ucs/01-relay/Relay.sol"; import "../contracts/apps/ucs/02-nft/NFT.sol"; import "../contracts/lib/Hex.sol"; @@ -53,7 +49,9 @@ library LIB { string constant NAMESPACE = "lib"; string constant MULTICALL = "multicall"; - function make(string memory lib) internal pure returns (string memory) { + function make( + string memory lib + ) internal pure returns (string memory) { return string(abi.encodePacked(NAMESPACE, "/", lib)); } } @@ -66,11 +64,9 @@ library LightClients { string constant NAMESPACE = "lightclients"; string constant COMETBLS = "cometbls"; - function make(string memory lightClient) - internal - pure - returns (string memory) - { + function make( + string memory lightClient + ) internal pure returns (string memory) { return string(abi.encodePacked(NAMESPACE, "/", lightClient)); } } @@ -81,11 +77,9 @@ library Protocols { string constant UCS01 = "ucs01"; string constant UCS02 = "ucs02"; - function make(string memory protocol) - internal - pure - returns (string memory) - { + function make( + string memory protocol + ) internal pure returns (string memory) { return string(abi.encodePacked(NAMESPACE, "/", protocol)); } } @@ -123,22 +117,15 @@ abstract contract UnionScript is UnionBase { ); } - function deployIBCHandler(address owner) internal returns (IBCHandler) { + function deployIBCHandler( + address owner + ) internal returns (IBCHandler) { return IBCHandler( deploy( IBC.BASED, abi.encode( address(new OwnableIBCHandler()), - abi.encodeCall( - IBCHandler.initialize, - ( - address(new IBCClient()), - address(new IBCConnection()), - address(new IBCChannelHandshake()), - address(new IBCPacket()), - owner - ) - ) + abi.encodeCall(IBCHandler.initialize, (owner)) ) ) ); @@ -191,7 +178,9 @@ abstract contract UnionScript is UnionBase { ); } - function deployIBC(address owner) + function deployIBC( + address owner + ) internal returns (IBCHandler, CometblsClient, UCS01Relay, UCS02NFT, Multicall) { @@ -258,7 +247,7 @@ contract DeployIBC is UnionScript { UCS02NFT nft, Multicall multicall ) = deployIBC(vm.addr(privateKey)); - handler.registerClient(LightClients.COMETBLS, client); + handler.registerClient(keccak256(bytes(LightClients.COMETBLS)), client); vm.stopBroadcast(); } @@ -285,7 +274,7 @@ contract DeployDeployerAndIBC is UnionScript { UCS02NFT nft, Multicall multicall ) = deployIBC(vm.addr(privateKey)); - handler.registerClient(LightClients.COMETBLS, client); + handler.registerClient(keccak256(bytes(LightClients.COMETBLS)), client); vm.stopBroadcast(); @@ -310,7 +299,9 @@ contract GetDeployed is Script { sender = vm.envAddress("SENDER"); } - function getDeployed(string memory salt) internal view returns (address) { + function getDeployed( + string memory salt + ) internal view returns (address) { return CREATE3.getDeployed( keccak256(abi.encodePacked(sender.toHexString(), "/", salt)), deployer @@ -352,7 +343,9 @@ contract DryUpgradeUCS01 is Script { owner = vm.envAddress("OWNER"); } - function getDeployed(string memory salt) internal returns (address) { + function getDeployed( + string memory salt + ) internal returns (address) { return CREATE3.getDeployed( keccak256(abi.encodePacked(sender.toHexString(), "/", salt)), deployer @@ -381,7 +374,9 @@ contract UpgradeUCS01 is Script { privateKey = vm.envUint("PRIVATE_KEY"); } - function getDeployed(string memory salt) internal returns (address) { + function getDeployed( + string memory salt + ) internal returns (address) { return CREATE3.getDeployed( keccak256(abi.encodePacked(sender.toHexString(), "/", salt)), deployer @@ -413,7 +408,9 @@ contract DryUpgradeIBCHandler is Script { owner = vm.envAddress("OWNER"); } - function getDeployed(string memory salt) internal returns (address) { + function getDeployed( + string memory salt + ) internal returns (address) { return CREATE3.getDeployed( keccak256(abi.encodePacked(sender.toHexString(), "/", salt)), deployer @@ -425,20 +422,9 @@ contract DryUpgradeIBCHandler is Script { console.log( string(abi.encodePacked("IBCHandler: ", handler.toHexString())) ); - address newHandlerImplementation = address(new OwnableIBCHandler()); - bytes memory upgradeImplsCall = abi.encodeCall( - IBCHandler.upgradeImpls, - ( - address(new IBCClient()), - address(new IBCConnection()), - address(new IBCChannelHandshake()), - address(new IBCPacket()) - ) - ); + address newImplementation = address(new OwnableIBCHandler()); vm.prank(owner); - IBCHandler(handler).upgradeToAndCall( - newHandlerImplementation, upgradeImplsCall - ); + IBCHandler(handler).upgradeToAndCall(newImplementation, new bytes(0)); } } @@ -455,7 +441,9 @@ contract UpgradeIBCHandler is Script { privateKey = vm.envUint("PRIVATE_KEY"); } - function getDeployed(string memory salt) internal returns (address) { + function getDeployed( + string memory salt + ) internal returns (address) { return CREATE3.getDeployed( keccak256(abi.encodePacked(sender.toHexString(), "/", salt)), deployer @@ -468,19 +456,8 @@ contract UpgradeIBCHandler is Script { string(abi.encodePacked("IBCHandler: ", handler.toHexString())) ); vm.startBroadcast(privateKey); - address newHandlerImplementation = address(new OwnableIBCHandler()); - IBCHandler(handler).upgradeToAndCall( - newHandlerImplementation, - abi.encodeCall( - IBCHandler.upgradeImpls, - ( - address(new IBCClient()), - address(new IBCConnection()), - address(new IBCChannelHandshake()), - address(new IBCPacket()) - ) - ) - ); + address newImplementation = address(new OwnableIBCHandler()); + IBCHandler(handler).upgradeToAndCall(newImplementation, new bytes(0)); vm.stopBroadcast(); } } diff --git a/evm/tests/src/02-client/IBCClient.t.sol b/evm/tests/src/02-client/IBCClient.t.sol new file mode 100644 index 0000000000..1bc5e535b2 --- /dev/null +++ b/evm/tests/src/02-client/IBCClient.t.sol @@ -0,0 +1,150 @@ +pragma solidity ^0.8.27; + +import "forge-std/Test.sol"; + +import "../core/IBCHandler.sol"; +import "../core/LightClient.sol"; + +import "../../../contracts/core/25-handler/IBCMsgs.sol"; + +contract IBCClientTests is Test { + TestIBCHandler handler; + TestLightClient lightClient; + + function setUp() public { + handler = new TestIBCHandler(); + lightClient = new TestLightClient(); + } + + function test_registerClient_ok(bytes32 typ, address impl) public { + vm.pauseGasMetering(); + vm.assume(impl != address(0)); + vm.expectEmit(); + emit IBCClientLib.ClientRegistered(typ, impl); + vm.resumeGasMetering(); + handler.registerClient(typ, ILightClient(impl)); + } + + function test_registerClient_alreadyRegistered( + bytes32 typ, + address impl + ) public { + vm.assume(impl != address(0)); + vm.expectEmit(); + emit IBCClientLib.ClientRegistered(typ, impl); + handler.registerClient(typ, ILightClient(impl)); + vm.expectRevert(IBCClientLib.ErrClientTypeAlreadyExists.selector); + handler.registerClient(typ, ILightClient(impl)); + } + + function test_createClient_ok( + IBCMsgs.MsgCreateClient calldata msg_ + ) public { + vm.pauseGasMetering(); + handler.registerClient(msg_.clientType, lightClient); + vm.expectEmit(); + emit IBCClientLib.ClientCreated(msg_.clientType, 0); + vm.resumeGasMetering(); + handler.createClient(msg_); + } + + function test_createClient_ko( + IBCMsgs.MsgCreateClient calldata msg_ + ) public { + lightClient.setRevertCreate(true); + handler.registerClient(msg_.clientType, lightClient); + vm.expectRevert(); + handler.createClient(msg_); + } + + function test_createClient_commitmentsSaved( + IBCMsgs.MsgCreateClient calldata msg_ + ) public { + vm.pauseGasMetering(); + handler.registerClient(msg_.clientType, lightClient); + vm.resumeGasMetering(); + uint32 clientId = handler.createClient(msg_); + assertEq( + handler.commitments( + IBCCommitment.clientStateCommitmentKey(clientId) + ), + keccak256(msg_.clientStateBytes) + ); + assertEq( + handler.commitments( + IBCCommitment.consensusStateCommitmentKey(clientId, 0) + ), + keccak256(msg_.consensusStateBytes) + ); + } + + function test_updateClient_ok( + IBCMsgs.MsgCreateClient calldata msg_, + bytes calldata clientMessage, + address relayer + ) public { + vm.pauseGasMetering(); + handler.registerClient(msg_.clientType, lightClient); + uint32 clientId = handler.createClient(msg_); + vm.expectEmit(); + emit IBCClientLib.ClientUpdated(0, 1); + vm.resumeGasMetering(); + handler.updateClient( + IBCMsgs.MsgUpdateClient({ + clientId: clientId, + clientMessage: clientMessage, + relayer: relayer + }) + ); + } + + function test_updateClient_ko( + IBCMsgs.MsgCreateClient calldata msg_, + bytes calldata clientMessage, + address relayer + ) public { + vm.pauseGasMetering(); + lightClient.setRevertUpdate(true); + handler.registerClient(msg_.clientType, lightClient); + uint32 clientId = handler.createClient(msg_); + vm.resumeGasMetering(); + vm.expectRevert(); + handler.updateClient( + IBCMsgs.MsgUpdateClient({ + clientId: clientId, + clientMessage: clientMessage, + relayer: relayer + }) + ); + } + + function test_updateClient_commitmentsSaved( + IBCMsgs.MsgCreateClient calldata msg_, + bytes calldata clientMessage, + address relayer + ) public { + vm.pauseGasMetering(); + handler.registerClient(msg_.clientType, lightClient); + uint32 clientId = handler.createClient(msg_); + vm.resumeGasMetering(); + handler.updateClient( + IBCMsgs.MsgUpdateClient({ + clientId: clientId, + clientMessage: clientMessage, + relayer: relayer + }) + ); + assertEq( + handler.commitments( + IBCCommitment.clientStateCommitmentKey(clientId) + ), + keccak256(msg_.clientStateBytes) + ); + assertEq( + handler.commitments( + IBCCommitment.consensusStateCommitmentKey(clientId, 1) + ), + keccak256(clientMessage) + ); + } +} diff --git a/evm/tests/src/02-client/IBCHeight.t.sol b/evm/tests/src/02-client/IBCHeight.t.sol deleted file mode 100644 index 54a5c27695..0000000000 --- a/evm/tests/src/02-client/IBCHeight.t.sol +++ /dev/null @@ -1,205 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; - -import {IBCHeight} from "../../../contracts/core/02-client/IBCHeight.sol"; -import {IbcCoreClientV1Height} from - "../../../contracts/proto/ibc/core/client/v1/client.sol"; - -// Required to have coverage counted. -contract IBCHeightProxy { - function toUint128(IbcCoreClientV1Height.Data memory self) - public - pure - returns (uint128) - { - return IBCHeight.toUint128(self); - } - - function fromUint128(uint128 composite) - public - pure - returns (IbcCoreClientV1Height.Data memory) - { - return IBCHeight.fromUint128(composite); - } - - function isZero(IbcCoreClientV1Height.Data memory self) - public - pure - returns (bool) - { - return IBCHeight.isZero(self); - } - - function lt( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) public pure returns (bool) { - return IBCHeight.lt(self, other); - } - - function lte( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) public pure returns (bool) { - return IBCHeight.lte(self, other); - } - - function eq( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) public pure returns (bool) { - return IBCHeight.eq(self, other); - } - - function gt( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) public pure returns (bool) { - return IBCHeight.gt(self, other); - } - - function gte( - IbcCoreClientV1Height.Data memory self, - IbcCoreClientV1Height.Data memory other - ) public pure returns (bool) { - return IBCHeight.gte(self, other); - } -} - -contract IBCHeightTests is Test { - IBCHeightProxy proxy; - - constructor() { - proxy = new IBCHeightProxy(); - } - - function test_toUint128_fromUint128_iso( - uint64 revisionNumber, - uint64 revisionHeight - ) public view { - IbcCoreClientV1Height.Data memory height = IbcCoreClientV1Height.Data({ - revision_number: revisionNumber, - revision_height: revisionHeight - }); - assertTrue(proxy.eq(height, proxy.fromUint128(proxy.toUint128(height)))); - } - - function test_isZero() public view { - assertTrue( - proxy.isZero( - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: 0 - }) - ) - ); - } - - function test_eq( - uint64 revisionNumber, - uint64 revisionHeight - ) public view { - assertTrue( - proxy.eq( - IbcCoreClientV1Height.Data({ - revision_number: revisionNumber, - revision_height: revisionHeight - }), - IbcCoreClientV1Height.Data({ - revision_number: revisionNumber, - revision_height: revisionHeight - }) - ) - ); - } - - function test_lt( - uint64 revisionNumberA, - uint64 revisionHeightA, - uint64 revisionNumberB, - uint64 revisionHeightB - ) public view { - vm.assume(revisionNumberB <= revisionNumberA); - vm.assume(revisionHeightB < revisionHeightA); - assertTrue( - proxy.lt( - IbcCoreClientV1Height.Data({ - revision_number: revisionNumberB, - revision_height: revisionHeightB - }), - IbcCoreClientV1Height.Data({ - revision_number: revisionNumberA, - revision_height: revisionHeightA - }) - ) - ); - } - - function test_lte( - uint64 revisionNumberA, - uint64 revisionHeightA, - uint64 revisionNumberB, - uint64 revisionHeightB - ) public view { - vm.assume(revisionNumberB <= revisionNumberA); - vm.assume(revisionHeightB <= revisionHeightA); - assertTrue( - proxy.lte( - IbcCoreClientV1Height.Data({ - revision_number: revisionNumberB, - revision_height: revisionHeightB - }), - IbcCoreClientV1Height.Data({ - revision_number: revisionNumberA, - revision_height: revisionHeightA - }) - ) - ); - } - - function test_gt( - uint64 revisionNumberA, - uint64 revisionHeightA, - uint64 revisionNumberB, - uint64 revisionHeightB - ) public view { - vm.assume(revisionNumberB >= revisionNumberA); - vm.assume(revisionHeightB > revisionHeightA); - assertTrue( - proxy.gt( - IbcCoreClientV1Height.Data({ - revision_number: revisionNumberB, - revision_height: revisionHeightB - }), - IbcCoreClientV1Height.Data({ - revision_number: revisionNumberA, - revision_height: revisionHeightA - }) - ) - ); - } - - function test_gte( - uint64 revisionNumberA, - uint64 revisionHeightA, - uint64 revisionNumberB, - uint64 revisionHeightB - ) public view { - vm.assume(revisionNumberB >= revisionNumberA); - vm.assume(revisionHeightB >= revisionHeightA); - assertTrue( - proxy.gte( - IbcCoreClientV1Height.Data({ - revision_number: revisionNumberB, - revision_height: revisionHeightB - }), - IbcCoreClientV1Height.Data({ - revision_number: revisionNumberA, - revision_height: revisionHeightA - }) - ) - ); - } -} diff --git a/evm/tests/src/03-connection/IBCConnection.t.sol b/evm/tests/src/03-connection/IBCConnection.t.sol new file mode 100644 index 0000000000..10417f1bc8 --- /dev/null +++ b/evm/tests/src/03-connection/IBCConnection.t.sol @@ -0,0 +1,233 @@ +pragma solidity ^0.8.27; + +import "forge-std/Test.sol"; + +import "../core/IBCHandler.sol"; +import "../core/LightClient.sol"; + +contract IBCConnectionTests is Test { + bytes32 public constant CLIENT_TYPE = keccak256("zkgm"); + + TestIBCHandler handler; + TestLightClient lightClient; + uint32 clientId; + + function setUp() public { + handler = new TestIBCHandler(); + lightClient = new TestLightClient(); + handler.registerClient(CLIENT_TYPE, lightClient); + clientId = handler.createClient( + IBCMsgs.MsgCreateClient({ + clientType: CLIENT_TYPE, + clientStateBytes: hex"CADEBABE", + consensusStateBytes: hex"DEADC0DE", + relayer: address(this) + }) + ); + } + + function test_connectionOpenInit_ok( + IBCMsgs.MsgConnectionOpenInit calldata msg_ + ) public { + vm.pauseGasMetering(); + vm.expectEmit(); + emit IBCConnectionLib.ConnectionOpenInit( + 0, msg_.clientId, msg_.counterparty.clientId + ); + vm.resumeGasMetering(); + handler.connectionOpenInit(msg_); + } + + function test_connectionOpenInit_commitmentSaved( + IBCMsgs.MsgConnectionOpenInit calldata msg_ + ) public { + uint32 connectionId = handler.connectionOpenInit(msg_); + assertEq( + handler.commitments( + IBCCommitment.connectionCommitmentKey(connectionId) + ), + keccak256( + abi.encode( + IBCConnection({ + clientId: msg_.clientId, + state: IBCConnectionState.Init, + counterparty: msg_.counterparty + }) + ) + ) + ); + } + + function test_connectionOpenTry_ok( + IBCMsgs.MsgConnectionOpenTry memory msg_ + ) public { + vm.pauseGasMetering(); + msg_.clientId = clientId; + lightClient.pushValidMembership(); + vm.expectEmit(); + emit IBCConnectionLib.ConnectionOpenTry( + 0, + msg_.clientId, + msg_.counterparty.clientId, + msg_.counterparty.connectionId + ); + vm.resumeGasMetering(); + handler.connectionOpenTry(msg_); + } + + function test_connectionOpenTry_clientNotFound( + IBCMsgs.MsgConnectionOpenTry memory msg_ + ) public { + vm.assume(msg_.clientId != clientId); + vm.expectRevert(IBCStoreLib.ErrClientNotFound.selector); + handler.connectionOpenTry(msg_); + } + + function test_connectionOpenTry_invalidProof( + IBCMsgs.MsgConnectionOpenTry memory msg_ + ) public { + msg_.clientId = clientId; + vm.expectRevert(IBCConnectionLib.ErrInvalidProof.selector); + handler.connectionOpenTry(msg_); + } + + function test_connectionOpenTry_commitmentSaved( + IBCMsgs.MsgConnectionOpenTry memory msg_ + ) public { + msg_.clientId = clientId; + lightClient.pushValidMembership(); + uint32 connectionId = handler.connectionOpenTry(msg_); + assertEq( + handler.commitments( + IBCCommitment.connectionCommitmentKey(connectionId) + ), + keccak256( + abi.encode( + IBCConnection({ + clientId: msg_.clientId, + state: IBCConnectionState.TryOpen, + counterparty: msg_.counterparty + }) + ) + ) + ); + } + + function test_connectionOpenInitOpenAck_ok( + IBCMsgs.MsgConnectionOpenInit memory msg_, + IBCMsgs.MsgConnectionOpenAck memory msgAck_ + ) public { + vm.pauseGasMetering(); + msg_.clientId = clientId; + uint32 connectionId = handler.connectionOpenInit(msg_); + msgAck_.connectionId = connectionId; + lightClient.pushValidMembership(); + vm.expectEmit(); + emit IBCConnectionLib.ConnectionOpenAck( + msgAck_.connectionId, + msg_.clientId, + msg_.counterparty.clientId, + // The connectionId of the counterpary must be updated after the ack. + msgAck_.counterpartyConnectionId + ); + vm.resumeGasMetering(); + handler.connectionOpenAck(msgAck_); + } + + function test_connectionOpenInitOpenAck_invalidProof( + IBCMsgs.MsgConnectionOpenInit memory msg_, + IBCMsgs.MsgConnectionOpenAck memory msgAck_ + ) public { + msg_.clientId = clientId; + uint32 connectionId = handler.connectionOpenInit(msg_); + msgAck_.connectionId = connectionId; + vm.expectRevert(IBCConnectionLib.ErrInvalidProof.selector); + handler.connectionOpenAck(msgAck_); + } + + function test_connectionOpenInitOpenAck_commitmentSaved( + IBCMsgs.MsgConnectionOpenInit memory msgInit_, + IBCMsgs.MsgConnectionOpenAck memory msgAck_ + ) public { + msgInit_.clientId = clientId; + uint32 connectionId = handler.connectionOpenInit(msgInit_); + msgAck_.connectionId = connectionId; + lightClient.pushValidMembership(); + handler.connectionOpenAck(msgAck_); + // The connectionId of the counterpary must be updated after the ack. + msgInit_.counterparty.connectionId = msgAck_.counterpartyConnectionId; + assertEq( + handler.commitments( + IBCCommitment.connectionCommitmentKey(connectionId) + ), + keccak256( + abi.encode( + IBCConnection({ + clientId: msgInit_.clientId, + state: IBCConnectionState.Open, + counterparty: msgInit_.counterparty + }) + ) + ) + ); + } + + function test_connectionOpenTryConfirm_ok( + IBCMsgs.MsgConnectionOpenTry memory msgTry_, + IBCMsgs.MsgConnectionOpenConfirm memory msgConfirm_ + ) public { + vm.pauseGasMetering(); + msgTry_.clientId = clientId; + lightClient.pushValidMembership(); + uint32 connectionId = handler.connectionOpenTry(msgTry_); + msgConfirm_.connectionId = connectionId; + lightClient.pushValidMembership(); + vm.expectEmit(); + emit IBCConnectionLib.ConnectionOpenConfirm( + connectionId, + msgTry_.clientId, + msgTry_.counterparty.clientId, + msgTry_.counterparty.connectionId + ); + vm.resumeGasMetering(); + handler.connectionOpenConfirm(msgConfirm_); + } + + function test_connectionOpenTryConfirm_invalidProof( + IBCMsgs.MsgConnectionOpenTry memory msgTry_, + IBCMsgs.MsgConnectionOpenConfirm memory msgConfirm_ + ) public { + msgTry_.clientId = clientId; + lightClient.pushValidMembership(); + uint32 connectionId = handler.connectionOpenTry(msgTry_); + msgConfirm_.connectionId = connectionId; + vm.expectRevert(IBCConnectionLib.ErrInvalidProof.selector); + handler.connectionOpenConfirm(msgConfirm_); + } + + function test_connectionOpenTryConfirm_commitmentSaved( + IBCMsgs.MsgConnectionOpenTry memory msgTry_, + IBCMsgs.MsgConnectionOpenConfirm memory msgConfirm_ + ) public { + msgTry_.clientId = clientId; + lightClient.pushValidMembership(); + uint32 connectionId = handler.connectionOpenTry(msgTry_); + msgConfirm_.connectionId = connectionId; + lightClient.pushValidMembership(); + handler.connectionOpenConfirm(msgConfirm_); + assertEq( + handler.commitments( + IBCCommitment.connectionCommitmentKey(connectionId) + ), + keccak256( + abi.encode( + IBCConnection({ + clientId: msgTry_.clientId, + state: IBCConnectionState.Open, + counterparty: msgTry_.counterparty + }) + ) + ) + ); + } +} diff --git a/evm/tests/src/04-channel/IBCChannel.t.sol b/evm/tests/src/04-channel/IBCChannel.t.sol new file mode 100644 index 0000000000..a2bf79208d --- /dev/null +++ b/evm/tests/src/04-channel/IBCChannel.t.sol @@ -0,0 +1,515 @@ +pragma solidity ^0.8.27; + +import "forge-std/Test.sol"; + +import "../core/IBCHandler.sol"; +import "../core/LightClient.sol"; +import "../core/Module.sol"; + +contract IBCChannelTests is Test { + bytes32 public constant CLIENT_TYPE = keccak256("zkgm"); + + TestIBCHandler handler; + TestLightClient lightClient; + TestModule module; + + uint32 clientId; + uint32 connectionId; + + function setUp() public { + handler = new TestIBCHandler(); + lightClient = new TestLightClient(); + module = new TestModule(handler); + handler.registerClient(CLIENT_TYPE, lightClient); + clientId = handler.createClient( + IBCMsgs.MsgCreateClient({ + clientType: CLIENT_TYPE, + clientStateBytes: hex"CADEBABE", + consensusStateBytes: hex"DEADC0DE", + relayer: address(this) + }) + ); + IBCMsgs.MsgConnectionOpenTry memory msgTry_ = IBCMsgs + .MsgConnectionOpenTry({ + counterparty: IBCConnectionCounterparty({ + clientId: 0xDEADC0DE, + connectionId: 0xCAFE + }), + clientId: clientId, + proofInit: hex"", + proofHeight: 0, + relayer: address(this) + }); + lightClient.pushValidMembership(); + connectionId = handler.connectionOpenTry(msgTry_); + IBCMsgs.MsgConnectionOpenConfirm memory msgConfirm_ = IBCMsgs + .MsgConnectionOpenConfirm({ + connectionId: connectionId, + proofAck: hex"", + proofHeight: 0, + relayer: address(this) + }); + lightClient.pushValidMembership(); + handler.connectionOpenConfirm(msgConfirm_); + } + + function test_channelOpenInit_ok( + uint32 counterpartyChannelId, + bytes32 version, + address relayer + ) public { + vm.pauseGasMetering(); + IBCMsgs.MsgChannelOpenInit memory msg_ = IBCMsgs.MsgChannelOpenInit({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.Init, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + relayer: relayer + }); + vm.expectEmit(); + emit IBCChannelLib.ChannelOpenInit( + msg_.portId, 0, msg_.channel.connectionId, msg_.channel.version + ); + vm.resumeGasMetering(); + handler.channelOpenInit(msg_); + } + + function test_channelOpenInit_invalidState( + uint32 counterpartyChannelId, + bytes32 version, + address relayer + ) public { + IBCMsgs.MsgChannelOpenInit memory msg_ = IBCMsgs.MsgChannelOpenInit({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.Unspecified, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + relayer: relayer + }); + vm.expectRevert(IBCChannelLib.ErrInvalidChannelState.selector); + handler.channelOpenInit(msg_); + } + + function test_channelOpenInit_invalidOrdering( + uint32 counterpartyChannelId, + bytes32 version, + address relayer + ) public { + IBCMsgs.MsgChannelOpenInit memory msg_ = IBCMsgs.MsgChannelOpenInit({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.Init, + connectionId: connectionId, + ordering: IBCChannelOrder.Unspecified, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + relayer: relayer + }); + vm.expectRevert(IBCChannelLib.ErrInvalidChannelOrdering.selector); + handler.channelOpenInit(msg_); + } + + function test_channelOpenInit_channelClaimed( + uint32 counterpartyChannelId, + bytes32 version, + address relayer + ) public { + IBCMsgs.MsgChannelOpenInit memory msg_ = IBCMsgs.MsgChannelOpenInit({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.Init, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + relayer: relayer + }); + uint32 channelId = handler.channelOpenInit(msg_); + assertEq(handler.channelOwner(channelId), address(module)); + } + + function test_channelOpenInit_commitmentSaved( + uint32 counterpartyChannelId, + bytes32 version, + address relayer + ) public { + IBCChannel memory channel = IBCChannel({ + state: IBCChannelState.Init, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }); + IBCMsgs.MsgChannelOpenInit memory msg_ = IBCMsgs.MsgChannelOpenInit({ + portId: address(module), + channel: channel, + relayer: relayer + }); + uint32 channelId = handler.channelOpenInit(msg_); + assertEq( + handler.commitments(IBCCommitment.channelCommitmentKey(channelId)), + keccak256(abi.encode(channel)) + ); + } + + function test_channelOpenTry_ok( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + vm.pauseGasMetering(); + IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.TryOpen, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + counterpartyVersion: counterpartyVersion, + proofInit: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + vm.expectEmit(); + emit IBCChannelLib.ChannelOpenTry( + msg_.portId, + 0, + msg_.channel.counterparty.channelId, + msg_.channel.connectionId, + msg_.counterpartyVersion + ); + vm.resumeGasMetering(); + handler.channelOpenTry(msg_); + } + + function test_channelOpenTry_invalidState( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.Unspecified, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + counterpartyVersion: counterpartyVersion, + proofInit: hex"", + proofHeight: 0, + relayer: relayer + }); + vm.expectRevert(IBCChannelLib.ErrInvalidChannelState.selector); + handler.channelOpenTry(msg_); + } + + function test_channelOpenTry_invalidOrdering( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.TryOpen, + connectionId: connectionId, + ordering: IBCChannelOrder.Unspecified, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + counterpartyVersion: counterpartyVersion, + proofInit: hex"", + proofHeight: 0, + relayer: relayer + }); + vm.expectRevert(IBCChannelLib.ErrInvalidChannelOrdering.selector); + handler.channelOpenTry(msg_); + } + + function test_channelOpenTry_invalidProof( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.TryOpen, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + counterpartyVersion: counterpartyVersion, + proofInit: hex"", + proofHeight: 0, + relayer: relayer + }); + vm.expectRevert(IBCChannelLib.ErrInvalidProof.selector); + handler.channelOpenTry(msg_); + } + + function test_channelOpenTry_channelClaimed( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.TryOpen, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + counterpartyVersion: counterpartyVersion, + proofInit: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + uint32 channelId = handler.channelOpenTry(msg_); + assertEq(handler.channelOwner(channelId), address(module)); + } + + function test_channelOpenTry_commitmentSaved( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + IBCChannel memory channel = IBCChannel({ + state: IBCChannelState.TryOpen, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }); + IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({ + portId: address(module), + channel: channel, + counterpartyVersion: counterpartyVersion, + proofInit: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + uint32 channelId = handler.channelOpenTry(msg_); + assertEq( + handler.commitments(IBCCommitment.channelCommitmentKey(channelId)), + keccak256(abi.encode(channel)) + ); + } + + function test_channelOpenInitOpenAck_ok( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + vm.pauseGasMetering(); + IBCMsgs.MsgChannelOpenInit memory msgInit_ = IBCMsgs.MsgChannelOpenInit({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.Init, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + relayer: relayer + }); + uint32 channelId = handler.channelOpenInit(msgInit_); + IBCMsgs.MsgChannelOpenAck memory msgAck_ = IBCMsgs.MsgChannelOpenAck({ + portId: address(module), + channelId: channelId, + counterpartyVersion: counterpartyVersion, + counterpartyChannelId: counterpartyChannelId, + proofTry: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + vm.expectEmit(); + emit IBCChannelLib.ChannelOpenAck( + address(module), 0, counterpartyChannelId, connectionId + ); + vm.resumeGasMetering(); + handler.channelOpenAck(msgAck_); + } + + function test_channelOpenInitOpenAck_invalidState( + uint32 channelId, + uint32 counterpartyChannelId, + bytes32 counterpartyVersion, + address relayer + ) public { + IBCMsgs.MsgChannelOpenAck memory msgAck_ = IBCMsgs.MsgChannelOpenAck({ + portId: address(module), + channelId: channelId, + counterpartyVersion: counterpartyVersion, + counterpartyChannelId: counterpartyChannelId, + proofTry: hex"", + proofHeight: 0, + relayer: relayer + }); + vm.expectRevert(IBCChannelLib.ErrInvalidChannelState.selector); + handler.channelOpenAck(msgAck_); + } + + function test_channelOpenInitOpenAck_commitmentSaved( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + IBCChannel memory channel = IBCChannel({ + state: IBCChannelState.Init, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }); + IBCMsgs.MsgChannelOpenInit memory msgInit_ = IBCMsgs.MsgChannelOpenInit({ + portId: address(module), + channel: channel, + relayer: relayer + }); + uint32 channelId = handler.channelOpenInit(msgInit_); + IBCMsgs.MsgChannelOpenAck memory msgAck_ = IBCMsgs.MsgChannelOpenAck({ + portId: address(module), + channelId: channelId, + counterpartyVersion: counterpartyVersion, + counterpartyChannelId: counterpartyChannelId, + proofTry: hex"", + proofHeight: 0, + relayer: relayer + }); + channel.version = counterpartyVersion; + channel.state = IBCChannelState.Open; + lightClient.pushValidMembership(); + handler.channelOpenAck(msgAck_); + assertEq( + handler.commitments(IBCCommitment.channelCommitmentKey(channelId)), + keccak256(abi.encode(channel)) + ); + } + + function test_channelOpenTryOpenConfirm_ok( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + vm.pauseGasMetering(); + IBCMsgs.MsgChannelOpenTry memory msgTry_ = IBCMsgs.MsgChannelOpenTry({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.TryOpen, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }), + counterpartyVersion: counterpartyVersion, + proofInit: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + uint32 channelId = handler.channelOpenTry(msgTry_); + IBCMsgs.MsgChannelOpenConfirm memory msgConfirm_ = IBCMsgs + .MsgChannelOpenConfirm({ + portId: address(module), + channelId: channelId, + proofAck: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + vm.expectEmit(); + emit IBCChannelLib.ChannelOpenConfirm( + address(module), 0, counterpartyChannelId, connectionId + ); + vm.resumeGasMetering(); + handler.channelOpenConfirm(msgConfirm_); + } + + function test_channelOpenTryOpenConfirm_invalidState( + uint32 channelId, + address relayer + ) public { + IBCMsgs.MsgChannelOpenConfirm memory msgConfirm_ = IBCMsgs + .MsgChannelOpenConfirm({ + portId: address(module), + channelId: channelId, + proofAck: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + vm.expectRevert(IBCChannelLib.ErrInvalidChannelState.selector); + handler.channelOpenConfirm(msgConfirm_); + } + + function test_channelOpenTryOpenConfirm_commitmentSaved( + uint32 counterpartyChannelId, + bytes32 version, + bytes32 counterpartyVersion, + address relayer + ) public { + IBCChannel memory channel = IBCChannel({ + state: IBCChannelState.TryOpen, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: version, + counterparty: IBCChannelCounterparty({channelId: counterpartyChannelId}) + }); + IBCMsgs.MsgChannelOpenTry memory msgTry_ = IBCMsgs.MsgChannelOpenTry({ + portId: address(module), + channel: channel, + counterpartyVersion: counterpartyVersion, + proofInit: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + uint32 channelId = handler.channelOpenTry(msgTry_); + IBCMsgs.MsgChannelOpenConfirm memory msgConfirm_ = IBCMsgs + .MsgChannelOpenConfirm({ + portId: address(module), + channelId: channelId, + proofAck: hex"", + proofHeight: 0, + relayer: relayer + }); + lightClient.pushValidMembership(); + handler.channelOpenConfirm(msgConfirm_); + channel.state = IBCChannelState.Open; + assertEq( + handler.commitments(IBCCommitment.channelCommitmentKey(channelId)), + keccak256(abi.encode(channel)) + ); + } +} diff --git a/evm/tests/src/04-channel/IBCPacket.t.sol b/evm/tests/src/04-channel/IBCPacket.t.sol new file mode 100644 index 0000000000..2eb4da7e1f --- /dev/null +++ b/evm/tests/src/04-channel/IBCPacket.t.sol @@ -0,0 +1,1133 @@ +pragma solidity ^0.8.27; + +import "forge-std/Test.sol"; + +import "../core/IBCHandler.sol"; +import "../core/LightClient.sol"; +import "../core/Module.sol"; + +import "@openzeppelin/utils/math/Math.sol"; + +contract IBCPacketTests is Test { + bytes32 public constant CLIENT_TYPE = keccak256("zkgm"); + bytes32 public constant VERSION = keccak256("protocol-1"); + uint32 public constant COUNTERPARTY_CHANNEL_ID = 0xDEADC0DE; + + TestIBCHandler handler; + TestLightClient lightClient; + TestModule module; + + uint32 clientId; + uint32 connectionId; + uint32 channelId; + + function setUp() public { + handler = new TestIBCHandler(); + lightClient = new TestLightClient(); + module = new TestModule(handler); + + // Create client + handler.registerClient(CLIENT_TYPE, lightClient); + clientId = handler.createClient( + IBCMsgs.MsgCreateClient({ + clientType: CLIENT_TYPE, + clientStateBytes: hex"CADEBABE", + consensusStateBytes: hex"DEADC0DE", + relayer: address(this) + }) + ); + + // Create connection + IBCMsgs.MsgConnectionOpenTry memory msgTry_ = IBCMsgs + .MsgConnectionOpenTry({ + counterparty: IBCConnectionCounterparty({ + clientId: 0xDEADC0DE, + connectionId: 0xCAFE + }), + clientId: clientId, + proofInit: hex"", + proofHeight: 0, + relayer: address(this) + }); + lightClient.pushValidMembership(); + connectionId = handler.connectionOpenTry(msgTry_); + IBCMsgs.MsgConnectionOpenConfirm memory msgConfirm_ = IBCMsgs + .MsgConnectionOpenConfirm({ + connectionId: connectionId, + proofAck: hex"", + proofHeight: 0, + relayer: address(this) + }); + lightClient.pushValidMembership(); + handler.connectionOpenConfirm(msgConfirm_); + + // Create channel + IBCMsgs.MsgChannelOpenInit memory msgInit_ = IBCMsgs.MsgChannelOpenInit({ + portId: address(module), + channel: IBCChannel({ + state: IBCChannelState.Init, + connectionId: connectionId, + ordering: IBCChannelOrder.Unordered, + version: VERSION, + counterparty: IBCChannelCounterparty({ + channelId: COUNTERPARTY_CHANNEL_ID + }) + }), + relayer: address(this) + }); + channelId = handler.channelOpenInit(msgInit_); + IBCMsgs.MsgChannelOpenAck memory msgAck_ = IBCMsgs.MsgChannelOpenAck({ + portId: address(module), + channelId: channelId, + counterpartyVersion: VERSION, + counterpartyChannelId: COUNTERPARTY_CHANNEL_ID, + proofTry: hex"", + proofHeight: 0, + relayer: address(this) + }); + lightClient.pushValidMembership(); + handler.channelOpenAck(msgAck_); + } + + function test_sendPacket_ok( + uint64 timeoutTimestamp, + uint64 timeoutHeight, + bytes calldata packet + ) public { + vm.pauseGasMetering(); + vm.assume(timeoutTimestamp != 0 || timeoutHeight != 0); + vm.prank(address(module)); + vm.resumeGasMetering(); + handler.sendPacket(channelId, timeoutTimestamp, timeoutHeight, packet); + } + + function test_sendPacket_increaseSequence( + uint64 timeoutTimestamp, + uint64 timeoutHeight, + bytes calldata packet + ) public { + vm.assume(timeoutTimestamp != 0 || timeoutHeight != 0); + vm.prank(address(module)); + uint64 sequence = handler.sendPacket( + channelId, timeoutTimestamp, timeoutHeight, packet + ); + assertEq( + handler.commitments( + IBCCommitment.nextSequenceSendCommitmentKey(channelId) + ), + bytes32(uint256(sequence + 1)) + ); + } + + function test_sendPacket_commitmentSaved( + uint64 timeoutHeight, + uint64 timeoutTimestamp, + bytes calldata message + ) public { + vm.assume(timeoutTimestamp != 0 || timeoutHeight != 0); + vm.prank(address(module)); + uint64 sequence = handler.sendPacket( + channelId, timeoutHeight, timeoutTimestamp, message + ); + IBCPacket memory packet = IBCPacket({ + sequence: sequence, + sourceChannel: channelId, + destinationChannel: COUNTERPARTY_CHANNEL_ID, + data: message, + timeoutHeight: timeoutHeight, + timeoutTimestamp: timeoutTimestamp + }); + assertEq( + handler.commitments( + IBCCommitment.batchPacketsCommitmentKey( + channelId, IBCPacketLib.commitPacketMemory(packet) + ) + ), + IBCPacketLib.COMMITMENT_MAGIC + ); + } + + function test_sendPacket_missingTimeout( + bytes calldata packet + ) public { + vm.expectRevert(IBCPacketLib.ErrTimeoutMustBeSet.selector); + vm.prank(address(module)); + handler.sendPacket(channelId, 0, 0, packet); + } + + function test_sendPacket_channelDoesntExist( + uint32 channelId_, + uint64 timeoutTimestamp, + uint64 timeoutHeight, + bytes calldata packet + ) public { + vm.assume(channelId_ != channelId); + vm.assume(timeoutTimestamp != 0 || timeoutHeight != 0); + vm.expectRevert(IBCPacketLib.ErrUnauthorized.selector); + vm.prank(address(module)); + handler.sendPacket(channelId_, timeoutTimestamp, timeoutHeight, packet); + } + + function test_sendPacket_moduleIsntChannelOwner( + uint64 timeoutTimestamp, + uint64 timeoutHeight, + bytes calldata packet, + address malicious + ) public { + vm.assume(malicious != address(module)); + vm.assume(timeoutTimestamp != 0 || timeoutHeight != 0); + vm.expectRevert(IBCPacketLib.ErrUnauthorized.selector); + vm.prank(malicious); + handler.sendPacket(channelId, timeoutTimestamp, timeoutHeight, packet); + } + + function createReceivePacket( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) internal view returns (IBCMsgs.MsgPacketRecv memory) { + IBCPacket[] memory packets = new IBCPacket[](nbPackets); + bytes[] memory relayerMsgs = new bytes[](nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + packets[i] = IBCPacket({ + sequence: i, + sourceChannel: sourceChannel, + destinationChannel: channelId, + data: message, + timeoutHeight: type(uint64).max, + timeoutTimestamp: type(uint64).max + }); + relayerMsgs[i] = abi.encodePacked(i); + } + IBCMsgs.MsgPacketRecv memory msg_ = IBCMsgs.MsgPacketRecv({ + packets: packets, + relayerMsgs: relayerMsgs, + relayer: address(this), + proof: hex"", + proofHeight: 0 + }); + return msg_; + } + + function test_recvPacket_ok_1( + uint32 sourceChannel, + bytes calldata message + ) public { + vm.pauseGasMetering(); + test_recvPacket_ok(sourceChannel, message, 1); + } + + function test_recvPacket_ok( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public returns (IBCMsgs.MsgPacketRecv memory) { + vm.pauseGasMetering(); + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + for (uint8 i = 0; i < nbPackets; i++) { + vm.expectEmit(); + emit IBCPacketLib.RecvPacket( + msg_.packets[i], msg_.relayer, msg_.relayerMsgs[i] + ); + emit IBCPacketLib.WriteAcknowledgement( + msg_.packets[i], TestModuleLib.ACKNOWLEDGEMENT + ); + } + vm.resumeGasMetering(); + handler.recvPacket(msg_); + vm.pauseGasMetering(); + return msg_; + } + + function test_recvPacket_invalidProof( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + vm.expectRevert(IBCPacketLib.ErrInvalidProof.selector); + handler.recvPacket(msg_); + } + + function test_recvPacket_invalidChannelState( + uint32 sourceChannel, + uint32 destinationChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + vm.assume(destinationChannel != channelId); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + // fake non existant channel + msg_.packets[0].destinationChannel = destinationChannel; + vm.expectRevert(IBCStoreLib.ErrInvalidChannelState.selector); + handler.recvPacket(msg_); + } + + function test_recvPacket_timeoutTimestamp( + uint32 timeout, + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(timeout > 0); + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + // Timeout is expressed as nano because of ibc-go... + msg_.packets[0].timeoutTimestamp = uint64(timeout) * 1e9; + vm.warp(timeout); + lightClient.pushValidMembership(); + vm.expectRevert(IBCPacketLib.ErrTimestampTimeout.selector); + handler.recvPacket(msg_); + } + + function test_recvPacket_timeoutHeight( + uint64 timeout, + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(timeout > 0); + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + // fake non existant channel + msg_.packets[0].timeoutHeight = timeout; + vm.roll(timeout); + lightClient.pushValidMembership(); + vm.expectRevert(IBCPacketLib.ErrHeightTimeout.selector); + handler.recvPacket(msg_); + } + + function test_recvPacket_ackCommitmentSaved( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + handler.recvPacket(msg_); + for (uint8 i = 0; i < nbPackets; i++) { + assertEq( + handler.commitments( + IBCCommitment.batchReceiptsCommitmentKey( + channelId, + IBCPacketLib.commitPacketMemory(msg_.packets[i]) + ) + ), + IBCPacketLib.commitAckMemory(TestModuleLib.ACKNOWLEDGEMENT) + ); + } + } + + function test_recvPacket_noAck_receiptCommitmentSaved( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + module.pauseAck(); + handler.recvPacket(msg_); + for (uint8 i = 0; i < nbPackets; i++) { + assertEq( + handler.commitments( + IBCCommitment.batchReceiptsCommitmentKey( + channelId, + IBCPacketLib.commitPacketMemory(msg_.packets[i]) + ) + ), + IBCPacketLib.COMMITMENT_MAGIC + ); + } + } + + function createReceiveIntentPacket( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) internal view returns (IBCMsgs.MsgIntentPacketRecv memory) { + IBCPacket[] memory packets = new IBCPacket[](nbPackets); + bytes[] memory marketMakerMsgs = new bytes[](nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + packets[i] = IBCPacket({ + sequence: i, + sourceChannel: sourceChannel, + destinationChannel: channelId, + data: message, + timeoutHeight: type(uint64).max, + timeoutTimestamp: type(uint64).max + }); + marketMakerMsgs[i] = abi.encodePacked(i); + } + IBCMsgs.MsgIntentPacketRecv memory msg_ = IBCMsgs.MsgIntentPacketRecv({ + packets: packets, + marketMakerMsgs: marketMakerMsgs, + marketMaker: address(this), + emptyProof: hex"" + }); + return msg_; + } + + function test_recvIntentPacket_ok_1( + uint32 sourceChannel, + bytes calldata message + ) public { + vm.pauseGasMetering(); + test_recvIntentPacket_ok(sourceChannel, message, 1); + } + + function test_recvIntentPacket_ok( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.pauseGasMetering(); + vm.assume(nbPackets > 0); + IBCMsgs.MsgIntentPacketRecv memory msg_ = + createReceiveIntentPacket(sourceChannel, message, nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + vm.expectEmit(); + emit IBCPacketLib.RecvIntentPacket( + msg_.packets[i], msg_.marketMaker, msg_.marketMakerMsgs[i] + ); + emit IBCPacketLib.WriteAcknowledgement( + msg_.packets[i], TestModuleLib.ACKNOWLEDGEMENT + ); + } + vm.resumeGasMetering(); + handler.recvIntentPacket(msg_); + } + + function test_recvIntentPacket_commitmentSaved( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgIntentPacketRecv memory msg_ = + createReceiveIntentPacket(sourceChannel, message, nbPackets); + handler.recvIntentPacket(msg_); + for (uint8 i = 0; i < nbPackets; i++) { + assertEq( + handler.commitments( + IBCCommitment.batchReceiptsCommitmentKey( + channelId, + IBCPacketLib.commitPacketMemory(msg_.packets[i]) + ) + ), + IBCPacketLib.commitAckMemory(TestModuleLib.ACKNOWLEDGEMENT) + ); + } + } + + function test_recvIntentPacket_timeoutTimestamp( + uint32 timeout, + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(timeout > 0); + vm.assume(nbPackets > 0); + IBCMsgs.MsgIntentPacketRecv memory msg_ = + createReceiveIntentPacket(sourceChannel, message, nbPackets); + // Timeout is expressed as nano because of ibc-go... + msg_.packets[0].timeoutTimestamp = uint64(timeout) * 1e9; + vm.warp(timeout); + vm.expectRevert(IBCPacketLib.ErrTimestampTimeout.selector); + handler.recvIntentPacket(msg_); + } + + function test_recvIntentPacket_timeoutHeight( + uint64 timeout, + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(timeout > 0); + vm.assume(nbPackets > 0); + IBCMsgs.MsgIntentPacketRecv memory msg_ = + createReceiveIntentPacket(sourceChannel, message, nbPackets); + // Timeout is expressed as nano because of ibc-go... + msg_.packets[0].timeoutHeight = timeout; + vm.roll(timeout); + vm.expectRevert(IBCPacketLib.ErrHeightTimeout.selector); + handler.recvIntentPacket(msg_); + } + + function createPacketAcknowledgement( + uint32 destinationChannel, + bytes calldata message, + uint8 nbPackets + ) internal view returns (IBCMsgs.MsgPacketAcknowledgement memory) { + IBCPacket[] memory packets = new IBCPacket[](nbPackets); + bytes[] memory acknowledgements = new bytes[](nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + packets[i] = IBCPacket({ + sequence: i, + sourceChannel: channelId, + destinationChannel: destinationChannel, + data: message, + timeoutHeight: type(uint64).max, + timeoutTimestamp: type(uint64).max + }); + acknowledgements[i] = abi.encodePacked(i); + } + IBCMsgs.MsgPacketAcknowledgement memory msg_ = IBCMsgs + .MsgPacketAcknowledgement({ + packets: packets, + acknowledgements: acknowledgements, + relayer: address(this), + proof: hex"", + proofHeight: 0 + }); + return msg_; + } + + function test_acknowledgePacket_ok( + uint32 destinationChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.pauseGasMetering(); + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketAcknowledgement memory msg_ = + createPacketAcknowledgement(destinationChannel, message, nbPackets); + lightClient.pushValidMembership(); + for (uint8 i = 0; i < nbPackets; i++) { + handler.assumePacketSent(channelId, msg_.packets[i]); + } + for (uint8 i = 0; i < nbPackets; i++) { + vm.expectEmit(); + emit IBCPacketLib.AcknowledgePacket( + msg_.packets[i], abi.encodePacked(i), msg_.relayer + ); + } + vm.resumeGasMetering(); + handler.acknowledgePacket(msg_); + } + + function test_acknowledgePacket_ok_1( + uint32 destinationChannel, + bytes calldata message + ) public { + vm.pauseGasMetering(); + test_acknowledgePacket_ok(destinationChannel, message, 1); + } + + function test_acknowledgePacket_tampered( + uint32 destinationChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketAcknowledgement memory msg_ = + createPacketAcknowledgement(destinationChannel, message, nbPackets); + lightClient.pushValidMembership(); + for (uint8 i = 0; i < nbPackets; i++) { + handler.assumePacketSent(channelId, msg_.packets[i]); + } + msg_.packets[0].data = abi.encodePacked(msg_.packets[0].data, hex"1337"); + vm.expectRevert(IBCPacketLib.ErrPacketCommitmentNotFound.selector); + handler.acknowledgePacket(msg_); + } + + function test_acknowledgePacket_notSent( + uint32 destinationChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketAcknowledgement memory msg_ = + createPacketAcknowledgement(destinationChannel, message, nbPackets); + lightClient.pushValidMembership(); + vm.expectRevert(IBCPacketLib.ErrPacketCommitmentNotFound.selector); + handler.acknowledgePacket(msg_); + } + + function test_acknowledgePacket_commitmentRemoved( + uint32 destinationChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketAcknowledgement memory msg_ = + createPacketAcknowledgement(destinationChannel, message, nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + handler.assumePacketSent(channelId, msg_.packets[i]); + } + lightClient.pushValidMembership(); + handler.acknowledgePacket(msg_); + for (uint8 i = 0; i < nbPackets; i++) { + assertEq( + handler.commitments( + IBCCommitment.batchPacketsCommitmentKey( + channelId, + IBCPacketLib.commitPacketMemory(msg_.packets[i]) + ) + ), + IBCPacketLib.COMMITMENT_NULL + ); + } + } + + function test_acknowledgePacket_invalidProof( + uint32 destinationChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketAcknowledgement memory msg_ = + createPacketAcknowledgement(destinationChannel, message, nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + handler.assumePacketSent(channelId, msg_.packets[i]); + } + vm.expectRevert(IBCPacketLib.ErrInvalidProof.selector); + handler.acknowledgePacket(msg_); + } + + function createPacketTimeout( + uint32 destinationChannel, + bytes calldata message + ) internal view returns (IBCMsgs.MsgPacketTimeout memory) { + IBCPacket memory packet = IBCPacket({ + sequence: 0xC0DE, + sourceChannel: channelId, + destinationChannel: destinationChannel, + data: message, + timeoutHeight: type(uint64).max, + timeoutTimestamp: type(uint64).max + }); + IBCMsgs.MsgPacketTimeout memory msg_ = IBCMsgs.MsgPacketTimeout({ + packet: packet, + relayer: address(this), + proof: hex"", + proofHeight: 0, + nextSequenceRecv: 0 + }); + return msg_; + } + + function test_timeoutPacket_timestamp_ok( + uint32 destinationChannel, + bytes calldata message, + uint32 timestamp, + uint32 k + ) public returns (IBCMsgs.MsgPacketTimeout memory) { + vm.pauseGasMetering(); + vm.assume(timestamp > 0); + vm.assume(k <= timestamp); + IBCMsgs.MsgPacketTimeout memory msg_ = + createPacketTimeout(destinationChannel, message); + // fake timeout + msg_.packet.timeoutTimestamp = timestamp; + msg_.packet.timeoutHeight = 0; + handler.assumePacketSent(channelId, msg_.packet); + lightClient.pushValidNonMembership(); + lightClient.setLatestTimestamp(uint64(timestamp) + k); + vm.expectEmit(); + emit IBCPacketLib.TimeoutPacket(msg_.packet, msg_.relayer); + vm.resumeGasMetering(); + handler.timeoutPacket(msg_); + vm.pauseGasMetering(); + return msg_; + } + + function test_timeoutPacket_timestamp_commitmentRemoved( + uint32 destinationChannel, + bytes calldata message, + uint32 timestamp, + uint32 k + ) public { + IBCMsgs.MsgPacketTimeout memory msg_ = test_timeoutPacket_timestamp_ok( + destinationChannel, message, timestamp, k + ); + assertEq( + handler.commitments( + IBCCommitment.batchPacketsCommitmentKey( + channelId, IBCPacketLib.commitPacketMemory(msg_.packet) + ) + ), + IBCPacketLib.COMMITMENT_NULL + ); + } + + function test_timeoutPacket_timestamp_invalidProof( + uint32 destinationChannel, + bytes calldata message, + uint32 timestamp, + uint32 k + ) public { + vm.assume(timestamp > 0); + vm.assume(k <= timestamp); + IBCMsgs.MsgPacketTimeout memory msg_ = + createPacketTimeout(destinationChannel, message); + // fake timeout + msg_.packet.timeoutTimestamp = timestamp; + msg_.packet.timeoutHeight = 0; + handler.assumePacketSent(channelId, msg_.packet); + lightClient.setLatestTimestamp(uint64(timestamp) + k); + vm.expectRevert(IBCPacketLib.ErrInvalidProof.selector); + handler.timeoutPacket(msg_); + } + + function test_timeoutPacket_timestamp_notReached( + uint32 destinationChannel, + bytes calldata message, + uint32 timestamp, + uint32 k + ) public { + vm.assume(timestamp > 0); + vm.assume(k <= timestamp); + IBCMsgs.MsgPacketTimeout memory msg_ = + createPacketTimeout(destinationChannel, message); + // fake timeout + msg_.packet.timeoutTimestamp = uint64(timestamp) + k + 1; + msg_.packet.timeoutHeight = 0; + handler.assumePacketSent(channelId, msg_.packet); + lightClient.pushValidNonMembership(); + lightClient.setLatestTimestamp(timestamp); + vm.expectRevert(IBCPacketLib.ErrTimeoutTimestampNotReached.selector); + handler.timeoutPacket(msg_); + } + + function test_timeoutPacket_height_ok( + uint32 destinationChannel, + bytes calldata message, + uint32 height, + uint32 k + ) public returns (IBCMsgs.MsgPacketTimeout memory) { + vm.pauseGasMetering(); + vm.assume(height > 0); + vm.assume(k <= height); + IBCMsgs.MsgPacketTimeout memory msg_ = + createPacketTimeout(destinationChannel, message); + // fake timeout + msg_.packet.timeoutTimestamp = 0; + msg_.packet.timeoutHeight = height; + handler.assumePacketSent(channelId, msg_.packet); + lightClient.pushValidNonMembership(); + lightClient.setLatestHeight(uint64(height) + k); + msg_.proofHeight = uint64(height) + k; + vm.expectEmit(); + emit IBCPacketLib.TimeoutPacket(msg_.packet, msg_.relayer); + vm.resumeGasMetering(); + handler.timeoutPacket(msg_); + vm.pauseGasMetering(); + return msg_; + } + + function test_timeoutPacket_height_commitmentRemoved( + uint32 destinationChannel, + bytes calldata message, + uint32 height, + uint32 k + ) public { + IBCMsgs.MsgPacketTimeout memory msg_ = + test_timeoutPacket_height_ok(destinationChannel, message, height, k); + assertEq( + handler.commitments( + IBCCommitment.batchPacketsCommitmentKey( + channelId, IBCPacketLib.commitPacketMemory(msg_.packet) + ) + ), + IBCPacketLib.COMMITMENT_NULL + ); + } + + function test_timeoutPacket_height_invalidProof( + uint32 destinationChannel, + bytes calldata message, + uint32 height, + uint32 k + ) public { + vm.assume(height > 0); + vm.assume(k <= height); + IBCMsgs.MsgPacketTimeout memory msg_ = + createPacketTimeout(destinationChannel, message); + // fake timeout + msg_.packet.timeoutTimestamp = 0; + msg_.packet.timeoutHeight = height; + handler.assumePacketSent(channelId, msg_.packet); + lightClient.setLatestHeight(uint64(height) + k); + msg_.proofHeight = uint64(height) + k; + vm.expectRevert(IBCPacketLib.ErrInvalidProof.selector); + handler.timeoutPacket(msg_); + } + + function test_timeoutPacket_height_notReached( + uint32 destinationChannel, + bytes calldata message, + uint32 height, + uint32 k + ) public { + vm.assume(height > 0); + vm.assume(k <= height); + IBCMsgs.MsgPacketTimeout memory msg_ = + createPacketTimeout(destinationChannel, message); + // fake timeout + msg_.packet.timeoutTimestamp = 0; + msg_.packet.timeoutHeight = uint64(height) + k + 1; + handler.assumePacketSent(channelId, msg_.packet); + lightClient.pushValidNonMembership(); + lightClient.setLatestHeight(height); + msg_.proofHeight = height; + vm.expectRevert(IBCPacketLib.ErrTimeoutHeightNotReached.selector); + handler.timeoutPacket(msg_); + } + + function test_writeAcknowledgement_ok( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public returns (IBCMsgs.MsgPacketRecv memory) { + vm.pauseGasMetering(); + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + module.pauseAck(); + for (uint8 i = 0; i < nbPackets; i++) { + vm.expectEmit(); + emit IBCPacketLib.RecvPacket( + msg_.packets[i], msg_.relayer, msg_.relayerMsgs[i] + ); + } + handler.recvPacket(msg_); + for (uint8 i = 0; i < nbPackets; i++) { + bytes memory ack = abi.encodePacked(i); + vm.expectEmit(); + emit IBCPacketLib.WriteAcknowledgement(msg_.packets[i], ack); + vm.prank(address(module)); + vm.resumeGasMetering(); + handler.writeAcknowledgement(msg_.packets[i], ack); + vm.pauseGasMetering(); + } + return msg_; + } + + function test_writeAcknowledgement_ok_1( + uint32 sourceChannel, + bytes calldata message + ) public { + vm.pauseGasMetering(); + test_writeAcknowledgement_ok(sourceChannel, message, 1); + } + + function test_writeAcknowledgement_moduleIsntChannelOwner( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets, + address malicious + ) public { + vm.assume(nbPackets > 0); + vm.assume(malicious != address(module)); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + module.pauseAck(); + for (uint8 i = 0; i < nbPackets; i++) { + vm.expectEmit(); + emit IBCPacketLib.RecvPacket( + msg_.packets[i], msg_.relayer, msg_.relayerMsgs[i] + ); + } + handler.recvPacket(msg_); + for (uint8 i = 0; i < nbPackets; i++) { + vm.expectRevert(IBCPacketLib.ErrUnauthorized.selector); + vm.prank(malicious); + handler.writeAcknowledgement(msg_.packets[i], hex"1337"); + } + } + + function test_writeAcknowledgement_packetNotReceived( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 0); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + module.pauseAck(); + for (uint8 i = 0; i < nbPackets; i++) { + vm.expectRevert(IBCPacketLib.ErrPacketNotReceived.selector); + vm.prank(address(module)); + handler.writeAcknowledgement(msg_.packets[i], hex"1337"); + } + } + + function test_writeAcknowledgement_alreadyExists( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + IBCMsgs.MsgPacketRecv memory msg_ = + test_writeAcknowledgement_ok(sourceChannel, message, nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + vm.expectRevert( + IBCPacketLib.ErrAcknowledgementAlreadyExists.selector + ); + vm.prank(address(module)); + handler.writeAcknowledgement(msg_.packets[i], hex"1337"); + } + } + + function test_writeAcknowledgement_commitmentSaved( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + IBCMsgs.MsgPacketRecv memory msg_ = + test_writeAcknowledgement_ok(sourceChannel, message, nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + assertEq( + handler.commitments( + IBCCommitment.batchReceiptsCommitmentKey( + channelId, + IBCPacketLib.commitPacketMemory(msg_.packets[i]) + ) + ), + IBCPacketLib.commitAckMemory(abi.encodePacked(i)) + ); + } + } + + function test_batchSend_ok( + uint64 timeoutTimestamp, + uint64 timeoutHeight, + uint8 nbPackets + ) public returns (IBCPacket[] memory) { + vm.pauseGasMetering(); + vm.assume(nbPackets > 1); + vm.assume(timeoutTimestamp != 0 || timeoutHeight != 0); + IBCPacket[] memory packets = new IBCPacket[](nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + vm.prank(address(module)); + bytes memory message = abi.encodePacked(i); + uint64 sequence = handler.sendPacket( + channelId, timeoutHeight, timeoutTimestamp, message + ); + IBCPacket memory packet = IBCPacket({ + sequence: sequence, + sourceChannel: channelId, + destinationChannel: COUNTERPARTY_CHANNEL_ID, + data: message, + timeoutHeight: timeoutHeight, + timeoutTimestamp: timeoutTimestamp + }); + packets[i] = packet; + } + vm.resumeGasMetering(); + handler.batchSend( + IBCMsgs.MsgBatchSend({sourceChannel: channelId, packets: packets}) + ); + vm.pauseGasMetering(); + return packets; + } + + function test_batchSend_ok_10( + uint64 timeoutTimestamp, + uint64 timeoutHeight + ) public { + vm.pauseGasMetering(); + test_batchSend_ok(timeoutTimestamp, timeoutHeight, 10); + } + + function test_batchSend_commitmentSaved( + uint64 timeoutTimestamp, + uint64 timeoutHeight, + uint8 nbPackets + ) public { + IBCPacket[] memory packets = + test_batchSend_ok(timeoutTimestamp, timeoutHeight, nbPackets); + assertEq( + handler.commitments( + IBCCommitment.batchPacketsCommitmentKey( + channelId, IBCPacketLib.commitPacketsMemory(packets) + ) + ), + IBCPacketLib.COMMITMENT_MAGIC + ); + } + + function test_batchSend_packetNotSent( + uint64 timeoutTimestamp, + uint64 timeoutHeight, + uint8 nbPackets + ) public { + vm.pauseGasMetering(); + vm.assume(nbPackets > 1); + vm.assume(timeoutTimestamp != 0 || timeoutHeight != 0); + IBCPacket[] memory packets = new IBCPacket[](nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + vm.prank(address(module)); + bytes memory message = abi.encodePacked(i); + uint64 sequence = handler.sendPacket( + channelId, timeoutHeight, timeoutTimestamp, message + ); + IBCPacket memory packet = IBCPacket({ + sequence: sequence, + sourceChannel: channelId, + destinationChannel: COUNTERPARTY_CHANNEL_ID, + data: message, + timeoutHeight: timeoutHeight, + timeoutTimestamp: timeoutTimestamp + }); + packets[i] = packet; + } + // tamper the data such that the commitment mismatch + packets[0].data = abi.encodePacked(packets[0].data, hex"C0DE"); + vm.resumeGasMetering(); + vm.expectRevert(IBCPacketLib.ErrPacketCommitmentNotFound.selector); + handler.batchSend( + IBCMsgs.MsgBatchSend({sourceChannel: channelId, packets: packets}) + ); + } + + function test_batchAcks_afterRecvPacket_ok( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets, + bytes calldata ack + ) public returns (IBCMsgs.MsgPacketRecv memory, bytes[] memory) { + vm.pauseGasMetering(); + vm.assume(ack.length > 0); + vm.assume(nbPackets > 1); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + module.setAck(ack); + handler.recvPacket(msg_); + bytes[] memory acks = new bytes[](nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + acks[i] = ack; + } + vm.resumeGasMetering(); + handler.batchAcks( + IBCMsgs.MsgBatchAcks({ + sourceChannel: channelId, + packets: msg_.packets, + acks: acks + }) + ); + vm.pauseGasMetering(); + return (msg_, acks); + } + + function test_batchAcks_afterRecvPacket_ok_10( + uint32 sourceChannel, + bytes calldata message, + bytes calldata ack + ) public { + vm.pauseGasMetering(); + test_batchAcks_afterRecvPacket_ok(sourceChannel, message, 10, ack); + } + + function test_batchAcks_afterRecvPacket_commitmentSaved( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets, + bytes calldata ack + ) public { + (IBCMsgs.MsgPacketRecv memory msg_, bytes[] memory acks) = + test_batchAcks_afterRecvPacket_ok( + sourceChannel, message, nbPackets, ack + ); + assertEq( + handler.commitments( + IBCCommitment.batchReceiptsCommitmentKey( + channelId, IBCPacketLib.commitPacketsMemory(msg_.packets) + ) + ), + IBCPacketLib.commitAcksMemory(acks) + ); + } + + function test_batchAcks_packetNotReceived( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets, + bytes calldata ack + ) public { + vm.assume(ack.length > 0); + vm.assume(nbPackets > 1); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + module.setAck(ack); + bytes[] memory acks = new bytes[](nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + acks[i] = ack; + } + vm.expectRevert(IBCPacketLib.ErrAcknowledgementIsEmpty.selector); + handler.batchAcks( + IBCMsgs.MsgBatchAcks({ + sourceChannel: channelId, + packets: msg_.packets, + acks: acks + }) + ); + } + + function test_batchAcks_afterRecvPacket_tamperedPacket( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets, + bytes calldata ack + ) public { + vm.assume(ack.length > 0); + vm.assume(nbPackets > 1); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + module.setAck(ack); + handler.recvPacket(msg_); + bytes[] memory acks = new bytes[](nbPackets); + for (uint8 i = 0; i < nbPackets; i++) { + acks[i] = ack; + } + // tamper one packet + msg_.packets[0].data = abi.encodePacked(msg_.packets[0].data, hex"1337"); + vm.expectRevert(IBCPacketLib.ErrAcknowledgementIsEmpty.selector); + handler.batchAcks( + IBCMsgs.MsgBatchAcks({ + sourceChannel: channelId, + packets: msg_.packets, + acks: acks + }) + ); + } + + function test_batchAcks_afterRecvPacket_asyncAck( + uint32 sourceChannel, + bytes calldata message, + uint8 nbPackets + ) public { + vm.assume(nbPackets > 1); + IBCMsgs.MsgPacketRecv memory msg_ = + createReceivePacket(sourceChannel, message, nbPackets); + lightClient.pushValidMembership(); + module.setAck(hex""); + handler.recvPacket(msg_); + bytes[] memory acks = new bytes[](nbPackets); + vm.expectRevert(IBCPacketLib.ErrAcknowledgementIsEmpty.selector); + handler.batchAcks( + IBCMsgs.MsgBatchAcks({ + sourceChannel: channelId, + packets: msg_.packets, + acks: acks + }) + ); + } +} diff --git a/evm/tests/src/24-host/IBCCommitment.t.sol b/evm/tests/src/24-host/IBCCommitment.t.sol deleted file mode 100644 index 1d7c87e65f..0000000000 --- a/evm/tests/src/24-host/IBCCommitment.t.sol +++ /dev/null @@ -1,121 +0,0 @@ -pragma solidity ^0.8.23; - -import {IBCCommitment} from "../../../contracts/core/24-host/IBCCommitment.sol"; - -import "../TestPlus.sol"; - -contract IBCCommitmentTest is TestPlus { - function test_clientStatePath() public pure { - assertStrEq( - IBCCommitment.clientStatePath("client-id"), - "clients/client-id/clientState" - ); - } - - function test_consensusStatePath() public pure { - assertStrEq( - IBCCommitment.consensusStatePath("client-id", 1, 2), - "clients/client-id/consensusStates/1-2" - ); - } - - function test_connectionPath() public pure { - assertStrEq( - IBCCommitment.connectionPath("conn-id"), "connections/conn-id" - ); - } - - function test_channelPath() public pure { - assertStrEq( - IBCCommitment.channelPath("port-id", "channel-id"), - "channelEnds/ports/port-id/channels/channel-id" - ); - } - - function test_packetCommitmentPath() public pure { - assertStrEq( - IBCCommitment.packetCommitmentPath("port-id", "channel-id", 1337), - "commitments/ports/port-id/channels/channel-id/sequences/1337" - ); - } - - function test_packetAcknowledgmentCommitmentPath() public pure { - assertStrEq( - IBCCommitment.packetAcknowledgementCommitmentPath( - "port-id", "channel-id", 1337 - ), - "acks/ports/port-id/channels/channel-id/sequences/1337" - ); - } - - function test_packetReceiptCommitmentPath() public pure { - assertStrEq( - IBCCommitment.packetReceiptCommitmentPath( - "port-id", "channel-id", 1337 - ), - "receipts/ports/port-id/channels/channel-id/sequences/1337" - ); - } - - function test_nextSequenceRecvCommitmentPath() public pure { - assertStrEq( - IBCCommitment.nextSequenceRecvCommitmentPath( - "port-id", "channel-id" - ), - "nextSequenceRecv/ports/port-id/channels/channel-id" - ); - } - - function test_clientStateCommitmentKey() public pure { - assertEq( - IBCCommitment.clientStateCommitmentKey("client-id"), - keccak256("clients/client-id/clientState") - ); - } - - function test_consensusStateCommitmentKey() public pure { - assertEq( - IBCCommitment.consensusStateCommitmentKey("client-id", 1, 2), - keccak256("clients/client-id/consensusStates/1-2") - ); - } - - function test_connectionCommitmentKey() public pure { - assertEq( - IBCCommitment.connectionCommitmentKey("conn-id"), - keccak256("connections/conn-id") - ); - } - - function test_channelCommitmentKey() public pure { - assertEq( - IBCCommitment.channelCommitmentKey("port-id", "channel-id"), - keccak256("channelEnds/ports/port-id/channels/channel-id") - ); - } - - function test_packetCommitmentKey() public pure { - assertEq( - IBCCommitment.packetCommitmentKey("port-id", "channel-id", 1337), - keccak256( - "commitments/ports/port-id/channels/channel-id/sequences/1337" - ) - ); - } - - function test_packetAcknowledgmentCommitmentKey() public pure { - assertEq( - IBCCommitment.packetAcknowledgementCommitmentKey( - "port-id", "channel-id", 1337 - ), - keccak256("acks/ports/port-id/channels/channel-id/sequences/1337") - ); - } - - function test_nextSequenceRecvCommitmentKey() public pure { - assertEq( - IBCCommitment.nextSequenceRecvCommitmentKey("port-id", "channel-id"), - keccak256("nextSequenceRecv/ports/port-id/channels/channel-id") - ); - } -} diff --git a/evm/tests/src/25-handler/IBCChannelHandler.t.sol b/evm/tests/src/25-handler/IBCChannelHandler.t.sol deleted file mode 100644 index e88f61591d..0000000000 --- a/evm/tests/src/25-handler/IBCChannelHandler.t.sol +++ /dev/null @@ -1,578 +0,0 @@ -pragma solidity ^0.8.23; - -import "solidity-bytes-utils/BytesLib.sol"; -import "solady/utils/LibString.sol"; -import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol"; - -import {IBCHandler} from "../../../contracts/core/25-handler/IBCHandler.sol"; -import {IBCConnection} from - "../../../contracts/core/03-connection/IBCConnection.sol"; -import {IBCClient} from "../../../contracts/core/02-client/IBCClient.sol"; -import {IBCChannelHandshake} from - "../../../contracts/core/04-channel/IBCChannelHandshake.sol"; -import { - IBCPacket, - IBCPacketLib -} from "../../../contracts/core/04-channel/IBCPacket.sol"; -import {CometblsClient} from "../../../contracts/clients/CometblsClientV2.sol"; -import {IBCChannelLib} from - "../../../contracts/core/04-channel/IBCChannelHandshake.sol"; -import {ILightClient} from "../../../contracts/core/02-client/ILightClient.sol"; -import {IBCMsgs} from "../../../contracts/core/25-handler/IBCMsgs.sol"; -import { - IbcCoreConnectionV1ConnectionEnd as ConnectionEnd, - IbcCoreConnectionV1Counterparty as ConnectionCounterparty, - IbcCoreConnectionV1GlobalEnums as ConnectionEnums -} from "../../../contracts/proto/ibc/core/connection/v1/connection.sol"; -import { - IbcCoreChannelV1Channel as Channel, - IbcCoreChannelV1GlobalEnums as ChannelEnums -} from "../../../contracts/proto/ibc/core/channel/v1/channel.sol"; -import {IbcCoreClientV1Height} from - "../../../contracts/proto/ibc/core/client/v1/client.sol"; -import {IbcCoreCommitmentV1MerklePrefix as CommitmentMerklePrefix} from - "../../../contracts/proto/ibc/core/commitment/v1/commitment.sol"; -import {TendermintTypesSignedHeader} from - "../../../contracts/proto/tendermint/types/canonical.sol"; -import { - TendermintTypesCommit, - TendermintTypesHeader, - TendermintTypesSignedHeader, - TendermintVersionConsensus, - TendermintTypesCommitSig, - TendermintTypesBlockID, - TendermintTypesPartSetHeader -} from "../../../contracts/proto/tendermint/types/types.sol"; -import - "../../../contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; - -import "../TestPlus.sol"; - -contract TestCometblsClient is CometblsClient { - uint256 validProof = 0; - - function pushValidProof() public { - validProof += 1; - } - - uint256 validMembership = 0; - - function pushValidMembership() public { - validMembership += 1; - } - - function internalVerifyZKP( - bytes calldata, - string memory, - bytes32, - UnionIbcLightclientsCometblsV1LightHeader.Data calldata - ) internal override returns (bool) { - bool ok = validProof > 0; - if (validProof > 0) { - validProof -= 1; - } - return ok; - } - - function verifyMembership( - string calldata, - IbcCoreClientV1Height.Data calldata, - uint64, - uint64, - bytes calldata, - bytes memory, - bytes calldata, - bytes calldata - ) external override returns (bool) { - bool ok = validMembership > 0; - if (validMembership > 0) { - validMembership -= 1; - } - return ok; - } - - function verifyNonMembership( - string calldata, - IbcCoreClientV1Height.Data calldata, - uint64, - uint64, - bytes calldata, - bytes calldata, - bytes calldata - ) external override returns (bool) { - bool ok = validMembership > 0; - if (validMembership > 0) { - validMembership -= 1; - } - return ok; - } -} - -contract IBCChannelHandlerTest is TestPlus { - using BytesLib for *; - using ConnectionCounterparty for *; - using LibString for *; - - string constant CLIENT_TYPE = "mock"; - - bytes32 constant ARBITRARY_INITIAL_APP_HASH = - hex"A8158610DD6858F3D26149CC0DB3339ABD580EA217DE0A151C9C451DED418E35"; - - IBCHandler_Testable handler; - TestCometblsClient client; - MockApp app; - string portId; - - function setUp() public { - handler = IBCHandler_Testable( - address( - new ERC1967Proxy( - address(new IBCHandler_Testable()), - abi.encodeCall( - IBCHandler.initialize, - ( - address(new IBCClient()), - address(new IBCConnection()), - address(new IBCChannelHandshake()), - address(new IBCPacket()), - address(this) - ) - ) - ) - ) - ); - client = TestCometblsClient( - address( - new ERC1967Proxy( - address(new TestCometblsClient()), - abi.encodeCall( - CometblsClient.initialize, - (address(handler), address(this)) - ) - ) - ) - ); - handler.registerClient(CLIENT_TYPE, client); - app = new MockApp(); - portId = address(app).toHexString(); - } - - function getValidHeader() - internal - pure - returns (TendermintTypesSignedHeader.Data memory) - { - TendermintTypesHeader.Data memory header = TendermintTypesHeader.Data({ - version: TendermintVersionConsensus.Data({block: 11, app: 0}), - chain_id: "union-devnet-1", - height: 139, - time: Timestamp.Data({secs: 1691496777, nanos: 793918988}), - last_block_id: TendermintTypesBlockID.Data({ - hash: hex"80DF3A892BF2586E3B22201D2AC5A65EDAB66ECE7BB6F51077F3B50CCE7526E1", - part_set_header: TendermintTypesPartSetHeader.Data({ - total: 1, - hash: hex"0468D541CAD891D571E2AD1DD9F43480993BDF18A1016F4C956555A417EFE681" - }) - }), - last_commit_hash: hex"DA6FCBD48131808D58B54E8B44737AB2B6F3A3DD1AFF946D0F6CEFD25306FD48", - data_hash: hex"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - validators_hash: hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60", - next_validators_hash: hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60", - consensus_hash: hex"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F", - app_hash: hex"983EF85676937CEC783601B5B50865733A72C3DF88E4CC0B3F11C108C9688459", - last_results_hash: hex"357B78587B9CD4469F1F63C29B96EAC1D7F643520B97D396B20A20505122AA01", - evidence_hash: hex"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - proposer_address: hex"4CE57693C82B50F830731DAB14FA759327762456" - }); - return TendermintTypesSignedHeader.Data({ - header: header, - // NOTE: validators are signing the block root which is computed - // from the above TendermintTypesHeader field. Relayers can tamper - // the commit but the client ensure that the block_id.hash matches - // hash(header). Signatures are not required as the ZKP is a proof - // that the validators signed the correct hash. - commit: TendermintTypesCommit.Data({ - height: header.height, - round: 0, - block_id: TendermintTypesBlockID.Data({ - hash: hex"90548CD1E2BA8603261FE6400ADFD97EA48150CBD5B24B9828B2542BAB9E27EC", - part_set_header: TendermintTypesPartSetHeader.Data({ - total: 1, - hash: hex"153E8B1F5B189A140FE5DA85DAB72FBD4A1DFA7E69C6FE5CE1FD66F0CCB5F6A1" - }) - }), - signatures: new TendermintTypesCommitSig.Data[](0) - }) - }); - } - - function assumeValidProofHeight(uint64 proofHeight) internal pure { - vm.assume( - 0 < proofHeight - && proofHeight < uint64(getValidHeader().header.height) - ); - } - - function createClient(uint64 proofHeight) - internal - returns (string memory) - { - assumeValidProofHeight(proofHeight); - TendermintTypesSignedHeader.Data memory signedHeader = getValidHeader(); - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - signedHeader.header.chain_id, - proofHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.header.validators_hash.toBytes32(0), - uint64(signedHeader.header.time.secs - 10) - ); - return handler.createClient(m); - } - - function test_handshake_init_ack_ok(uint64 proofHeight) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenInit("", "", "", "", ""); - string memory channelId = handler.channelOpenInit(msg_init); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenAck memory msg_ack = - MsgMocks.channelOpenAck(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelOpenAck(msg_ack); - } - - function test_handshake_init_ack_invalidProof(uint64 proofHeight) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenInit("", "", "", "", ""); - string memory channelId = handler.channelOpenInit(msg_init); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenAck memory msg_ack = - MsgMocks.channelOpenAck(portId, channelId, proofHeight); - vm.expectRevert(IBCChannelLib.ErrInvalidProof.selector); - handler.channelOpenAck(msg_ack); - } - - function test_handshake_init_noHop(uint64 proofHeight) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - msg_init.channel.connection_hops = new string[](0); - vm.expectRevert(IBCChannelLib.ErrConnNotSingleHop.selector); - handler.channelOpenInit(msg_init); - } - - function test_handshake_init_noConnection( - uint64 proofHeight, - address portIdParam - ) public { - vm.assume(proofHeight > 0); - - IBCMsgs.MsgChannelOpenInit memory msg_init = MsgMocks.channelOpenInit( - "invalid-connection", portIdParam.toHexString() - ); - vm.expectRevert(IBCChannelLib.ErrInvalidConnectionState.selector); - handler.channelOpenInit(msg_init); - } - - function test_handshake_init_unsupportedFeature(uint64 proofHeight) - public - { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - msg_init.channel.ordering = ChannelEnums.Order.ORDER_NONE_UNSPECIFIED; - vm.expectRevert(IBCChannelLib.ErrUnsupportedFeature.selector); - handler.channelOpenInit(msg_init); - } - - function test_handshake_init_notInit(uint64 proofHeight) public { - vm.assume(proofHeight > 0); - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - msg_init.channel.state = ChannelEnums.State.STATE_OPEN; - vm.expectRevert(IBCChannelLib.ErrInvalidChannelState.selector); - handler.channelOpenInit(msg_init); - } - - function test_handshake_init_nonEmptyCounterpartyChannel(uint64 proofHeight) - public - { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - msg_init.channel.counterparty.channel_id = "invalid"; - vm.expectRevert(IBCChannelLib.ErrCounterpartyChannelNotEmpty.selector); - handler.channelOpenInit(msg_init); - } - - function test_handshake_init_ack_close_init_ok(uint64 proofHeight) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenInit("", "", "", "", ""); - string memory channelId = handler.channelOpenInit(msg_init); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenAck memory msg_ack = - MsgMocks.channelOpenAck(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelOpenAck(msg_ack); - - IBCMsgs.MsgChannelCloseInit memory msg_close = - MsgMocks.channelCloseInit(portId, channelId); - handler.channelCloseInit(msg_close); - } - - function test_handshake_init_ack_close_confirm_ok(uint64 proofHeight) - public - { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenInit("", "", "", "", ""); - string memory channelId = handler.channelOpenInit(msg_init); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenAck memory msg_ack = - MsgMocks.channelOpenAck(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelOpenAck(msg_ack); - - IBCMsgs.MsgChannelCloseConfirm memory msg_close = - MsgMocks.channelCloseConfirm(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelCloseConfirm(msg_close); - } - - function test_handshake_init_ack_close_confirm_invalidProof( - uint64 proofHeight - ) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connId, portId); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenInit("", "", "", "", ""); - string memory channelId = handler.channelOpenInit(msg_init); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenAck memory msg_ack = - MsgMocks.channelOpenAck(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelOpenAck(msg_ack); - - IBCMsgs.MsgChannelCloseConfirm memory msg_close = - MsgMocks.channelCloseConfirm(portId, channelId, proofHeight); - vm.expectRevert(IBCChannelLib.ErrInvalidProof.selector); - handler.channelCloseConfirm(msg_close); - } - - function test_handshake_try_confirm_ok(uint64 proofHeight) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenTry memory msg_try = - MsgMocks.channelOpenTry(connId, portId, proofHeight); - client.pushValidMembership(); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenTry("", "", "", "", "", ""); - string memory channelId = handler.channelOpenTry(msg_try); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenConfirm memory msg_confirm = - MsgMocks.channelOpenConfirm(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelOpenConfirm(msg_confirm); - } - - function test_handshake_try_confirm_invalidProof(uint64 proofHeight) - public - { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenTry memory msg_try = - MsgMocks.channelOpenTry(connId, portId, proofHeight); - client.pushValidMembership(); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenTry("", "", "", "", "", ""); - string memory channelId = handler.channelOpenTry(msg_try); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenConfirm memory msg_confirm = - MsgMocks.channelOpenConfirm(portId, channelId, proofHeight); - vm.expectRevert(IBCChannelLib.ErrInvalidProof.selector); - handler.channelOpenConfirm(msg_confirm); - } - - function test_handshake_try_invalidProof(uint64 proofHeight) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenTry memory msg_try = - MsgMocks.channelOpenTry(connId, portId, proofHeight); - vm.expectRevert(IBCChannelLib.ErrInvalidProof.selector); - handler.channelOpenTry(msg_try); - } - - function test_handshake_try_notTryOpen( - uint64 proofHeight, - address portIdParam - ) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenTry memory msg_try = MsgMocks.channelOpenTry( - connId, portIdParam.toHexString(), proofHeight - ); - msg_try.channel.state = ChannelEnums.State.STATE_INIT; - - client.pushValidMembership(); - vm.expectRevert(IBCChannelLib.ErrInvalidChannelState.selector); - handler.channelOpenTry(msg_try); - } - - function test_handshake_try_confirm_close_init_ok(uint64 proofHeight) - public - { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenTry memory msg_try = - MsgMocks.channelOpenTry(connId, portId, proofHeight); - client.pushValidMembership(); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenTry("", "", "", "", "", ""); - string memory channelId = handler.channelOpenTry(msg_try); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenConfirm memory msg_confirm = - MsgMocks.channelOpenConfirm(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelOpenConfirm(msg_confirm); - - IBCMsgs.MsgChannelCloseInit memory msg_close = - MsgMocks.channelCloseInit(portId, channelId); - handler.channelCloseInit(msg_close); - } - - function test_handshake_try_confirm_close_confirm_ok(uint64 proofHeight) - public - { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenTry memory msg_try = - MsgMocks.channelOpenTry(connId, portId, proofHeight); - - client.pushValidMembership(); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenTry("", "", "", "", "", ""); - string memory channelId = handler.channelOpenTry(msg_try); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenConfirm memory msg_confirm = - MsgMocks.channelOpenConfirm(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelOpenConfirm(msg_confirm); - - IBCMsgs.MsgChannelCloseConfirm memory msg_close = - MsgMocks.channelCloseConfirm(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelCloseConfirm(msg_close); - } - - function test_handshake_try_confirm_close_confirm_invalidProof( - uint64 proofHeight - ) public { - (, string memory connId) = setupConnection(proofHeight); - - IBCMsgs.MsgChannelOpenTry memory msg_try = - MsgMocks.channelOpenTry(connId, portId, proofHeight); - - client.pushValidMembership(); - vm.expectEmit(false, false, false, false); - emit IBCChannelLib.ChannelOpenTry("", "", "", "", "", ""); - string memory channelId = handler.channelOpenTry(msg_try); - - assertEq( - handler.capabilities(string.concat(portId, "/", channelId)), - address(app) - ); - - IBCMsgs.MsgChannelOpenConfirm memory msg_confirm = - MsgMocks.channelOpenConfirm(portId, channelId, proofHeight); - client.pushValidMembership(); - handler.channelOpenConfirm(msg_confirm); - - IBCMsgs.MsgChannelCloseConfirm memory msg_close = - MsgMocks.channelCloseConfirm(portId, channelId, proofHeight); - vm.expectRevert(IBCChannelLib.ErrInvalidProof.selector); - handler.channelCloseConfirm(msg_close); - } - - function setupConnection(uint64 proofHeight) - internal - returns (string memory, string memory) - { - string memory clientId = createClient(proofHeight); - IBCMsgs.MsgConnectionOpenInit memory msg_init = - MsgMocks.connectionOpenInit(clientId); - string memory connId = handler.connectionOpenInit(msg_init); - IBCMsgs.MsgConnectionOpenAck memory msg_ack = - MsgMocks.connectionOpenAck(clientId, connId, proofHeight); - client.pushValidMembership(); - client.pushValidMembership(); - handler.connectionOpenAck(msg_ack); - return (clientId, connId); - } -} diff --git a/evm/tests/src/25-handler/IBCClientHandler.t.sol b/evm/tests/src/25-handler/IBCClientHandler.t.sol deleted file mode 100644 index 6c38673607..0000000000 --- a/evm/tests/src/25-handler/IBCClientHandler.t.sol +++ /dev/null @@ -1,1415 +0,0 @@ -pragma solidity ^0.8.23; - -import "solidity-bytes-utils/BytesLib.sol"; -import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol"; - -import {IBCHandler} from "../../../contracts/core/25-handler/IBCHandler.sol"; -import {IBCConnection} from - "../../../contracts/core/03-connection/IBCConnection.sol"; -import {IBCClient} from "../../../contracts/core/02-client/IBCClient.sol"; -import {IBCChannelHandshake} from - "../../../contracts/core/04-channel/IBCChannelHandshake.sol"; -import { - IBCPacket, - IBCPacketLib -} from "../../../contracts/core/04-channel/IBCPacket.sol"; -import {IBCClientLib} from "../../../contracts/core/02-client/IBCClient.sol"; -import { - ILightClient, - ConsensusStateUpdate -} from "../../../contracts/core/02-client/ILightClient.sol"; -import { - CometblsClient, - CometblsClientLib -} from "../../../contracts/clients/CometblsClientV2.sol"; -import {IBCMsgs} from "../../../contracts/core/25-handler/IBCMsgs.sol"; -import {IBCCommitment} from "../../../contracts/core/24-host/IBCCommitment.sol"; -import {IbcCoreClientV1Height} from - "../../../contracts/proto/ibc/core/client/v1/client.sol"; -import { - TendermintTypesCommit, - TendermintTypesSignedHeader, - TendermintVersionConsensus, - TendermintTypesCommitSig, - TendermintTypesBlockID, - TendermintTypesPartSetHeader -} from "../../../contracts/proto/tendermint/types/types.sol"; -import - "../../../contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; - -import "../TestPlus.sol"; - -contract TestCometblsClient is CometblsClient { - uint256 validProof = 0; - - function pushValidProof() public { - validProof += 1; - } - - uint256 validMembership = 0; - - function pushValidMembership() public { - validMembership += 1; - } - - function internalVerifyZKP( - bytes calldata, - string memory, - bytes32, - UnionIbcLightclientsCometblsV1LightHeader.Data calldata - ) internal override returns (bool) { - bool ok = validProof > 0; - if (validProof > 0) { - validProof -= 1; - } - return ok; - } - - function verifyMembership( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayPeriodTime, - uint64 delayPeriodBlocks, - bytes calldata, - bytes memory, - bytes calldata, - bytes calldata - ) external override returns (bool) { - validateDelayPeriod( - clientId, height, delayPeriodTime, delayPeriodBlocks - ); - - bool ok = validMembership > 0; - if (validMembership > 0) { - validMembership -= 1; - } - return ok; - } - - function verifyNonMembership( - string calldata clientId, - IbcCoreClientV1Height.Data calldata height, - uint64 delayPeriodTime, - uint64 delayPeriodBlocks, - bytes calldata, - bytes calldata, - bytes calldata - ) external override returns (bool) { - validateDelayPeriod( - clientId, height, delayPeriodTime, delayPeriodBlocks - ); - - bool ok = validMembership > 0; - if (validMembership > 0) { - validMembership -= 1; - } - return ok; - } -} - -contract IBCClientHandlerTests is TestPlus { - using BytesLib for bytes; - using CometblsClientLib for *; - - IBCHandler_Testable handler; - - string constant CLIENT_TYPE = "mock"; - TestCometblsClient client; - TestCometblsClient client2; - - bytes32 constant ARBITRARY_INITIAL_APP_HASH = - hex"A8158610DD6858F3D26149CC0DB3339ABD580EA217DE0A151C9C451DED418E35"; - - function setUp() public { - handler = IBCHandler_Testable( - address( - new ERC1967Proxy( - address(new IBCHandler_Testable()), - abi.encodeCall( - IBCHandler.initialize, - ( - address(new IBCClient()), - address(new IBCConnection()), - address(new IBCChannelHandshake()), - address(new IBCPacket()), - address(this) - ) - ) - ) - ) - ); - client = TestCometblsClient( - address( - new ERC1967Proxy( - address(new TestCometblsClient()), - abi.encodeCall( - CometblsClient.initialize, - (address(handler), address(this)) - ) - ) - ) - ); - client2 = TestCometblsClient( - address( - new ERC1967Proxy( - address(new TestCometblsClient()), - abi.encodeCall( - CometblsClient.initialize, - (address(handler), address(this)) - ) - ) - ) - ); - vm.warp(1); - } - - function getValidTransition() - internal - pure - returns ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) - { - zkp = - hex"195562CC376E9265A7FD89A086855C100173B717B0DEA58AC9F50120E9CBDD7402D59ADAC8A274C5DDB199915B03B5CFB7A91032A71723876F946A7662135D4912EB1FAD1FCA5E88AD1D9097870391D1D477F4CD2A26F27DB3CFC8B511922C482F374A4821BEE34818589A052995CC5994CE787538207F1BA0D595890EB96D751D947274566F6338FC14BB1728C9E42F47F9D47A8A7F46CFA341D3EC71F0A8E80ECDAA9E38B4D6090989B165E536C4332BDF470E860D85001362EC7B369DE0092FD13C85FE2A16247E574B759B7B8EBFE8C7ED19CE7520A693BD09FD604CA54E2FA277AC176ACEC9626313DA7022E8B8DB599E1B02C25DA90AD508AA315DA67C0EAF8A0F41C4CDC897A4941F3BFA7D0E0C2BDD3030D5B0025FB4030A31C886F417B2509E9ECFEA86AA22F75402599E72C21623E9C32A499D7B14B6DBC3A1251E119244B7DC12B54A74FBC3B23E7954435491D89AFA7ABF6F07E1DADE0B28F0DA1978EC72A2C2C0F1FE8DEDA8DD8DDA7E82454618C3DFF1341C9901456F7E656A"; - signedHeader = UnionIbcLightclientsCometblsV1LightHeader.Data({ - height: 139, - time: Timestamp.Data({secs: 1691496777, nanos: 793918988}), - validators_hash: hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60", - next_validators_hash: hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60", - app_hash: hex"983EF85676937CEC783601B5B50865733A72C3DF88E4CC0B3F11C108C9688459" - }); - } - - function test_registerClient() public { - handler.registerClient(CLIENT_TYPE, client); - handler.registerClient("other", client2); - - assertEq(handler.clientRegistry(CLIENT_TYPE), address(client)); - assertEq(handler.clientRegistry("other"), address(client2)); - } - - function test_registerClient_alreadyRegistered() public { - handler.registerClient(CLIENT_TYPE, client); - - vm.expectRevert(IBCClientLib.ErrClientTypeAlreadyExists.selector); - handler.registerClient(CLIENT_TYPE, client); - } - - function test_registerClient_self() public { - vm.expectRevert(IBCClientLib.ErrClientMustNotBeSelf.selector); - handler.registerClient(CLIENT_TYPE, ILightClient(address(handler))); - } - - function test_createClient( - string memory chainId, - uint64 revisionHeight, - bytes32 rootHash, - bytes32 nextValidatorsHash - ) public { - vm.assume(bytes(chainId).length < 32); - vm.assume(revisionHeight > 0); - - handler.registerClient(CLIENT_TYPE, client); - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - chainId, - revisionHeight, - rootHash, - nextValidatorsHash, - uint64(vm.getBlockTimestamp()) - ); - - string memory id = handler.createClient(m); - - assertEq(handler.clientTypes(id), m.clientType); - assertEq(handler.clientImpls(id), address(client)); - assertEq( - handler.commitments(keccak256(IBCCommitment.clientStatePath(id))), - keccak256(m.clientStateBytes) - ); - assertEq( - handler.commitments( - IBCCommitment.consensusStateCommitmentKey(id, 0, revisionHeight) - ), - keccak256(m.consensusStateBytes) - ); - } - - function test_createClient_chainIdExceedScalarField( - string memory chainId, - bytes32 rootHash, - bytes32 nextValidatorsHash - ) public { - vm.assume(bytes(chainId).length > 31); - - handler.registerClient(CLIENT_TYPE, client); - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - chainId, - 0, - rootHash, - nextValidatorsHash, - uint64(vm.getBlockTimestamp()) - ); - - vm.expectRevert(IBCClientLib.ErrFailedToCreateClient.selector); - handler.createClient(m); - } - - function test_createClient_zeroHeight( - string memory chainId, - bytes32 rootHash, - bytes32 nextValidatorsHash - ) public { - handler.registerClient(CLIENT_TYPE, client); - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - chainId, - 0, - rootHash, - nextValidatorsHash, - uint64(vm.getBlockTimestamp()) - ); - - vm.expectRevert(IBCClientLib.ErrFailedToCreateClient.selector); - handler.createClient(m); - } - - function test_createClient_invalidType( - string memory chainId, - uint64 revisionHeight, - bytes32 rootHash, - bytes32 nextValidatorsHash - ) public { - handler.registerClient(CLIENT_TYPE, client); - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - "other", - chainId, - revisionHeight, - rootHash, - nextValidatorsHash, - uint64(vm.getBlockTimestamp()) - ); - - vm.expectRevert(IBCClientLib.ErrClientTypeNotFound.selector); - handler.createClient(m); - } - - function test_createClient_onlyIBC(uint64 trustedHeight) public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - client.pushValidProof(); - vm.expectRevert(CometblsClientLib.ErrNotIBC.selector); - client.createClient("blabla", m.clientStateBytes, m.consensusStateBytes); - } - - function test_updateClient_onlyIBC( - uint64 trustedHeight, - uint64 updateLatency - ) public { - vm.assume(updateLatency < Cometbls.TRUSTING_PERIOD); - - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory id = handler.createClient(m); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(id, signedHeader, trustedHeight, zkp); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - client.pushValidProof(); - vm.expectRevert(CometblsClientLib.ErrNotIBC.selector); - client.updateClient(m2.clientId, m2.clientMessage); - } - - function test_updateClient_newCommitment( - uint64 trustedHeight, - uint64 updateLatency - ) public { - vm.assume(updateLatency < Cometbls.TRUSTING_PERIOD); - - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory id = handler.createClient(m); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(id, signedHeader, trustedHeight, zkp); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - client.pushValidProof(); - vm.prank(address(handler)); - (bytes32 clientStateCommitment, ConsensusStateUpdate[] memory updates) = - client.updateClient(m2.clientId, m2.clientMessage); - assertEq( - clientStateCommitment, - keccak256( - Cometbls.createClientState( - "union-devnet-10", uint64(signedHeader.height) - ).encodeMemory() - ) - ); - assertEq(updates.length, 1); - assertEq( - updates[0].consensusStateCommitment, - keccak256( - Cometbls.createConsensusState( - signedHeader.app_hash.toBytes32(0), - signedHeader.validators_hash.toBytes32(0), - uint64(signedHeader.time.secs) * 1e9 - + uint64(signedHeader.time.nanos) - ).encodeMemory() - ) - ); - assertEq(updates[0].height.revision_height, uint64(signedHeader.height)); - } - - function test_updateClient_validZKP( - uint64 trustedHeight, - uint64 updateLatency - ) public { - vm.assume(updateLatency < Cometbls.TRUSTING_PERIOD); - - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory id = handler.createClient(m); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(id, signedHeader, trustedHeight, zkp); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - client.pushValidProof(); - handler.updateClient(m2); - } - - function test_updateClient_invalidZKP( - uint64 trustedHeight, - uint64 updateLatency - ) public { - vm.assume(updateLatency < Cometbls.TRUSTING_PERIOD); - - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory id = handler.createClient(m); - - // Tamper the ZKP - zkp[0] = 0xCA; - zkp[1] = 0xFE; - zkp[2] = 0xBA; - zkp[3] = 0xBE; - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(id, signedHeader, trustedHeight, zkp); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - vm.expectRevert(CometblsClientLib.ErrInvalidZKP.selector); - handler.updateClient(m2); - } - - // Test that the on-chain hash(signedHeader.header) is equal to the off-chain provided signedHeader.commit.block_id.hash. - // NOTE: Optimization-wise, this is probably unecessary as we direcyly compute that on chain. i.e. we could remove commit.block_id entirely. - function test_updateClient_invalidBlockRoot( - uint64 trustedHeight, - uint64 updateLatency - ) public { - vm.assume(updateLatency < Cometbls.TRUSTING_PERIOD); - - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory id = handler.createClient(m); - - // Tamper the header such that the block root != commit, as if a relayer tampered the commit or the block. - signedHeader.app_hash = abi.encodePacked(uint256(0)); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(id, signedHeader, trustedHeight, zkp); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - vm.expectRevert(CometblsClientLib.ErrInvalidZKP.selector); - handler.updateClient(m2); - } - - function test_updateClient_nextRevisionLower( - uint64 trustedHeight, - uint64 updateLatency - ) public { - vm.assume(updateLatency < Cometbls.TRUSTING_PERIOD); - - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume(trustedHeight > uint64(signedHeader.height)); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory id = handler.createClient(m); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(id, signedHeader, trustedHeight, zkp); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - vm.expectRevert( - CometblsClientLib.ErrUntrustedHeightLTETrustedHeight.selector - ); - handler.updateClient(m2); - } - - function test_updateClient_trustingPeriodExpired(uint64 trustedHeight) - public - { - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory id = handler.createClient(m); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(id, signedHeader, trustedHeight, zkp); - - // The block timestamp will be out of the trusting period window - vm.warp(uint64(signedHeader.time.secs) + Cometbls.TRUSTING_PERIOD + 1); - - vm.expectRevert(CometblsClientLib.ErrHeaderExpired.selector); - handler.updateClient(m2); - } - - function test_getTimestampAtHeight() public { - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - uint64 updateLatency = Cometbls.TRUSTING_PERIOD - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(clientId, signedHeader, trustedHeight, zkp); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - client.pushValidProof(); - handler.updateClient(m2); - - uint64 timestamp = client.getTimestampAtHeight( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: uint64(signedHeader.height) - }) - ); - assertEq( - timestamp, - uint64(signedHeader.time.secs) * 1e9 - + uint64(signedHeader.time.nanos) - ); - } - - function test_getClientState() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - bytes memory clientStateBytes = client.getClientState(clientId); - assertEq(clientStateBytes, m.clientStateBytes); - } - - function test_getClientState_noClientState() public { - getValidTransition(); - - handler.registerClient(CLIENT_TYPE, client); - - client.getClientState("blabla"); - // REVIEW: Not sure how best to check if the bytes is the zero of the type - // assertEq(clientStateBytes, ""); - } - - function test_getClientState_step( - uint64 trustedHeight, - uint64 updateLatency - ) public { - vm.assume(updateLatency < Cometbls.TRUSTING_PERIOD); - - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - bytes memory clientStateBytes = client.getClientState(clientId); - assertEq(clientStateBytes, m.clientStateBytes); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(clientId, signedHeader, trustedHeight, zkp); - - client.pushValidProof(); - handler.updateClient(m2); - - clientStateBytes = client.getClientState(clientId); - assertEq( - clientStateBytes, - Cometbls.createClientState( - "union-devnet-10", uint64(signedHeader.height) - ).encodeMemory() - ); - } - - function test_getConsensusState() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - bytes memory consensusStateBytes = client.getConsensusState( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }) - ); - - assertEq( - consensusStateBytes, - Cometbls.createConsensusState( - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ).encodeMemory() - ); - } - - function test_getConsensusState_noConsensus() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - client.getConsensusState( - "blabla", - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }) - ); - // REVIEW: Not sure how best to check if the bytes is the zero of the type - // assertEq(consensusStateBytes, ""); - } - - function test_getConsensusState_step( - uint64 trustedHeight, - uint64 updateLatency - ) public { - vm.assume(updateLatency < Cometbls.TRUSTING_PERIOD); - - ( - bytes memory zkp, - UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader - ) = getValidTransition(); - - vm.assume( - 0 < trustedHeight && trustedHeight < uint64(signedHeader.height) - ); - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - vm.warp(uint64(signedHeader.time.secs)); - - string memory clientId = handler.createClient(m); - - bytes memory consensusStateBytes = client.getConsensusState( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: uint64(signedHeader.height) - }) - ); - // REVIEW: Not sure how best to check if the bytes is the zero of the type - // assertEq(consensusStateBytes, ""); - - IBCMsgs.MsgUpdateClient memory m2 = - Cometbls.updateClient(clientId, signedHeader, trustedHeight, zkp); - - vm.warp(uint64(signedHeader.time.secs) + updateLatency); - - client.pushValidProof(); - handler.updateClient(m2); - - consensusStateBytes = client.getConsensusState( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: uint64(signedHeader.height) - }) - ); - assertEq( - consensusStateBytes, - Cometbls.createConsensusState( - signedHeader.app_hash.toBytes32(0), - signedHeader.validators_hash.toBytes32(0), - uint64(signedHeader.time.secs) * 1e9 - + uint64(signedHeader.time.nanos) - ).encodeMemory() - ); - } - - function test_verifyMembership_noConsensus() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.expectRevert( - CometblsClientLib.ErrTrustedConsensusStateNotFound.selector - ); - client.verifyMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - 1 - }), - 0, - 0, - bytes(""), - bytes(""), - bytes(""), - bytes("") - ); - } - - function test_verifyMembership_ok() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - client.pushValidMembership(); - bool ok = client.verifyMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - 0, - 0, - bytes(""), - bytes(""), - bytes(""), - bytes("") - ); - assertTrue(ok); - } - - function test_verifyMembership_ko() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - bool ok = client.verifyMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - 0, - 0, - bytes(""), - bytes(""), - bytes(""), - bytes("") - ); - assertFalse(ok); - } - - function test_verifyMembership_delayPeriodNotExpired_time( - uint64 delayPeriodTime, - uint64 delayTime - ) public { - vm.assume(0 < delayPeriodTime && delayPeriodTime < 360000); - vm.assume(0 < delayTime && delayTime < delayPeriodTime); - - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.warp(vm.getBlockTimestamp() + delayTime); - - vm.expectRevert(CometblsClientLib.ErrDelayPeriodNotExpired.selector); - client.verifyMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - // Expected to be in nanos - delayPeriodTime * 1e9, - 0, - bytes(""), - bytes(""), - bytes(""), - bytes("") - ); - } - - function test_verifyMembership_delayPeriodNotExpired_block( - uint64 delayPeriodBlocks, - uint64 delayBlocks - ) public { - vm.assume(0 < delayPeriodBlocks && delayPeriodBlocks < 1000000); - vm.assume(0 < delayBlocks && delayBlocks < delayPeriodBlocks); - - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.warp(vm.getBlockNumber() + delayBlocks); - - vm.expectRevert(CometblsClientLib.ErrDelayPeriodNotExpired.selector); - client.verifyMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - 0, - delayPeriodBlocks, - bytes(""), - bytes(""), - bytes(""), - bytes("") - ); - } - - function test_verifyMembership_delayPeriodExpired_time( - uint64 delayPeriodTime - ) public { - vm.assume(0 < delayPeriodTime && delayPeriodTime < 360000); - - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.warp(vm.getBlockTimestamp() + delayPeriodTime); - - client.pushValidMembership(); - bool ok = client.verifyMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - delayPeriodTime, - 0, - bytes(""), - bytes(""), - bytes(""), - bytes("") - ); - assertTrue(ok); - } - - function test_verifyMembership_delayPeriodExpired_block( - uint64 delayPeriodBlocks - ) public { - vm.assume(0 < delayPeriodBlocks && delayPeriodBlocks < 1000000); - - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.roll(vm.getBlockNumber() + delayPeriodBlocks); - - client.pushValidMembership(); - bool ok = client.verifyMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - 0, - delayPeriodBlocks, - bytes(""), - bytes(""), - bytes(""), - bytes("") - ); - assertTrue(ok); - } - - function test_verifyNonMembership_ok() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - client.pushValidMembership(); - bool ok = client.verifyNonMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - 0, - 0, - bytes(""), - bytes(""), - bytes("") - ); - assertTrue(ok); - } - - function test_verifyNonMembership_ko() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - bool ok = client.verifyNonMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - 0, - 0, - bytes(""), - bytes(""), - bytes("") - ); - assertFalse(ok); - } - - function test_verifyNonMembership_delayPeriodNotExpired_time( - uint64 delayPeriodTime, - uint64 delayTime - ) public { - vm.assume(0 < delayPeriodTime && delayPeriodTime < 360000); - vm.assume(0 < delayTime && delayTime < delayPeriodTime); - - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.warp(vm.getBlockTimestamp() + delayTime); - - vm.expectRevert(CometblsClientLib.ErrDelayPeriodNotExpired.selector); - client.verifyNonMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - // Expected to be in nanos - delayPeriodTime * 1e9, - 0, - bytes(""), - bytes(""), - bytes("") - ); - } - - function test_verifyNonMembership_delayPeriodNotExpired_block( - uint64 delayPeriodBlocks, - uint64 delayBlocks - ) public { - vm.assume(0 < delayPeriodBlocks && delayPeriodBlocks < 1000000); - vm.assume(0 < delayBlocks && delayBlocks < delayPeriodBlocks); - - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.warp(vm.getBlockNumber() + delayBlocks); - - vm.expectRevert(CometblsClientLib.ErrDelayPeriodNotExpired.selector); - client.verifyNonMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - 0, - delayPeriodBlocks, - bytes(""), - bytes(""), - bytes("") - ); - } - - function test_verifyNonMembership_delayPeriodExpired_time( - uint64 delayPeriodTime - ) public { - vm.assume(0 < delayPeriodTime && delayPeriodTime < 360000); - - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.warp(vm.getBlockTimestamp() + delayPeriodTime); - - client.pushValidMembership(); - bool ok = client.verifyNonMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - delayPeriodTime, - 0, - bytes(""), - bytes(""), - bytes("") - ); - assertTrue(ok); - } - - function test_verifyNonMembership_delayPeriodExpired_block( - uint64 delayPeriodBlocks - ) public { - vm.assume(0 < delayPeriodBlocks && delayPeriodBlocks < 1000000); - - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - vm.roll(vm.getBlockNumber() + delayPeriodBlocks); - - client.pushValidMembership(); - bool ok = client.verifyNonMembership( - clientId, - IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - 0, - delayPeriodBlocks, - bytes(""), - bytes(""), - bytes("") - ); - assertTrue(ok); - } - - function test_getLatestHeight_noClientState() public { - getValidTransition(); - - handler.registerClient(CLIENT_TYPE, client); - - IbcCoreClientV1Height.Data memory latestHeight = - client.getLatestHeight("blabla"); - - assertEq(uint64(latestHeight.revision_height), 0); - assertEq(uint64(latestHeight.revision_number), 0); - } - - function test_getLatestHeight_ok() public { - (, UnionIbcLightclientsCometblsV1LightHeader.Data memory signedHeader) = - getValidTransition(); - - uint64 trustedHeight = uint64(signedHeader.height) - 1; - - handler.registerClient(CLIENT_TYPE, client); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - "union-devnet-10", - trustedHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.validators_hash.toBytes32(0), - (uint64(signedHeader.time.secs) - 10) * 1e9 - ); - - string memory clientId = handler.createClient(m); - - IbcCoreClientV1Height.Data memory latestHeight = - client.getLatestHeight(clientId); - - assertEq(uint64(latestHeight.revision_height), trustedHeight); - assertEq(uint64(latestHeight.revision_number), 0); - } -} diff --git a/evm/tests/src/25-handler/IBCConnectionHandler.t.sol b/evm/tests/src/25-handler/IBCConnectionHandler.t.sol deleted file mode 100644 index 96a0b8cd21..0000000000 --- a/evm/tests/src/25-handler/IBCConnectionHandler.t.sol +++ /dev/null @@ -1,625 +0,0 @@ -pragma solidity ^0.8.23; - -import "solidity-bytes-utils/BytesLib.sol"; -import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol"; - -import {IBCHandler} from "../../../contracts/core/25-handler/IBCHandler.sol"; -import { - IBCConnectionLib, - IBCConnection -} from "../../../contracts/core/03-connection/IBCConnection.sol"; -import {IBCClient} from "../../../contracts/core/02-client/IBCClient.sol"; -import {IBCChannelHandshake} from - "../../../contracts/core/04-channel/IBCChannelHandshake.sol"; -import { - IBCPacket, - IBCPacketLib -} from "../../../contracts/core/04-channel/IBCPacket.sol"; -import {CometblsClient} from "../../../contracts/clients/CometblsClientV2.sol"; -import {IBCMsgs} from "../../../contracts/core/25-handler/IBCMsgs.sol"; -import { - IbcCoreConnectionV1ConnectionEnd, - IbcCoreConnectionV1Counterparty, - IbcCoreConnectionV1GlobalEnums -} from "../../../contracts/proto/ibc/core/connection/v1/connection.sol"; -import {ILightClient} from "../../../contracts/core/02-client/ILightClient.sol"; -import {IBCCommitment} from "../../../contracts/core/24-host/IBCCommitment.sol"; -import {IbcCoreCommitmentV1MerklePrefix as CommitmentMerklePrefix} from - "../../../contracts/proto/ibc/core/commitment/v1/commitment.sol"; -import {TendermintTypesSignedHeader} from - "../../../contracts/proto/tendermint/types/canonical.sol"; -import {IbcCoreClientV1Height} from - "../../../contracts/proto/ibc/core/client/v1/client.sol"; -import { - TendermintTypesCommit, - TendermintTypesHeader, - TendermintTypesSignedHeader, - TendermintVersionConsensus, - TendermintTypesCommitSig, - TendermintTypesBlockID, - TendermintTypesPartSetHeader -} from "../../../contracts/proto/tendermint/types/types.sol"; -import - "../../../contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; - -import "../TestPlus.sol"; - -contract TestCometblsClient is CometblsClient { - uint256 calls; - mapping(uint256 => bool) validMembershipProof; - - function reset() public { - calls = 0; - } - - function pushValidMembership(uint256 index) public { - validMembershipProof[index] = true; - } - - function internalVerifyZKP( - bytes calldata, - string memory, - bytes32, - UnionIbcLightclientsCometblsV1LightHeader.Data calldata - ) internal pure override returns (bool) { - return true; - } - - function verifyMembership( - string calldata, - IbcCoreClientV1Height.Data calldata, - uint64, - uint64, - bytes calldata, - bytes memory, - bytes calldata, - bytes calldata - ) external override returns (bool) { - bool validMembership = validMembershipProof[calls]; - validMembershipProof[calls] = false; - calls++; - return validMembership; - } - - function verifyNonMembership( - string calldata, - IbcCoreClientV1Height.Data calldata, - uint64, - uint64, - bytes calldata, - bytes calldata, - bytes calldata - ) external override returns (bool) { - bool validMembership = validMembershipProof[calls]; - validMembershipProof[calls] = false; - calls++; - return validMembership; - } -} - -contract IBCConnectionHandlerTests is TestPlus { - using BytesLib for bytes; - using ConnectionCounterparty for ConnectionCounterparty.Data; - - string constant CLIENT_TYPE = "mock"; - - bytes32 constant ARBITRARY_INITIAL_APP_HASH = - hex"A8158610DD6858F3D26149CC0DB3339ABD580EA217DE0A151C9C451DED418E35"; - - IBCHandler_Testable handler; - TestCometblsClient client; - - function setUp() public { - handler = IBCHandler_Testable( - address( - new ERC1967Proxy( - address(new IBCHandler_Testable()), - abi.encodeCall( - IBCHandler.initialize, - ( - address(new IBCClient()), - address(new IBCConnection()), - address(new IBCChannelHandshake()), - address(new IBCPacket()), - address(this) - ) - ) - ) - ) - ); - client = TestCometblsClient( - address( - new ERC1967Proxy( - address(new TestCometblsClient()), - abi.encodeCall( - CometblsClient.initialize, - (address(handler), address(this)) - ) - ) - ) - ); - handler.registerClient(CLIENT_TYPE, client); - } - - function getValidHeader() - internal - pure - returns (TendermintTypesSignedHeader.Data memory) - { - TendermintTypesHeader.Data memory header = TendermintTypesHeader.Data({ - version: TendermintVersionConsensus.Data({block: 11, app: 0}), - chain_id: "union-devnet-1", - height: 139, - time: Timestamp.Data({secs: 1691496777, nanos: 793918988}), - last_block_id: TendermintTypesBlockID.Data({ - hash: hex"80DF3A892BF2586E3B22201D2AC5A65EDAB66ECE7BB6F51077F3B50CCE7526E1", - part_set_header: TendermintTypesPartSetHeader.Data({ - total: 1, - hash: hex"0468D541CAD891D571E2AD1DD9F43480993BDF18A1016F4C956555A417EFE681" - }) - }), - last_commit_hash: hex"DA6FCBD48131808D58B54E8B44737AB2B6F3A3DD1AFF946D0F6CEFD25306FD48", - data_hash: hex"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - validators_hash: hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60", - next_validators_hash: hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60", - consensus_hash: hex"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F", - app_hash: hex"983EF85676937CEC783601B5B50865733A72C3DF88E4CC0B3F11C108C9688459", - last_results_hash: hex"357B78587B9CD4469F1F63C29B96EAC1D7F643520B97D396B20A20505122AA01", - evidence_hash: hex"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", - proposer_address: hex"4CE57693C82B50F830731DAB14FA759327762456" - }); - return TendermintTypesSignedHeader.Data({ - header: header, - // NOTE: validators are signing the block root which is computed - // from the above TendermintTypesHeader field. Relayers can tamper - // the commit but the client ensure that the block_id.hash matches - // hash(header). Signatures are not required as the ZKP is a proof - // that the validators signed the correct hash. - commit: TendermintTypesCommit.Data({ - height: header.height, - round: 0, - block_id: TendermintTypesBlockID.Data({ - hash: hex"90548CD1E2BA8603261FE6400ADFD97EA48150CBD5B24B9828B2542BAB9E27EC", - part_set_header: TendermintTypesPartSetHeader.Data({ - total: 1, - hash: hex"153E8B1F5B189A140FE5DA85DAB72FBD4A1DFA7E69C6FE5CE1FD66F0CCB5F6A1" - }) - }), - signatures: new TendermintTypesCommitSig.Data[](0) - }) - }); - } - - function assumeValidProofHeight(uint64 proofHeight) internal pure { - vm.assume( - 0 < proofHeight - && proofHeight < uint64(getValidHeader().header.height) - ); - } - - function createClient(uint64 proofHeight) - internal - returns (string memory) - { - assumeValidProofHeight(proofHeight); - TendermintTypesSignedHeader.Data memory signedHeader = getValidHeader(); - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - signedHeader.header.chain_id, - proofHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.header.validators_hash.toBytes32(0), - uint64(signedHeader.header.time.secs - 10) - ); - return handler.createClient(m); - } - - function preInitOk() public { - client.reset(); - } - - function preAckValidProofs() public { - client.reset(); - client.pushValidMembership(0); - client.pushValidMembership(1); - } - - function preAckInvalidConnectionStateProof() public { - client.reset(); - vm.expectRevert(IBCConnectionLib.ErrInvalidConnectionProof.selector); - } - - function preAckInvalidClientStateProof() public { - client.reset(); - client.pushValidMembership(0); - vm.expectRevert(IBCConnectionLib.ErrInvalidClientStateProof.selector); - } - - function preTryValidProofs() public { - client.reset(); - client.pushValidMembership(0); - client.pushValidMembership(1); - } - - function preTryInvalidConnectionStateProof() public { - client.reset(); - vm.expectRevert(IBCConnectionLib.ErrInvalidConnectionProof.selector); - } - - function preTryInvalidClientStateProof() public { - client.reset(); - client.pushValidMembership(0); - vm.expectRevert(IBCConnectionLib.ErrInvalidClientStateProof.selector); - } - - function preConfirmValidProofs() public { - client.reset(); - client.pushValidMembership(0); - } - - function preConfirmInvalidConnectionState() public { - vm.expectRevert(IBCConnectionLib.ErrInvalidConnectionProof.selector); - } - - function preConfirmInvalidClientState() public { - vm.expectRevert(IBCConnectionLib.ErrInvalidClientStateProof.selector); - } - - function test_handshake_init_ack_ok(uint64 proofHeight) public { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenInit memory msg_init = - MsgMocks.connectionOpenInit(clientId); - preInitOk(); - string memory connId = handler.connectionOpenInit(msg_init); - - ConnectionEnd.Data memory connection = handler.getConnection(connId); - assertEq(connection.client_id, clientId, "clientId mismatch"); - assertEq( - connection.delay_period, - msg_init.delayPeriod, - "delayPeriod mismatch" - ); - assertEq( - connection.counterparty.encode(), - msg_init.counterparty.encode(), - "counterparty mismatch" - ); - assert(connection.state == ConnectionEnums.State.STATE_INIT); - assertEq(connection.versions.length, 1); - assertEq(connection.versions[0].features.length, 2); - assertEq(connection.versions[0].identifier, "1"); - assertEq(connection.versions[0].features[0], "ORDER_ORDERED"); - assertEq(connection.versions[0].features[1], "ORDER_UNORDERED"); - - assertEq( - handler.commitments(IBCCommitment.connectionCommitmentKey(connId)), - keccak256(IbcCoreConnectionV1ConnectionEnd.encode(connection)) - ); - - IBCMsgs.MsgConnectionOpenAck memory msg_ack = - MsgMocks.connectionOpenAck(clientId, connId, proofHeight); - preAckValidProofs(); - handler.connectionOpenAck(msg_ack); - - ConnectionCounterparty.Data memory expectedCounterparty = - msg_init.counterparty; - expectedCounterparty.connection_id = msg_ack.counterpartyConnectionID; - - connection = handler.getConnection(connId); - assertEq(connection.client_id, clientId, "clientId mismatch"); - assertEq( - connection.delay_period, - msg_init.delayPeriod, - "delayPeriod mismatch" - ); - assertEq( - connection.counterparty.encode(), - expectedCounterparty.encode(), - "counterparty mismatch" - ); - assert(connection.state == ConnectionEnums.State.STATE_OPEN); - assertEq(connection.versions.length, 1); - assertEq(connection.versions[0].features.length, 2); - assertEq(connection.versions[0].identifier, "1"); - assertEq(connection.versions[0].features[0], "ORDER_ORDERED"); - assertEq(connection.versions[0].features[1], "ORDER_UNORDERED"); - - assertEq( - handler.commitments(IBCCommitment.connectionCommitmentKey(connId)), - keccak256(IbcCoreConnectionV1ConnectionEnd.encode(connection)) - ); - } - - function test_handshake_ack_noInit(uint64 proofHeight) public { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenAck memory msg_ack = - MsgMocks.connectionOpenAck(clientId, "", proofHeight); - preAckValidProofs(); - vm.expectRevert(IBCConnectionLib.ErrInvalidConnectionState.selector); - handler.connectionOpenAck(msg_ack); - } - - function test_handshake_init_ack_unsupportedVersion(uint64 proofHeight) - public - { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenInit memory msg_init = - MsgMocks.connectionOpenInit(clientId); - preInitOk(); - string memory connId = handler.connectionOpenInit(msg_init); - - ConnectionEnd.Data memory connection = handler.getConnection(connId); - assertEq(connection.client_id, clientId, "clientId mismatch"); - assertEq( - connection.delay_period, - msg_init.delayPeriod, - "delayPeriod mismatch" - ); - assertEq( - connection.counterparty.encode(), - msg_init.counterparty.encode(), - "counterparty mismatch" - ); - assert(connection.state == ConnectionEnums.State.STATE_INIT); - assertEq(connection.versions.length, 1); - assertEq(connection.versions[0].features.length, 2); - assertEq(connection.versions[0].identifier, "1"); - assertEq(connection.versions[0].features[0], "ORDER_ORDERED"); - assertEq(connection.versions[0].features[1], "ORDER_UNORDERED"); - - assertEq( - handler.commitments(IBCCommitment.connectionCommitmentKey(connId)), - keccak256(IbcCoreConnectionV1ConnectionEnd.encode(connection)) - ); - - IBCMsgs.MsgConnectionOpenAck memory msg_ack = - MsgMocks.connectionOpenAck(clientId, connId, proofHeight); - msg_ack.version.identifier = "2"; - preAckValidProofs(); - vm.expectRevert(IBCConnectionLib.ErrUnsupportedVersion.selector); - handler.connectionOpenAck(msg_ack); - } - - function test_handshake_init_ack_invalidConnectionStateProof( - uint64 proofHeight - ) public { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenInit memory msg_init = - MsgMocks.connectionOpenInit(clientId); - preInitOk(); - string memory connId = handler.connectionOpenInit(msg_init); - - ConnectionEnd.Data memory connection = handler.getConnection(connId); - assertEq(connection.client_id, clientId, "clientId mismatch"); - assertEq( - connection.delay_period, - msg_init.delayPeriod, - "delayPeriod mismatch" - ); - assertEq( - connection.counterparty.encode(), - msg_init.counterparty.encode(), - "counterparty mismatch" - ); - assert(connection.state == ConnectionEnums.State.STATE_INIT); - assertEq(connection.versions.length, 1); - assertEq(connection.versions[0].features.length, 2); - assertEq(connection.versions[0].identifier, "1"); - assertEq(connection.versions[0].features[0], "ORDER_ORDERED"); - assertEq(connection.versions[0].features[1], "ORDER_UNORDERED"); - - assertEq( - handler.commitments(IBCCommitment.connectionCommitmentKey(connId)), - keccak256(IbcCoreConnectionV1ConnectionEnd.encode(connection)) - ); - - IBCMsgs.MsgConnectionOpenAck memory msg_ack = - MsgMocks.connectionOpenAck(clientId, connId, proofHeight); - preAckInvalidConnectionStateProof(); - handler.connectionOpenAck(msg_ack); - } - - function test_handshake_init_ack_invalidClientStateProof(uint64 proofHeight) - public - { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenInit memory msg_init = - MsgMocks.connectionOpenInit(clientId); - preInitOk(); - string memory connId = handler.connectionOpenInit(msg_init); - - ConnectionEnd.Data memory connection = handler.getConnection(connId); - assertEq(connection.client_id, clientId, "clientId mismatch"); - assertEq( - connection.delay_period, - msg_init.delayPeriod, - "delayPeriod mismatch" - ); - assertEq( - connection.counterparty.encode(), - msg_init.counterparty.encode(), - "counterparty mismatch" - ); - assert(connection.state == ConnectionEnums.State.STATE_INIT); - assertEq(connection.versions.length, 1); - assertEq(connection.versions[0].features.length, 2); - assertEq(connection.versions[0].identifier, "1"); - assertEq(connection.versions[0].features[0], "ORDER_ORDERED"); - assertEq(connection.versions[0].features[1], "ORDER_UNORDERED"); - - assertEq( - handler.commitments(IBCCommitment.connectionCommitmentKey(connId)), - keccak256(IbcCoreConnectionV1ConnectionEnd.encode(connection)) - ); - - IBCMsgs.MsgConnectionOpenAck memory msg_ack = - MsgMocks.connectionOpenAck(clientId, connId, proofHeight); - preAckInvalidClientStateProof(); - handler.connectionOpenAck(msg_ack); - } - - function test_handshake_try_confirm_ok(uint64 proofHeight) public { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenTry memory msg_try = - MsgMocks.connectionOpenTry(clientId, proofHeight); - preTryValidProofs(); - string memory connId = handler.connectionOpenTry(msg_try); - - ConnectionEnd.Data memory connection = handler.getConnection(connId); - assertEq(connection.client_id, clientId, "clientId mismatch"); - assertEq( - connection.delay_period, msg_try.delayPeriod, "delayPeriod mismatch" - ); - assertEq( - connection.counterparty.encode(), - msg_try.counterparty.encode(), - "counterparty mismatch" - ); - assert(connection.state == ConnectionEnums.State.STATE_TRYOPEN); - assertEq(connection.versions.length, 1); - assertEq(connection.versions[0].features.length, 2); - assertEq(connection.versions[0].identifier, "1"); - assertEq(connection.versions[0].features[0], "ORDER_ORDERED"); - assertEq(connection.versions[0].features[1], "ORDER_UNORDERED"); - - assertEq( - handler.commitments(IBCCommitment.connectionCommitmentKey(connId)), - keccak256(IbcCoreConnectionV1ConnectionEnd.encode(connection)) - ); - - IBCMsgs.MsgConnectionOpenConfirm memory msg_confirm = - MsgMocks.connectionOpenConfirm(clientId, connId, proofHeight); - preConfirmValidProofs(); - handler.connectionOpenConfirm(msg_confirm); - - connection = handler.getConnection(connId); - assertEq(connection.client_id, clientId, "clientId mismatch"); - assertEq( - connection.delay_period, msg_try.delayPeriod, "delayPeriod mismatch" - ); - assertEq( - connection.counterparty.encode(), - msg_try.counterparty.encode(), - "counterparty mismatch" - ); - assert(connection.state == ConnectionEnums.State.STATE_OPEN); - assertEq(connection.versions.length, 1); - assertEq(connection.versions[0].features.length, 2); - assertEq(connection.versions[0].identifier, "1"); - assertEq(connection.versions[0].features[0], "ORDER_ORDERED"); - assertEq(connection.versions[0].features[1], "ORDER_UNORDERED"); - - assertEq( - handler.commitments(IBCCommitment.connectionCommitmentKey(connId)), - keccak256(IbcCoreConnectionV1ConnectionEnd.encode(connection)) - ); - } - - function test_handshake_try_unsupportedVersion(uint64 proofHeight) public { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenTry memory msg_try = - MsgMocks.connectionOpenTry(clientId, proofHeight); - msg_try.counterpartyVersions[0].identifier = "4"; - preTryValidProofs(); - vm.expectRevert(IBCConnectionLib.ErrUnsupportedVersion.selector); - handler.connectionOpenTry(msg_try); - } - - function test_handshake_try_invalidConnectionStateProof(uint64 proofHeight) - public - { - TendermintTypesSignedHeader.Data memory signedHeader = getValidHeader(); - vm.assume( - 0 < proofHeight && proofHeight < uint64(signedHeader.header.height) - ); - - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - signedHeader.header.chain_id, - proofHeight, - ARBITRARY_INITIAL_APP_HASH, - signedHeader.header.validators_hash.toBytes32(0), - uint64(signedHeader.header.time.secs - 10) - ); - string memory clientId = handler.createClient(m); - - IBCMsgs.MsgConnectionOpenTry memory msg_try = - MsgMocks.connectionOpenTry(clientId, proofHeight); - preTryInvalidConnectionStateProof(); - handler.connectionOpenTry(msg_try); - } - - function test_handshake_try_invalidClientStateProof(uint64 proofHeight) - public - { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenTry memory msg_try = - MsgMocks.connectionOpenTry(clientId, proofHeight); - preTryInvalidClientStateProof(); - handler.connectionOpenTry(msg_try); - } - - function test_handshake_try_confirm_invalidClientStateProof( - uint64 proofHeight - ) public { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenTry memory msg_try = - MsgMocks.connectionOpenTry(clientId, proofHeight); - preTryValidProofs(); - string memory connId = handler.connectionOpenTry(msg_try); - - ConnectionEnd.Data memory connection = handler.getConnection(connId); - assertEq(connection.client_id, clientId, "clientId mismatch"); - assertEq( - connection.delay_period, msg_try.delayPeriod, "delayPeriod mismatch" - ); - assertEq( - connection.counterparty.encode(), - msg_try.counterparty.encode(), - "counterparty mismatch" - ); - assert(connection.state == ConnectionEnums.State.STATE_TRYOPEN); - assertEq(connection.versions.length, 1); - assertEq(connection.versions[0].features.length, 2); - assertEq(connection.versions[0].identifier, "1"); - assertEq(connection.versions[0].features[0], "ORDER_ORDERED"); - assertEq(connection.versions[0].features[1], "ORDER_UNORDERED"); - - assertEq( - handler.commitments(IBCCommitment.connectionCommitmentKey(connId)), - keccak256(IbcCoreConnectionV1ConnectionEnd.encode(connection)) - ); - - IBCMsgs.MsgConnectionOpenConfirm memory msg_confirm = - MsgMocks.connectionOpenConfirm(clientId, connId, proofHeight); - preConfirmInvalidClientState(); - handler.connectionOpenConfirm(msg_confirm); - } - - function test_handshake_confirm_notTryOpen(uint64 proofHeight) public { - string memory clientId = createClient(proofHeight); - - IBCMsgs.MsgConnectionOpenConfirm memory msg_confirm = - MsgMocks.connectionOpenConfirm(clientId, "", proofHeight); - preConfirmValidProofs(); - vm.expectRevert(IBCConnectionLib.ErrInvalidConnectionState.selector); - handler.connectionOpenConfirm(msg_confirm); - } - - function test_handshake_init_uniqueId() public { - IBCMsgs.MsgConnectionOpenInit memory m = - MsgMocks.connectionOpenInit("client-1"); - string memory id = handler.connectionOpenInit(m); - string memory id2 = handler.connectionOpenInit(m); - assertStrNotEq(id, id2); - } -} diff --git a/evm/tests/src/25-handler/IBCPacketHandler.t.sol b/evm/tests/src/25-handler/IBCPacketHandler.t.sol deleted file mode 100644 index f80ff633c5..0000000000 --- a/evm/tests/src/25-handler/IBCPacketHandler.t.sol +++ /dev/null @@ -1,1237 +0,0 @@ -pragma solidity ^0.8.23; - -import "solady/utils/LibString.sol"; -import "solidity-bytes-utils/BytesLib.sol"; -import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol"; -import "@openzeppelin/utils/math/Math.sol"; - -import {IBCHandler} from "../../../contracts/core/25-handler/IBCHandler.sol"; -import {IBCConnection} from - "../../../contracts/core/03-connection/IBCConnection.sol"; -import {IBCClient} from "../../../contracts/core/02-client/IBCClient.sol"; -import {IBCChannelHandshake} from - "../../../contracts/core/04-channel/IBCChannelHandshake.sol"; -import { - IBCPacket, - IBCPacketLib -} from "../../../contracts/core/04-channel/IBCPacket.sol"; -import {IIBCPacket} from "../../../contracts/core/04-channel/IIBCPacket.sol"; -import {IBCMsgs} from "../../../contracts/core/25-handler/IBCMsgs.sol"; -import {IbcCoreClientV1Height as ClientHeight} from - "../../../contracts/proto/MockClient.sol"; -import { - IbcCoreConnectionV1ConnectionEnd as ConnectionEnd, - IbcCoreConnectionV1Counterparty as ConnectionCounterparty, - IbcCoreConnectionV1GlobalEnums as ConnectionEnums -} from "../../../contracts/proto/ibc/core/connection/v1/connection.sol"; -import {IbcCoreChannelV1Packet} from - "../../../contracts/proto/ibc/core/channel/v1/channel.sol"; -import {ILightClient} from "../../../contracts/core/02-client/ILightClient.sol"; -import {IBCCommitment} from "../../../contracts/core/24-host/IBCCommitment.sol"; -import {IbcCoreCommitmentV1MerklePrefix as CommitmentMerklePrefix} from - "../../../contracts/proto/ibc/core/commitment/v1/commitment.sol"; -import {IbcCoreClientV1Height} from - "../../../contracts/proto/ibc/core/client/v1/client.sol"; -import {TendermintTypesSignedHeader} from - "../../../contracts/proto/tendermint/types/canonical.sol"; -import { - TendermintTypesCommit, - TendermintTypesHeader, - TendermintTypesSignedHeader, - TendermintVersionConsensus, - TendermintTypesCommitSig, - TendermintTypesBlockID, - TendermintTypesPartSetHeader -} from "../../../contracts/proto/tendermint/types/types.sol"; -import - "../../../contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; -import "../../../contracts/clients/CometblsClientV2.sol"; - -import "../TestPlus.sol"; - -contract IBCHandlerFake is IBCHandler {} - -contract TestCometblsClient is CometblsClient { - uint256 validMembership = 0; - - function pushValidMembership() public { - validMembership += 1; - } - - uint256 validProof = 0; - - function pushValidProof() public { - validProof += 1; - } - - function internalVerifyZKP( - bytes calldata, - string memory, - bytes32, - UnionIbcLightclientsCometblsV1LightHeader.Data calldata - ) internal override returns (bool) { - bool ok = validProof > 0; - if (validProof > 0) { - validProof -= 1; - } - return ok; - } - - function verifyMembership( - string calldata, - IbcCoreClientV1Height.Data calldata, - uint64, - uint64, - bytes calldata, - bytes memory, - bytes calldata, - bytes calldata - ) external override returns (bool) { - bool ok = validMembership > 0; - if (validMembership > 0) { - validMembership -= 1; - } - return ok; - } - - function verifyNonMembership( - string calldata, - IbcCoreClientV1Height.Data calldata, - uint64, - uint64, - bytes calldata, - bytes calldata, - bytes calldata - ) external override returns (bool) { - bool ok = validMembership > 0; - if (validMembership > 0) { - validMembership -= 1; - } - return ok; - } -} - -contract IBCPacketHandlerTest is TestPlus { - using CometblsClientLib for *; - using BytesLib for *; - using LibString for *; - using ConnectionCounterparty for *; - - string constant CLIENT_TYPE = "mock"; - - bytes32 constant ARBITRARY_INITIAL_NEXT_VALIDATORS = - hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60"; - bytes32 constant ARBITRARY_INITIAL_APP_HASH = - hex"A8158610DD6858F3D26149CC0DB3339ABD580EA217DE0A151C9C451DED418E35"; - string constant CHAIN_ID = "testnet-1337"; - uint64 constant LATEST_HEIGHT = 0x1337; - uint64 constant LATEST_TIMESTAMP = 0xCAFEBABE; - - uint64 constant LOCAL_HEIGHT = LATEST_HEIGHT + 0xDEAD; - uint64 constant LOCAL_TIMESTAMP = LATEST_TIMESTAMP + 0xC0DE; - - bytes constant ARBITRARY_ZKP = - hex"195562CC376E9265A7FD89A086855C100173B717B0DEA58AC9F50120E9CBDD7402D59ADAC8A274C5DDB199915B03B5CFB7A91032A71723876F946A7662135D4912EB1FAD1FCA5E88AD1D9097870391D1D477F4CD2A26F27DB3CFC8B511922C482F374A4821BEE34818589A052995CC5994CE787538207F1BA0D595890EB96D751D947274566F6338FC14BB1728C9E42F47F9D47A8A7F46CFA341D3EC71F0A8E80ECDAA9E38B4D6090989B165E536C4332BDF470E860D85001362EC7B369DE0092FD13C85FE2A16247E574B759B7B8EBFE8C7ED19CE7520A693BD09FD604CA54E2FA277AC176ACEC9626313DA7022E8B8DB599E1B02C25DA90AD508AA315DA67C0EAF8A0F41C4CDC897A4941F3BFA7D0E0C2BDD3030D5B0025FB4030A31C886F417B2509E9ECFEA86AA22F75402599E72C21623E9C32A499D7B14B6DBC3A1251E119244B7DC12B54A74FBC3B23E7954435491D89AFA7ABF6F07E1DADE0B28F0DA1978EC72A2C2C0F1FE8DEDA8DD8DDA7E82454618C3DFF1341C9901456F7E656A"; - - IBCHandlerFake handler; - TestCometblsClient client; - MockApp app; - - string clientId; - string connectionId; - string channelId; - - function mkWriteAckPacket( - string memory destinationChannel, - uint64 sequence - ) public view returns (IbcCoreChannelV1Packet.Data memory) { - return IbcCoreChannelV1Packet.Data({ - sequence: sequence, - source_port: "", - source_channel: "", - destination_port: address(app).toHexString(), - destination_channel: destinationChannel, - data: bytes(""), - timeout_height: IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: 0 - }), - timeout_timestamp: 0 - }); - } - - function setUp() public { - handler = IBCHandlerFake( - address( - new ERC1967Proxy( - address(new IBCHandlerFake()), - abi.encodeCall( - IBCHandler.initialize, - ( - address(new IBCClient()), - address(new IBCConnection()), - address(new IBCChannelHandshake()), - address(new IBCPacket()), - address(this) - ) - ) - ) - ) - ); - client = TestCometblsClient( - address( - new ERC1967Proxy( - address(new TestCometblsClient()), - abi.encodeCall( - CometblsClient.initialize, - (address(handler), address(this)) - ) - ) - ) - ); - handler.registerClient(CLIENT_TYPE, client); - app = new MockApp(); - createClient(); - setupConnection(); - setupChannel(); - - vm.warp(LOCAL_TIMESTAMP); - vm.roll(LOCAL_HEIGHT); - } - - function createClient() internal { - IBCMsgs.MsgCreateClient memory m = Cometbls.createClient( - CLIENT_TYPE, - CHAIN_ID, - LATEST_HEIGHT, - ARBITRARY_INITIAL_APP_HASH, - ARBITRARY_INITIAL_NEXT_VALIDATORS, - LATEST_TIMESTAMP - ); - clientId = handler.createClient(m); - } - - function setupConnection() internal { - IBCMsgs.MsgConnectionOpenInit memory msg_init = - MsgMocks.connectionOpenInit(clientId); - connectionId = handler.connectionOpenInit(msg_init); - IBCMsgs.MsgConnectionOpenAck memory msg_ack = - MsgMocks.connectionOpenAck(clientId, connectionId, LATEST_HEIGHT); - client.pushValidMembership(); - client.pushValidMembership(); - handler.connectionOpenAck(msg_ack); - } - - function setupChannel() internal { - IBCMsgs.MsgChannelOpenInit memory msg_init = - MsgMocks.channelOpenInit(connectionId, address(app).toHexString()); - channelId = handler.channelOpenInit(msg_init); - IBCMsgs.MsgChannelOpenAck memory msg_ack = MsgMocks.channelOpenAck( - address(app).toHexString(), channelId, LATEST_HEIGHT - ); - client.pushValidMembership(); - handler.channelOpenAck(msg_ack); - } - - function makeHeader( - uint64 height, - uint64 timestamp - ) - internal - pure - returns (UnionIbcLightclientsCometblsV1LightHeader.Data memory) - { - return UnionIbcLightclientsCometblsV1LightHeader.Data({ - height: int64(height), - time: Timestamp.Data({secs: int64(timestamp), nanos: 0}), - validators_hash: hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60", - next_validators_hash: hex"F09E25471B41514B2F8B08B5F4C9093C5D6ED134E107FF491CED2374B947DF60", - app_hash: hex"983EF85676937CEC783601B5B50865733A72C3DF88E4CC0B3F11C108C9688459" - }); - } - - function test_sendPacket_ok( - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp, - payload - ); - } - - function test_sendPacket_newCommitment( - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp, - payload - ); - assertEq( - handler.commitments( - IBCCommitment.packetCommitmentKey( - address(app).toHexString(), channelId, 1 - ) - ), - keccak256( - abi.encodePacked( - sha256( - abi.encodePacked( - timeoutTimestamp, - uint64(0), - timeoutHeight, - sha256(payload) - ) - ) - ) - ) - ); - } - - function test_sendPacket_unauthorized( - address malicious, - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(malicious != address(0) && malicious != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.expectRevert(IBCPacketLib.ErrUnauthorized.selector); - vm.prank(malicious); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp, - payload - ); - } - - function test_sendPacket_incrementSequence( - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - uint64 sequenceBefore = uint64( - uint256( - handler.commitments( - IBCCommitment.nextSequenceSendCommitmentKey( - address(app).toHexString(), channelId - ) - ) - ) - ); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp, - payload - ); - uint64 sequenceAfter = uint64( - uint256( - handler.commitments( - IBCCommitment.nextSequenceSendCommitmentKey( - address(app).toHexString(), channelId - ) - ) - ) - ); - assertEq(sequenceAfter, sequenceBefore + 1); - } - - function test_sendPacket_invalidTimeoutHeight( - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(0 < timeoutHeight && timeoutHeight <= LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.prank(address(app)); - vm.expectRevert(IBCPacketLib.ErrInvalidTimeoutHeight.selector); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp, - payload - ); - } - - function test_sendPacket_invalidTimeoutTimestamp( - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(0 < timeoutTimestamp && timeoutTimestamp <= LATEST_TIMESTAMP); - vm.prank(address(app)); - vm.expectRevert(IBCPacketLib.ErrInvalidTimeoutTimestamp.selector); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp, - payload - ); - } - - function test_recvPacket_ok( - address relayer, - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > vm.getBlockNumber()); - vm.assume(timeoutTimestamp > vm.getBlockTimestamp()); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - client.pushValidMembership(); - vm.prank(relayer); - handler.recvPacket( - MsgMocks.packetRecv( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload - ) - ); - } - - function test_recvPacket_receiptSet( - address relayer, - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > vm.getBlockNumber()); - vm.assume(timeoutTimestamp > vm.getBlockTimestamp()); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - IBCMsgs.MsgPacketRecv memory msg_ = MsgMocks.packetRecv( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload - ); - assertEq( - handler.commitments( - IBCCommitment.packetReceiptCommitmentKey( - msg_.packet.destination_port, - msg_.packet.destination_channel, - msg_.packet.sequence - ) - ), - bytes32(uint256(0)) - ); - client.pushValidMembership(); - vm.prank(relayer); - handler.recvPacket(msg_); - assertEq( - handler.commitments( - IBCCommitment.packetReceiptCommitmentKey( - msg_.packet.destination_port, - msg_.packet.destination_channel, - msg_.packet.sequence - ) - ), - bytes32(uint256(1)) - ); - } - - function test_recvPacket_alreadyReceived( - address relayer, - bytes memory payload, - uint64 timeoutHeight - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > vm.getBlockNumber()); - uint64 timeoutTimestamp = uint64(vm.getBlockTimestamp()) + 1; - client.pushValidMembership(); - IBCMsgs.MsgPacketRecv memory msg_ = MsgMocks.packetRecv( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload - ); - vm.prank(relayer); - handler.recvPacket(msg_); - client.pushValidMembership(); - vm.expectRevert(IBCPacketLib.ErrPacketAlreadyReceived.selector); - vm.prank(relayer); - handler.recvPacket(msg_); - } - - function test_recvPacket_timeoutHeight( - address relayer, - bytes memory payload, - uint32 timeoutHeightDelta, - uint64 timeoutTimestamp - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeightDelta > 0); - vm.assume(timeoutTimestamp > vm.getBlockTimestamp()); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - client.pushValidMembership(); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrHeightTimeout.selector); - handler.recvPacket( - MsgMocks.packetRecv( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - // If the height is zero it's considered not to be a timeout on height, we need to ensure its properly clamped - LOCAL_HEIGHT - - uint64(Math.min(LOCAL_HEIGHT - 1, timeoutHeightDelta)), - timeoutTimestamp * 1e9, - payload - ) - ); - } - - function test_recvPacket_timeoutTimestamp( - address relayer, - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(0 < timeoutHeight && timeoutHeight > vm.getBlockNumber()); - vm.assume(timeoutTimestamp < LOCAL_TIMESTAMP); - client.pushValidMembership(); - vm.expectRevert(IBCPacketLib.ErrTimestampTimeout.selector); - vm.prank(relayer); - handler.recvPacket( - MsgMocks.packetRecv( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - (LOCAL_TIMESTAMP - timeoutTimestamp) * 1e9, - payload - ) - ); - } - - function test_recvPacket_invalidProof( - address relayer, - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > vm.getBlockNumber()); - vm.assume(timeoutTimestamp > vm.getBlockTimestamp()); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.expectRevert(IBCPacketLib.ErrInvalidProof.selector); - vm.prank(relayer); - handler.recvPacket( - MsgMocks.packetRecv( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload - ) - ); - } - - function test_recvPacket_invalidOriginPort( - address relayer, - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(relayer != address(0)); - vm.assume(timeoutHeight > vm.getBlockNumber()); - vm.assume(timeoutTimestamp > vm.getBlockTimestamp()); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - IBCMsgs.MsgPacketRecv memory msg_ = MsgMocks.packetRecv( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp, - payload - ); - msg_.packet.source_port = "invalid"; - client.pushValidMembership(); - vm.expectRevert( - IBCPacketLib.ErrSourceAndCounterpartyPortMismatch.selector - ); - vm.prank(relayer); - handler.recvPacket(msg_); - } - - function test_recvPacket_invalidOriginChannel( - address relayer, - bytes memory payload, - uint64 timeoutHeight, - uint64 timeoutTimestamp - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > vm.getBlockNumber()); - vm.assume(timeoutTimestamp > vm.getBlockTimestamp()); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - IBCMsgs.MsgPacketRecv memory msg_ = MsgMocks.packetRecv( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp, - payload - ); - msg_.packet.source_channel = "invalid"; - client.pushValidMembership(); - vm.expectRevert( - IBCPacketLib.ErrSourceAndCounterpartyChannelMismatch.selector - ); - vm.prank(relayer); - handler.recvPacket(msg_); - } - - function test_writeAcknowledgement_ok( - uint64 sequence, - bytes memory acknowledgement - ) public { - vm.assume(acknowledgement.length > 0); - vm.prank(address(app)); - handler.writeAcknowledgement( - mkWriteAckPacket(channelId, sequence), acknowledgement - ); - } - - function test_writeAcknowledgement_alreadyExist( - uint64 sequence, - bytes memory acknowledgement - ) public { - vm.assume(acknowledgement.length > 0); - client.pushValidMembership(); - vm.prank(address(app)); - handler.writeAcknowledgement( - mkWriteAckPacket(channelId, sequence), acknowledgement - ); - vm.prank(address(app)); - vm.expectRevert(IBCPacketLib.ErrAcknowledgementAlreadyExists.selector); - handler.writeAcknowledgement( - mkWriteAckPacket(channelId, sequence), acknowledgement - ); - } - - function test_writeAcknowledgement_emptyAcknowledgement(uint64 sequence) - public - { - vm.prank(address(app)); - vm.expectRevert(IBCPacketLib.ErrAcknowledgementIsEmpty.selector); - handler.writeAcknowledgement( - mkWriteAckPacket(channelId, sequence), bytes("") - ); - } - - function test_writeAcknowledgement_unauthorized( - address malicious, - uint64 sequence, - bytes memory acknowledgement - ) public { - vm.assume(malicious != address(0) && malicious != address(app)); - vm.assume(acknowledgement.length > 0); - vm.prank(address(malicious)); - vm.expectRevert(IBCPacketLib.ErrUnauthorized.selector); - handler.writeAcknowledgement( - mkWriteAckPacket(channelId, sequence), acknowledgement - ); - } - - function test_acknowledgePacket_ok( - address relayer, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload, - bytes memory acknowledgement - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp * 1e9, - payload - ); - client.pushValidMembership(); - vm.prank(relayer); - handler.acknowledgePacket( - MsgMocks.packetAck( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload, - acknowledgement - ) - ); - } - - function test_acknowledgePacket_alreadyAcknowledged( - address relayer, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload, - bytes memory acknowledgement - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp * 1e9, - payload - ); - client.pushValidMembership(); - vm.prank(relayer); - handler.acknowledgePacket( - MsgMocks.packetAck( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload, - acknowledgement - ) - ); - client.pushValidMembership(); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrPacketCommitmentNotFound.selector); - handler.acknowledgePacket( - MsgMocks.packetAck( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload, - acknowledgement - ) - ); - } - - function test_acknowledgePacket_invalidProof( - address relayer, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload, - bytes memory acknowledgement - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp * 1e9, - payload - ); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrInvalidProof.selector); - handler.acknowledgePacket( - MsgMocks.packetAck( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload, - acknowledgement - ) - ); - } - - function test_acknowledgePacket_notSent( - address relayer, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload, - bytes memory acknowledgement - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrPacketCommitmentNotFound.selector); - handler.acknowledgePacket( - MsgMocks.packetAck( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload, - acknowledgement - ) - ); - } - - function test_acknowledgePacket_payloadTampered( - address relayer, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload, - bytes memory acknowledgement - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp * 1e9, - payload - ); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrInvalidPacketCommitment.selector); - handler.acknowledgePacket( - MsgMocks.packetAck( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - abi.encodePacked(payload, hex"00"), - acknowledgement - ) - ); - } - - function test_acknowledgePacket_invalidDestinationPort( - address relayer, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload, - bytes memory acknowledgement - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp * 1e9, - payload - ); - client.pushValidMembership(); - IBCMsgs.MsgPacketAcknowledgement memory msg_ = MsgMocks.packetAck( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload, - acknowledgement - ); - msg_.packet.destination_port = "invalid"; - vm.prank(relayer); - vm.expectRevert( - IBCPacketLib.ErrDestinationAndCounterpartyPortMismatch.selector - ); - handler.acknowledgePacket(msg_); - } - - function test_acknowledgePacket_invalidDestinationChannel( - address relayer, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload, - bytes memory acknowledgement - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp * 1e9, - payload - ); - client.pushValidMembership(); - IBCMsgs.MsgPacketAcknowledgement memory msg_ = MsgMocks.packetAck( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - payload, - acknowledgement - ); - msg_.packet.destination_channel = "invalid"; - vm.prank(relayer); - vm.expectRevert( - IBCPacketLib.ErrDestinationAndCounterpartyChannelMismatch.selector - ); - handler.acknowledgePacket(msg_); - } - - // TODO: acknowledgePacket tests against ORDERED channel - - function test_timeoutPacket_payloadTampered( - address relayer, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT); - vm.assume(timeoutTimestamp > LATEST_TIMESTAMP); - vm.assume(timeoutTimestamp < type(uint64).max / 1e9); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - }), - timeoutTimestamp * 1e9, - payload - ); - vm.warp(timeoutTimestamp); - client.pushValidMembership(); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrInvalidPacketCommitment.selector); - handler.timeoutPacket( - MsgMocks.packetTimeout( - address(app).toHexString(), - channelId, - LATEST_HEIGHT, - timeoutHeight, - timeoutTimestamp * 1e9, - abi.encodePacked(hex"00", payload) - ) - ); - } - - function test_timeoutPacket_height_ok( - address relayer, - uint64 timeoutHeight, - bytes memory payload - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT + 1); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - 1 - }), - 0, - payload - ); - client.pushValidProof(); - vm.prank(relayer); - handler.updateClient( - Cometbls.updateClient( - clientId, - makeHeader(timeoutHeight, LATEST_TIMESTAMP + 1), - LATEST_HEIGHT, - ARBITRARY_ZKP - ) - ); - client.pushValidMembership(); - vm.prank(relayer); - handler.timeoutPacket( - MsgMocks.packetTimeout( - address(app).toHexString(), - channelId, - timeoutHeight, - timeoutHeight - 1, - 0, - payload - ) - ); - } - - function test_timeoutPacket_alreadyTimedout( - address relayer, - uint64 timeoutHeight, - bytes memory payload - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT + 1); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - 1 - }), - 0, - payload - ); - client.pushValidProof(); - vm.prank(relayer); - handler.updateClient( - Cometbls.updateClient( - clientId, - makeHeader(timeoutHeight, LATEST_TIMESTAMP + 1), - LATEST_HEIGHT, - ARBITRARY_ZKP - ) - ); - client.pushValidMembership(); - vm.prank(relayer); - handler.timeoutPacket( - MsgMocks.packetTimeout( - address(app).toHexString(), - channelId, - timeoutHeight, - timeoutHeight - 1, - 0, - payload - ) - ); - client.pushValidMembership(); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrPacketCommitmentNotFound.selector); - handler.timeoutPacket( - MsgMocks.packetTimeout( - address(app).toHexString(), - channelId, - timeoutHeight, - timeoutHeight - 1, - 0, - payload - ) - ); - } - - function test_timeoutPacket_invalidProof( - address relayer, - uint64 timeoutHeight, - bytes memory payload - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT + 1); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - 1 - }), - 0, - payload - ); - client.pushValidProof(); - vm.prank(relayer); - handler.updateClient( - Cometbls.updateClient( - clientId, - makeHeader(timeoutHeight, LATEST_TIMESTAMP + 1), - LATEST_HEIGHT, - ARBITRARY_ZKP - ) - ); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrInvalidProof.selector); - handler.timeoutPacket( - MsgMocks.packetTimeout( - address(app).toHexString(), - channelId, - timeoutHeight, - timeoutHeight - 1, - 0, - payload - ) - ); - } - - function test_timeoutPacket_height_notReached( - address relayer, - uint64 timeoutHeight, - bytes memory payload - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.assume(timeoutHeight > LATEST_HEIGHT + 1); - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({ - revision_number: 0, - revision_height: timeoutHeight - 1 - }), - 0, - payload - ); - client.pushValidProof(); - vm.prank(relayer); - handler.updateClient( - Cometbls.updateClient( - clientId, - makeHeader(timeoutHeight - 1, LATEST_TIMESTAMP + 1), - LATEST_HEIGHT, - ARBITRARY_ZKP - ) - ); - client.pushValidMembership(); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrTimeoutHeightNotReached.selector); - handler.timeoutPacket( - MsgMocks.packetTimeout( - address(app).toHexString(), - channelId, - timeoutHeight - 1, - timeoutHeight - 1, - 0, - payload - ) - ); - } - - function test_timeoutPacket_timestamp_ok( - address relayer, - bytes memory payload - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - vm.prank(address(app)); - uint64 timeoutTimestamp = LATEST_TIMESTAMP + 2; - handler.sendPacket( - channelId, - ClientHeight.Data({revision_number: 0, revision_height: 0}), - (timeoutTimestamp - 1) * 1e9, - payload - ); - vm.warp(timeoutTimestamp); - client.pushValidProof(); - vm.prank(relayer); - handler.updateClient( - Cometbls.updateClient( - clientId, - makeHeader(LATEST_HEIGHT + 1, timeoutTimestamp), - LATEST_HEIGHT, - ARBITRARY_ZKP - ) - ); - client.pushValidMembership(); - vm.prank(relayer); - handler.timeoutPacket( - MsgMocks.packetTimeout( - address(app).toHexString(), - channelId, - LATEST_HEIGHT + 1, - 0, - (timeoutTimestamp - 1) * 1e9, - payload - ) - ); - } - - function test_timeoutPacket_timestamp_notReached( - address relayer, - bytes memory payload - ) public { - vm.assume(relayer != address(0) && relayer != address(app)); - uint64 timeoutTimestamp = LATEST_TIMESTAMP + 2; - vm.prank(address(app)); - handler.sendPacket( - channelId, - ClientHeight.Data({revision_number: 0, revision_height: 0}), - (timeoutTimestamp - 1) * 1e9, - payload - ); - vm.warp(timeoutTimestamp - 1); - client.pushValidProof(); - vm.prank(relayer); - handler.updateClient( - Cometbls.updateClient( - clientId, - makeHeader(LATEST_HEIGHT + 1, timeoutTimestamp - 1), - LATEST_HEIGHT, - ARBITRARY_ZKP - ) - ); - client.pushValidMembership(); - vm.prank(relayer); - vm.expectRevert(IBCPacketLib.ErrTimeoutTimestampNotReached.selector); - handler.timeoutPacket( - MsgMocks.packetTimeout( - address(app).toHexString(), - channelId, - LATEST_HEIGHT + 1, - 0, - (timeoutTimestamp - 1) * 1e9, - payload - ) - ); - } -} diff --git a/evm/tests/src/Codec.t.sol b/evm/tests/src/Codec.t.sol deleted file mode 100644 index 412a3382ea..0000000000 --- a/evm/tests/src/Codec.t.sol +++ /dev/null @@ -1,29 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; -import "../../contracts/clients/CometblsClientV2.sol"; -import "../../contracts/proto/tendermint/types/canonical.sol"; - -contract CodecTest is Test { - function test_consensusState_encode_decode_iso( - uint64 timestamp, - bytes32 appHash, - bytes32 nextValidatorsHash - ) public pure { - OptimizedConsensusState memory consensusState = OptimizedConsensusState({ - timestamp: timestamp, - appHash: appHash, - nextValidatorsHash: nextValidatorsHash - }); - - OptimizedConsensusState memory consensusState2 = - abi.decode(abi.encode(consensusState), (OptimizedConsensusState)); - - assertEq(consensusState.timestamp, consensusState2.timestamp); - assertEq(consensusState.appHash, consensusState2.appHash); - assertEq( - consensusState.nextValidatorsHash, - consensusState2.nextValidatorsHash - ); - } -} diff --git a/evm/tests/src/ICS23.t.sol b/evm/tests/src/ICS23.t.sol deleted file mode 100644 index 21a6476668..0000000000 --- a/evm/tests/src/ICS23.t.sol +++ /dev/null @@ -1,367 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; -import "../../contracts/proto/cosmos/ics23/v1/proofs.sol"; -import "../../contracts/proto/ibc/core/commitment/v1/commitment.sol"; -import "../../contracts/lib/ICS23.sol"; -import "../../contracts/clients/ICS23MembershipVerifier.sol"; - -contract ICS23Test is Test { - function verifyMembership( - bytes32 root, - bytes calldata proof, - bytes calldata prefix, - bytes calldata path, - bytes calldata value - ) external pure returns (bool) { - return ICS23MembershipVerifier.verifyMembership( - root, proof, prefix, path, value - ); - } - - function verifyNonMembership( - bytes32 root, - bytes calldata proof, - bytes calldata prefix, - bytes calldata path - ) external pure returns (bool) { - return ICS23MembershipVerifier.verifyNonMembership( - root, proof, prefix, path - ); - } - - function test_decode() public pure { - bytes memory proof = - hex"0acf0112cc010a0441413d3d1ac3010a20636c69656e74732f30392d6c6f63616c686f73742f636c69656e74537461746512350a2a2f6962632e6c69676874636c69656e74732e6c6f63616c686f73742e76322e436c69656e74537461746512070a05080210d9021a0c0801180120012a040002b205222c080112050204b205201a212075c4910f51207d3c65960120fe931f138e2624668d75869f51b8442593dd5eab222c08011205060ab205201a2120c617eef82d350859fc4c1b0118079fad20ecd1e5fe2294c86a86e94c0d14ca550afe010afb010a03696263122016df45c79ca168d31360706db2979a792fcd9c2371478a77af951f39ec59487d1a090801180120012a0100222708011201011a20c505c0fd48b1cf2b65619f12b3144e19c60b4e6b62525ee936be93d041623ebf222708011201011a20dd55097e1841a5872eb9dbdf5ca65b54143f01aa24b598538786884a824191602225080112210182c1cabef1a0591f8016c06a396858762bb949a7dfc03e568b4273b3c205273d222508011221010d9399f8bc11620accd23dbfaeca52b7cda51a92ec71c044cd1d39a34bea2826222708011201011a2022ecbf124eff995ecf01998dd8346b71810af164e192feeb4d4287085128b9df"; - - CosmosIcs23V1CommitmentProof.decode(proof); - } - - function getExists(IbcCoreCommitmentV1MerkleProof.Data memory decoded) - internal - pure - returns ( - UnionIcs23.ExistenceProof memory, - UnionIcs23.ExistenceProof memory - ) - { - UnionIcs23.ExistenceProof memory existProof; - existProof.key = decoded.proofs[0].exist.key; - existProof.value = decoded.proofs[0].exist.value; - existProof.leafPrefix = decoded.proofs[0].exist.leaf.prefix; - - existProof.path = - new UnionIcs23.InnerOp[](decoded.proofs[0].exist.path.length); - for (uint256 i; i < existProof.path.length; i++) { - existProof.path[i].prefix = decoded.proofs[0].exist.path[i].prefix; - existProof.path[i].suffix = decoded.proofs[0].exist.path[i].suffix; - } - - UnionIcs23.ExistenceProof memory existProof2; - existProof2.key = decoded.proofs[1].exist.key; - existProof2.value = decoded.proofs[1].exist.value; - existProof2.leafPrefix = decoded.proofs[1].exist.leaf.prefix; - - existProof2.path = - new UnionIcs23.InnerOp[](decoded.proofs[1].exist.path.length); - for (uint256 i; i < existProof2.path.length; i++) { - existProof2.path[i].prefix = decoded.proofs[1].exist.path[i].prefix; - existProof2.path[i].suffix = decoded.proofs[1].exist.path[i].suffix; - } - - return (existProof, existProof2); - } - - function test_accountExist() public { - vm.pauseGasMetering(); - bytes32 root = - hex"B802C903BEFE08624832AAF853DBEA4EDE1F7D50E88BEDD6317831F45CC74A3D"; - bytes memory proof = - hex"0afa020af7020a15014152090b0c95c948edc407995560feed4a9df81e129e010a202f636f736d6f732e617574682e763162657461312e426173654163636f756e74127a0a2c756e696f6e31673966716a7a63766a687935336d77797137763432633837613439666d37713772646568386312460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103820c4b94dccd7d74706216c426fe884d9a4404410df69d6421899595c5a9c122180120011a0b0801180120012a0300020222290801122502040220170c890f01b9fa9ab803511bbc7be7c25359309f04d021a72e0a9b93b8ff72c020222b08011204040802201a2120a89a7b1aedf861a8c6316009af3d19448bfe8834dfb5546c7e1af7f95c3000b4222b08011204061002201a212029347d33c119e85fc1335f43ad17c4a1986ad44c71837158ceffd36e2f38f986222b080112040a3002201a2120e284b7ed0385d018b1ffcd6f33bf6ac575fb7731704d0ae71be278bd8bf5e0b50a80020afd010a03616363122082d7d632a58654a81bb6764379eff4b6e641e96620a12dac0e250e6caf94f7761a090801180120012a010022250801122101ba30cf8122e71a87fea08d0da9499e0373495a64e1648de8f08ca1a73e1fc1a8222708011201011a208a19e0585632ebada293099d24f28707d453266ae7ded6e854dfd8a025c7ce71222708011201011a204a22410f42f7706402b38c460e74d712c95cea8e6e370c691f43c0abf3f4e104222708011201011a20b999d9a62cbd36a843f207580c4802d194e6441f7f3715ddce55d5194d46e57a222708011201011a2022ecbf124eff995ecf01998dd8346b71810af164e192feeb4d4287085128b9df"; - bytes memory value = - hex"0a202f636f736d6f732e617574682e763162657461312e426173654163636f756e74127a0a2c756e696f6e31673966716a7a63766a687935336d77797137763432633837613439666d37713772646568386312460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103820c4b94dccd7d74706216c426fe884d9a4404410df69d6421899595c5a9c12218012001"; - IbcCoreCommitmentV1MerkleProof.Data memory decoded = - IbcCoreCommitmentV1MerkleProof.decode(proof); - - ( - UnionIcs23.ExistenceProof memory existProof, - UnionIcs23.ExistenceProof memory existProof2 - ) = getExists(decoded); - - bytes memory encoded = abi.encode(existProof, existProof2); - vm.resumeGasMetering(); - assertTrue( - this.verifyMembership( - root, - encoded, - bytes("acc"), - hex"014152090B0C95C948EDC407995560FEED4A9DF81E", - value - ) - ); - } - - function test_connectionExist() public { - vm.pauseGasMetering(); - bytes32 root = - hex"899CD0B55A4FEDE9AF3C959C43ED3AE6805293642590A81CD95B4C97F89CC424"; - bytes memory proof = - hex"0abc020ab9020a18636f6e6e656374696f6e732f636f6e6e656374696f6e2d31125b0a0930382d7761736d2d3112230a0131120d4f524445525f4f524445524544120f4f524445525f554e4f524445524544180222250a0e636f6d6574626c732d6e65772d30120c636f6e6e656374696f6e2d301a050a0369626328061a0c0801180120012a040002f006222c080112050204f006201a212075c4910f51207d3c65960120fe931f138e2624668d75869f51b8442593dd5eab222a080112260408de0a2002b6fcf07091245d162f1196b003c555c564980e02c4d4a9fa0a249798f4b25e20222c08011205060ede0a201a2120ff6b0a04e076eecbabfee4e751c0523cbedba898211b5847404e2d954a2203e3222a08011226081ede0a20635053419cfb6a81c839860d99f3ed002840124a790ddd9f066d8bce63f9df54200afc010af9010a03696263122024b15e198bcf648dee62c7ca1fd8c3950c85c3d898833180c3e3c412ccbc559d1a090801180120012a01002225080112210106b99c0d8119ff1edbcbe165d0f19337dbbc080e677c88e57aa2ae767ebf0f0f222708011201011a20aa650406ea0d76e39dd43d2ea6a91e3fdaa1c908fc21a7ca68e5e62cc8115639222508011221016ac3182364d7cdaa1f52a77b6081e070aa29b2d253f3642169693cde336e2bdc222508011221016376cbd7b917c7105ddac35bdeddd79e6c9cbbc66dd227941599de2b9bc8b3de222708011201011a200d68ac7c3e8daf94c65ccdfe5b7397f50e80325240ef9b2a0ec483afaea30544"; - bytes memory value = - hex"0a0930382d7761736d2d3112230a0131120d4f524445525f4f524445524544120f4f524445525f554e4f524445524544180222250a0e636f6d6574626c732d6e65772d30120c636f6e6e656374696f6e2d301a050a036962632806"; - IbcCoreCommitmentV1MerkleProof.Data memory decoded = - IbcCoreCommitmentV1MerkleProof.decode(proof); - ( - UnionIcs23.ExistenceProof memory existProof, - UnionIcs23.ExistenceProof memory existProof2 - ) = getExists(decoded); - - bytes memory encoded = abi.encode(existProof, existProof2); - vm.resumeGasMetering(); - assertTrue( - this.verifyMembership( - root, - encoded, - bytes("ibc"), - bytes("connections/connection-1"), - value - ) - ); - } - - function test_clientStateExist() public { - vm.pauseGasMetering(); - bytes32 root = - hex"971AF378C1F256110B3BA2EFD90325D5B5AFC8185997F2C12A7C4638B906CC2F"; - bytes memory proof = - hex"0ab0030aad030a1d636c69656e74732f30382d7761736d2d312f636c69656e74537461746512c7010a252f6962632e6c69676874636c69656e74732e7761736d2e76312e436c69656e745374617465129d010a720a20d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b807818e0fac1950622310a04900000691a060a049000007022060a04900000712a060a049000007232110a040400000010ffffffffffffffffff01280c30203880024204080110034880c2d72f50a0f4a4011220e8dcc770de5a013041588233812f73ac797ec6078b0011cbcbfe49d474f4c1191a051081f2e7011a0c0801180120012a040002ae06222c080112050204b006201a2120980ab410769397da376376a2756754b225f34cc0eea404b068924f64180abcc4222c080112050408b006201a21209d79cf7fc2f248ea0a56cff266ac54cfbc06687e25ffee99aec2884856d0104f222a080112260610b006203e808c2bc895d44d05d7af6d8b0424fabb1d9ab6f53b10cdb084b2996f75bfa620222c08011205081eb006201a212095bb7de983d8ea1282a2d60e2f6c675bec25f82be86aa874ff0f15827c1ab3ed0afc010af9010a036962631220859b7ac80b1c0ca82504e0d8e9de460d42ca66a03e708cbd09869e5216c73a591a090801180120012a01002225080112210106b99c0d8119ff1edbcbe165d0f19337dbbc080e677c88e57aa2ae767ebf0f0f222708011201011a20aa650406ea0d76e39dd43d2ea6a91e3fdaa1c908fc21a7ca68e5e62cc8115639222508011221016ac3182364d7cdaa1f52a77b6081e070aa29b2d253f3642169693cde336e2bdc22250801122101c9d0a585c82dc572f3fcedc70302d4c3fbbc9e84f0618c6b446a70efa312e8dc222708011201011a20952029410a533cf530124179204303bea59a86f5b4993291c5b8ca406412c5f7"; - bytes memory value = - hex"0a252f6962632e6c69676874636c69656e74732e7761736d2e76312e436c69656e745374617465129d010a720a20d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b807818e0fac1950622310a04900000691a060a049000007022060a04900000712a060a049000007232110a040400000010ffffffffffffffffff01280c30203880024204080110034880c2d72f50a0f4a4011220e8dcc770de5a013041588233812f73ac797ec6078b0011cbcbfe49d474f4c1191a051081f2e701"; - IbcCoreCommitmentV1MerkleProof.Data memory decoded = - IbcCoreCommitmentV1MerkleProof.decode(proof); - ( - UnionIcs23.ExistenceProof memory existProof, - UnionIcs23.ExistenceProof memory existProof2 - ) = getExists(decoded); - - bytes memory encoded = abi.encode(existProof, existProof2); - vm.resumeGasMetering(); - assertTrue( - this.verifyMembership( - root, - encoded, - bytes("ibc"), - bytes("clients/08-wasm-1/clientState"), - value - ) - ); - } - - function test_existenceProofRootMismatch() public { - vm.pauseGasMetering(); - bytes32 root = - hex"971AF378C1F256110B3BA2EFD90325D5B5AFC8185997F2C12A7C4638B906CC22"; - bytes memory proof = - hex"0ab0030aad030a1d636c69656e74732f30382d7761736d2d312f636c69656e74537461746512c7010a252f6962632e6c69676874636c69656e74732e7761736d2e76312e436c69656e745374617465129d010a720a20d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b807818e0fac1950622310a04900000691a060a049000007022060a04900000712a060a049000007232110a040400000010ffffffffffffffffff01280c30203880024204080110034880c2d72f50a0f4a4011220e8dcc770de5a013041588233812f73ac797ec6078b0011cbcbfe49d474f4c1191a051081f2e7011a0c0801180120012a040002ae06222c080112050204b006201a2120980ab410769397da376376a2756754b225f34cc0eea404b068924f64180abcc4222c080112050408b006201a21209d79cf7fc2f248ea0a56cff266ac54cfbc06687e25ffee99aec2884856d0104f222a080112260610b006203e808c2bc895d44d05d7af6d8b0424fabb1d9ab6f53b10cdb084b2996f75bfa620222c08011205081eb006201a212095bb7de983d8ea1282a2d60e2f6c675bec25f82be86aa874ff0f15827c1ab3ed0afc010af9010a036962631220859b7ac80b1c0ca82504e0d8e9de460d42ca66a03e708cbd09869e5216c73a591a090801180120012a01002225080112210106b99c0d8119ff1edbcbe165d0f19337dbbc080e677c88e57aa2ae767ebf0f0f222708011201011a20aa650406ea0d76e39dd43d2ea6a91e3fdaa1c908fc21a7ca68e5e62cc8115639222508011221016ac3182364d7cdaa1f52a77b6081e070aa29b2d253f3642169693cde336e2bdc22250801122101c9d0a585c82dc572f3fcedc70302d4c3fbbc9e84f0618c6b446a70efa312e8dc222708011201011a20952029410a533cf530124179204303bea59a86f5b4993291c5b8ca406412c5f7"; - bytes memory value = - hex"0a252f6962632e6c69676874636c69656e74732e7761736d2e76312e436c69656e745374617465129d010a720a20d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b807818e0fac1950622310a04900000691a060a049000007022060a04900000712a060a049000007232110a040400000010ffffffffffffffffff01280c30203880024204080110034880c2d72f50a0f4a4011220e8dcc770de5a013041588233812f73ac797ec6078b0011cbcbfe49d474f4c1191a051081f2e701"; - IbcCoreCommitmentV1MerkleProof.Data memory decoded = - IbcCoreCommitmentV1MerkleProof.decode(proof); - ( - UnionIcs23.ExistenceProof memory existProof, - UnionIcs23.ExistenceProof memory existProof2 - ) = getExists(decoded); - - bytes memory encoded = abi.encode(existProof, existProof2); - vm.resumeGasMetering(); - assertFalse( - this.verifyMembership( - root, - encoded, - bytes("ibc"), - bytes("clients/08-wasm-1/clientState"), - value - ) - ); - } - - function test_existenceProofKeyMismatch() public { - vm.pauseGasMetering(); - bytes32 root = - hex"971AF378C1F256110B3BA2EFD90325D5B5AFC8185997F2C12A7C4638B906CC2F"; - bytes memory proof = - hex"0ab0030aad030a1d636c69656e74732f30382d7761736d2d312f636c69656e74537461746512c7010a252f6962632e6c69676874636c69656e74732e7761736d2e76312e436c69656e745374617465129d010a720a20d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b807818e0fac1950622310a04900000691a060a049000007022060a04900000712a060a049000007232110a040400000010ffffffffffffffffff01280c30203880024204080110034880c2d72f50a0f4a4011220e8dcc770de5a013041588233812f73ac797ec6078b0011cbcbfe49d474f4c1191a051081f2e7011a0c0801180120012a040002ae06222c080112050204b006201a2120980ab410769397da376376a2756754b225f34cc0eea404b068924f64180abcc4222c080112050408b006201a21209d79cf7fc2f248ea0a56cff266ac54cfbc06687e25ffee99aec2884856d0104f222a080112260610b006203e808c2bc895d44d05d7af6d8b0424fabb1d9ab6f53b10cdb084b2996f75bfa620222c08011205081eb006201a212095bb7de983d8ea1282a2d60e2f6c675bec25f82be86aa874ff0f15827c1ab3ed0afc010af9010a036962631220859b7ac80b1c0ca82504e0d8e9de460d42ca66a03e708cbd09869e5216c73a591a090801180120012a01002225080112210106b99c0d8119ff1edbcbe165d0f19337dbbc080e677c88e57aa2ae767ebf0f0f222708011201011a20aa650406ea0d76e39dd43d2ea6a91e3fdaa1c908fc21a7ca68e5e62cc8115639222508011221016ac3182364d7cdaa1f52a77b6081e070aa29b2d253f3642169693cde336e2bdc22250801122101c9d0a585c82dc572f3fcedc70302d4c3fbbc9e84f0618c6b446a70efa312e8dc222708011201011a20952029410a533cf530124179204303bea59a86f5b4993291c5b8ca406412c5f7"; - bytes memory value = - hex"0a252f6962632e6c69676874636c69656e74732e7761736d2e76312e436c69656e745374617465129d010a720a20d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b807818e0fac1950622310a04900000691a060a049000007022060a04900000712a060a049000007232110a040400000010ffffffffffffffffff01280c30203880024204080110034880c2d72f50a0f4a4011220e8dcc770de5a013041588233812f73ac797ec6078b0011cbcbfe49d474f4c1191a051081f2e701"; - IbcCoreCommitmentV1MerkleProof.Data memory decoded = - IbcCoreCommitmentV1MerkleProof.decode(proof); - ( - UnionIcs23.ExistenceProof memory existProof, - UnionIcs23.ExistenceProof memory existProof2 - ) = getExists(decoded); - - bytes memory encoded = abi.encode(existProof, existProof2); - vm.resumeGasMetering(); - assertFalse( - this.verifyMembership( - root, - encoded, - bytes("ibc"), - bytes("clients/08-wasm-2/clientState"), - value - ) - ); - } - - function test_existenceProofValueMismatch() public { - vm.pauseGasMetering(); - bytes32 root = - hex"971AF378C1F256110B3BA2EFD90325D5B5AFC8185997F2C12A7C4638B906CC2F"; - bytes memory proof = - hex"0ab0030aad030a1d636c69656e74732f30382d7761736d2d312f636c69656e74537461746512c7010a252f6962632e6c69676874636c69656e74732e7761736d2e76312e436c69656e745374617465129d010a720a20d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b807818e0fac1950622310a04900000691a060a049000007022060a04900000712a060a049000007232110a040400000010ffffffffffffffffff01280c30203880024204080110034880c2d72f50a0f4a4011220e8dcc770de5a013041588233812f73ac797ec6078b0011cbcbfe49d474f4c1191a051081f2e7011a0c0801180120012a040002ae06222c080112050204b006201a2120980ab410769397da376376a2756754b225f34cc0eea404b068924f64180abcc4222c080112050408b006201a21209d79cf7fc2f248ea0a56cff266ac54cfbc06687e25ffee99aec2884856d0104f222a080112260610b006203e808c2bc895d44d05d7af6d8b0424fabb1d9ab6f53b10cdb084b2996f75bfa620222c08011205081eb006201a212095bb7de983d8ea1282a2d60e2f6c675bec25f82be86aa874ff0f15827c1ab3ed0afc010af9010a036962631220859b7ac80b1c0ca82504e0d8e9de460d42ca66a03e708cbd09869e5216c73a591a090801180120012a01002225080112210106b99c0d8119ff1edbcbe165d0f19337dbbc080e677c88e57aa2ae767ebf0f0f222708011201011a20aa650406ea0d76e39dd43d2ea6a91e3fdaa1c908fc21a7ca68e5e62cc8115639222508011221016ac3182364d7cdaa1f52a77b6081e070aa29b2d253f3642169693cde336e2bdc22250801122101c9d0a585c82dc572f3fcedc70302d4c3fbbc9e84f0618c6b446a70efa312e8dc222708011201011a20952029410a533cf530124179204303bea59a86f5b4993291c5b8ca406412c5f7"; - bytes memory value = - hex"0a252f6962632e6c69676874636c69656e74732e7761736d2e76312e436c69656e745374617465129d010a720a20d8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b807818e0fac1950622310a04900000691a060a049000007022060a04900000712a060a049000007232110a040400000010ffffffffffffffffff01280c30203880024204080110034880c2d72f50a0f4a4011220e8dcc770de5a013041588233812f73ac797ec6078b0011cbcbfe49d474f4c1191a051081f2e700"; - IbcCoreCommitmentV1MerkleProof.Data memory decoded = - IbcCoreCommitmentV1MerkleProof.decode(proof); - ( - UnionIcs23.ExistenceProof memory existProof, - UnionIcs23.ExistenceProof memory existProof2 - ) = getExists(decoded); - - bytes memory encoded = abi.encode(existProof, existProof2); - vm.resumeGasMetering(); - assertFalse( - this.verifyMembership( - root, - encoded, - bytes("ibc"), - bytes("clients/08-wasm-1/clientState"), - value - ) - ); - } - - function getNonExists(IbcCoreCommitmentV1MerkleProof.Data memory decoded) - internal - pure - returns ( - UnionIcs23.NonExistenceProof memory, - UnionIcs23.ExistenceProof memory - ) - { - UnionIcs23.NonExistenceProof memory nonExistProof; - nonExistProof.key = decoded.proofs[0].nonexist.key; - - UnionIcs23.ExistenceProof memory leftExistProof; - leftExistProof.key = decoded.proofs[0].nonexist.left.key; - leftExistProof.value = decoded.proofs[0].nonexist.left.value; - leftExistProof.leafPrefix = decoded.proofs[0].nonexist.left.leaf.prefix; - - leftExistProof.path = new UnionIcs23.InnerOp[]( - decoded.proofs[0].nonexist.left.path.length - ); - for (uint256 i; i < leftExistProof.path.length; i++) { - leftExistProof.path[i].prefix = - decoded.proofs[0].nonexist.left.path[i].prefix; - leftExistProof.path[i].suffix = - decoded.proofs[0].nonexist.left.path[i].suffix; - } - - UnionIcs23.ExistenceProof memory rightExistProof; - rightExistProof.key = decoded.proofs[0].nonexist.right.key; - rightExistProof.value = decoded.proofs[0].nonexist.right.value; - rightExistProof.leafPrefix = - decoded.proofs[0].nonexist.right.leaf.prefix; - - rightExistProof.path = new UnionIcs23.InnerOp[]( - decoded.proofs[0].nonexist.right.path.length - ); - for (uint256 i; i < rightExistProof.path.length; i++) { - rightExistProof.path[i].prefix = - decoded.proofs[0].nonexist.right.path[i].prefix; - rightExistProof.path[i].suffix = - decoded.proofs[0].nonexist.right.path[i].suffix; - } - - nonExistProof.left = leftExistProof; - nonExistProof.right = rightExistProof; - - UnionIcs23.ExistenceProof memory existProof2; - existProof2.key = decoded.proofs[1].exist.key; - existProof2.value = decoded.proofs[1].exist.value; - existProof2.leafPrefix = decoded.proofs[1].exist.leaf.prefix; - - existProof2.path = - new UnionIcs23.InnerOp[](decoded.proofs[1].exist.path.length); - for (uint256 i; i < existProof2.path.length; i++) { - existProof2.path[i].prefix = decoded.proofs[1].exist.path[i].prefix; - existProof2.path[i].suffix = decoded.proofs[1].exist.path[i].suffix; - } - - return (nonExistProof, existProof2); - } - - function test_accountNonExistence() public { - vm.pauseGasMetering(); - bytes32 root = - hex"C9A25B954FEF48EC601359591A28C9A2FD32A411421AEF2DC16DC8A68B3CFA98"; - bytes memory proof = - hex"0a96061293060a15014152090b0c95c948edc407995560feed4a9df88812fa020a15014152090b0c95c948edc407995560feed4a9df81e129e010a202f636f736d6f732e617574682e763162657461312e426173654163636f756e74127a0a2c756e696f6e31673966716a7a63766a687935336d77797137763432633837613439666d37713772646568386312460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103820c4b94dccd7d74706216c426fe884d9a4404410df69d6421899595c5a9c122180420031a0b0801180120012a0300027822290801122502047820170c890f01b9fa9ab803511bbc7be7c25359309f04d021a72e0a9b93b8ff72c020222c0801120504089601201a21205f282a80f1d186fa1f7b237f81e8bc9a4bb40d5a03cbbdffdd421b1ad4cb16f4222c0801120506109601201a2120e9c65294b7106c7323dcabe4532232c319afc78cd373e338f12df43f8ecfa909222c080112050a309601201a2120a95af7890dba33514ea28a3db7b409f4887b058d6d1e43960c4cd45bb1d9bef81afc020a150143e46d91544517a037a8029b6c7f86f62bab389b129e010a202f636f736d6f732e617574682e763162657461312e426173654163636f756e74127a0a2c756e696f6e3167306a786d79323567357436716461677132646b636c7578376334366b77796d38646563667712460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21034611ea6606f6241fdeb0db1854a785eaa2fef5770694237daaf46057cadb3903180320031a0c0801180120012a0400029601222c0801120502049601201a2120532543090d1564b206e953fd6f97000d9b78bd5a8a424f551d483a58b3f54c57222a0801122604089601207e55a1ee8006e9c29c895a8de8ea8cdc6aaddc10e05ea3d3ee8fac786a73c02d20222c0801120506109601201a2120e9c65294b7106c7323dcabe4532232c319afc78cd373e338f12df43f8ecfa909222c080112050a309601201a2120a95af7890dba33514ea28a3db7b409f4887b058d6d1e43960c4cd45bb1d9bef80a80020afd010a0361636312205281c416bf4f80b9d99428a09f91ff311968a3b2adb199342d63c9db20a417e91a090801180120012a010022250801122101ba30cf8122e71a87fea08d0da9499e0373495a64e1648de8f08ca1a73e1fc1a8222708011201011a203489cd05a389a1d165f19003cea0994df9e55a5cb53b3d659417040be528b86d222708011201011a20e5c60ddccacb1c6b0be7957e8d7a86dc0f8bcec91c91d666d39eb1ebedd1bdf1222708011201011a2047a4c9a64496594e8b255443aa979293b2c7120150cf31e0eeeb8a2a987fd7e8222708011201011a2053bca15bed4becbdfd1b4cd0e63bd3845646022a99a2289a6678d8608f092207"; - IbcCoreCommitmentV1MerkleProof.Data memory decoded = - IbcCoreCommitmentV1MerkleProof.decode(proof); - ( - UnionIcs23.NonExistenceProof memory nonExistProof, - UnionIcs23.ExistenceProof memory existProof - ) = getNonExists(decoded); - - bytes memory encoded = abi.encode(nonExistProof, existProof); - vm.resumeGasMetering(); - assertTrue( - this.verifyNonMembership( - root, - encoded, - bytes("acc"), - hex"014152090b0c95c948edc407995560feed4a9df888" - ) - ); - } - - function test_accountNonExistenceEthAbi() public { - vm.pauseGasMetering(); - bytes32 root = - hex"C9A25B954FEF48EC601359591A28C9A2FD32A411421AEF2DC16DC8A68B3CFA98"; - bytes memory proof = - hex"00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000c60000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000006600000000000000000000000000000000000000000000000000000000000000015014152090b0c95c948edc407995560feed4a9df8880000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000015014152090b0c95c948edc407995560feed4a9df81e0000000000000000000000000000000000000000000000000000000000000000000000000000000000009e0a202f636f736d6f732e617574682e763162657461312e426173654163636f756e74127a0a2c756e696f6e31673966716a7a63766a687935336d77797137763432633837613439666d37713772646568386312460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103820c4b94dccd7d74706216c426fe884d9a4404410df69d6421899595c5a9c1221804200300000000000000000000000000000000000000000000000000000000000000000003000278000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002502047820170c890f01b9fa9ab803511bbc7be7c25359309f04d021a72e0a9b93b8ff72c020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000504089601200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021205f282a80f1d186fa1f7b237f81e8bc9a4bb40d5a03cbbdffdd421b1ad4cb16f4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000050610960120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002120e9c65294b7106c7323dcabe4532232c319afc78cd373e338f12df43f8ecfa909000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000050a30960120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002120a95af7890dba33514ea28a3db7b409f4887b058d6d1e43960c4cd45bb1d9bef800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000150143e46d91544517a037a8029b6c7f86f62bab389b0000000000000000000000000000000000000000000000000000000000000000000000000000000000009e0a202f636f736d6f732e617574682e763162657461312e426173654163636f756e74127a0a2c756e696f6e3167306a786d79323567357436716461677132646b636c7578376334366b77796d38646563667712460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21034611ea6606f6241fdeb0db1854a785eaa2fef5770694237daaf46057cadb390318032003000000000000000000000000000000000000000000000000000000000000000000040002960100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000050204960120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002120532543090d1564b206e953fd6f97000d9b78bd5a8a424f551d483a58b3f54c5700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002604089601207e55a1ee8006e9c29c895a8de8ea8cdc6aaddc10e05ea3d3ee8fac786a73c02d20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000050610960120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002120e9c65294b7106c7323dcabe4532232c319afc78cd373e338f12df43f8ecfa909000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000050a30960120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002120a95af7890dba33514ea28a3db7b409f4887b058d6d1e43960c4cd45bb1d9bef800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000003616363000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000205281c416bf4f80b9d99428a09f91ff311968a3b2adb199342d63c9db20a417e900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002101ba30cf8122e71a87fea08d0da9499e0373495a64e1648de8f08ca1a73e1fc1a8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000203489cd05a389a1d165f19003cea0994df9e55a5cb53b3d659417040be528b86d00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020e5c60ddccacb1c6b0be7957e8d7a86dc0f8bcec91c91d666d39eb1ebedd1bdf10000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002047a4c9a64496594e8b255443aa979293b2c7120150cf31e0eeeb8a2a987fd7e80000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002053bca15bed4becbdfd1b4cd0e63bd3845646022a99a2289a6678d8608f092207"; - - vm.resumeGasMetering(); - assertTrue( - this.verifyNonMembership( - root, - proof, - bytes("acc"), - hex"014152090b0c95c948edc407995560feed4a9df888" - ) - ); - } - - function test_accountExistEthAbi() public { - vm.pauseGasMetering(); - bytes32 root = - hex"B802C903BEFE08624832AAF853DBEA4EDE1F7D50E88BEDD6317831F45CC74A3D"; - bytes memory proof = - hex"00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000015014152090b0c95c948edc407995560feed4a9df81e0000000000000000000000000000000000000000000000000000000000000000000000000000000000009e0a202f636f736d6f732e617574682e763162657461312e426173654163636f756e74127a0a2c756e696f6e31673966716a7a63766a687935336d77797137763432633837613439666d37713772646568386312460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103820c4b94dccd7d74706216c426fe884d9a4404410df69d6421899595c5a9c1221801200100000000000000000000000000000000000000000000000000000000000000000003000202000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002502040220170c890f01b9fa9ab803511bbc7be7c25359309f04d021a72e0a9b93b8ff72c02000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000040408022000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002120a89a7b1aedf861a8c6316009af3d19448bfe8834dfb5546c7e1af7f95c3000b400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000004061002200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000212029347d33c119e85fc1335f43ad17c4a1986ad44c71837158ceffd36e2f38f986000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000040a30022000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002120e284b7ed0385d018b1ffcd6f33bf6ac575fb7731704d0ae71be278bd8bf5e0b500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000036163630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002082d7d632a58654a81bb6764379eff4b6e641e96620a12dac0e250e6caf94f77600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002101ba30cf8122e71a87fea08d0da9499e0373495a64e1648de8f08ca1a73e1fc1a8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000208a19e0585632ebada293099d24f28707d453266ae7ded6e854dfd8a025c7ce71000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000204a22410f42f7706402b38c460e74d712c95cea8e6e370c691f43c0abf3f4e10400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020b999d9a62cbd36a843f207580c4802d194e6441f7f3715ddce55d5194d46e57a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002022ecbf124eff995ecf01998dd8346b71810af164e192feeb4d4287085128b9df"; - bytes memory value = - hex"0a202f636f736d6f732e617574682e763162657461312e426173654163636f756e74127a0a2c756e696f6e31673966716a7a63766a687935336d77797137763432633837613439666d37713772646568386312460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103820c4b94dccd7d74706216c426fe884d9a4404410df69d6421899595c5a9c12218012001"; - - vm.resumeGasMetering(); - assertTrue( - this.verifyMembership( - root, - proof, - bytes("acc"), - hex"014152090B0C95C948EDC407995560FEED4A9DF81E", - value - ) - ); - } -} diff --git a/evm/tests/src/TestPlus.sol b/evm/tests/src/TestPlus.sol deleted file mode 100644 index 5bd344732b..0000000000 --- a/evm/tests/src/TestPlus.sol +++ /dev/null @@ -1,30 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; -import "./utils/MsgMocks.sol"; -import "./utils/Cometbls.sol"; -import "./utils/MockApp.sol"; -import "./utils/IBCHandler_Testable.sol"; - -abstract contract TestPlus is Test { - function assertStrEq(bytes memory a, string memory b) internal pure { - require( - keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)), - "strings not equal" - ); - } - - function assertStrEq(string memory a, string memory b) internal pure { - require( - keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)), - "strings not equal" - ); - } - - function assertStrNotEq(string memory a, string memory b) internal pure { - require( - keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b)), - "strings equal" - ); - } -} diff --git a/evm/tests/src/TestableIBCHandler.t.sol b/evm/tests/src/TestableIBCHandler.t.sol deleted file mode 100644 index e5dfb00f39..0000000000 --- a/evm/tests/src/TestableIBCHandler.t.sol +++ /dev/null @@ -1,5 +0,0 @@ -pragma solidity ^0.8.23; - -import "../../contracts/core/OwnableIBCHandler.sol"; - -contract TestableIBCHandler is OwnableIBCHandler {} diff --git a/evm/tests/src/Verifier.t.sol b/evm/tests/src/Verifier.t.sol deleted file mode 100644 index bdacaf3ab2..0000000000 --- a/evm/tests/src/Verifier.t.sol +++ /dev/null @@ -1,78 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; - -import "../../contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; -import "../../contracts/proto/ibc/lightclients/wasm/v1/wasm.sol"; -import "../../contracts/proto/ibc/core/commitment/v1/commitment.sol"; -import "../../contracts/proto/ibc/lightclients/tendermint/v1/tendermint.sol"; -import "../../contracts/proto/tendermint/types/types.sol"; -import "../../contracts/proto/tendermint/types/validator.sol"; -import "../../contracts/proto/tendermint/types/canonical.sol"; -import "../../contracts/lib/Common.sol"; -import {CometblsClient} from "../../contracts/clients/CometblsClientV2.sol"; - -contract VerifierProxy { - CometblsClient client; - - constructor() { - client = new CometblsClient(); - } - - function verifyZKP( - bytes memory zkp, - string memory chainId, - bytes32 trustedValidatorsHash, - UnionIbcLightclientsCometblsV1LightHeader.Data memory header - ) public returns (bool) { - return client.verifyZKP(zkp, chainId, trustedValidatorsHash, header); - } -} - -contract VerifierTests is Test { - VerifierProxy proxy; - - function setUp() public { - proxy = new VerifierProxy(); - } - - function test_verifyZKP_ok() public { - assertTrue( - proxy.verifyZKP( - hex"294A48A750D5C2CF926516752FF484EEBE55FF26CF8A8A7536D98794CF062DB6214D0C9E5C6B164111927A1630889619DBBB40149D8E2D32898E7ACB765542CD0EB8A8E04CCC254C3BFDC2FCE627D59C3C05E2AC76E03977855DD889C1C9BA432FF7FF4DEFCB5286555D36D22DD073A859140508AF9B977F38EB9A604E99A5F6109D43A4AFA0AB161DA2B261DED80FBC0C36E57DE2001338941C834E3262CF751BC1BFC6EC27BB8E106BAAB976285BAC1D4AC38D1B759C8A2852D65CE239974F1275CC6765B3D174FD1122EFDE86137D19F07483FEF5244B1D74B2D9DC598AC32A5CA10E8837FBC89703F4D0D46912CF4AF82341C30C2A1F3941849CC011A56E18AD2162EEB71289B8821CC01875BC1E35E5FC1EBD9114C0B2C0F0D9A96C394001468C70A1716CA98EBE82B1E614D4D9B07292EBAD5B60E0C76FD1D58B485E7D1FB1E07F51A0C68E4CA59A399FCF0634D9585BE478E37480423681B984E96C0A1698D8FCB1DF51CAE023B045E114EED9CB233A5742D9E60E1097206EB20A5058", - "union-devnet-1337", - 0x1B7EA0F1B3E574F8D50A12827CCEA43CFF858C2716AE05370CC40AE8EC521FD8, - UnionIbcLightclientsCometblsV1LightHeader.Data({ - height: int64(3405691582), - time: GoogleProtobufTimestamp.Data({ - secs: int64(1710783278), - nanos: 499600406 - }), - validators_hash: hex"1B7EA0F1B3E574F8D50A12827CCEA43CFF858C2716AE05370CC40AE8EC521FD8", - next_validators_hash: hex"1B7EA0F1B3E574F8D50A12827CCEA43CFF858C2716AE05370CC40AE8EC521FD8", - app_hash: hex"3A34FC963EEFAAE9B7C0D3DFF89180D91F3E31073E654F732340CEEDD77DD25B" - }) - ) - ); - } - - function test_verifyZKP_tamperedBlock() public { - assertFalse( - proxy.verifyZKP( - hex"294A48A750D5C2CF926516752FF484EEBE55FF26CF8A8A7536D98794CF062DB6214D0C9E5C6B164111927A1630889619DBBB40149D8E2D32898E7ACB765542CD0EB8A8E04CCC254C3BFDC2FCE627D59C3C05E2AC76E03977855DD889C1C9BA432FF7FF4DEFCB5286555D36D22DD073A859140508AF9B977F38EB9A604E99A5F6109D43A4AFA0AB161DA2B261DED80FBC0C36E57DE2001338941C834E3262CF751BC1BFC6EC27BB8E106BAAB976285BAC1D4AC38D1B759C8A2852D65CE239974F1275CC6765B3D174FD1122EFDE86137D19F07483FEF5244B1D74B2D9DC598AC32A5CA10E8837FBC89703F4D0D46912CF4AF82341C30C2A1F3941849CC011A56E18AD2162EEB71289B8821CC01875BC1E35E5FC1EBD9114C0B2C0F0D9A96C394001468C70A1716CA98EBE82B1E614D4D9B07292EBAD5B60E0C76FD1D58B485E7D1FB1E07F51A0C68E4CA59A399FCF0634D9585BE478E37480423681B984E96C0A1698D8FCB1DF51CAE023B045E114EED9CB233A5742D9E60E1097206EB20A5058", - "union-devnet-1337", - 0x1B7EA0F1B3E574F8D50A12827CCEA43CFF858C2716AE05370CC40AE8EC521FD8, - UnionIbcLightclientsCometblsV1LightHeader.Data({ - height: int64(3405691583), - time: GoogleProtobufTimestamp.Data({ - secs: int64(1710783278), - nanos: 499600406 - }), - validators_hash: hex"1B7EA0F1B3E574F8D50A12827CCEA43CFF858C2716AE05370CC40AE8EC521FD8", - next_validators_hash: hex"1B7EA0F1B3E574F8D50A12827CCEA43CFF858C2716AE05370CC40AE8EC521FD8", - app_hash: hex"3A34FC963EEFAAE9B7C0D3DFF89180D91F3E31073E654F732340CEEDD77DD25B" - }) - ) - ); - } -} diff --git a/evm/tests/src/apps/ucs/01-relay/Relay.t.sol b/evm/tests/src/apps/ucs/01-relay/Relay.t.sol deleted file mode 100644 index 2924f2b63f..0000000000 --- a/evm/tests/src/apps/ucs/01-relay/Relay.t.sol +++ /dev/null @@ -1,1737 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; -import "solidity-stringutils/strings.sol"; -import "solady/utils/LibString.sol"; -import "@openzeppelin/token/ERC20/IERC20.sol"; -import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol"; -import "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol"; -import "../../../../../contracts/lib/Hex.sol"; -import "../../../../../contracts/apps/Base.sol"; -import "../../../../../contracts/apps/ucs/01-relay/Relay.sol"; -import "../../../../../contracts/apps/ucs/01-relay/ERC20Denom.sol"; -import "../../../../../contracts/apps/ucs/01-relay/IERC20Denom.sol"; -import "../../../utils/IBCHandler_Testable.sol"; -import {IBCHandler} from - "../../../../../contracts/core/25-handler/IBCHandler.sol"; -import {IBCConnection} from - "../../../../../contracts/core/03-connection/IBCConnection.sol"; -import {IBCClient} from "../../../../../contracts/core/02-client/IBCClient.sol"; -import {IBCHeight} from "../../../../../contracts/core/02-client/IBCHeight.sol"; -import {IBCChannelHandshake} from - "../../../../../contracts/core/04-channel/IBCChannelHandshake.sol"; -import {IIBCPacket} from - "../../../../../contracts/core/04-channel/IIBCPacket.sol"; -import {IBCPacket} from "../../../../../contracts/core/04-channel/IBCPacket.sol"; - -contract IBCHandlerFake is IBCHandler { - using LibString for *; - - IbcCoreChannelV1Packet.Data[] packets; - uint64 sequence; - - function sendPacket( - string calldata sourceChannel, - IbcCoreClientV1Height.Data calldata timeoutHeight, - uint64 timeoutTimestamp, - bytes calldata data - ) external override returns (uint64) { - uint64 packetSequence = sequence; - sequence++; - packets.push( - IbcCoreChannelV1Packet.Data({ - sequence: packetSequence, - source_port: msg.sender.toHexString(), - source_channel: sourceChannel, - destination_port: "dummy-port", - destination_channel: "dummy-channel", - data: data, - timeout_height: timeoutHeight, - timeout_timestamp: timeoutTimestamp - }) - ); - return packetSequence; - } - - function lastPacket() - public - view - returns (IbcCoreChannelV1Packet.Data memory) - { - return packets[packets.length - 1]; - } -} - -contract RelayTests is Test { - using LibString for *; - using strings for *; - - IBCHandlerFake ibcHandler; - IRelay relay; - - function setUp() public { - ibcHandler = IBCHandlerFake( - address( - new ERC1967Proxy( - address(new IBCHandlerFake()), - abi.encodeCall( - IBCHandler.initialize, - ( - address(new IBCClient()), - address(new IBCConnection()), - address(new IBCChannelHandshake()), - address(new IBCPacket()), - address(this) - ) - ) - ) - ) - ); - relay = IRelay( - address( - new ERC1967Proxy( - address(new UCS01Relay()), - abi.encodeCall( - UCS01Relay.initialize, (ibcHandler, address(this)) - ) - ) - ) - ); - } - - function initChannel( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.prank(address(ibcHandler)); - relay.onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED, - new string[](0), - destinationPort, - destinationChannel, - IbcCoreChannelV1Counterparty.Data({ - port_id: sourcePort, - channel_id: sourceChannel - }), - RelayLib.VERSION, - RelayLib.VERSION, - relayer - ); - } - - function sendLocalToken( - string memory, - string memory sourceChannel, - address sender, - bytes memory receiver, - string memory denomName, - uint128 amount, - string memory extension - ) public returns (address) { - address denomAddress = address(new ERC20Denom(denomName)); - IERC20Denom(denomAddress).mint(address(sender), amount); - - vm.prank(sender); - IERC20Denom(denomAddress).approve(address(relay), amount); - - LocalToken[] memory localTokens = new LocalToken[](1); - localTokens[0].denom = denomAddress; - localTokens[0].amount = amount; - - vm.expectEmit(); - emit IERC20.Transfer(address(sender), address(relay), amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Sent(0, sourceChannel, address(0), "", "", address(0), 0); - - vm.prank(sender); - relay.send( - sourceChannel, receiver, localTokens, extension, IBCHeight.zero(), 0 - ); - - return denomAddress; - } - - function sendRemoteToken( - string memory, - string memory sourceChannel, - bytes memory sender, - address receiver, - address denomAddress, - uint128 amount, - string memory extension - ) public { - vm.prank(receiver); - IERC20Denom(denomAddress).approve(address(relay), amount); - - LocalToken[] memory localTokens = new LocalToken[](1); - localTokens[0].denom = denomAddress; - localTokens[0].amount = amount; - - // Burn from user to zero - vm.expectEmit(); - emit IERC20.Transfer(address(receiver), address(0), amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Sent(0, sourceChannel, address(0), "", "", address(0), 0); - - vm.prank(receiver); - relay.send( - sourceChannel, sender, localTokens, extension, IBCHeight.zero(), 0 - ); - } - - function receiveRemoteToken( - uint64 sequence, - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - uint64 timeoutRevisionNumber, - uint64 timeoutRevisionHeight, - uint64 timeoutTimestamp, - bytes memory sender, - address receiver, - address relayer, - string memory denomName, - uint128 amount, - string memory extension - ) public { - Token[] memory tokens = new Token[](1); - tokens[0].denom = denomName; - tokens[0].amount = amount; - - vm.expectEmit(false, false, false, false); - emit RelayLib.DenomCreated(sequence, sourceChannel, "", address(0)); - - vm.expectEmit(false, false, false, false); - emit IERC20.Transfer(address(0), address(0), 0); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Received( - sequence, sourceChannel, "", address(0), "", address(0), 0 - ); - - vm.prank(address(ibcHandler)); - relay.onRecvPacket( - IbcCoreChannelV1Packet.Data({ - sequence: sequence, - source_port: sourcePort, - source_channel: sourceChannel, - destination_port: destinationPort, - destination_channel: destinationChannel, - data: RelayPacketLib.encode( - RelayPacket({ - sender: sender, - receiver: abi.encodePacked(receiver), - tokens: tokens, - extension: extension - }) - ), - timeout_height: IbcCoreClientV1Height.Data({ - revision_number: timeoutRevisionNumber, - revision_height: timeoutRevisionHeight - }), - timeout_timestamp: timeoutTimestamp - }), - relayer - ); - } - - function test_isRemote_ok() public pure { - assertEq(RelayLib.isFromChannel("a", "b", "a/b/X"), true); - assertEq(RelayLib.isFromChannel("aa.bb", "c", "aa.bb/c/X"), true); - } - - function test_isRemote_ko() public pure { - assertEq(RelayLib.isFromChannel("a", "b", "b/b/X"), false); - assertEq(RelayLib.isFromChannel("aa.bb", "c", "aa.b/c/X"), false); - } - - function test_makeForeignDenom() public pure { - assertEq(RelayLib.makeForeignDenom("a", "b", "BLA"), "a/b/BLA"); - assertEq( - RelayLib.makeForeignDenom("wasm.xyz", "channel-1", "muno"), - "wasm.xyz/channel-1/muno" - ); - } - - function test_makeDenomPrefix() public pure { - assertEq(RelayLib.makeDenomPrefix("a", "b"), "a/b/"); - assertEq( - RelayLib.makeDenomPrefix("wasm.xyz", "channel-99"), - "wasm.xyz/channel-99/" - ); - } - - function test_hexToAddress(address addr) public pure { - assertEq(Hex.hexToAddress(addr.toHexString()), addr); - } - - function test_hexToUint256(uint256 v) public pure { - assertEq(Hex.hexToUint256(v.toHexString()), v); - } - - function test_openInit_onlyIBC( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(IBCAppLib.ErrNotIBC.selector); - relay.onChanOpenInit( - IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED, - new string[](0), - destinationPort, - destinationChannel, - IbcCoreChannelV1Counterparty.Data({ - port_id: sourcePort, - channel_id: sourceChannel - }), - RelayLib.VERSION, - relayer - ); - } - - function test_openInit_wrongVersion( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(RelayLib.ErrInvalidProtocolVersion.selector); - vm.prank(address(ibcHandler)); - relay.onChanOpenInit( - IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED, - new string[](0), - destinationPort, - destinationChannel, - IbcCoreChannelV1Counterparty.Data({ - port_id: sourcePort, - channel_id: sourceChannel - }), - "blabla", - relayer - ); - } - - function test_openInit_wrongOrdering( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(RelayLib.ErrInvalidProtocolOrdering.selector); - vm.prank(address(ibcHandler)); - relay.onChanOpenInit( - IbcCoreChannelV1GlobalEnums.Order.ORDER_ORDERED, - new string[](0), - destinationPort, - destinationChannel, - IbcCoreChannelV1Counterparty.Data({ - port_id: sourcePort, - channel_id: sourceChannel - }), - RelayLib.VERSION, - relayer - ); - } - - function test_openTry_onlyIBC( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(IBCAppLib.ErrNotIBC.selector); - relay.onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED, - new string[](0), - destinationPort, - destinationChannel, - IbcCoreChannelV1Counterparty.Data({ - port_id: sourcePort, - channel_id: sourceChannel - }), - RelayLib.VERSION, - RelayLib.VERSION, - relayer - ); - } - - function test_openTry_wrongVersion( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(RelayLib.ErrInvalidProtocolVersion.selector); - vm.prank(address(ibcHandler)); - relay.onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED, - new string[](0), - destinationPort, - destinationChannel, - IbcCoreChannelV1Counterparty.Data({ - port_id: sourcePort, - channel_id: sourceChannel - }), - "0xDEADC0DE", - RelayLib.VERSION, - relayer - ); - } - - function test_openTry_wrongOrdering( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(RelayLib.ErrInvalidProtocolOrdering.selector); - vm.prank(address(ibcHandler)); - relay.onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order.ORDER_ORDERED, - new string[](0), - destinationPort, - destinationChannel, - IbcCoreChannelV1Counterparty.Data({ - port_id: sourcePort, - channel_id: sourceChannel - }), - RelayLib.VERSION, - RelayLib.VERSION, - relayer - ); - } - - function test_openTry_wrongCounterpartyVersion( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(RelayLib.ErrInvalidCounterpartyProtocolVersion.selector); - vm.prank(address(ibcHandler)); - relay.onChanOpenTry( - IbcCoreChannelV1GlobalEnums.Order.ORDER_UNORDERED, - new string[](0), - destinationPort, - destinationChannel, - IbcCoreChannelV1Counterparty.Data({ - port_id: sourcePort, - channel_id: sourceChannel - }), - RelayLib.VERSION, - "ok", - relayer - ); - } - - function test_openAck_onlyIBC( - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(IBCAppLib.ErrNotIBC.selector); - relay.onChanOpenAck( - destinationPort, - destinationChannel, - sourceChannel, - RelayLib.VERSION, - relayer - ); - } - - function test_openAck_wrongVersion( - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(RelayLib.ErrInvalidCounterpartyProtocolVersion.selector); - vm.prank(address(ibcHandler)); - relay.onChanOpenAck( - destinationPort, - destinationChannel, - sourceChannel, - "ucs01version", - relayer - ); - } - - function test_openConfirm_onlyIBC( - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(IBCAppLib.ErrNotIBC.selector); - relay.onChanOpenConfirm(destinationPort, destinationChannel, relayer); - } - - function test_openConfirm( - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.prank(address(ibcHandler)); - relay.onChanOpenConfirm(destinationPort, destinationChannel, relayer); - } - - function test_closeInit_onlyIBC( - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(IBCAppLib.ErrNotIBC.selector); - relay.onChanCloseInit(destinationPort, destinationChannel, relayer); - } - - function test_closeInit_impossible( - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(RelayLib.ErrUnstoppable.selector); - vm.prank(address(ibcHandler)); - relay.onChanCloseInit(destinationPort, destinationChannel, relayer); - } - - function test_closeConfirm_onlyIBC( - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(IBCAppLib.ErrNotIBC.selector); - relay.onChanCloseConfirm(destinationPort, destinationChannel, relayer); - } - - function test_closeConfirm_impossible( - string memory destinationPort, - string memory destinationChannel, - address relayer - ) public { - vm.expectRevert(RelayLib.ErrUnstoppable.selector); - vm.prank(address(ibcHandler)); - relay.onChanCloseConfirm(destinationPort, destinationChannel, relayer); - } - - function test_onRecvPacketProcessing_onlySelf( - address malicious, - uint64 sequence, - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - uint64 timeoutRevisionNumber, - uint64 timeoutRevisionHeight, - uint64 timeoutTimestamp, - address relayer - ) public { - vm.assume(malicious != address(relay)); - vm.expectRevert(RelayLib.ErrUnauthorized.selector); - vm.prank(address(malicious)); - UCS01Relay(address(relay)).onRecvPacketProcessing( - IbcCoreChannelV1Packet.Data({ - sequence: sequence, - source_port: sourcePort, - source_channel: sourceChannel, - destination_port: destinationPort, - destination_channel: destinationChannel, - data: hex"00", - timeout_height: IbcCoreClientV1Height.Data({ - revision_number: timeoutRevisionNumber, - revision_height: timeoutRevisionHeight - }), - timeout_timestamp: timeoutTimestamp - }), - relayer - ); - } - - function test_onRecvPacket_onlyIBC( - uint64 sequence, - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - uint64 timeoutRevisionNumber, - uint64 timeoutRevisionHeight, - uint64 timeoutTimestamp, - address relayer - ) public { - vm.record(); - vm.expectRevert(IBCAppLib.ErrNotIBC.selector); - relay.onRecvPacket( - IbcCoreChannelV1Packet.Data({ - sequence: sequence, - source_port: sourcePort, - source_channel: sourceChannel, - destination_port: destinationPort, - destination_channel: destinationChannel, - data: hex"00", - timeout_height: IbcCoreClientV1Height.Data({ - revision_number: timeoutRevisionNumber, - revision_height: timeoutRevisionHeight - }), - timeout_timestamp: timeoutTimestamp - }), - relayer - ); - } - - function test_onRecvPacket_revertProcessing_noop( - uint64 sequence, - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address denom, - address sender, - uint128 amount, - uint64 timeoutRevisionNumber, - uint64 timeoutRevisionHeight, - uint64 timeoutTimestamp, - address relayer, - string memory extension - ) public { - vm.assume(sender != address(0)); - vm.assume(denom != address(0)); - vm.assume(amount > 0); - - // Receive a token that hasn't been escrowed - Token[] memory tokens = new Token[](1); - tokens[0].denom = RelayLib.makeForeignDenom( - sourcePort, sourceChannel, denom.toHexString() - ); - tokens[0].amount = amount; - - vm.record(); - vm.prank(address(ibcHandler)); - bytes memory acknowledgement = relay.onRecvPacket( - IbcCoreChannelV1Packet.Data({ - sequence: sequence, - source_port: sourcePort, - source_channel: sourceChannel, - destination_port: destinationPort, - destination_channel: destinationChannel, - data: RelayPacketLib.encode( - RelayPacket({ - sender: abi.encodePacked(sender), - receiver: abi.encodePacked(sender), - tokens: tokens, - extension: extension - }) - ), - timeout_height: IbcCoreClientV1Height.Data({ - revision_number: timeoutRevisionNumber, - revision_height: timeoutRevisionHeight - }), - timeout_timestamp: timeoutTimestamp - }), - relayer - ); - - assertEq(acknowledgement, abi.encodePacked(RelayLib.ACK_FAILURE)); - (, bytes32[] memory writes) = vm.accesses(address(relay)); - assertEq(writes.length, 0); - } - - struct ReceiveLocalToken { - uint64 sequence; - string sourcePort; - string sourceChannel; - string destinationPort; - string destinationChannel; - uint64 timeoutRevisionNumber; - uint64 timeoutRevisionHeight; - uint64 timeoutTimestamp; - address sender; - bytes receiver; - address relayer; - string denomName; - uint128 amount; - string extension; - } - - function test_receive_localToken(ReceiveLocalToken memory args) public { - vm.assume(args.sender != address(0)); - vm.assume(args.relayer != address(0)); - vm.assume(args.amount > 0); - - initChannel( - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.relayer - ); - - address denomAddress = address(new ERC20Denom(args.denomName)); - IERC20Denom(denomAddress).mint(address(args.sender), args.amount); - - LocalToken[] memory localTokens = new LocalToken[](1); - localTokens[0].denom = denomAddress; - localTokens[0].amount = args.amount; - - vm.prank(args.sender); - IERC20Denom(denomAddress).approve(address(relay), args.amount); - - // A single transfer without mint as the token was previously escrowed - vm.expectEmit(); - emit IERC20.Transfer(address(args.sender), address(relay), args.amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Sent( - args.sequence, args.sourceChannel, address(0), "", "", address(0), 0 - ); - - vm.prank(args.sender); - relay.send( - args.destinationChannel, - args.receiver, - localTokens, - args.extension, - IBCHeight.zero(), - 0 - ); - - Token[] memory tokens = new Token[](1); - tokens[0].denom = RelayLib.makeForeignDenom( - args.sourcePort, args.sourceChannel, denomAddress.toHexString() - ); - tokens[0].amount = args.amount; - - // A single transfer without mint as the token was previously escrowed - vm.expectEmit(false, false, false, false); - emit IERC20.Transfer(address(0), address(args.sender), args.amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Received( - args.sequence, args.sourceChannel, "", address(0), "", address(0), 0 - ); - - uint256 outstandingBefore = - relay.getOutstanding(args.destinationChannel, denomAddress); - - vm.prank(address(ibcHandler)); - relay.onRecvPacket( - IbcCoreChannelV1Packet.Data({ - sequence: args.sequence, - source_port: args.sourcePort, - source_channel: args.sourceChannel, - destination_port: args.destinationPort, - destination_channel: args.destinationChannel, - data: RelayPacketLib.encode( - RelayPacket({ - sender: args.receiver, - receiver: abi.encodePacked(args.sender), - tokens: tokens, - extension: args.extension - }) - ), - timeout_height: IbcCoreClientV1Height.Data({ - revision_number: args.timeoutRevisionNumber, - revision_height: args.timeoutRevisionHeight - }), - timeout_timestamp: args.timeoutTimestamp - }), - args.relayer - ); - - // Local tokens are tracked, outstanding for the channel must be diminished by the amount - assertEq( - relay.getOutstanding(args.destinationChannel, denomAddress) - + args.amount, - outstandingBefore - ); - } - - struct ReceiveRemoteToken { - uint64 sequence; - string sourcePort; - string sourceChannel; - string destinationPort; - string destinationChannel; - uint64 timeoutRevisionNumber; - uint64 timeoutRevisionHeight; - uint64 timeoutTimestamp; - bytes sender; - address receiver; - address relayer; - string denomName; - uint128 amount; - string extension; - } - - function test_receive_remoteToken(ReceiveRemoteToken memory args) public { - vm.assume(args.receiver != address(0)); - vm.assume(args.relayer != address(0)); - vm.assume(args.amount > 0); - - initChannel( - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.relayer - ); - - receiveRemoteToken( - args.sequence, - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.timeoutRevisionNumber, - args.timeoutRevisionHeight, - args.timeoutTimestamp, - args.sender, - args.receiver, - args.relayer, - args.denomName, - args.amount, - args.extension - ); - } - - function test_send_local( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address sender, - bytes memory receiver, - string memory denomName, - uint128 amount, - string memory extension, - address relayer - ) public { - vm.assume(sender != address(0)); - vm.assume(amount > 0); - - initChannel( - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - relayer - ); - - address denomAddress = address(new ERC20Denom(denomName)); - IERC20Denom(denomAddress).mint(sender, amount); - - LocalToken[] memory localTokens = new LocalToken[](1); - localTokens[0].denom = denomAddress; - localTokens[0].amount = amount; - - vm.prank(sender); - IERC20Denom(denomAddress).approve(address(relay), amount); - - assertEq(relay.getOutstanding(destinationChannel, denomAddress), 0); - - vm.expectEmit(); - emit IERC20.Transfer(address(sender), address(relay), amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Sent(0, sourceChannel, address(0), "", "", address(0), 0); - - vm.prank(sender); - relay.send( - destinationChannel, - receiver, - localTokens, - extension, - IBCHeight.zero(), - 0 - ); - - // Local tokens must be tracked as outstanding for the channel - assertEq(relay.getOutstanding(destinationChannel, denomAddress), amount); - } - - function test_send_remote( - uint64 sequence, - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - uint64 timeoutRevisionNumber, - uint64 timeoutRevisionHeight, - uint64 timeoutTimestamp, - bytes memory sender, - address receiver, - address relayer, - string memory denomName, - uint128 amount, - string memory extension - ) public { - vm.assume(receiver != address(0)); - vm.assume(relayer != address(0)); - vm.assume(amount > 0); - - initChannel( - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - relayer - ); - - receiveRemoteToken( - sequence, - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - timeoutRevisionNumber, - timeoutRevisionHeight, - timeoutTimestamp, - sender, - receiver, - relayer, - denomName, - amount, - extension - ); - - address denomAddress = relay.getDenomAddress( - destinationChannel, - RelayLib.makeForeignDenom( - destinationPort, destinationChannel, denomName - ) - ); - - LocalToken[] memory localTokens = new LocalToken[](1); - localTokens[0].denom = denomAddress; - localTokens[0].amount = amount; - - vm.prank(receiver); - IERC20Denom(denomAddress).approve(address(relay), amount); - - // Burn from sender to zero - vm.expectEmit(); - emit IERC20.Transfer(address(receiver), address(0), amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Sent( - sequence, sourceChannel, address(0), "", "", address(0), 0 - ); - - uint256 outstandingBefore = - relay.getOutstanding(destinationChannel, denomAddress); - - vm.prank(receiver); - relay.send( - destinationChannel, - abi.encodePacked(receiver), - localTokens, - extension, - IBCHeight.zero(), - 0 - ); - - uint256 outstandingAfter = - relay.getOutstanding(destinationChannel, denomAddress); - - // Remote tokens are not tracked as outstanding - assertEq(outstandingBefore, outstandingAfter); - } - - function test_send_local_from_remote( - uint64 sequence, - string memory destinationPort, - string memory sourcePort, - string memory sourceChannel, - uint64 timeoutRevisionNumber, - uint64 timeoutRevisionHeight, - uint64 timeoutTimestamp, - bytes memory sender, - address receiver, - address relayer, - string memory denomName, - uint128 amount, - string memory extension - ) public { - vm.assume(sequence < 1000000000); - vm.assume(receiver != address(0)); - vm.assume(relayer != address(0)); - vm.assume(amount > 0); - - // Open two different local channels with the same counterparty - initChannel( - sourcePort, sourceChannel, destinationPort, "channel-1", relayer - ); - initChannel( - sourcePort, sourceChannel, destinationPort, "channel-2", relayer - ); - - receiveRemoteToken( - sequence, - sourcePort, - sourceChannel, - destinationPort, - "channel-1", - timeoutRevisionNumber, - timeoutRevisionHeight, - timeoutTimestamp, - sender, - receiver, - relayer, - denomName, - amount, - extension - ); - - receiveRemoteToken( - sequence + 1, - sourcePort, - sourceChannel, - destinationPort, - "channel-2", - timeoutRevisionNumber, - timeoutRevisionHeight, - timeoutTimestamp, - sender, - receiver, - relayer, - denomName, - amount, - extension - ); - - { - address denomAddress = relay.getDenomAddress( - "channel-1", - RelayLib.makeForeignDenom( - destinationPort, "channel-1", denomName - ) - ); - - LocalToken[] memory localTokens = new LocalToken[](1); - localTokens[0].denom = denomAddress; - localTokens[0].amount = amount; - - vm.prank(receiver); - IERC20Denom(denomAddress).approve(address(relay), amount); - - uint256 outstandingBefore = - relay.getOutstanding("channel-2", denomAddress); - - vm.expectEmit(); - emit IERC20.Transfer(address(receiver), address(relay), amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Sent( - sequence, sourceChannel, address(0), "", "", address(0), 0 - ); - - vm.prank(receiver); - relay.send( - "channel-2", - abi.encodePacked(receiver), - localTokens, - extension, - IBCHeight.zero(), - 0 - ); - - uint256 outstandingAfter = - relay.getOutstanding("channel-2", denomAddress); - - // Remote tokens are not tracked as outstanding - assertEq(outstandingBefore + amount, outstandingAfter); - } - } - - struct NoCollision { - uint64 sequence; - string destinationPort; - string sourcePort; - string sourceChannel; - uint64 timeoutRevisionNumber; - uint64 timeoutRevisionHeight; - uint64 timeoutTimestamp; - bytes sender; - address receiver; - address relayer; - string denomName; - uint128 amount; - string extension; - } - - function test_receive_remote_no_collision(NoCollision calldata args) - public - { - vm.assume(!args.sourcePort.eq(args.destinationPort)); - vm.assume(args.sequence < 1000000000); - vm.assume(args.receiver != address(0)); - vm.assume(args.relayer != address(0)); - vm.assume(args.amount > 0); - - // Open two different local channels with the same counterparty - initChannel( - args.sourcePort, - args.sourceChannel, - args.destinationPort, - "channel-1", - args.relayer - ); - initChannel( - args.sourcePort, - args.sourceChannel, - args.destinationPort, - "channel-2", - args.relayer - ); - - receiveRemoteToken( - args.sequence, - args.sourcePort, - args.sourceChannel, - args.destinationPort, - "channel-1", - args.timeoutRevisionNumber, - args.timeoutRevisionHeight, - args.timeoutTimestamp, - args.sender, - args.receiver, - args.relayer, - RelayLib.makeForeignDenom( - args.destinationPort, "channel-1", args.denomName - ), - args.amount, - args.extension - ); - - receiveRemoteToken( - args.sequence + 1, - args.sourcePort, - args.sourceChannel, - args.destinationPort, - "channel-2", - args.timeoutRevisionNumber, - args.timeoutRevisionHeight, - args.timeoutTimestamp, - args.sender, - args.receiver, - args.relayer, - RelayLib.makeForeignDenom( - args.destinationPort, "channel-2", args.denomName - ), - args.amount, - args.extension - ); - } - - function test_onTimeout_onlyIBC( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address sender, - bytes memory receiver, - address relayer, - string memory denomName, - uint128 amount, - string memory extension - ) public { - vm.assume(sender != address(0)); - vm.assume(relayer != address(0)); - vm.assume(amount > 0); - - initChannel( - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - relayer - ); - - sendLocalToken( - destinationPort, - destinationChannel, - sender, - receiver, - denomName, - amount, - extension - ); - - IbcCoreChannelV1Packet.Data memory packet = ibcHandler.lastPacket(); - - vm.expectRevert(IBCAppLib.ErrNotIBC.selector); - relay.onTimeoutPacket(packet, relayer); - } - - function test_onTimeout_refund_local( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address sender, - bytes memory receiver, - address relayer, - string memory denomName, - uint128 amount, - string memory extension - ) public { - vm.assume(sender != address(0)); - vm.assume(relayer != address(0)); - vm.assume(amount > 0); - - initChannel( - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - relayer - ); - - address denomAddress = sendLocalToken( - destinationPort, - destinationChannel, - sender, - receiver, - denomName, - amount, - extension - ); - - IbcCoreChannelV1Packet.Data memory packet = ibcHandler.lastPacket(); - - vm.expectEmit(); - emit IERC20.Transfer(address(relay), address(sender), amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Refunded( - 0, sourceChannel, address(0), "", "", address(this), 0 - ); - - assertEq(relay.getOutstanding(destinationChannel, denomAddress), amount); - - vm.prank(address(ibcHandler)); - relay.onTimeoutPacket(packet, relayer); - - /* Tokens must be unescrowed and no longer outstanding */ - assertEq(relay.getOutstanding(destinationChannel, denomAddress), 0); - } - - struct OnTimeoutRefundRemote { - uint64 sequence; - string sourcePort; - string sourceChannel; - string destinationPort; - string destinationChannel; - uint64 timeoutRevisionNumber; - uint64 timeoutRevisionHeight; - uint64 timeoutTimestamp; - bytes sender; - address receiver; - address relayer; - string denomName; - uint128 amount; - string extension; - } - - function test_onTimeout_refund_remote(OnTimeoutRefundRemote memory args) - public - { - vm.assume( - !RelayLib.isFromChannel( - args.destinationPort, args.destinationChannel, args.denomName - ) - ); - vm.assume(args.receiver != address(0)); - vm.assume(args.relayer != address(0)); - vm.assume(args.amount > 0); - - initChannel( - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.relayer - ); - - receiveRemoteToken( - args.sequence, - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.timeoutRevisionNumber, - args.timeoutRevisionHeight, - args.timeoutTimestamp, - args.sender, - args.receiver, - args.relayer, - args.denomName, - args.amount, - args.extension - ); - - address denomAddress = relay.getDenomAddress( - args.destinationChannel, - RelayLib.makeForeignDenom( - args.destinationPort, args.destinationChannel, args.denomName - ) - ); - - sendRemoteToken( - args.destinationPort, - args.destinationChannel, - args.sender, - args.receiver, - denomAddress, - args.amount, - args.extension - ); - - IbcCoreChannelV1Packet.Data memory packet = ibcHandler.lastPacket(); - - vm.expectEmit(); - emit IERC20.Transfer(address(0), address(args.receiver), args.amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Refunded( - args.sequence, - args.sourceChannel, - address(0), - "", - "", - address(this), - 0 - ); - - uint256 outstandingBefore = - relay.getOutstanding(args.destinationChannel, denomAddress); - - vm.prank(address(ibcHandler)); - relay.onTimeoutPacket(packet, args.relayer); - - // Outstanding must not be touched - assertEq( - relay.getOutstanding(args.destinationChannel, denomAddress), - outstandingBefore - ); - } - - function test_ack_failure_refund_local( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address sender, - bytes memory receiver, - address relayer, - string memory denomName, - uint128 amount, - string memory extension - ) public { - vm.assume(sender != address(0)); - vm.assume(relayer != address(0)); - vm.assume(amount > 0); - - initChannel( - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - relayer - ); - - address denomAddress = sendLocalToken( - destinationPort, - destinationChannel, - sender, - receiver, - denomName, - amount, - extension - ); - - IbcCoreChannelV1Packet.Data memory packet = ibcHandler.lastPacket(); - - vm.expectEmit(); - emit IERC20.Transfer(address(relay), address(sender), amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Refunded( - 0, sourceChannel, address(0), "", "", address(this), 0 - ); - - assertEq(relay.getOutstanding(destinationChannel, denomAddress), amount); - - vm.prank(address(ibcHandler)); - relay.onAcknowledgementPacket( - packet, abi.encodePacked(RelayLib.ACK_FAILURE), relayer - ); - - /* Tokens must be unescrowed and no longer outstanding */ - assertEq(relay.getOutstanding(destinationChannel, denomAddress), 0); - } - - struct AckFailureRefundRemote { - uint64 sequence; - string sourcePort; - string sourceChannel; - string destinationPort; - string destinationChannel; - uint64 timeoutRevisionNumber; - uint64 timeoutRevisionHeight; - uint64 timeoutTimestamp; - bytes sender; - address receiver; - address relayer; - string denomName; - uint128 amount; - string extension; - } - - function test_ack_failure_refund_remote(AckFailureRefundRemote memory args) - public - { - vm.assume( - !RelayLib.isFromChannel( - args.destinationPort, args.destinationChannel, args.denomName - ) - ); - vm.assume(args.receiver != address(0)); - vm.assume(args.relayer != address(0)); - vm.assume(args.amount > 0); - - initChannel( - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.relayer - ); - - receiveRemoteToken( - args.sequence, - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.timeoutRevisionNumber, - args.timeoutRevisionHeight, - args.timeoutTimestamp, - args.sender, - args.receiver, - args.relayer, - args.denomName, - args.amount, - args.extension - ); - - address denomAddress = relay.getDenomAddress( - args.destinationChannel, - RelayLib.makeForeignDenom( - args.destinationPort, args.destinationChannel, args.denomName - ) - ); - - sendRemoteToken( - args.destinationPort, - args.destinationChannel, - args.sender, - args.receiver, - denomAddress, - args.amount, - args.extension - ); - - IbcCoreChannelV1Packet.Data memory packet = ibcHandler.lastPacket(); - - vm.expectEmit(); - emit IERC20.Transfer(address(0), address(args.receiver), args.amount); - - vm.expectEmit(false, false, false, false); - emit RelayLib.Refunded( - args.sequence, - args.sourceChannel, - address(0), - "", - "", - address(this), - 0 - ); - - uint256 outstandingBefore = - relay.getOutstanding(args.destinationChannel, denomAddress); - - vm.prank(address(ibcHandler)); - relay.onAcknowledgementPacket( - packet, abi.encodePacked(RelayLib.ACK_FAILURE), args.relayer - ); - - // Outstanding must not be touched - assertEq( - relay.getOutstanding(args.destinationChannel, denomAddress), - outstandingBefore - ); - } - - function test_ack_success_noop_local( - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - address sender, - bytes memory receiver, - address relayer, - string memory denomName, - uint128 amount, - string memory extension - ) public { - vm.assume(sender != address(0)); - vm.assume(relayer != address(0)); - vm.assume(amount > 0); - - initChannel( - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - relayer - ); - - sendLocalToken( - destinationPort, - destinationChannel, - sender, - receiver, - denomName, - amount, - extension - ); - - IbcCoreChannelV1Packet.Data memory packet = ibcHandler.lastPacket(); - - vm.record(); - - vm.prank(address(ibcHandler)); - relay.onAcknowledgementPacket( - packet, abi.encodePacked(RelayLib.ACK_SUCCESS), relayer - ); - - (, bytes32[] memory writes) = vm.accesses(address(relay)); - assertEq(writes.length, 0); - } - - function test_ack_success_noop_remote( - uint64 sequence, - string memory sourcePort, - string memory sourceChannel, - string memory destinationPort, - string memory destinationChannel, - uint64 timeoutRevisionNumber, - uint64 timeoutRevisionHeight, - uint64 timeoutTimestamp, - bytes memory sender, - address receiver, - address relayer, - string memory denomName, - uint128 amount, - string memory extension - ) public { - vm.assume(receiver != address(0)); - vm.assume(relayer != address(0)); - vm.assume(amount > 0); - - initChannel( - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - relayer - ); - - receiveRemoteToken( - sequence, - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - timeoutRevisionNumber, - timeoutRevisionHeight, - timeoutTimestamp, - sender, - receiver, - relayer, - denomName, - amount, - extension - ); - - address denomAddress = relay.getDenomAddress( - destinationChannel, - RelayLib.makeForeignDenom( - destinationPort, destinationChannel, denomName - ) - ); - - sendRemoteToken( - destinationPort, - destinationChannel, - sender, - receiver, - denomAddress, - amount, - extension - ); - - IbcCoreChannelV1Packet.Data memory packet = ibcHandler.lastPacket(); - - vm.record(); - - vm.prank(address(ibcHandler)); - relay.onAcknowledgementPacket( - packet, abi.encodePacked(RelayLib.ACK_SUCCESS), relayer - ); - - (, bytes32[] memory writes) = vm.accesses(address(relay)); - assertEq(writes.length, 0); - } - - struct UpdateTokenMetadataArg { - string name; - string symbol; - uint8 decimals; - } - - function test_updateTokenMetadata_ok( - ReceiveRemoteToken memory args, - UpdateTokenMetadataArg memory updateArgs - ) public { - vm.assume(args.receiver != address(0)); - vm.assume(args.relayer != address(0)); - vm.assume(args.sequence > 1); - vm.assume(args.amount > 0); - vm.assume( - keccak256(bytes(args.denomName)) - != keccak256(bytes(updateArgs.name)) - ); - - initChannel( - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.relayer - ); - - receiveRemoteToken( - args.sequence - 1, - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.timeoutRevisionNumber, - args.timeoutRevisionHeight, - args.timeoutTimestamp, - args.sender, - args.receiver, - args.relayer, - args.denomName, - args.amount, - args.extension - ); - - IERC20Denom denom = IERC20Denom( - relay.getDenomAddress( - args.destinationChannel, - RelayLib.makeForeignDenom( - args.destinationPort, - args.destinationChannel, - args.denomName - ) - ) - ); - - vm.prank(address(this)); - UCS01Relay(address(relay)).updateMetadata( - denom, updateArgs.name, updateArgs.symbol, updateArgs.decimals - ); - - assertEq(updateArgs.name, denom.name()); - assertEq(updateArgs.symbol, denom.symbol()); - assertEq(updateArgs.decimals, denom.decimals()); - } - - function test_updateTokenMetadata_onlyOwner( - ReceiveRemoteToken memory args, - UpdateTokenMetadataArg memory updateArgs, - address malicious - ) public { - vm.assume(malicious != address(this)); - vm.assume(args.receiver != address(0)); - vm.assume(args.relayer != address(0)); - vm.assume(args.sequence > 1); - vm.assume(args.amount > 0); - vm.assume( - keccak256(bytes(args.denomName)) - != keccak256(bytes(updateArgs.name)) - ); - - initChannel( - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.relayer - ); - - receiveRemoteToken( - args.sequence - 1, - args.sourcePort, - args.sourceChannel, - args.destinationPort, - args.destinationChannel, - args.timeoutRevisionNumber, - args.timeoutRevisionHeight, - args.timeoutTimestamp, - args.sender, - args.receiver, - args.relayer, - args.denomName, - args.amount, - args.extension - ); - - IERC20Denom denom = IERC20Denom( - relay.getDenomAddress( - args.destinationChannel, - RelayLib.makeForeignDenom( - args.destinationPort, - args.destinationChannel, - args.denomName - ) - ) - ); - - vm.expectRevert( - abi.encodeWithSelector( - OwnableUpgradeable.OwnableUnauthorizedAccount.selector, - malicious - ) - ); - vm.prank(address(malicious)); - UCS01Relay(address(relay)).updateMetadata( - denom, updateArgs.name, updateArgs.symbol, updateArgs.decimals - ); - } -} diff --git a/evm/tests/src/core/IBCHandler.sol b/evm/tests/src/core/IBCHandler.sol new file mode 100644 index 0000000000..28597f5fc9 --- /dev/null +++ b/evm/tests/src/core/IBCHandler.sol @@ -0,0 +1,14 @@ +pragma solidity ^0.8.27; + +import "../../../contracts/core/25-handler/IBCHandler.sol"; + +contract TestIBCHandler is IBCHandler { + function assumePacketSent( + uint32 channel, + IBCPacket calldata packet + ) public { + commitments[IBCCommitment.batchPacketsCommitmentKey( + channel, IBCPacketLib.commitPacket(packet) + )] = IBCPacketLib.COMMITMENT_MAGIC; + } +} diff --git a/evm/tests/src/core/LightClient.sol b/evm/tests/src/core/LightClient.sol new file mode 100644 index 0000000000..a75d4b91ff --- /dev/null +++ b/evm/tests/src/core/LightClient.sol @@ -0,0 +1,144 @@ +pragma solidity ^0.8.27; + +import "../../../contracts/core/02-client/ILightClient.sol"; + +contract TestLightClient is ILightClient { + bool revertCreate; + bool revertUpdate; + uint64 validMembership; + uint64 validNonMembership; + bytes clientState; + + uint64 latestHeight; + + mapping(uint64 => uint64) timestamps; + + constructor() { + revertCreate = false; + revertUpdate = false; + latestHeight = 0; + } + + function setRevertCreate( + bool v + ) public { + revertCreate = v; + } + + function setRevertUpdate( + bool v + ) public { + revertUpdate = v; + } + + function pushValidMembership() public { + validMembership += 1; + } + + function pushValidNonMembership() public { + validNonMembership += 1; + } + + function setLatestTimestamp( + uint64 timestamp + ) public { + timestamps[latestHeight] = timestamp; + } + + function setLatestHeight( + uint64 height + ) public { + latestHeight = height; + timestamps[height] = 1; + } + + function createClient( + uint32, + bytes calldata clientStateBytes, + bytes calldata consensusStateBytes + ) external returns (ConsensusStateUpdate memory) { + if (revertCreate) { + revert(); + } + clientState = clientStateBytes; + return ConsensusStateUpdate({ + clientStateCommitment: keccak256(clientStateBytes), + consensusStateCommitment: keccak256(consensusStateBytes), + height: latestHeight + }); + } + + function getTimestampAtHeight( + uint32, + uint64 height + ) external view returns (uint64) { + return timestamps[height]; + } + + function getLatestHeight( + uint32 + ) external view returns (uint64) { + return latestHeight; + } + + function updateClient( + uint32, + bytes calldata clientMessageBytes + ) external returns (ConsensusStateUpdate memory) { + if (revertUpdate) { + revert(); + } + latestHeight += 1; + return ConsensusStateUpdate({ + clientStateCommitment: keccak256(clientState), + consensusStateCommitment: keccak256(clientMessageBytes), + height: latestHeight + }); + } + + function verifyMembership( + uint32, + uint64, + bytes calldata, + bytes calldata, + bytes calldata + ) external returns (bool) { + bool valid = validMembership > 0; + if (validMembership > 0) { + validMembership -= 1; + } + return valid; + } + + function verifyNonMembership( + uint32, + uint64, + bytes calldata, + bytes calldata + ) external returns (bool) { + bool valid = validNonMembership > 0; + if (validNonMembership > 0) { + validNonMembership -= 1; + } + return valid; + } + + function getClientState( + uint32 + ) external pure returns (bytes memory) { + return hex""; + } + + function getConsensusState( + uint32, + uint64 + ) external pure returns (bytes memory) { + return hex""; + } + + function isFrozen( + uint32 + ) external pure returns (bool) { + return false; + } +} diff --git a/evm/tests/src/core/Module.sol b/evm/tests/src/core/Module.sol new file mode 100644 index 0000000000..7e8aab5560 --- /dev/null +++ b/evm/tests/src/core/Module.sol @@ -0,0 +1,61 @@ +pragma solidity ^0.8.27; + +import "../../../contracts/core/25-handler/IBCHandler.sol"; +import "../../../contracts/apps/Base.sol"; + +library TestModuleLib { + bytes public constant ACKNOWLEDGEMENT = hex"BEEF"; +} + +contract TestModule is IBCAppBase { + IBCHandler private immutable ibcHandler; + + bool ack; + bytes ackValue; + + constructor( + IBCHandler ibcHandler_ + ) { + ibcHandler = ibcHandler_; + ack = true; + ackValue = TestModuleLib.ACKNOWLEDGEMENT; + } + + function ibcAddress() public view virtual override returns (address) { + return address(ibcHandler); + } + + function pauseAck() public { + ack = false; + } + + function resumeAck() public { + ack = true; + } + + function setAck( + bytes memory value + ) public { + ackValue = value; + } + + function onRecvPacket( + IBCPacket calldata, + address, + bytes calldata + ) external virtual override onlyIBC returns (bytes memory) { + if (!ack) { + return hex""; + } else { + return ackValue; + } + } + + function onRecvIntentPacket( + IBCPacket calldata, + address, + bytes calldata + ) external virtual override onlyIBC returns (bytes memory) { + return ackValue; + } +} diff --git a/evm/tests/src/utils/Cometbls.sol b/evm/tests/src/utils/Cometbls.sol deleted file mode 100644 index a0fb53ba01..0000000000 --- a/evm/tests/src/utils/Cometbls.sol +++ /dev/null @@ -1,137 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; -import {IBCMsgs} from "../../../contracts/core/25-handler/IBCMsgs.sol"; -import { - IbcLightclientsMockV1ClientState as MockClientState, - IbcLightclientsMockV1Header as MockHeader, - IbcLightclientsMockV1ConsensusState as MockConsensusState, - IbcCoreClientV1Height as ClientHeight -} from "../../../contracts/proto/MockClient.sol"; -import {GoogleProtobufAny as Any} from - "../../../contracts/proto/GoogleProtobufAny.sol"; -import { - GoogleProtobufDuration as Duration, - GoogleProtobufTimestamp as Timestamp -} from "../../../contracts/proto/ProtoBufRuntime.sol"; -import { - IbcCoreChannelV1Counterparty as ChannelCounterparty, - IbcCoreChannelV1Channel as Channel, - IbcCoreChannelV1GlobalEnums as ChannelEnums, - IbcCoreChannelV1Counterparty as ChannelCounterparty -} from "../../../contracts/proto/ibc/core/channel/v1/channel.sol"; -import { - IbcCoreConnectionV1Counterparty as ConnectionCounterparty, - IbcCoreConnectionV1Version as ConnectionVersion, - IbcCoreConnectionV1ConnectionEnd as ConnectionEnd, - IbcCoreConnectionV1GlobalEnums as ConnectionEnums -} from "../../../contracts/proto/ibc/core/connection/v1/connection.sol"; -import {IbcCoreCommitmentV1MerklePrefix as CommitmentMerklePrefix} from - "../../../contracts/proto/ibc/core/commitment/v1/commitment.sol"; -import { - CometblsClientLib, - OptimizedConsensusState -} from "../../../contracts/clients/CometblsClientV2.sol"; -import { - UnionIbcLightclientsCometblsV1ClientState as CometblsClientState, - UnionIbcLightclientsCometblsV1Header as CometblsHeader, - UnionIbcLightclientsCometblsV1Header as CometblsHeader, - UnionIbcLightclientsCometblsV1LightHeader as CometblsLightHeader -} from - "../../../contracts/proto/union/ibc/lightclients/cometbls/v1/cometbls.sol"; -import {IbcLightclientsWasmV1ClientState as WasmClientState} from - "../../../contracts/proto/ibc/lightclients/wasm/v1/wasm.sol"; -import { - TendermintTypesCommit, - TendermintTypesHeader, - TendermintTypesSignedHeader, - TendermintVersionConsensus -} from "../../../contracts/proto/tendermint/types/types.sol"; -import {IbcLightclientsTendermintV1Fraction as Fraction} from - "../../../contracts/proto/ibc/lightclients/tendermint/v1/tendermint.sol"; - -library Cometbls { - using CometblsClientLib for *; - - uint64 constant HOUR = 3600; - uint64 constant DAY = 24 * HOUR; - uint64 constant WEEK = 7 * DAY; - uint64 constant MONTH = 4 * WEEK; - uint64 constant YEAR = 12 * MONTH; - - /* - * The max clock drift allow the local chain clock to drift from the counterparty clock - */ - uint64 constant MAX_CLOCK_DRIFT = HOUR; - - /* - * The trusting period is the maximum difference in timestamp between two blocks that client will accept to process - */ - uint64 constant TRUSTING_PERIOD = WEEK; - - function createClientState( - string memory chainId, - uint64 latestHeight - ) internal pure returns (CometblsClientState.Data memory) { - return CometblsClientState.Data({ - chain_id: chainId, - // TODO: all this could be fuzzed - trusting_period: TRUSTING_PERIOD * 1e9, - unbonding_period: 300, - max_clock_drift: MAX_CLOCK_DRIFT * 1e9, - frozen_height: ClientHeight.Data({ - revision_number: 0, - revision_height: 0 - }), - latest_height: ClientHeight.Data({ - revision_number: 0, - revision_height: latestHeight - }) - }); - } - - function createConsensusState( - bytes32 appHash, - bytes32 nextValidatorsHash, - uint64 timestamp - ) internal pure returns (OptimizedConsensusState memory) { - return OptimizedConsensusState({ - timestamp: timestamp, - appHash: appHash, - nextValidatorsHash: nextValidatorsHash - }); - } - - function createClient( - string memory clientType, - string memory chainId, - uint64 latestHeight, - bytes32 appHash, - bytes32 nextValidatorsHash, - uint64 timestamp - ) internal pure returns (IBCMsgs.MsgCreateClient memory m) { - m.clientType = clientType; - m.clientStateBytes = - createClientState(chainId, latestHeight).encodeMemory(); - m.consensusStateBytes = createConsensusState( - appHash, nextValidatorsHash, timestamp - ).encodeMemory(); - } - - function updateClient( - string memory clientId, - CometblsLightHeader.Data memory signedHeader, - uint64 trustedHeight, - bytes memory zkp - ) internal pure returns (IBCMsgs.MsgUpdateClient memory m) { - m.clientId = clientId; - m.clientMessage = CometblsHeader.Data({ - signed_header: signedHeader, - trusted_height: ClientHeight.Data({ - revision_number: 0, - revision_height: trustedHeight - }), - zero_knowledge_proof: zkp - }).encodeMemory(); - } -} diff --git a/evm/tests/src/utils/IBCHandler_Testable.sol b/evm/tests/src/utils/IBCHandler_Testable.sol deleted file mode 100644 index 499d644e4a..0000000000 --- a/evm/tests/src/utils/IBCHandler_Testable.sol +++ /dev/null @@ -1,11 +0,0 @@ -pragma solidity ^0.8.23; - -import {IBCHandler} from "../../../contracts/core/25-handler/IBCHandler.sol"; - -import "../../../contracts/proto/ibc/core/client/v1/client.sol"; -import "../../../contracts/core/02-client/ILightClient.sol"; -import "../../../contracts/core/24-host/IBCStore.sol"; -import "../../../contracts/core/05-port/ModuleManager.sol"; -import "../../../contracts/core/24-host/IBCCommitment.sol"; - -contract IBCHandler_Testable is IBCHandler {} diff --git a/evm/tests/src/utils/MockApp.sol b/evm/tests/src/utils/MockApp.sol deleted file mode 100644 index aa60eb9b28..0000000000 --- a/evm/tests/src/utils/MockApp.sol +++ /dev/null @@ -1,105 +0,0 @@ -pragma solidity ^0.8.23; - -import { - IbcCoreChannelV1Packet as Packet, - IbcCoreChannelV1GlobalEnums as ChannelEnums, - IbcCoreChannelV1Counterparty as ChannelCounterparty -} from "../../../contracts/proto/ibc/core/channel/v1/channel.sol"; -import {IIBCModule} from "../../../contracts/core/05-port/IIBCModule.sol"; -import {IBCHandler} from "../../../contracts/core/25-handler/IBCHandler.sol"; -import {IBCHost} from "../../../contracts/core/24-host/IBCHost.sol"; -import {Context} from "@openzeppelin/utils/Context.sol"; - -contract MockApp is IIBCModule { - event MockPacketRecv(); - event MockPacketAck(); - event MockPacketTimeout(); - event MockChannelOpenInit(string portId, string channelId); - event MockChannelOpenTry(); - event MockChannelOpenAck(); - event MockChannelOpenConfirm(); - event MockChannelCloseInit(); - event MockChannelCloseConfirm(); - - function onRecvPacket( - Packet.Data calldata, - address - ) external virtual override returns (bytes memory) { - emit MockPacketRecv(); - return bytes("1"); - } - - function onAcknowledgementPacket( - Packet.Data calldata, - bytes calldata, - address - ) external virtual override { - emit MockPacketAck(); - } - - function onTimeoutPacket( - Packet.Data calldata, - address - ) external virtual override { - emit MockPacketTimeout(); - } - - function onChanOpenInit( - ChannelEnums.Order, - string[] calldata, - string calldata portId, - string calldata channelId, - ChannelCounterparty.Data calldata, - string calldata, - address - ) external virtual override { - emit MockChannelOpenInit(portId, channelId); - } - - function onChanOpenTry( - ChannelEnums.Order, - string[] calldata, - string calldata, - string calldata, - ChannelCounterparty.Data calldata, - string calldata, - string calldata, - address - ) external virtual override { - emit MockChannelOpenTry(); - } - - function onChanOpenAck( - string calldata, - string calldata, - string calldata, - string calldata, - address - ) external virtual override { - emit MockChannelOpenAck(); - } - - function onChanOpenConfirm( - string calldata, - string calldata, - address - ) external virtual override { - emit MockChannelOpenConfirm(); - } - - function onChanCloseInit( - string calldata, - string calldata, - address - ) external virtual override { - emit MockChannelCloseInit(); - } - - function onChanCloseConfirm( - string calldata, - string calldata, - address - ) external virtual override { - emit MockChannelCloseConfirm(); - } -} diff --git a/evm/tests/src/utils/MsgMocks.sol b/evm/tests/src/utils/MsgMocks.sol deleted file mode 100644 index 840be1bc77..0000000000 --- a/evm/tests/src/utils/MsgMocks.sol +++ /dev/null @@ -1,407 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; -import {IBCMsgs} from "../../../contracts/core/25-handler/IBCMsgs.sol"; -import { - IbcLightclientsMockV1ClientState as MockClientState, - IbcLightclientsMockV1Header as MockHeader, - IbcLightclientsMockV1ConsensusState as MockConsensusState, - IbcCoreClientV1Height as ClientHeight -} from "../../../contracts/proto/MockClient.sol"; -import {GoogleProtobufAny as Any} from - "../../../contracts/proto/GoogleProtobufAny.sol"; -import { - IbcCoreChannelV1Counterparty as ChannelCounterparty, - IbcCoreChannelV1Channel as Channel, - IbcCoreChannelV1GlobalEnums as ChannelEnums, - IbcCoreChannelV1Counterparty as ChannelCounterparty -} from "../../../contracts/proto/ibc/core/channel/v1/channel.sol"; -import { - IbcCoreConnectionV1Counterparty as ConnectionCounterparty, - IbcCoreConnectionV1Version as ConnectionVersion, - IbcCoreConnectionV1ConnectionEnd as ConnectionEnd, - IbcCoreConnectionV1GlobalEnums as ConnectionEnums -} from "../../../contracts/proto/ibc/core/connection/v1/connection.sol"; -import {IbcCoreCommitmentV1MerklePrefix as CommitmentMerklePrefix} from - "../../../contracts/proto/ibc/core/commitment/v1/commitment.sol"; - -library MsgMocks { - // - // IBCClient msgs - // - - /// Builds a MsgCreateClient - function createClient( - string memory clientType, - uint64 revisionHeight - ) internal view returns (IBCMsgs.MsgCreateClient memory m) { - m.clientType = clientType; - m.clientStateBytes = wrapAnyMockClientState( - MockClientState.Data({ - latest_height: ClientHeight.Data({ - revision_number: 0, - revision_height: revisionHeight - }) - }) - ); - m.consensusStateBytes = wrapAnyMockConsensusState( - MockConsensusState.Data({timestamp: uint64(block.timestamp)}) - ); - } - - /// Builds a MsgUpdateClient - function updateClient( - string memory clientId, - uint64 nextRevisionHeight - ) internal view returns (IBCMsgs.MsgUpdateClient memory m) { - m.clientId = clientId; - m.clientMessage = wrapAnyMockHeader( - MockHeader.Data({ - height: ClientHeight.Data({ - revision_number: 0, - revision_height: nextRevisionHeight - }), - timestamp: uint64(block.timestamp) - }) - ); - } - - // - // IBCConnection msgs - // - - /// Builds a MsgConnectionOpenInit - function connectionOpenInit(string memory clientId) - internal - pure - returns (IBCMsgs.MsgConnectionOpenInit memory m) - { - m.clientId = clientId; - m.counterparty.client_id = "counterparty-client-id"; - m.counterparty.connection_id = "counterparty-conn-id"; - } - - /// Builds a MsgConnectionOpenTry - function connectionOpenTry( - string memory clientId, - uint64 proofHeight - ) internal pure returns (IBCMsgs.MsgConnectionOpenTry memory m) { - m.clientId = clientId; - m.counterparty.client_id = "counterparty-client-id"; - m.counterparty.connection_id = "counterparty-conn-id"; - m.counterpartyVersions = new ConnectionVersion.Data[](1); - m.counterpartyVersions[0] = - ConnectionVersion.Data({identifier: "1", features: new string[](2)}); - m.counterpartyVersions[0].features[0] = "ORDER_ORDERED"; - m.counterpartyVersions[0].features[1] = "ORDER_UNORDERED"; - - // mocking connection data - ConnectionEnd.Data memory connection = ConnectionEnd.Data({ - client_id: "counterparty-client-id", - versions: m.counterpartyVersions, - state: ConnectionEnums.State.STATE_INIT, - delay_period: 0, - counterparty: ConnectionCounterparty.Data({ - client_id: clientId, - connection_id: "", - prefix: CommitmentMerklePrefix.Data({ - key_prefix: bytes(commitment_prefix()) - }) - }) - }); - - bytes memory encodedConnection = ConnectionEnd.encode(connection); - m.proofInit = abi.encodePacked(sha256(encodedConnection)); - - // it just checks sha256(clientStateBytes) == proofClient - m.clientStateBytes = abi.encodePacked(bytes32(uint256(0x1))); - m.proofClient = abi.encodePacked(sha256(m.clientStateBytes)); - m.proofHeight.revision_height = proofHeight; - } - - /// Builds a MsgConnectionOpenAck - function connectionOpenAck( - string memory clientId, - string memory connId, - uint64 proofHeight - ) internal pure returns (IBCMsgs.MsgConnectionOpenAck memory m) { - m.connectionId = connId; - m.version = - ConnectionVersion.Data({identifier: "1", features: new string[](2)}); - m.version.features[0] = "ORDER_ORDERED"; - m.version.features[1] = "ORDER_UNORDERED"; - m.counterpartyConnectionID = "counterparty-conn-id"; - - // mocking connection data - ConnectionEnd.Data memory connection = ConnectionEnd.Data({ - client_id: "counterparty-client-id", - versions: new ConnectionVersion.Data[](1), - state: ConnectionEnums.State.STATE_TRYOPEN, - delay_period: 0, - counterparty: ConnectionCounterparty.Data({ - client_id: clientId, - connection_id: connId, - prefix: CommitmentMerklePrefix.Data({ - key_prefix: bytes(commitment_prefix()) - }) - }) - }); - connection.versions[0] = m.version; - - bytes memory encodedConnection = ConnectionEnd.encode(connection); - - // it just checks sha256(clientStateBytes) == proofClient - m.clientStateBytes = abi.encodePacked(bytes32(uint256(0x1))); - m.proofClient = abi.encodePacked(sha256(m.clientStateBytes)); - m.proofTry = abi.encodePacked(sha256(encodedConnection)); - m.proofHeight.revision_height = proofHeight; - } - - /// Builds a MsgConnectionOpenConfirm - function connectionOpenConfirm( - string memory clientId, - string memory connId, - uint64 proofHeight - ) internal pure returns (IBCMsgs.MsgConnectionOpenConfirm memory m) { - m.connectionId = connId; - - // mocking connection data - ConnectionEnd.Data memory connection = ConnectionEnd.Data({ - client_id: "counterparty-client-id", - versions: new ConnectionVersion.Data[](1), - state: ConnectionEnums.State.STATE_OPEN, - delay_period: 0, - counterparty: ConnectionCounterparty.Data({ - client_id: clientId, - connection_id: connId, - prefix: CommitmentMerklePrefix.Data({ - key_prefix: bytes(commitment_prefix()) - }) - }) - }); - connection.versions[0] = - ConnectionVersion.Data({identifier: "1", features: new string[](2)}); - connection.versions[0].features[0] = "ORDER_ORDERED"; - connection.versions[0].features[1] = "ORDER_UNORDERED"; - - bytes memory encodedConnection = ConnectionEnd.encode(connection); - m.proofAck = abi.encodePacked(sha256(encodedConnection)); - m.proofHeight.revision_height = proofHeight; - } - - /// Builds a MsgChannelOpenInit - function channelOpenInit( - string memory connId, - string memory portId - ) internal pure returns (IBCMsgs.MsgChannelOpenInit memory m) { - ChannelCounterparty.Data memory counterparty; - counterparty.port_id = "counterparty-port-id"; - counterparty.channel_id = ""; - string[] memory hops = new string[](1); - hops[0] = connId; - - m.channel.state = ChannelEnums.State.STATE_INIT; - m.channel.counterparty = counterparty; - m.channel.connection_hops = hops; - m.channel.ordering = ChannelEnums.Order.ORDER_UNORDERED; - m.portId = portId; - } - - function channelOpenAck( - string memory portId, - string memory channelId, - uint64 proofHeight - ) internal pure returns (IBCMsgs.MsgChannelOpenAck memory m) { - m.portId = portId; - m.channelId = channelId; - m.counterpartyVersion = "counterparty-version"; - m.counterpartyChannelId = "counterparty-channel-id"; - - // mocking channel data - Channel.Data memory channel = Channel.Data({ - state: ChannelEnums.State.STATE_TRYOPEN, - ordering: ChannelEnums.Order.ORDER_UNORDERED, - counterparty: ChannelCounterparty.Data({ - port_id: portId, - channel_id: channelId - }), - connection_hops: new string[](1), - version: m.counterpartyVersion - }); - channel.connection_hops[0] = "counterparty-conn-id"; - m.proofHeight.revision_height = proofHeight; - } - - function commitment_prefix() internal pure returns (string memory) { - return "ibc"; - } - - function channelOpenTry( - string memory connId, - string memory portId, - uint64 proofHeight - ) internal pure returns (IBCMsgs.MsgChannelOpenTry memory m) { - m.portId = portId; - m.counterpartyVersion = "counterparty-version"; - m.channel = Channel.Data({ - state: ChannelEnums.State.STATE_TRYOPEN, - ordering: ChannelEnums.Order.ORDER_UNORDERED, - counterparty: ChannelCounterparty.Data({port_id: portId, channel_id: ""}), - connection_hops: new string[](1), - version: m.counterpartyVersion - }); - m.channel.connection_hops[0] = connId; - - // expected channel - Channel.Data memory expectedChannel = Channel.Data({ - state: ChannelEnums.State.STATE_INIT, - ordering: ChannelEnums.Order.ORDER_UNORDERED, - counterparty: ChannelCounterparty.Data({port_id: portId, channel_id: ""}), - connection_hops: new string[](1), - version: m.counterpartyVersion - }); - expectedChannel.connection_hops[0] = "counterparty-conn-id"; - m.proofHeight.revision_height = proofHeight; - } - - function channelOpenConfirm( - string memory portId, - string memory channelId, - uint64 proofHeight - ) internal pure returns (IBCMsgs.MsgChannelOpenConfirm memory m) { - m.portId = portId; - m.channelId = channelId; - - Channel.Data memory expectedChannel = Channel.Data({ - state: ChannelEnums.State.STATE_OPEN, - ordering: ChannelEnums.Order.ORDER_UNORDERED, - counterparty: ChannelCounterparty.Data({ - port_id: portId, - channel_id: channelId - }), - connection_hops: new string[](1), - version: "counterparty-version" - }); - expectedChannel.connection_hops[0] = "counterparty-conn-id"; - m.proofHeight.revision_height = proofHeight; - } - - function channelCloseInit( - string memory portId, - string memory channelId - ) internal pure returns (IBCMsgs.MsgChannelCloseInit memory m) { - m.portId = portId; - m.channelId = channelId; - } - - function channelCloseConfirm( - string memory portId, - string memory channelId, - uint64 proofHeight - ) internal pure returns (IBCMsgs.MsgChannelCloseConfirm memory m) { - m.portId = portId; - m.channelId = channelId; - - Channel.Data memory expectedChannel = Channel.Data({ - state: ChannelEnums.State.STATE_CLOSED, - ordering: ChannelEnums.Order.ORDER_UNORDERED, - counterparty: ChannelCounterparty.Data({ - port_id: portId, - channel_id: channelId - }), - connection_hops: new string[](1), - version: "counterparty-version" - }); - - expectedChannel.connection_hops[0] = "counterparty-conn-id"; - m.proofHeight.revision_height = proofHeight; - } - - function packetRecv( - string memory portId, - string memory channelId, - uint64 proofHeight, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload - ) internal pure returns (IBCMsgs.MsgPacketRecv memory m) { - m.packet.destination_port = portId; - m.packet.destination_channel = channelId; - m.packet.source_port = "counterparty-port-id"; - m.packet.source_channel = "counterparty-channel-id"; - m.packet.data = payload; - m.packet.sequence = 1; - m.packet.timeout_height.revision_height = timeoutHeight; - m.packet.timeout_timestamp = timeoutTimestamp; - m.proofHeight.revision_height = proofHeight; - } - - function packetAck( - string memory portId, - string memory channelId, - uint64 proofHeight, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload, - bytes memory acknowledgement - ) internal pure returns (IBCMsgs.MsgPacketAcknowledgement memory m) { - m.packet.source_port = portId; - m.packet.source_channel = channelId; - m.packet.destination_port = "counterparty-port-id"; - m.packet.destination_channel = "counterparty-channel-id"; - m.packet.data = payload; - m.packet.sequence = 1; - m.packet.timeout_height.revision_height = timeoutHeight; - m.packet.timeout_timestamp = timeoutTimestamp; - m.proofHeight.revision_height = proofHeight; - m.acknowledgement = acknowledgement; - } - - function packetTimeout( - string memory portId, - string memory channelId, - uint64 proofHeight, - uint64 timeoutHeight, - uint64 timeoutTimestamp, - bytes memory payload - ) internal pure returns (IBCMsgs.MsgPacketTimeout memory m) { - m.packet.source_port = portId; - m.packet.source_channel = channelId; - m.packet.destination_port = "counterparty-port-id"; - m.packet.destination_channel = "counterparty-channel-id"; - m.packet.data = payload; - m.packet.sequence = 1; - m.packet.timeout_height.revision_height = timeoutHeight; - m.packet.timeout_timestamp = timeoutTimestamp; - m.proofHeight.revision_height = proofHeight; - } -} - -function wrapAnyMockHeader(MockHeader.Data memory header) - pure - returns (bytes memory) -{ - Any.Data memory anyHeader; - anyHeader.type_url = "/ibc.lightclients.mock.v1.Header"; - anyHeader.value = MockHeader.encode(header); - return Any.encode(anyHeader); -} - -function wrapAnyMockClientState(MockClientState.Data memory clientState) - pure - returns (bytes memory) -{ - Any.Data memory anyClientState; - anyClientState.type_url = "/ibc.lightclients.mock.v1.ClientState"; - anyClientState.value = MockClientState.encode(clientState); - return Any.encode(anyClientState); -} - -function wrapAnyMockConsensusState( - MockConsensusState.Data memory consensusState -) pure returns (bytes memory) { - Any.Data memory anyConsensusState; - anyConsensusState.type_url = "/ibc.lightclients.mock.v1.ConsensusState"; - anyConsensusState.value = MockConsensusState.encode(consensusState); - return Any.encode(anyConsensusState); -} diff --git a/evm/tests/src/utils/TestUtils.sol b/evm/tests/src/utils/TestUtils.sol deleted file mode 100644 index 50d4f4c5fc..0000000000 --- a/evm/tests/src/utils/TestUtils.sol +++ /dev/null @@ -1,203 +0,0 @@ -pragma solidity ^0.8.23; - -import "forge-std/Test.sol"; -import {IBCMsgs} from "../../../contracts/core/25-handler/IBCMsgs.sol"; -import { - IbcLightclientsMockV1ClientState, - IbcLightclientsMockV1Header, - IbcLightclientsMockV1ConsensusState, - IbcCoreClientV1Height -} from "../../../contracts/proto/MockClient.sol"; -import {GoogleProtobufAny as Any} from - "../../../contracts/proto/GoogleProtobufAny.sol"; -import { - IbcCoreChannelV1Counterparty, - IbcCoreChannelV1Channel, - IbcCoreChannelV1GlobalEnums -} from "../../../contracts/proto/ibc/core/channel/v1/channel.sol"; -import { - IbcCoreConnectionV1Counterparty, - IbcCoreConnectionV1Version, - IbcCoreConnectionV1ConnectionEnd, - IbcCoreConnectionV1GlobalEnums -} from "../../../contracts/proto/ibc/core/connection/v1/connection.sol"; -import {IbcCoreCommitmentV1MerklePrefix} from - "../../../contracts/proto/ibc/core/commitment/v1/commitment.sol"; - -contract TestPlus is Test { - function assertStrEq(string memory a, string memory b) internal pure { - require( - keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)), - "strings not equal" - ); - } - - function assertStrNotEq(string memory a, string memory b) internal pure { - require( - keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b)), - "strings equal" - ); - } -} - -library MsgMocks { - function connectionOpenInit(string memory clientId) - internal - pure - returns (IBCMsgs.MsgConnectionOpenInit memory m) - { - m.clientId = clientId; - m.counterparty.client_id = "counterparty-client-id"; - m.counterparty.connection_id = "counterparty-conn-id"; - } - - function connectionOpenTry( - string memory clientId, - string memory connId - ) internal pure returns (IBCMsgs.MsgConnectionOpenTry memory m) { - m.clientId = clientId; - m.counterparty.client_id = clientId; - m.counterparty.connection_id = connId; - m.counterpartyVersions = new IbcCoreConnectionV1Version.Data[](1); - m.counterpartyVersions[0] = IbcCoreConnectionV1Version.Data({ - identifier: "1", - features: new string[](0) - }); - } - - function connectionOpenAck( - string memory clientId, - string memory connId, - uint64 proofHeight - ) internal pure returns (IBCMsgs.MsgConnectionOpenAck memory m) { - m.connectionId = connId; - m.version = IbcCoreConnectionV1Version.Data({ - identifier: "1", - features: new string[](0) - }); - m.proofHeight.revision_height = proofHeight; - - IbcCoreConnectionV1Counterparty.Data memory expectedCounterparty = - IbcCoreConnectionV1Counterparty.Data({ - client_id: clientId, - connection_id: connId, - prefix: IbcCoreCommitmentV1MerklePrefix.Data({ - key_prefix: bytes(commitment_prefix()) - }) - }); - - IbcCoreConnectionV1ConnectionEnd.Data memory expectedConnection = - IbcCoreConnectionV1ConnectionEnd.Data({ - client_id: "counterparty-client-id", - versions: new IbcCoreConnectionV1Version.Data[](1), - state: IbcCoreConnectionV1GlobalEnums.State.STATE_TRYOPEN, - delay_period: 0, - counterparty: expectedCounterparty - }); - expectedConnection.versions[0] = m.version; - - bytes memory encodedConnection = - IbcCoreConnectionV1ConnectionEnd.encode(expectedConnection); - bytes32 proof = sha256(encodedConnection); - m.proofTry = abi.encodePacked(proof); - - // m.proofClient = ...; - // m.clientStateBytes = ...; - - // TODO: MockClient.verifyMembership ignores this value, but we probably need to fill it for CometblsClient I supose? - // m.counterpartyConnectionId = ...; - - // TODO: what other fields should we fill here? - } - - function createClient( - string memory clientType, - uint64 revisionHeight - ) internal view returns (IBCMsgs.MsgCreateClient memory m) { - m.clientType = clientType; - m.clientStateBytes = wrapAnyMockClientState( - IbcLightclientsMockV1ClientState.Data({ - latest_height: IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: revisionHeight - }) - }) - ); - m.consensusStateBytes = wrapAnyMockConsensusState( - IbcLightclientsMockV1ConsensusState.Data({ - timestamp: uint64(block.timestamp) - }) - ); - } - - function updateClient( - string memory clientId, - uint64 nextRevisionHeight - ) internal view returns (IBCMsgs.MsgUpdateClient memory m) { - m.clientId = clientId; - m.clientMessage = wrapAnyMockHeader( - IbcLightclientsMockV1Header.Data({ - height: IbcCoreClientV1Height.Data({ - revision_number: 0, - revision_height: nextRevisionHeight - }), - timestamp: uint64(block.timestamp) - }) - ); - } - - function channelOpenInit( - string memory portId, - uint64 - ) internal pure returns (IBCMsgs.MsgChannelOpenInit memory m) { - IbcCoreChannelV1Counterparty.Data memory counterparty; - counterparty.port_id = "1"; - counterparty.channel_id = "1"; - string[] memory hops = new string[](1); - hops[0] = "hop-1"; - - m.portId = portId; - m.channel = IbcCoreChannelV1Channel.Data({ - state: IbcCoreChannelV1GlobalEnums.State.STATE_UNINITIALIZED_UNSPECIFIED, - ordering: IbcCoreChannelV1GlobalEnums.Order.ORDER_NONE_UNSPECIFIED, - counterparty: counterparty, - connection_hops: hops, - version: "v1" - }); - } - - function commitment_prefix() private pure returns (string memory) { - return "ibc"; - } - - function wrapAnyMockHeader(IbcLightclientsMockV1Header.Data memory header) - private - pure - returns (bytes memory) - { - Any.Data memory anyHeader; - anyHeader.type_url = "/ibc.lightclients.mock.v1.Header"; - anyHeader.value = IbcLightclientsMockV1Header.encode(header); - return Any.encode(anyHeader); - } - - function wrapAnyMockClientState( - IbcLightclientsMockV1ClientState.Data memory clientState - ) private pure returns (bytes memory) { - Any.Data memory anyClientState; - anyClientState.type_url = "/ibc.lightclients.mock.v1.ClientState"; - anyClientState.value = - IbcLightclientsMockV1ClientState.encode(clientState); - return Any.encode(anyClientState); - } - - function wrapAnyMockConsensusState( - IbcLightclientsMockV1ConsensusState.Data memory consensusState - ) private pure returns (bytes memory) { - Any.Data memory anyConsensusState; - anyConsensusState.type_url = "/ibc.lightclients.mock.v1.ConsensusState"; - anyConsensusState.value = - IbcLightclientsMockV1ConsensusState.encode(consensusState); - return Any.encode(anyConsensusState); - } -} diff --git a/flake.lock b/flake.lock index 363dfe2ea6..5bcb3532db 100644 --- a/flake.lock +++ b/flake.lock @@ -271,16 +271,16 @@ ] }, "locked": { - "lastModified": 1712135466, - "narHash": "sha256-+xFfYk17EI0zZTGmhh3MyeSpl7RVohoVp/4HaSvGj4I=", + "lastModified": 1727687420, + "narHash": "sha256-MD/Fm3KhENvuMP0oR+aGuH7th21DIAxp8yKIQUbFfEk=", "owner": "shazow", "repo": "foundry.nix", - "rev": "ece7c960a440c6725a7a5576d1f49a5fabde3747", + "rev": "5cec83883f18b0cde2ffa8977d3540fe707a84cd", "type": "github" }, "original": { "owner": "shazow", - "ref": "monthly", + "ref": "main", "repo": "foundry.nix", "type": "github" } diff --git a/flake.nix b/flake.nix index eb52ba54ac..c4a760d36a 100644 --- a/flake.nix +++ b/flake.nix @@ -23,7 +23,7 @@ url = "github:numtide/treefmt-nix"; }; foundry = { - url = "github:shazow/foundry.nix/monthly"; + url = "github:shazow/foundry.nix/main"; inputs.nixpkgs.follows = "nixpkgs"; }; rust-overlay = { @@ -391,10 +391,10 @@ else super.stdenv.mkDerivation rec { pname = "solc-static"; - version = "0.8.23"; + version = "0.8.27"; src = pkgs.fetchurl { url = "https://github.com/ethereum/solidity/releases/download/v${version}/solc-static-linux"; - hash = "sha256-KHJqRSKQxw4ZhPFcU60wiOfZh4PuMHCxGzZk2ndBVzI="; + hash = "sha256-uZd9UAwXy6bwAyypOe+YxN7PY2PxnzhtBfsC9wgRUmQ="; }; dontUnpack = true; nativeBuildInputs = pkgs.lib.optionals (!super.stdenv.isDarwin) [ super.autoPatchelfHook ]; diff --git a/tools/generate-rust-sol-bindings/generate-rust-sol-bindings.nix b/tools/generate-rust-sol-bindings/generate-rust-sol-bindings.nix index 531b0c3cf1..3931b115e5 100644 --- a/tools/generate-rust-sol-bindings/generate-rust-sol-bindings.nix +++ b/tools/generate-rust-sol-bindings/generate-rust-sol-bindings.nix @@ -42,7 +42,7 @@ _: { ${self'.packages.evm-contracts}/out/IBCHandler.sol/IBCHandler.json \ ${self'.packages.evm-contracts}/out/IBCClient.sol/IBCClient.json \ ${self'.packages.evm-contracts}/out/IBCConnection.sol/IBCConnection.json \ - ${self'.packages.evm-contracts}/out/IBCChannelHandshake.sol/IBCChannelHandshake.json \ + ${self'.packages.evm-contracts}/out/IBCChannel.sol/IBCChannel.json \ ${self'.packages.evm-contracts}/out/IBCPacket.sol/IBCPacket.json \ ${self'.packages.evm-contracts}/out/Glue.sol/Glue.json \ ${self'.packages.evm-contracts}/out/ERC20.sol/ERC20.json \