Skip to content

Commit

Permalink
feat: add contractsregistry and generic constructor args dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
kamikazechaser committed Sep 25, 2024
1 parent 60e461e commit cc96027
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
32 changes: 32 additions & 0 deletions internal/container/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (c *Container) RegisterPublishCommands() []*cli.Command {
c.ethFaucet(),
c.accountsIndex(),
c.erc20(),
c.contractsRegistry(),
}
}

Expand Down Expand Up @@ -447,6 +448,37 @@ func (c *Container) erc20() *cli.Command {
}
}

func (c *Container) contractsRegistry() *cli.Command {
return &cli.Command{
Name: "contracts-registry",
Aliases: []string{"registry"},
Usage: "Publish the contracts registry smart contract",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "identifier",
Usage: "Contract identifier",
Required: true,
},
},
Action: func(cCtx *cli.Context) error {
contract := contract.NewContractsRegistry(cCtx.StringSlice("identifier"))
bytecode, err := contract.Bytecode()
if err != nil {
return err
}
c.logInitStage(contract)

resp, err := c.SendContractPublishTx(cCtx, bytecode, contract.MaxGasLimit())
if err != nil {
return err
}
c.logPublishedStage(contract, resp)

return nil
},
}
}

func (c *Container) logInitStage(contract contract.Contract) {
c.Logg.Info(fmt.Sprintf("publishing %s contract", contract.Name()),
"version", contract.Version(),
Expand Down
15 changes: 15 additions & 0 deletions pkg/contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/grassrootseconomics/ge-publish/pkg/accountsindex"
"github.com/grassrootseconomics/ge-publish/pkg/contractsregistry"
"github.com/grassrootseconomics/ge-publish/pkg/decimalquote"
"github.com/grassrootseconomics/ge-publish/pkg/erc20"
"github.com/grassrootseconomics/ge-publish/pkg/erc20demurrage"
Expand Down Expand Up @@ -154,3 +155,17 @@ func NewERC20(args ERC20ConstructorArgs) Contract {
},
}
}

