wemixarchive / go-wemix

Go implementation of the Wemix project.
https://www.wemix.com/
GNU Lesser General Public License v3.0
29 stars 25 forks source link

Migrate governance-contracts #89

Closed felix-shin-wt closed 4 months ago

felix-shin-wt commented 6 months ago
  1. The version control for the governance-contract is managed in go-wemix. (commit: e04c2b07fd0d773cc3e07cacddadd182074a1863) go-wemix/wemix/governance-contract 1-1. The contract code, excluding the hardhat part, was copied to go-wemix/wemix/governance-contract/contracts. 1-2. Test code to verify the operation was written in Golang and can be found at go-wemix/wemix/governance-contracts/test.

  2. The contract bound in the wemix package is used. go-wemix/wemix/bind 2-1. The code for binding the contract was done in go-wemix/wemix/governance-contract/contracts/abigen.go. 2-2. All instances of using 'metclient.RemoteContract' were removed and replaced with the bound contract.

  3. A 'SimulatedBackend' including the governance-contract was created. 'go-wemix/wemix/bind/backends' 3-1. Functions were added and some were modified in 'go-wemix/accounts/abi/bind/backends'. 3-2. Modifications were made to prevent errors from occurring when adding a future block in simulation mode (ModeFake of ethash).

jed-wemade commented 6 months ago

ABIs in wemix/governance_abi.go is generated based on wemix/contracts/WemixGovernance.js. (The abi definitions are used in wemix/admin.go)

wemix/governance_abi.go: wemix/contracts/WemixGovernance.js
    @cat $< | awk $(AWK_CODE_2) > $@

Currently, the js file must be updated manually whenever governance contracts are changed. ~For smoother integration, I suggest change Makefile updating the js file or generating abi.go directly by compiling governance contracts.~

This PR makes wemix/admin.go no longer use wemix/governance_abi.go. So generating abi.go is not needed anymore.

steve-oh-wt commented 5 months ago

To ensure compile-time checking for commonly used contract names, it would be beneficial to declare them as constants. ("Registry" "Gov", "GovImp", "NCPExit", "NCPExitImp" "Staking", "StakingImp", "BallotStorage", "BallotStorageImp", "EnvStorage", "EnvStorageImp")

const (
    Registry         = "Registry"
    Gov              = "Gov"
    GovImp           = "GovImp"
    NCPExit          = "NCPExit"
    NCPExitImp       = "NCPExitImp"
    Staking          = "Staking"
    StakingImp       = "StakingImp"
    BallotStorage    = "BallotStorage"
    BallotStorageImp = "BallotStorageImp"
    EnvStorage       = "EnvStorage"
    EnvStorageImp    = "EnvStorageImp"
)
jed-wemade commented 5 months ago

In Ethereum, error is created by errors.New() for simple messages and fmt.Errorf() for formatted messages. Also "pkg/errors" package is no longer maintained (https://github.com/pkg/errors/issues/245) so I recommend to replace the package with "errors" standard library.

Currently, the below codes use "github.com/pkg/errors".