github.com/aswedchain/aswed@v1.0.1/consensus/congress/systemcontract/abi.go (about)

     1  package systemcontract
     2  
     3  import (
     4  	"github.com/aswedchain/aswed/accounts/abi"
     5  	"github.com/aswedchain/aswed/common"
     6  	"github.com/aswedchain/aswed/params"
     7  	"math/big"
     8  	"strings"
     9  )
    10  
    11  // ValidatorsInteractiveABI contains all methods to interactive with validator contracts.
    12  const ValidatorsInteractiveABI = `
    13  [
    14  	{
    15  		"inputs": [
    16  		  {
    17  			"internalType": "address[]",
    18  			"name": "vals",
    19  			"type": "address[]"
    20  		  }
    21  		],
    22  		"name": "initialize",
    23  		"outputs": [],
    24  		"stateMutability": "nonpayable",
    25  		"type": "function"
    26  	},
    27  	{
    28  		"inputs": [],
    29  		"name": "distributeBlockReward",
    30  		"outputs": [],
    31  		"stateMutability": "payable",
    32  		"type": "function"
    33  	},
    34  	{
    35  		"inputs": [],
    36  		"name": "getTopValidators",
    37  		"outputs": [
    38  		  {
    39  			"internalType": "address[]",
    40  			"name": "",
    41  			"type": "address[]"
    42  		  }
    43  		],
    44  		"stateMutability": "view",
    45  		"type": "function"
    46  	},
    47  	{
    48  		"inputs": [
    49  		  {
    50  			"internalType": "address[]",
    51  			"name": "newSet",
    52  			"type": "address[]"
    53  		  },
    54  		  {
    55  			"internalType": "uint256",
    56  			"name": "epoch",
    57  			"type": "uint256"
    58  		  }
    59  		],
    60  		"name": "updateActiveValidatorSet",
    61  		"outputs": [],
    62  		"stateMutability": "nonpayable",
    63  		"type": "function"
    64  	},
    65  	{
    66        "inputs": [
    67          {
    68            "internalType": "address",
    69            "name": "val",
    70            "type": "address"
    71          }
    72        ],
    73        "name": "getValidatorInfo",
    74        "outputs": [
    75          {
    76            "internalType": "address payable",
    77            "name": "",
    78            "type": "address"
    79          },
    80          {
    81            "internalType": "enum Validators.Status",
    82            "name": "",
    83            "type": "uint8"
    84          },
    85          {
    86            "internalType": "uint256",
    87            "name": "",
    88            "type": "uint256"
    89          },
    90          {
    91            "internalType": "uint256",
    92            "name": "",
    93            "type": "uint256"
    94          },
    95          {
    96            "internalType": "uint256",
    97            "name": "",
    98            "type": "uint256"
    99          },
   100          {
   101            "internalType": "uint256",
   102            "name": "",
   103            "type": "uint256"
   104          },
   105          {
   106            "internalType": "address[]",
   107            "name": "",
   108            "type": "address[]"
   109          }
   110        ],
   111        "stateMutability": "view",
   112        "type": "function"
   113      }
   114  ]
   115  `
   116  
   117  const PunishInteractiveABI = `
   118  [
   119  	{
   120  		"inputs": [],
   121  		"name": "initialize",
   122  		"outputs": [],
   123  		"stateMutability": "nonpayable",
   124  		"type": "function"
   125  	},
   126  	{
   127  		"inputs": [
   128  		  {
   129  			"internalType": "address",
   130  			"name": "val",
   131  			"type": "address"
   132  		  }
   133  		],
   134  		"name": "punish",
   135  		"outputs": [],
   136  		"stateMutability": "nonpayable",
   137  		"type": "function"
   138  	},
   139  	{
   140  		"inputs": [
   141  		  {
   142  			"internalType": "uint256",
   143  			"name": "epoch",
   144  			"type": "uint256"
   145  		  }
   146  		],
   147  		"name": "decreaseMissedBlocksCounter",
   148  		"outputs": [],
   149  		"stateMutability": "nonpayable",
   150  		"type": "function"
   151  	  }
   152  ]
   153  `
   154  
   155  const ProposalInteractiveABI = `
   156  [
   157  	{
   158  		"inputs": [
   159  		  {
   160  			"internalType": "address[]",
   161  			"name": "vals",
   162  			"type": "address[]"
   163  		  }
   164  		],
   165  		"name": "initialize",
   166  		"outputs": [],
   167  		"stateMutability": "nonpayable",
   168  		"type": "function"
   169  	}
   170  ]
   171  `
   172  
   173  const SysGovInteractiveABI = `
   174  [
   175      {
   176  		"inputs": [
   177  			{
   178  				"internalType": "uint256",
   179  				"name": "id",
   180  				"type": "uint256"
   181  			}
   182  		],
   183  		"name": "finishProposalById",
   184  		"outputs": [],
   185  		"stateMutability": "nonpayable",
   186  		"type": "function"
   187  	},
   188  	{
   189  		"inputs": [
   190  			{
   191  				"internalType": "uint32",
   192  				"name": "index",
   193  				"type": "uint32"
   194  			}
   195  		],
   196  		"name": "getPassedProposalByIndex",
   197  		"outputs": [
   198  			{
   199  				"internalType": "uint256",
   200  				"name": "id",
   201  				"type": "uint256"
   202  			},
   203  			{
   204          		"internalType": "uint256",
   205          		"name": "action",
   206          		"type": "uint256"
   207          	},
   208  			{
   209  				"internalType": "address",
   210  				"name": "from",
   211  				"type": "address"
   212  			},
   213  			{
   214  				"internalType": "address",
   215  				"name": "to",
   216  				"type": "address"
   217  			},
   218  			{
   219  				"internalType": "uint256",
   220  				"name": "value",
   221  				"type": "uint256"
   222  			},
   223  			{
   224  				"internalType": "bytes",
   225  				"name": "data",
   226  				"type": "bytes"
   227  			}
   228  		],
   229  		"stateMutability": "view",
   230  		"type": "function"
   231  	},
   232  	{
   233  		"inputs": [],
   234  		"name": "getPassedProposalCount",
   235  		"outputs": [
   236  			{
   237  				"internalType": "uint32",
   238  				"name": "",
   239  				"type": "uint32"
   240  			}
   241  		],
   242  		"stateMutability": "view",
   243  		"type": "function"
   244  	},
   245  	{
   246  		"inputs": [
   247  			{
   248  				"internalType": "address",
   249  				"name": "_admin",
   250  				"type": "address"
   251  			}
   252  		],
   253  		"name": "initialize",
   254  		"outputs": [],
   255  		"stateMutability": "nonpayable",
   256  		"type": "function"
   257  	}
   258  ]`
   259  
   260  const AddrListInteractiveABI = `
   261  [
   262      {
   263          "inputs": [],
   264          "name": "devVerifyEnabled",
   265          "outputs": [
   266              {
   267                  "internalType": "bool",
   268                  "name": "",
   269                  "type": "bool"
   270              }
   271          ],
   272          "stateMutability": "view",
   273          "type": "function"
   274      },
   275      {
   276          "inputs": [],
   277          "name": "getBlacksFrom",
   278          "outputs": [
   279              {
   280                  "internalType": "address[]",
   281                  "name": "",
   282                  "type": "address[]"
   283              }
   284          ],
   285          "stateMutability": "view",
   286          "type": "function"
   287      },
   288      {
   289          "inputs": [],
   290          "name": "getBlacksTo",
   291          "outputs": [
   292              {
   293                  "internalType": "address[]",
   294                  "name": "",
   295                  "type": "address[]"
   296              }
   297          ],
   298          "stateMutability": "view",
   299          "type": "function"
   300      },
   301      {
   302          "inputs": [
   303              {
   304                  "internalType": "address",
   305                  "name": "_admin",
   306                  "type": "address"
   307              }
   308          ],
   309          "name": "initialize",
   310          "outputs": [],
   311          "stateMutability": "nonpayable",
   312          "type": "function"
   313      },
   314      {
   315          "inputs": [
   316              {
   317                  "internalType": "address",
   318                  "name": "addr",
   319                  "type": "address"
   320              }
   321          ],
   322          "name": "isDeveloper",
   323          "outputs": [
   324              {
   325                  "internalType": "bool",
   326                  "name": "",
   327                  "type": "bool"
   328              }
   329          ],
   330          "stateMutability": "view",
   331          "type": "function"
   332      }
   333  ]`
   334  
   335  const ValidatorsV1InteractiveABI = `[
   336      {
   337          "inputs": [
   338              {
   339                  "internalType": "uint256",
   340                  "name": "",
   341                  "type": "uint256"
   342              }
   343          ],
   344          "name": "activeValidators",
   345          "outputs": [
   346              {
   347                  "internalType": "address",
   348                  "name": "",
   349                  "type": "address"
   350              }
   351          ],
   352          "stateMutability": "view",
   353          "type": "function"
   354      },
   355      {
   356          "inputs": [],
   357          "name": "distributeBlockReward",
   358          "outputs": [],
   359          "stateMutability": "payable",
   360          "type": "function"
   361      },
   362      {
   363          "inputs": [],
   364          "name": "getTopValidators",
   365          "outputs": [
   366              {
   367                  "internalType": "address[]",
   368                  "name": "",
   369                  "type": "address[]"
   370              }
   371          ],
   372          "stateMutability": "view",
   373          "type": "function"
   374      },
   375      {
   376          "inputs": [
   377              {
   378                  "internalType": "address[]",
   379                  "name": "_candidates",
   380                  "type": "address[]"
   381              },
   382              {
   383                  "internalType": "address[]",
   384                  "name": "_manager",
   385                  "type": "address[]"
   386              },
   387              {
   388                  "internalType": "address",
   389                  "name": "_admin",
   390                  "type": "address"
   391              }
   392          ],
   393          "name": "initialize",
   394          "outputs": [],
   395          "stateMutability": "nonpayable",
   396          "type": "function"
   397      },
   398      {
   399          "inputs": [
   400              {
   401                  "internalType": "address[]",
   402                  "name": "newSet",
   403                  "type": "address[]"
   404              },
   405              {
   406                  "internalType": "uint256",
   407                  "name": "epoch",
   408                  "type": "uint256"
   409              }
   410          ],
   411          "name": "updateActiveValidatorSet",
   412          "outputs": [],
   413          "stateMutability": "nonpayable",
   414          "type": "function"
   415      }
   416  ]`
   417  
   418  const PunishV1InteractiveABI = `[
   419      {
   420        "inputs": [],
   421        "name": "initialize",
   422        "outputs": [],
   423        "stateMutability": "nonpayable",
   424        "type": "function"
   425      }
   426  ]`
   427  
   428  // DevMappingPosition is the position of the state variable `devs`.
   429  // Since the state variables are as follow:
   430  //    bool public initialized;
   431  //    bool public enabled;
   432  //    address public admin;
   433  //    address public pendingAdmin;
   434  //    mapping(address => bool) private devs;
   435  //
   436  // according to [Layout of State Variables in Storage](https://docs.soliditylang.org/en/v0.8.4/internals/layout_in_storage.html),
   437  // and after optimizer enabled, the `initialized`, `enabled` and `admin` will be packed, and stores at slot 0,
   438  // `pendingAdmin` stores at slot 1, so the position for `devs` is 2.
   439  const DevMappingPosition = 2
   440  
   441  var (
   442  	ValidatorsContractName   = "validators"
   443  	PunishContractName       = "punish"
   444  	ProposalContractName     = "proposal"
   445  	SysGovContractName       = "governance"
   446  	AddressListContractName  = "address_list"
   447  	ValidatorsV1ContractName = "validators_v1"
   448  	PunishV1ContractName     = "punish_v1"
   449  	ValidatorsContractAddr   = common.HexToAddress("0x000000000000000000000000000000000000f000")
   450  	PunishContractAddr       = common.HexToAddress("0x000000000000000000000000000000000000f001")
   451  	ProposalAddr             = common.HexToAddress("0x000000000000000000000000000000000000f002")
   452  	SysGovContractAddr       = common.HexToAddress("0x000000000000000000000000000000000000F003")
   453  	AddressListContractAddr  = common.HexToAddress("0x000000000000000000000000000000000000F004")
   454  	ValidatorsV1ContractAddr = common.HexToAddress("0x000000000000000000000000000000000000F005")
   455  	PunishV1ContractAddr     = common.HexToAddress("0x000000000000000000000000000000000000F006")
   456  	// SysGovToAddr is the To address for the system governance transaction, NOT contract address
   457  	SysGovToAddr = common.HexToAddress("0x000000000000000000000000000000000000ffff")
   458  
   459  	abiMap map[string]abi.ABI
   460  )
   461  
   462  func init() {
   463  	abiMap = make(map[string]abi.ABI, 0)
   464  	tmpABI, _ := abi.JSON(strings.NewReader(ValidatorsInteractiveABI))
   465  	abiMap[ValidatorsContractName] = tmpABI
   466  	tmpABI, _ = abi.JSON(strings.NewReader(PunishInteractiveABI))
   467  	abiMap[PunishContractName] = tmpABI
   468  	tmpABI, _ = abi.JSON(strings.NewReader(ProposalInteractiveABI))
   469  	abiMap[ProposalContractName] = tmpABI
   470  	tmpABI, _ = abi.JSON(strings.NewReader(SysGovInteractiveABI))
   471  	abiMap[SysGovContractName] = tmpABI
   472  	tmpABI, _ = abi.JSON(strings.NewReader(AddrListInteractiveABI))
   473  	abiMap[AddressListContractName] = tmpABI
   474  
   475  	tmpABI, _ = abi.JSON(strings.NewReader(ValidatorsV1InteractiveABI))
   476  	abiMap[ValidatorsV1ContractName] = tmpABI
   477  	tmpABI, _ = abi.JSON(strings.NewReader(PunishV1InteractiveABI))
   478  	abiMap[PunishV1ContractName] = tmpABI
   479  }
   480  
   481  func GetInteractiveABI() map[string]abi.ABI {
   482  	return abiMap
   483  }
   484  
   485  func GetValidatorAddr(blockNum *big.Int, config *params.ChainConfig) *common.Address {
   486  	if config.IsRedCoast(blockNum) {
   487  		return &ValidatorsV1ContractAddr
   488  	}
   489  	return &ValidatorsContractAddr
   490  }
   491  
   492  func GetPunishAddr(blockNum *big.Int, config *params.ChainConfig) *common.Address {
   493  	if config.IsRedCoast(blockNum) {
   494  		return &PunishV1ContractAddr
   495  	}
   496  	return &PunishContractAddr
   497  }