func NewContractsRegistry(identifiers []string) Contract {
// bytes32[] memory _identifiers
byte32identifiers := []common.Hash{}
for _, v := range identifiers {
byte32identifiers = append(byte32identifiers, common.BytesToHash(common.RightPadBytes([]byte(v), 32)))
}

return &contractsregistry.ContractsRegistry{
Constructor: []any{
byte32identifiers,
},
}
}
1 change: 1 addition & 0 deletions pkg/contractsregistry/ContractsRegistry.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b50604051610ce4380380610ce483398181016040528101906100329190610279565b33600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060005b81518110156100cf576002828281518110610094576100936102c2565b5b602002602001015190806001815401808255809150506001900390600052602060002001600090919091909150558080600101915050610076565b50506102f1565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610138826100ef565b810181811067ffffffffffffffff8211171561015757610156610100565b5b80604052505050565b600061016a6100d6565b9050610176828261012f565b919050565b600067ffffffffffffffff82111561019657610195610100565b5b602082029050602081019050919050565b600080fd5b6000819050919050565b6101bf816101ac565b81146101ca57600080fd5b50565b6000815190506101dc816101b6565b92915050565b60006101f56101f08461017b565b610160565b90508083825260208201905060208402830185811115610218576102176101a7565b5b835b81811015610241578061022d88826101cd565b84526020840193505060208101905061021a565b5050509392505050565b600082601f8301126102605761025f6100ea565b5b81516102708482602086016101e2565b91505092915050565b60006020828403121561028f5761028e6100e0565b5b600082015167ffffffffffffffff8111156102ad576102ac6100e5565b5b6102b98482850161024b565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6109e4806103006000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c8063ba44593c1161005b578063ba44593c146100ee578063bb34534c1461011e578063d56b7d4e1461014e578063f2fde38b1461017e5761007d565b806301ffc9a7146100825780633480c704146100b25780638da5cb5b146100d0575b600080fd5b61009c60048036038101906100979190610690565b6101ae565b6040516100a991906106d8565b60405180910390f35b6100ba61025c565b6040516100c7919061070c565b60405180910390f35b6100d8610269565b6040516100e59190610768565b60405180910390f35b610108600480360381019061010391906107e5565b61028f565b60405161011591906106d8565b60405180910390f35b61013860048036038101906101339190610825565b610476565b6040516101459190610768565b60405180910390f35b6101686004803603810190610163919061087e565b6104b2565b60405161017591906108ba565b60405180910390f35b610198600480360381019061019391906108d5565b6104d6565b6040516101a591906106d8565b60405180910390f35b600063effbf67160e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916036101e65760019050610257565b6301ffc9a760e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19160361021c5760019050610257565b639493f8b260e01b827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916036102525760019050610257565b600090505b919050565b6000600280549050905090565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102eb57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008085815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461035657600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361038f57600080fd5b6000805b6002805490508110156103d75784600282815481106103b5576103b4610902565b5b9060005260206000200154036103ca57600191505b8080600101915050610393565b50806103e257600080fd5b8260008086815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550837f3465c39c7e9b14641553cf015fbfe670207bd64c689d17806d885bda47899feb846040516104639190610768565b60405180910390a2600191505092915050565b600080600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b600281815481106104c257600080fd5b906000526020600020016000915090505481565b600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610569576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105609061098e565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905082600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508273ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36001915050919050565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61066d81610638565b811461067857600080fd5b50565b60008135905061068a81610664565b92915050565b6000602082840312156106a6576106a5610633565b5b60006106b48482850161067b565b91505092915050565b60008115159050919050565b6106d2816106bd565b82525050565b60006020820190506106ed60008301846106c9565b92915050565b6000819050919050565b610706816106f3565b82525050565b600060208201905061072160008301846106fd565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061075282610727565b9050919050565b61076281610747565b82525050565b600060208201905061077d6000830184610759565b92915050565b6000819050919050565b61079681610783565b81146107a157600080fd5b50565b6000813590506107b38161078d565b92915050565b6107c281610747565b81146107cd57600080fd5b50565b6000813590506107df816107b9565b92915050565b600080604083850312156107fc576107fb610633565b5b600061080a858286016107a4565b925050602061081b858286016107d0565b9150509250929050565b60006020828403121561083b5761083a610633565b5b6000610849848285016107a4565b91505092915050565b61085b816106f3565b811461086657600080fd5b50565b60008135905061087881610852565b92915050565b60006020828403121561089457610893610633565b5b60006108a284828501610869565b91505092915050565b6108b481610783565b82525050565b60006020820190506108cf60008301846108ab565b92915050565b6000602082840312156108eb576108ea610633565b5b60006108f9848285016107d0565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082825260208201905092915050565b7f4552525f41585800000000000000000000000000000000000000000000000000600082015250565b6000610978600783610931565b915061098382610942565b602082019050919050565b600060208201905081810360008301526109a78161096b565b905091905056fea26469706673582212208481cd850af765f501a8e9a244677a5e20c552e0de70a0e1516fc01dde74682664736f6c63430008190033
1 change: 1 addition & 0 deletions pkg/contractsregistry/ContractsRegistry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"bytes32[]","name":"_identifiers","type":"bytes32[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"_key","type":"bytes32"},{"indexed":false,"internalType":"address","name":"_address","type":"address"}],"name":"AddressKey","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"_newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"identifier","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"identifierCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_identifier","type":"bytes32"},{"internalType":"address","name":"_address","type":"address"}],"name":"set","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
68 changes: 68 additions & 0 deletions pkg/contractsregistry/contractsregistry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package contractsregistry

import (
_ "embed"

"github.com/grassrootseconomics/ethutils"
"github.com/grassrootseconomics/ge-publish/pkg/util"
)

type (
ContractsRegistry struct {
Constructor []any
}
)

const (
name = "ContractsRegistry"
version = "v0.11.0"
license = "AGPL-3.0"
source = "https://git.grassecon.net/cicnet/eth-contract-registry/src/branch/dev-0.11.0/solidity"
solidityVersion = "0.8.25+commit.b61c2a91"
evmFork = "istanbul"

gasLimit = 2_000_000
)

var (
//go:embed ContractsRegistry.bin
bin string
//go:embed ContractsRegistry.json
abi string
)

func (c *ContractsRegistry) Name() string {
return name
}

func (c *ContractsRegistry) Version() string {
return version
}

func (c *ContractsRegistry) License() string {
return license
}

func (c *ContractsRegistry) Source() string {
return source
}

func (c *ContractsRegistry) SolidityVersion() string {
return solidityVersion
}

func (c *ContractsRegistry) EVMFork() string {
return evmFork
}

func (c *ContractsRegistry) ConstructorArgs() []string {
return util.DumpConstructorArgs(c.Constructor)
}

func (c *ContractsRegistry) Bytecode() ([]byte, error) {
return ethutils.PrepareContractBytecodeData(bin, abi, c.Constructor)
}

func (c *ContractsRegistry) MaxGasLimit() uint64 {
return gasLimit
}
2 changes: 2 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func DumpConstructorArgs(constructorArgs []any) []string {
dumpedArgs[i] = v.String()
case common.Address:
dumpedArgs[i] = v.String()
default:
dumpedArgs[i] = fmt.Sprintf("%v", v)
}
}
return dumpedArgs
Expand Down

0 comments on commit cc96027

Please sign in to comment.