Coverage Summary for Class: BridgeMethods (co.rsk.peg)

Class Class, % Method, % Line, %
BridgeMethods 0% (0/1) 0% (0/41) 0% (0/290)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2018 RSK Labs Ltd. 4  * 5  * This program is free software: you can redistribute it and/or modify 6  * it under the terms of the GNU Lesser General Public License as published by 7  * the Free Software Foundation, either version 3 of the License, or 8  * (at your option) any later version. 9  * 10  * This program is distributed in the hope that it will be useful, 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  * GNU Lesser General Public License for more details. 14  * 15  * You should have received a copy of the GNU Lesser General Public License 16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 17  */ 18 package co.rsk.peg; 19  20 import org.ethereum.config.blockchain.upgrades.ActivationConfig; 21 import org.ethereum.core.CallTransaction; 22 import org.ethereum.db.ByteArrayWrapper; 23  24 import java.util.Map; 25 import java.util.Optional; 26 import java.util.function.Function; 27 import java.util.stream.Collectors; 28 import java.util.stream.Stream; 29  30 import static org.ethereum.config.blockchain.upgrades.ConsensusRule.*; 31  32 /** 33  * This enum holds the basic information of the Bridge contract methods: the ABI, the cost and the implementation. 34  */ 35 public enum BridgeMethods { 36  ADD_FEDERATOR_PUBLIC_KEY( 37  CallTransaction.Function.fromSignature( 38  "addFederatorPublicKey", 39  new String[]{"bytes"}, 40  new String[]{"int256"} 41  ), 42  fixedCost(13000L), 43  (BridgeMethodExecutorTyped) Bridge::addFederatorPublicKey, 44  activations -> !activations.isActive(RSKIP123), 45  fixedPermission(false) 46  ), 47  ADD_FEDERATOR_PUBLIC_KEY_MULTIKEY( 48  CallTransaction.Function.fromSignature( 49  "addFederatorPublicKeyMultikey", 50  new String[]{"bytes", "bytes", "bytes"}, 51  new String[]{"int256"} 52  ), 53  fixedCost(13000L), 54  (BridgeMethodExecutorTyped) Bridge::addFederatorPublicKeyMultikey, 55  activations -> activations.isActive(RSKIP123), 56  fixedPermission(false) 57  ), 58  ADD_LOCK_WHITELIST_ADDRESS( 59  CallTransaction.Function.fromSignature( 60  "addLockWhitelistAddress", 61  new String[]{"string", "int256"}, 62  new String[]{"int256"} 63  ), 64  fixedCost(25000L), 65  (BridgeMethodExecutorTyped) Bridge::addOneOffLockWhitelistAddress, 66  activations -> !activations.isActive(RSKIP87), 67  fixedPermission(false) 68  ), 69  ADD_ONE_OFF_LOCK_WHITELIST_ADDRESS( 70  CallTransaction.Function.fromSignature( 71  "addOneOffLockWhitelistAddress", 72  new String[]{"string", "int256"}, 73  new String[]{"int256"} 74  ), 75  fixedCost(25000L), // using same gas estimation as ADD_LOCK_WHITELIST_ADDRESS 76  (BridgeMethodExecutorTyped) Bridge::addOneOffLockWhitelistAddress, 77  activations -> activations.isActive(RSKIP87), 78  fixedPermission(false) 79  ), 80  ADD_UNLIMITED_LOCK_WHITELIST_ADDRESS( 81  CallTransaction.Function.fromSignature( 82  "addUnlimitedLockWhitelistAddress", 83  new String[]{"string"}, 84  new String[]{"int256"} 85  ), 86  fixedCost(25000L), // using same gas estimation as ADD_LOCK_WHITELIST_ADDRESS 87  (BridgeMethodExecutorTyped) Bridge::addUnlimitedLockWhitelistAddress, 88  activations -> activations.isActive(RSKIP87), 89  fixedPermission(false) 90  ), 91  ADD_SIGNATURE( 92  CallTransaction.Function.fromSignature( 93  "addSignature", 94  new String[]{"bytes", "bytes[]", "bytes"}, 95  new String[]{} 96  ), 97  fixedCost(70000L), 98  Bridge.activeAndRetiringFederationOnly((BridgeMethodExecutorVoid) Bridge::addSignature, "addSignature"), 99  fixedPermission(false) 100  ), 101  COMMIT_FEDERATION( 102  CallTransaction.Function.fromSignature( 103  "commitFederation", 104  new String[]{"bytes"}, 105  new String[]{"int256"} 106  ), 107  fixedCost(38000L), 108  (BridgeMethodExecutorTyped) Bridge::commitFederation, 109  fixedPermission(false) 110  ), 111  CREATE_FEDERATION( 112  CallTransaction.Function.fromSignature( 113  "createFederation", 114  new String[]{}, 115  new String[]{"int256"} 116  ), 117  fixedCost(11000L), 118  (BridgeMethodExecutorTyped) Bridge::createFederation, 119  fixedPermission(false) 120  ), 121  GET_BTC_BLOCKCHAIN_BEST_CHAIN_HEIGHT( 122  CallTransaction.Function.fromSignature( 123  "getBtcBlockchainBestChainHeight", 124  new String[]{}, 125  new String[]{"int"} 126  ), 127  fixedCost(19000L), 128  (BridgeMethodExecutorTyped) Bridge::getBtcBlockchainBestChainHeight, 129  fromMethod(Bridge::getBtcBlockchainBestChainHeightOnlyAllowsLocalCalls) 130  ), 131  GET_BTC_BLOCKCHAIN_INITIAL_BLOCK_HEIGHT( 132  CallTransaction.Function.fromSignature( 133  "getBtcBlockchainInitialBlockHeight", 134  new String[]{}, 135  new String[]{"int"} 136  ), 137  fixedCost(20000L), 138  (BridgeMethodExecutorTyped) Bridge::getBtcBlockchainInitialBlockHeight, 139  activations -> activations.isActive(RSKIP89), 140  fixedPermission(true) 141  ), 142  GET_BTC_BLOCKCHAIN_BLOCK_LOCATOR( 143  CallTransaction.Function.fromSignature( 144  "getBtcBlockchainBlockLocator", 145  new String[]{}, 146  new String[]{"string[]"} 147  ), 148  fixedCost(76000L), 149  (BridgeMethodExecutorTyped) Bridge::getBtcBlockchainBlockLocator, 150  activations -> !activations.isActive(RSKIP89), 151  fixedPermission(true) 152  ), 153  GET_BTC_BLOCKCHAIN_BLOCK_HASH_AT_DEPTH( 154  CallTransaction.Function.fromSignature( 155  "getBtcBlockchainBlockHashAtDepth", 156  new String[]{"int256"}, 157  new String[]{"bytes"} 158  ), 159  fixedCost(20000L), 160  (BridgeMethodExecutorTyped) Bridge::getBtcBlockchainBlockHashAtDepth, 161  activations -> activations.isActive(RSKIP89), 162  fixedPermission(true) 163  ), 164  GET_BTC_TRANSACTION_CONFIRMATIONS( 165  CallTransaction.Function.fromSignature( 166  "getBtcTransactionConfirmations", 167  new String[]{"bytes32", "bytes32", "uint256", "bytes32[]"}, 168  new String[]{"int256"} 169  ), 170  fromMethod(Bridge::getBtcTransactionConfirmationsGetCost), 171  (BridgeMethodExecutorTyped) Bridge::getBtcTransactionConfirmations, 172  activations -> activations.isActive(RSKIP122), 173  fixedPermission(false) 174  ), 175  GET_BTC_TX_HASH_PROCESSED_HEIGHT( 176  CallTransaction.Function.fromSignature( 177  "getBtcTxHashProcessedHeight", 178  new String[]{"string"}, 179  new String[]{"int64"} 180  ), 181  fixedCost(22000L), 182  (BridgeMethodExecutorTyped) Bridge::getBtcTxHashProcessedHeight, 183  fixedPermission(true) 184  ), 185  GET_FEDERATION_ADDRESS( 186  CallTransaction.Function.fromSignature( 187  "getFederationAddress", 188  new String[]{}, 189  new String[]{"string"} 190  ), 191  fixedCost(11000L), 192  (BridgeMethodExecutorTyped) Bridge::getFederationAddress, 193  fixedPermission(true) 194  ), 195  GET_FEDERATION_CREATION_BLOCK_NUMBER( 196  CallTransaction.Function.fromSignature( 197  "getFederationCreationBlockNumber", 198  new String[]{}, 199  new String[]{"int256"} 200  ), 201  fixedCost(10000L), 202  (BridgeMethodExecutorTyped) Bridge::getFederationCreationBlockNumber, 203  fixedPermission(true) 204  ), 205  GET_FEDERATION_CREATION_TIME( 206  CallTransaction.Function.fromSignature( 207  "getFederationCreationTime", 208  new String[]{}, 209  new String[]{"int256"} 210  ), 211  fixedCost(10000L), 212  (BridgeMethodExecutorTyped) Bridge::getFederationCreationTime, 213  fixedPermission(true) 214  ), 215  GET_FEDERATION_SIZE( 216  CallTransaction.Function.fromSignature( 217  "getFederationSize", 218  new String[]{}, 219  new String[]{"int256"} 220  ), 221  fixedCost(10000L), 222  (BridgeMethodExecutorTyped) Bridge::getFederationSize, 223  fixedPermission(true) 224  ), 225  GET_FEDERATION_THRESHOLD( 226  CallTransaction.Function.fromSignature( 227  "getFederationThreshold", 228  new String[]{}, 229  new String[]{"int256"} 230  ), 231  fixedCost(11000L), 232  (BridgeMethodExecutorTyped) Bridge::getFederationThreshold, 233  fixedPermission(true) 234  ), 235  GET_FEDERATOR_PUBLIC_KEY( 236  CallTransaction.Function.fromSignature( 237  "getFederatorPublicKey", 238  new String[]{"int256"}, 239  new String[]{"bytes"} 240  ), 241  fixedCost(10000L), 242  (BridgeMethodExecutorTyped) Bridge::getFederatorPublicKey, 243  activations -> !activations.isActive(RSKIP123), 244  fixedPermission(true) 245  ), 246  GET_FEDERATOR_PUBLIC_KEY_OF_TYPE( 247  CallTransaction.Function.fromSignature( 248  "getFederatorPublicKeyOfType", 249  new String[]{"int256", "string"}, 250  new String[]{"bytes"} 251  ), 252  fixedCost(10000L), 253  (BridgeMethodExecutorTyped) Bridge::getFederatorPublicKeyOfType, 254  activations -> activations.isActive(RSKIP123), 255  fixedPermission(true) 256  ), 257  GET_FEE_PER_KB( 258  CallTransaction.Function.fromSignature( 259  "getFeePerKb", 260  new String[]{}, 261  new String[]{"int256"} 262  ), 263  fixedCost(2000L), 264  (BridgeMethodExecutorTyped) Bridge::getFeePerKb, 265  fixedPermission(true) 266  ), 267  GET_LOCK_WHITELIST_ADDRESS( 268  CallTransaction.Function.fromSignature( 269  "getLockWhitelistAddress", 270  new String[]{"int256"}, 271  new String[]{"string"} 272  ), 273  fixedCost(16000L), 274  (BridgeMethodExecutorTyped) Bridge::getLockWhitelistAddress, 275  fixedPermission(true) 276  ), 277  GET_LOCK_WHITELIST_ENTRY_BY_ADDRESS( 278  CallTransaction.Function.fromSignature( 279  "getLockWhitelistEntryByAddress", 280  new String[]{"string"}, 281  new String[]{"int256"} 282  ), 283  fixedCost(16000L), 284  (BridgeMethodExecutorTyped) Bridge::getLockWhitelistEntryByAddress, 285  activations -> activations.isActive(RSKIP87), 286  fixedPermission(true) 287  ), 288  GET_LOCK_WHITELIST_SIZE( 289  CallTransaction.Function.fromSignature( 290  "getLockWhitelistSize", 291  new String[]{}, 292  new String[]{"int256"} 293  ), 294  fixedCost(16000L), 295  (BridgeMethodExecutorTyped) Bridge::getLockWhitelistSize, 296  fixedPermission(true) 297  ), 298  GET_MINIMUM_LOCK_TX_VALUE( 299  CallTransaction.Function.fromSignature( 300  "getMinimumLockTxValue", 301  new String[]{}, 302  new String[]{"int"} 303  ), 304  fixedCost(2000L), 305  (BridgeMethodExecutorTyped) Bridge::getMinimumLockTxValue, 306  fixedPermission(true) 307  ), 308  GET_PENDING_FEDERATION_HASH( 309  CallTransaction.Function.fromSignature( 310  "getPendingFederationHash", 311  new String[]{}, 312  new String[]{"bytes"} 313  ), 314  fixedCost(3000L), 315  (BridgeMethodExecutorTyped) Bridge::getPendingFederationHash, 316  fixedPermission(true) 317  ), 318  GET_PENDING_FEDERATION_SIZE( 319  CallTransaction.Function.fromSignature( 320  "getPendingFederationSize", 321  new String[]{}, 322  new String[]{"int256"} 323  ), 324  fixedCost(3000L), 325  (BridgeMethodExecutorTyped) Bridge::getPendingFederationSize, 326  fixedPermission(true) 327  ), 328  GET_PENDING_FEDERATOR_PUBLIC_KEY( 329  CallTransaction.Function.fromSignature( 330  "getPendingFederatorPublicKey", 331  new String[]{"int256"}, 332  new String[]{"bytes"} 333  ), 334  fixedCost(3000L), 335  (BridgeMethodExecutorTyped) Bridge::getPendingFederatorPublicKey, 336  activations -> !activations.isActive(RSKIP123), 337  fixedPermission(true) 338  ), 339  GET_PENDING_FEDERATOR_PUBLIC_KEY_OF_TYPE( 340  CallTransaction.Function.fromSignature( 341  "getPendingFederatorPublicKeyOfType", 342  new String[]{"int256", "string"}, 343  new String[]{"bytes"} 344  ), 345  fixedCost(3000L), 346  (BridgeMethodExecutorTyped) Bridge::getPendingFederatorPublicKeyOfType, 347  activations -> activations.isActive(RSKIP123), 348  fixedPermission(true) 349  ), 350  GET_RETIRING_FEDERATION_ADDRESS( 351  CallTransaction.Function.fromSignature( 352  "getRetiringFederationAddress", 353  new String[]{}, 354  new String[]{"string"} 355  ), 356  fixedCost(3000L), 357  (BridgeMethodExecutorTyped) Bridge::getRetiringFederationAddress, 358  fixedPermission(true) 359  ), 360  GET_RETIRING_FEDERATION_CREATION_BLOCK_NUMBER( 361  CallTransaction.Function.fromSignature( 362  "getRetiringFederationCreationBlockNumber", 363  new String[]{}, 364  new String[]{"int256"} 365  ), 366  fixedCost(3000L), 367  (BridgeMethodExecutorTyped) Bridge::getRetiringFederationCreationBlockNumber, 368  fixedPermission(true) 369  ), 370  GET_RETIRING_FEDERATION_CREATION_TIME( 371  CallTransaction.Function.fromSignature( 372  "getRetiringFederationCreationTime", 373  new String[]{}, 374  new String[]{"int256"} 375  ), 376  fixedCost(3000L), 377  (BridgeMethodExecutorTyped) Bridge::getRetiringFederationCreationTime, 378  fixedPermission(true) 379  ), 380  GET_RETIRING_FEDERATION_SIZE( 381  CallTransaction.Function.fromSignature( 382  "getRetiringFederationSize", 383  new String[]{}, 384  new String[]{"int256"} 385  ), 386  fixedCost(3000L), 387  (BridgeMethodExecutorTyped) Bridge::getRetiringFederationSize, 388  fixedPermission(true) 389  ), 390  GET_RETIRING_FEDERATION_THRESHOLD( 391  CallTransaction.Function.fromSignature( 392  "getRetiringFederationThreshold", 393  new String[]{}, 394  new String[]{"int256"} 395  ), 396  fixedCost(3000L), 397  (BridgeMethodExecutorTyped) Bridge::getRetiringFederationThreshold, 398  fixedPermission(true) 399  ), 400  GET_RETIRING_FEDERATOR_PUBLIC_KEY( 401  CallTransaction.Function.fromSignature( 402  "getRetiringFederatorPublicKey", 403  new String[]{"int256"}, 404  new String[]{"bytes"} 405  ), 406  fixedCost(3000L), 407  (BridgeMethodExecutorTyped) Bridge::getRetiringFederatorPublicKey, 408  activations -> !activations.isActive(RSKIP123), 409  fixedPermission(true) 410  ), 411  GET_RETIRING_FEDERATOR_PUBLIC_KEY_OF_TYPE( 412  CallTransaction.Function.fromSignature( 413  "getRetiringFederatorPublicKeyOfType", 414  new String[]{"int256", "string"}, 415  new String[]{"bytes"} 416  ), 417  fixedCost(3000L), 418  (BridgeMethodExecutorTyped) Bridge::getRetiringFederatorPublicKeyOfType, 419  activations -> activations.isActive(RSKIP123), 420  fixedPermission(true) 421  ), 422  GET_STATE_FOR_BTC_RELEASE_CLIENT( 423  CallTransaction.Function.fromSignature( 424  "getStateForBtcReleaseClient", 425  new String[]{}, 426  new String[]{"bytes"} 427  ), 428  fixedCost(4000L), 429  (BridgeMethodExecutorTyped) Bridge::getStateForBtcReleaseClient, 430  fixedPermission(true) 431  ), 432  GET_STATE_FOR_DEBUGGING( 433  CallTransaction.Function.fromSignature( 434  "getStateForDebugging", 435  new String[]{}, 436  new String[]{"bytes"} 437  ), 438  fixedCost(3_000_000L), 439  (BridgeMethodExecutorTyped) Bridge::getStateForDebugging, 440  fixedPermission(true) 441  ), 442  GET_LOCKING_CAP( 443  CallTransaction.Function.fromSignature( 444  "getLockingCap", 445  new String[]{}, 446  new String[]{"int256"} 447  ), 448  fixedCost(3_000L), 449  (BridgeMethodExecutorTyped) Bridge::getLockingCap, 450  activations -> activations.isActive(RSKIP134), 451  fixedPermission(true) 452  ), 453  GET_ACTIVE_FEDERATION_CREATION_BLOCK_HEIGHT( 454  CallTransaction.Function.fromSignature( 455  "getActiveFederationCreationBlockHeight", 456  new String[]{}, 457  new String[]{"uint256"} 458  ), 459  fixedCost(3_000L), 460  (BridgeMethodExecutorTyped) Bridge::getActiveFederationCreationBlockHeight, 461  activations -> activations.isActive(RSKIP186), 462  fixedPermission(false) 463  ), 464  INCREASE_LOCKING_CAP( 465  CallTransaction.Function.fromSignature( 466  "increaseLockingCap", 467  new String[]{"int256"}, 468  new String[]{"bool"} 469  ), 470  fixedCost(8_000L), 471  (BridgeMethodExecutorTyped) Bridge::increaseLockingCap, 472  activations -> activations.isActive(RSKIP134), 473  fixedPermission(false) 474  ), 475  IS_BTC_TX_HASH_ALREADY_PROCESSED( 476  CallTransaction.Function.fromSignature( 477  "isBtcTxHashAlreadyProcessed", 478  new String[]{"string"}, 479  new String[]{"bool"} 480  ), 481  fixedCost(23000L), 482  (BridgeMethodExecutorTyped) Bridge::isBtcTxHashAlreadyProcessed, 483  fixedPermission(true) 484  ), 485  RECEIVE_HEADERS( 486  CallTransaction.Function.fromSignature( 487  "receiveHeaders", 488  new String[]{"bytes[]"}, 489  new String[]{} 490  ), 491  fromMethod(Bridge::receiveHeadersGetCost), 492  Bridge.executeIfElse( 493  Bridge::receiveHeadersIsPublic, 494  (BridgeMethodExecutorVoid) Bridge::receiveHeaders, 495  Bridge.activeAndRetiringFederationOnly((BridgeMethodExecutorVoid) Bridge::receiveHeaders, "receiveHeaders") 496  ), 497  fixedPermission(false) 498  ), 499  RECEIVE_HEADER( 500  CallTransaction.Function.fromSignature( 501  "receiveHeader", 502  new String[]{"bytes"}, 503  new String[]{"int256"} 504  ), 505  fixedCost(22_000L), // TODO: calculate gas cost. 506  (BridgeMethodExecutorTyped) Bridge::receiveHeader, 507  activations -> activations.isActive(RSKIP200), 508  fixedPermission(false) 509  ), 510  REGISTER_BTC_TRANSACTION( 511  CallTransaction.Function.fromSignature( 512  "registerBtcTransaction", 513  new String[]{"bytes", "int", "bytes"}, 514  new String[]{} 515  ), 516  fixedCost(22000L), 517  Bridge.executeIfElse( 518  Bridge::registerBtcTransactionIsPublic, 519  (BridgeMethodExecutorVoid) Bridge::registerBtcTransaction, 520  Bridge.activeAndRetiringFederationOnly((BridgeMethodExecutorVoid) Bridge::registerBtcTransaction, "registerBtcTransaction") 521  ), 522  fixedPermission(false) 523  ), 524  RELEASE_BTC( 525  CallTransaction.Function.fromSignature( 526  "releaseBtc", 527  new String[]{}, 528  new String[]{} 529  ), 530  fixedCost(23000L), 531  (BridgeMethodExecutorVoid) Bridge::releaseBtc, 532  fixedPermission(false) 533  ), 534  REMOVE_LOCK_WHITELIST_ADDRESS( 535  CallTransaction.Function.fromSignature( 536  "removeLockWhitelistAddress", 537  new String[]{"string"}, 538  new String[]{"int256"} 539  ), 540  fixedCost(24000L), 541  (BridgeMethodExecutorTyped) Bridge::removeLockWhitelistAddress, 542  fixedPermission(false) 543  ), 544  ROLLBACK_FEDERATION( 545  CallTransaction.Function.fromSignature( 546  "rollbackFederation", 547  new String[]{}, 548  new String[]{"int256"} 549  ), 550  fixedCost(12000L), 551  (BridgeMethodExecutorTyped) Bridge::rollbackFederation, 552  fixedPermission(false) 553  ), 554  SET_LOCK_WHITELIST_DISABLE_BLOCK_DELAY( 555  CallTransaction.Function.fromSignature( 556  "setLockWhitelistDisableBlockDelay", 557  new String[]{"int256"}, 558  new String[]{"int256"} 559  ), 560  fixedCost(24000L), 561  (BridgeMethodExecutorTyped) Bridge::setLockWhitelistDisableBlockDelay, 562  fixedPermission(false) 563  ), 564  UPDATE_COLLECTIONS( 565  CallTransaction.Function.fromSignature( 566  "updateCollections", 567  new String[]{}, 568  new String[]{} 569  ), 570  fixedCost(48000L), 571  Bridge.activeAndRetiringFederationOnly((BridgeMethodExecutorVoid) Bridge::updateCollections, "updateCollections"), 572  fixedPermission(false) 573  ), 574  VOTE_FEE_PER_KB( 575  CallTransaction.Function.fromSignature( 576  "voteFeePerKbChange", 577  new String[]{"int256"}, 578  new String[]{"int256"} 579  ), 580  fixedCost(10000L), 581  (BridgeMethodExecutorTyped) Bridge::voteFeePerKbChange, 582  fixedPermission(false) 583  ), 584  REGISTER_BTC_COINBASE_TRANSACTION( 585  CallTransaction.Function.fromSignature( 586  "registerBtcCoinbaseTransaction", 587  new String[]{"bytes", "bytes32", "bytes", "bytes32", "bytes32"}, 588  new String[]{} 589  ), 590  fixedCost(10000L), 591  (BridgeMethodExecutorVoid) Bridge::registerBtcCoinbaseTransaction, 592  activations -> activations.isActive(RSKIP143), 593  fixedPermission(false) 594  ), 595  HAS_BTC_BLOCK_COINBASE_TRANSACTION_INFORMATION( 596  CallTransaction.Function.fromSignature( 597  "hasBtcBlockCoinbaseTransactionInformation", 598  new String[]{"bytes32"}, 599  new String[]{"bool"} 600  ), 601  fixedCost(5000L), 602  (BridgeMethodExecutorTyped) Bridge::hasBtcBlockCoinbaseTransactionInformation, 603  activations -> activations.isActive(RSKIP143), 604  fixedPermission(false) 605  ), 606  REGISTER_FAST_BRIDGE_BTC_TRANSACTION( 607  CallTransaction.Function.fromSignature( 608  "registerFastBridgeBtcTransaction", 609  new String[]{"bytes", "uint256", "bytes", "bytes32", "bytes", "address", "bytes", "bool"}, 610  new String[]{"int256"} 611  ), 612  fixedCost(10000L), // TODO: Define a cost 613  (BridgeMethodExecutorTyped) Bridge::registerFastBridgeBtcTransaction, 614  activations -> activations.isActive(RSKIP176), 615  fixedPermission(false) 616  ), 617  GET_BTC_BLOCKCHAIN_BEST_BLOCK_HEADER( 618  CallTransaction.Function.fromSignature( 619  "getBtcBlockchainBestBlockHeader", 620  new String[0], 621  new String[]{"bytes"} 622  ), 623  fixedCost(20000L), // TODO: calculate gas cost 624  (BridgeMethodExecutorTyped) Bridge::getBtcBlockchainBestBlockHeader, 625  activations -> activations.isActive(RSKIP220), 626  fixedPermission(false) 627  ), 628  GET_BTC_BLOCKCHAIN_BLOCK_HEADER_BY_HASH( 629  CallTransaction.Function.fromSignature( 630  "getBtcBlockchainBlockHeaderByHash", 631  new String[]{"bytes32"}, 632  new String[]{"bytes"} 633  ), 634  fixedCost(20000L), // TODO: calculate gas cost 635  (BridgeMethodExecutorTyped) Bridge::getBtcBlockchainBlockHeaderByHash, 636  activations -> activations.isActive(RSKIP220), 637  fixedPermission(false) 638  ), 639  GET_BTC_BLOCKCHAIN_BLOCK_HEADER_BY_HEIGHT( 640  CallTransaction.Function.fromSignature( 641  "getBtcBlockchainBlockHeaderByHeight", 642  new String[]{"uint256"}, 643  new String[]{"bytes"} 644  ), 645  fixedCost(20000L), // TODO: calculate gas cost 646  (BridgeMethodExecutorTyped) Bridge::getBtcBlockchainBlockHeaderByHeight, 647  activations -> activations.isActive(RSKIP220), 648  fixedPermission(false) 649  ), 650  GET_BTC_BLOCKCHAIN_PARENT_BLOCK_HEADER_BY_HASH( 651  CallTransaction.Function.fromSignature( 652  "getBtcBlockchainParentBlockHeaderByHash", 653  new String[]{"bytes32"}, 654  new String[]{"bytes"} 655  ), 656  fixedCost(20000L), // TODO: calculate gas cost 657  (BridgeMethodExecutorTyped) Bridge::getBtcBlockchainParentBlockHeaderByHash, 658  activations -> activations.isActive(RSKIP220), 659  fixedPermission(false) 660  ); 661  662  private final CallTransaction.Function function; 663  private final CostProvider costProvider; 664  private final Function<ActivationConfig.ForBlock, Boolean> isEnabledFunction; 665  private final BridgeMethodExecutor executor; 666  private final BridgeCallPermissionProvider callPermissionProvider; 667  668  BridgeMethods( 669  CallTransaction.Function function, 670  CostProvider costProvider, 671  BridgeMethodExecutor executor, 672  BridgeCallPermissionProvider callPermissionProvider) { 673  674  this(function, costProvider, executor, activations -> Boolean.TRUE, callPermissionProvider); 675  } 676  677  BridgeMethods( 678  CallTransaction.Function function, 679  CostProvider costProvider, 680  BridgeMethodExecutor executor, 681  Function<ActivationConfig.ForBlock, Boolean> isEnabled, 682  BridgeCallPermissionProvider callPermissionProvider) { 683  684  this.function = function; 685  this.costProvider = costProvider; 686  this.executor = executor; 687  this.isEnabledFunction = isEnabled; 688  this.callPermissionProvider = callPermissionProvider; 689  } 690  691  public static Optional<BridgeMethods> findBySignature(byte[] encoding) { 692  return Optional.ofNullable(SIGNATURES.get(new ByteArrayWrapper(encoding))); 693  } 694  695  public CallTransaction.Function getFunction() { 696  return function; 697  } 698  699  public Boolean isEnabled(ActivationConfig.ForBlock activations) { 700  return this.isEnabledFunction.apply(activations); 701  } 702  703  public long getCost(Bridge bridge, ActivationConfig.ForBlock config, Object[] args) { 704  return costProvider.getCost(bridge, config, args); 705  } 706  707  public BridgeMethodExecutor getExecutor() { 708  return executor; 709  } 710  711  public boolean onlyAllowsLocalCalls(Bridge bridge, Object[] args) { 712  return callPermissionProvider.getOnlyAllowLocalCallsPermission(bridge, args); 713  } 714  715  public interface BridgeCondition { 716  boolean isTrue(Bridge bridge); 717  } 718  719  public interface BridgeMethodExecutor { 720  Optional<?> execute(Bridge self, Object[] args) throws Exception; 721  } 722  723  private interface BridgeMethodExecutorTyped<T> extends BridgeMethodExecutor { 724  @Override 725  default Optional<T> execute(Bridge self, Object[] args) throws Exception { 726  return Optional.ofNullable(executeTyped(self, args)); 727  } 728  729  T executeTyped(Bridge self, Object[] args) throws Exception; 730  } 731  732  private interface BridgeMethodExecutorVoid extends BridgeMethodExecutor { 733  @Override 734  default Optional<?> execute(Bridge self, Object[] args) throws Exception { 735  executeVoid(self, args); 736  return Optional.empty(); 737  } 738  739  void executeVoid(Bridge self, Object[] args) throws Exception; 740  } 741  742  private interface CostProvider { 743  long getCost(Bridge bridge, ActivationConfig.ForBlock config, Object[] args); 744  } 745  746  private interface BridgeCostProvider { 747  long getCost(Bridge bridge, Object[] args); 748  } 749  750  private static CostProvider fixedCost(long cost) { 751  return (Bridge bridge, ActivationConfig.ForBlock config, Object[] args) -> cost; 752  } 753  754  private static CostProvider fromMethod(BridgeCostProvider bridgeCostProvider) { 755  return (Bridge bridge, ActivationConfig.ForBlock config, Object[] args) -> bridgeCostProvider.getCost(bridge, args); 756  } 757  758  private interface BridgeCallPermissionProvider { 759  boolean getOnlyAllowLocalCallsPermission(Bridge bridge, Object[] args); 760  } 761  762  private static BridgeCallPermissionProvider fixedPermission(boolean onlyAllowsLocalCalls) { 763  return (Bridge bridge, Object[] args) -> onlyAllowsLocalCalls; 764  } 765  766  private static BridgeCallPermissionProvider fromMethod(BridgeCallPermissionProvider bridgeCallPermissionProvider) { 767  return (Bridge bridge, Object[] args) -> bridgeCallPermissionProvider.getOnlyAllowLocalCallsPermission(bridge, args); 768  } 769  770  private static final Map<ByteArrayWrapper, BridgeMethods> SIGNATURES = Stream.of(BridgeMethods.values()) 771  .collect(Collectors.toMap( 772  m -> new ByteArrayWrapper(m.getFunction().encodeSignature()), 773  Function.identity() 774  )); 775  776 }