github.com/InjectiveLabs/sdk-go@v1.53.0/chain/peggy/types/key.go (about) 1 package types 2 3 import ( 4 sdk "github.com/cosmos/cosmos-sdk/types" 5 "github.com/ethereum/go-ethereum/common" 6 ) 7 8 const ( 9 // ModuleName is the name of the module 10 ModuleName = "peggy" 11 12 // StoreKey to be used when creating the KVStore 13 StoreKey = ModuleName 14 15 // RouterKey is the module name router key 16 RouterKey = ModuleName 17 18 // QuerierRoute to be used for querierer msgs 19 QuerierRoute = ModuleName 20 ) 21 22 var ( 23 // EthAddressByValidatorKey indexes cosmos validator account addresses 24 // i.e. cosmos1ahx7f8wyertuus9r20284ej0asrs085case3kn 25 EthAddressByValidatorKey = []byte{0x1} 26 27 // ValidatorByEthAddressKey indexes ethereum addresses 28 // i.e. 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B 29 ValidatorByEthAddressKey = []byte{0xfb} 30 31 // ValsetRequestKey indexes valset requests by nonce 32 ValsetRequestKey = []byte{0x2} 33 34 // ValsetConfirmKey indexes valset confirmations by nonce and the validator account address 35 // i.e cosmos1ahx7f8wyertuus9r20284ej0asrs085case3kn 36 ValsetConfirmKey = []byte{0x3} 37 38 // ParamKey indexes peggy's module params 39 ParamKey = []byte{0x4} 40 41 // OracleAttestationKey attestation details by nonce and validator address 42 // i.e. cosmosvaloper1ahx7f8wyertuus9r20284ej0asrs085case3kn 43 // An attestation can be thought of as the 'event to be executed' while 44 // the Claims are an individual validator saying that they saw an event 45 // occur the Attestation is 'the event' that multiple claims vote on and 46 // eventually executes 47 OracleAttestationKey = []byte{0x5} 48 49 // OutgoingTXPoolKey indexes the last nonce for the outgoing tx pool 50 OutgoingTXPoolKey = []byte{0x6} 51 52 // SecondIndexOutgoingTXFeeKey indexes fee amounts by token contract address 53 SecondIndexOutgoingTXFeeKey = []byte{0x9} 54 55 // OutgoingTXBatchKey indexes outgoing tx batches under a nonce and token address 56 OutgoingTXBatchKey = []byte{0xa} 57 58 // OutgoingTXBatchBlockKey indexes outgoing tx batches under a block height and token address 59 OutgoingTXBatchBlockKey = []byte{0xb} 60 61 // BatchConfirmKey indexes validator confirmations by token contract address 62 BatchConfirmKey = []byte{0xe1} 63 64 // LastEventNonceByValidatorKey indexes lateset event nonce by validator 65 LastEventNonceByValidatorKey = []byte{0xe2} 66 67 // LastEventByValidatorKey indexes lateset claim event by validator 68 LastEventByValidatorKey = []byte{0xf1} 69 70 // LastObservedEventNonceKey indexes the latest event nonce 71 LastObservedEventNonceKey = []byte{0xf2} 72 73 // SequenceKeyPrefix indexes different txids 74 SequenceKeyPrefix = []byte{0x7} 75 76 // KeyLastTXPoolID indexes the lastTxPoolID 77 KeyLastTXPoolID = append(SequenceKeyPrefix, []byte("lastTxPoolId")...) 78 79 // KeyLastOutgoingBatchID indexes the lastBatchID 80 KeyLastOutgoingBatchID = append(SequenceKeyPrefix, []byte("lastBatchId")...) 81 82 // KeyOrchestratorAddress indexes the validator keys for an orchestrator 83 KeyOrchestratorAddress = []byte{0xe8} 84 85 // LastObservedEthereumBlockHeightKey indexes the latest Ethereum block height 86 LastObservedEthereumBlockHeightKey = []byte{0xf9} 87 88 // DenomToERC20Key prefixes the index of Cosmos originated asset denoms to ERC20s 89 DenomToERC20Key = []byte{0xf3} 90 91 // ERC20ToDenomKey prefixes the index of Cosmos originated assets ERC20s to denoms 92 ERC20ToDenomKey = []byte{0xf4} 93 94 // LastSlashedValsetNonce indexes the latest slashed valset nonce 95 LastSlashedValsetNonce = []byte{0xf5} 96 97 // LatestValsetNonce indexes the latest valset nonce 98 LatestValsetNonce = []byte{0xf6} 99 100 // LastSlashedBatchBlock indexes the latest slashed batch block height 101 LastSlashedBatchBlock = []byte{0xf7} 102 103 // LastUnbondingBlockHeight indexes the last validator unbonding block height 104 LastUnbondingBlockHeight = []byte{0xf8} 105 106 // LastObservedValsetNonceKey indexes the latest observed valset nonce 107 // HERE THERE BE DRAGONS, do not use this value as an up to date validator set 108 // on Ethereum it will always lag significantly and may be totally wrong at some 109 // times. 110 LastObservedValsetKey = []byte{0xfa} 111 112 // PastEthSignatureCheckpointKey indexes eth signature checkpoints that have existed 113 PastEthSignatureCheckpointKey = []byte{0x1b} 114 115 EthereumBlacklistKey = []byte{0x1c} 116 ) 117 118 func GetEthereumBlacklistStoreKey(addr common.Address) []byte { 119 return append(EthereumBlacklistKey, addr.Bytes()...) 120 } 121 122 // GetOrchestratorAddressKey returns the following key format 123 // prefix 124 // [0xe8][cosmos1ahx7f8wyertuus9r20284ej0asrs085case3kn] 125 func GetOrchestratorAddressKey(orc sdk.AccAddress) []byte { 126 return append(KeyOrchestratorAddress, orc.Bytes()...) 127 } 128 129 // GetEthAddressByValidatorKey returns the following key format 130 // prefix cosmos-validator 131 // [0x0][cosmosvaloper1ahx7f8wyertuus9r20284ej0asrs085case3kn] 132 func GetEthAddressByValidatorKey(validator sdk.ValAddress) []byte { 133 return append(EthAddressByValidatorKey, validator.Bytes()...) 134 } 135 136 // GetValidatorByEthAddressKey returns the following key format 137 // prefix cosmos-validator 138 // [0xf9][0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B] 139 func GetValidatorByEthAddressKey(ethAddress common.Address) []byte { 140 return append(ValidatorByEthAddressKey, ethAddress.Bytes()...) 141 } 142 143 // GetValsetKey returns the following key format 144 // prefix nonce 145 // [0x0][0 0 0 0 0 0 0 1] 146 func GetValsetKey(nonce uint64) []byte { 147 return append(ValsetRequestKey, UInt64Bytes(nonce)...) 148 } 149 150 // GetValsetConfirmKey returns the following key format 151 // prefix nonce validator-address 152 // [0x0][0 0 0 0 0 0 0 1][cosmos1ahx7f8wyertuus9r20284ej0asrs085case3kn] 153 // MARK finish-batches: this is where the key is created in the old (presumed working) code 154 func GetValsetConfirmKey(nonce uint64, validator sdk.AccAddress) []byte { 155 return append(ValsetConfirmKey, append(UInt64Bytes(nonce), validator.Bytes()...)...) 156 } 157 158 // GetAttestationKey returns the following key format 159 // prefix nonce claim-details-hash 160 // [0x5][0 0 0 0 0 0 0 1][fd1af8cec6c67fcf156f1b61fdf91ebc04d05484d007436e75342fc05bbff35a] 161 // An attestation is an event multiple people are voting on, this function needs the claim 162 // details because each Attestation is aggregating all claims of a specific event, lets say 163 // validator X and validator y where making different claims about the same event nonce 164 // Note that the claim hash does NOT include the claimer address and only identifies an event 165 func GetAttestationKey(eventNonce uint64, claimHash []byte) []byte { 166 key := make([]byte, len(OracleAttestationKey)+len(UInt64Bytes(0))+len(claimHash)) 167 copy(key[0:], OracleAttestationKey) 168 copy(key[len(OracleAttestationKey):], UInt64Bytes(eventNonce)) 169 copy(key[len(OracleAttestationKey)+len(UInt64Bytes(0)):], claimHash) 170 return key 171 } 172 173 // GetAttestationKeyWithHash returns the following key format 174 // prefix nonce claim-details-hash 175 // [0x5][0 0 0 0 0 0 0 1][fd1af8cec6c67fcf156f1b61fdf91ebc04d05484d007436e75342fc05bbff35a] 176 // An attestation is an event multiple people are voting on, this function needs the claim 177 // details because each Attestation is aggregating all claims of a specific event, lets say 178 // validator X and validator y where making different claims about the same event nonce 179 // Note that the claim hash does NOT include the claimer address and only identifies an event 180 func GetAttestationKeyWithHash(eventNonce uint64, claimHash []byte) []byte { 181 key := make([]byte, len(OracleAttestationKey)+len(UInt64Bytes(0))+len(claimHash)) 182 copy(key[0:], OracleAttestationKey) 183 copy(key[len(OracleAttestationKey):], UInt64Bytes(eventNonce)) 184 copy(key[len(OracleAttestationKey)+len(UInt64Bytes(0)):], claimHash) 185 return key 186 } 187 188 // GetOutgoingTxPoolKey returns the following key format 189 // prefix id 190 // [0x6][0 0 0 0 0 0 0 1] 191 func GetOutgoingTxPoolKey(id uint64) []byte { 192 buf := make([]byte, 0, len(OutgoingTXPoolKey)+8) 193 buf = append(buf, OutgoingTXPoolKey...) 194 buf = append(buf, sdk.Uint64ToBigEndian(id)...) 195 196 return buf 197 } 198 199 // GetOutgoingTxBatchKey returns the following key format 200 // prefix nonce eth-contract-address 201 // [0xa][0 0 0 0 0 0 0 1][0xc783df8a850f42e7F7e57013759C285caa701eB6] 202 func GetOutgoingTxBatchKey(tokenContract common.Address, nonce uint64) []byte { 203 buf := make([]byte, 0, len(OutgoingTXBatchKey)+8+ETHContractAddressLen) 204 buf = append(buf, OutgoingTXBatchKey...) 205 buf = append(buf, UInt64Bytes(nonce)...) 206 buf = append(buf, tokenContract.Bytes()...) 207 208 return buf 209 } 210 211 // GetOutgoingTxBatchBlockKey returns the following key format 212 // prefix blockheight 213 // [0xb][0 0 0 0 2 1 4 3] 214 func GetOutgoingTxBatchBlockKey(block uint64) []byte { 215 return append(OutgoingTXBatchBlockKey, UInt64Bytes(block)...) 216 } 217 218 // GetBatchConfirmKey returns the following key format 219 // prefix eth-contract-address BatchNonce Validator-address 220 // [0xe1][0xc783df8a850f42e7F7e57013759C285caa701eB6][0 0 0 0 0 0 0 1][cosmosvaloper1ahx7f8wyertuus9r20284ej0asrs085case3kn] 221 // TODO this should be a sdk.ValAddress 222 func GetBatchConfirmKey(tokenContract common.Address, batchNonce uint64, validator sdk.AccAddress) []byte { 223 buf := make([]byte, 0, len(BatchConfirmKey)+ETHContractAddressLen+8+len(validator)) 224 buf = append(buf, BatchConfirmKey...) 225 buf = append(buf, tokenContract.Bytes()...) 226 buf = append(buf, UInt64Bytes(batchNonce)...) 227 buf = append(buf, validator.Bytes()...) 228 229 return buf 230 } 231 232 // GetFeeSecondIndexKey returns the following key format 233 // prefix eth-contract-address fee_amount 234 // [0x9][0xc783df8a850f42e7F7e57013759C285caa701eB6][0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 235 func GetFeeSecondIndexKey(tokenContract common.Address, fee *ERC20Token) []byte { 236 buf := make([]byte, 0, len(SecondIndexOutgoingTXFeeKey)+ETHContractAddressLen+32) 237 buf = append(buf, SecondIndexOutgoingTXFeeKey...) 238 buf = append(buf, tokenContract.Bytes()...) 239 240 // sdk.BigInt represented as a zero-extended big-endian byte slice (32 bytes) 241 amount := make([]byte, 32) 242 amount = fee.Amount.BigInt().FillBytes(amount) 243 buf = append(buf, amount...) 244 245 return buf 246 } 247 248 // GetLastEventNonceByValidatorKey indexes lateset event nonce by validator 249 // GetLastEventNonceByValidatorKey returns the following key format 250 // prefix cosmos-validator 251 // [0x0][cosmos1ahx7f8wyertuus9r20284ej0asrs085case3kn] 252 func GetLastEventNonceByValidatorKey(validator sdk.ValAddress) []byte { 253 buf := make([]byte, 0, len(LastEventNonceByValidatorKey)+len(validator)) 254 buf = append(buf, LastEventNonceByValidatorKey...) 255 buf = append(buf, validator.Bytes()...) 256 257 return buf 258 } 259 260 // GetLastEventByValidatorKey indexes lateset event by validator 261 // GetLastEventByValidatorKey returns the following key format 262 // prefix cosmos-validator 263 // [0x0][cosmos1ahx7f8wyertuus9r20284ej0asrs085case3kn] 264 func GetLastEventByValidatorKey(validator sdk.ValAddress) []byte { 265 buf := make([]byte, 0, len(LastEventByValidatorKey)+len(validator)) 266 buf = append(buf, LastEventByValidatorKey...) 267 buf = append(buf, validator.Bytes()...) 268 269 return buf 270 } 271 272 func GetCosmosDenomToERC20Key(denom string) []byte { 273 buf := make([]byte, 0, len(DenomToERC20Key)+len(denom)) 274 buf = append(buf, DenomToERC20Key...) 275 buf = append(buf, denom...) 276 277 return buf 278 } 279 280 func GetERC20ToCosmosDenomKey(tokenContract common.Address) []byte { 281 buf := make([]byte, 0, len(ERC20ToDenomKey)+ETHContractAddressLen) 282 buf = append(buf, ERC20ToDenomKey...) 283 buf = append(buf, tokenContract.Bytes()...) 284 285 return buf 286 } 287 288 // GetPastEthSignatureCheckpointKey returns the following key format 289 // prefix checkpoint 290 // [0x0][ checkpoint bytes ] 291 func GetPastEthSignatureCheckpointKey(checkpoint common.Hash) []byte { 292 return append(PastEthSignatureCheckpointKey, checkpoint[:]...) 293 }