Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abigen generated bindings can be optimized by parsing abi once during an init function #386

Open
trinhdn2 opened this issue Oct 2, 2023 · 0 comments

Comments

@trinhdn2
Copy link

trinhdn2 commented Oct 2, 2023

We are working with multiple bound contracts which are serving the consensus and exclusive services like TomoX/TomoZ. Let's take the BlockSigner contract for example, this bindBlockSigner function is called each time the validator want to make a call or an transaction to this contract at 0x0000000000000000000000000000000000000089

package contract

// bindBlockSigner binds a generic wrapper to an already deployed contract.
func bindBlockSigner(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
	parsed, err := abi.JSON(strings.NewReader(BlockSignerABI))
	if err != nil {
		return nil, err
	}
	return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
}

To prevent re-initializing the ABI each time. we can move the parsed abi.ABI to an init function of the contract package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant