Skip to content

Commit

Permalink
add getABI method
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust committed Jan 8, 2024
1 parent bb3e6c1 commit d261c90
Show file tree
Hide file tree
Showing 32 changed files with 373 additions and 607 deletions.
4 changes: 2 additions & 2 deletions .ci/ethPrecompiled/bn256.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .ci/ethPrecompiled/bn256_gm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .ci/hello/HelloWorld.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions .ci/store/Store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,3 @@ module github.com/FISCO-BCOS/go-sdk

go 1.21.5

replace (
// github.com/FISCO-BCOS/bcos-c-sdk v0.0.0-20231221132830-c0cfb1d98eec => ../bcos-c-sdk
golang.org/x/net => github.com/golang/net v0.0.0-20190415214537-1da14a5a36f2
golang.org/x/sync => github.com/golang/sync v0.0.0-20190412183630-56d357773e84
)

require (
github.com/FISCO-BCOS/crypto v0.0.0-20200202032121-bd8ab0b5d4f1
github.com/ethereum/go-ethereum v1.10.21
github.com/sirupsen/logrus v1.4.2
)

require (
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
)
23 changes: 0 additions & 23 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +0,0 @@
github.com/FISCO-BCOS/crypto v0.0.0-20200202032121-bd8ab0b5d4f1 h1:ThPht4qK10+cMZC5COIjHPq0INm5HAMVYqrez5zEgFI=
github.com/FISCO-BCOS/crypto v0.0.0-20200202032121-bd8ab0b5d4f1/go.mod h1:UrLdwsFrjiaCsvdcPLcH6B7s/FUmym3qfM93u2ziR+4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ethereum/go-ethereum v1.10.21 h1:5lqsEx92ZaZzRyOqBEXux4/UR06m296RGzN3ol3teJY=
github.com/ethereum/go-ethereum v1.10.21/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions v3/abi/bind/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ type ContractTransactor interface {
// PendingCodeAt returns the code of the given account in the pending state.
PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
// SendTransaction injects the transaction into the pending pool for execution.
SendTransaction(ctx context.Context, tx *types.Transaction, contract *common.Address, input []byte) (*types.Receipt, error)
AsyncSendTransaction(ctx context.Context, tx *types.Transaction, contract *common.Address, input []byte, handler func(*types.Receipt, error)) error
SendTransaction(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
AsyncSendTransaction(ctx context.Context, tx *types.Transaction, handler func(*types.Receipt, error)) error
// GetGroupID returns the groupID of the client
GetGroupID() string
// GetChainID returns the chainID of the blockchain
Expand Down
35 changes: 19 additions & 16 deletions v3/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,27 @@ func NewBoundContract(address common.Address, abi abi.ABI, caller ContractCaller

// DeployContract deploys a contract onto the Ethereum blockchain and binds the
// deployment address with a Go wrapper.
func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend ContractBackend, params ...interface{}) (common.Address, *types.Receipt, *BoundContract, error) {
_, receipt, c, err := deploy(opts, abi, bytecode, backend, params...)
func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, abiStr string, backend ContractBackend, params ...interface{}) (common.Address, *types.Receipt, *BoundContract, error) {
_, receipt, c, err := deploy(opts, abi, bytecode, abiStr, backend, params...)
addr := common.Address{}
if receipt != nil {
addr = common.HexToAddress(receipt.ContractAddress)
}
return addr, receipt, c, err
}
func DeployContractGetReceipt(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend ContractBackend, params ...interface{}) (*types.Transaction, *types.Receipt, *BoundContract, error) {
tx, receipt, c, err := deploy(opts, abi, bytecode, backend, params...)

func DeployContractGetReceipt(opts *TransactOpts, abi abi.ABI, bytecode []byte, abiStr string, backend ContractBackend, params ...interface{}) (*types.Transaction, *types.Receipt, *BoundContract, error) {
tx, receipt, c, err := deploy(opts, abi, bytecode, abiStr, backend, params...)
return tx, receipt, c, err
}

func deploy(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend ContractBackend, params ...interface{}) (*types.Transaction, *types.Receipt, *BoundContract, error) {
func deploy(opts *TransactOpts, abi abi.ABI, bytecode []byte, abiStr string, backend ContractBackend, params ...interface{}) (*types.Transaction, *types.Receipt, *BoundContract, error) {
c := NewBoundContract(common.Address{}, abi, backend, backend, backend)
input, err := c.abi.Pack("", params...)
if err != nil {
return nil, nil, nil, err
}
tx, receipt, err := c.transact(opts, nil, append(bytecode, input...))
tx, receipt, err := c.transact(opts, nil, append(bytecode, input...), abiStr)
if err != nil {
return nil, nil, nil, err
}
Expand All @@ -127,15 +128,15 @@ func deploy(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend ContractBa
return tx, receipt, c, nil
}

func AsyncDeployContract(opts *TransactOpts, handler func(*types.Receipt, error), abi abi.ABI, bytecode []byte, backend ContractBackend, params ...interface{}) (*types.Transaction, error) {
func AsyncDeployContract(opts *TransactOpts, handler func(*types.Receipt, error), abi abi.ABI, bytecode []byte, abiStr string, backend ContractBackend, params ...interface{}) (*types.Transaction, error) {
// Otherwise try to deploy the contract
c := NewBoundContract(common.Address{}, abi, backend, backend, backend)

input, err := c.abi.Pack("", params...)
if err != nil {
return nil, err
}
return c.asyncTransact(opts, nil, append(bytecode, input...), handler)
return c.asyncTransact(opts, nil, append(bytecode, input...), abiStr, handler)
}

// Call invokes the (constant) contract method with params as input values and
Expand Down Expand Up @@ -198,7 +199,7 @@ func (c *BoundContract) TransactWithResult(opts *TransactOpts, result interface{
if err != nil {
return nil, nil, err
}
tx, receipt, err := c.transact(opts, &c.address, input)
tx, receipt, err := c.transact(opts, &c.address, input, "")
c.abi.Unpack(result, method, common.FromHex(receipt.GetOutput()))
return tx, receipt, err
}
Expand All @@ -210,7 +211,7 @@ func (c *BoundContract) Transact(opts *TransactOpts, method string, params ...in
if err != nil {
return nil, nil, err
}
return c.transact(opts, &c.address, input)
return c.transact(opts, &c.address, input, "")
}

func (c *BoundContract) AsyncTransact(opts *TransactOpts, handler func(*types.Receipt, error), method string, params ...interface{}) (*types.Transaction, error) {
Expand All @@ -219,28 +220,30 @@ func (c *BoundContract) AsyncTransact(opts *TransactOpts, handler func(*types.Re
if err != nil {
return nil, err
}
return c.asyncTransact(opts, &c.address, input, handler)
return c.asyncTransact(opts, &c.address, input, "", handler)
}

// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (c *BoundContract) Transfer(opts *TransactOpts) (*types.Transaction, *types.Receipt, error) {
return c.transact(opts, &c.address, nil)
return c.transact(opts, &c.address, nil, "")
}

// transact executes an actual transaction invocation, first deriving any missing
// authorization fields, and then scheduling the transaction for execution.
func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, input []byte) (*types.Transaction, *types.Receipt, error) {
func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, input []byte, abi string) (*types.Transaction, *types.Receipt, error) {
var receipt *types.Receipt
var err error
if receipt, err = c.transactor.SendTransaction(ensureContext(opts.Context), nil, contract, input); err != nil {
tx := types.NewSimpleTx(contract, input, abi, "", "", c.transactor.SMCrypto())
if receipt, err = c.transactor.SendTransaction(ensureContext(opts.Context), tx); err != nil {
return nil, nil, err
}
return nil, receipt, nil
}

func (c *BoundContract) asyncTransact(opts *TransactOpts, contract *common.Address, input []byte, handler func(*types.Receipt, error)) (*types.Transaction, error) {
if err := c.transactor.AsyncSendTransaction(ensureContext(opts.Context), nil, contract, input, handler); err != nil {
func (c *BoundContract) asyncTransact(opts *TransactOpts, contract *common.Address, input []byte, abi string, handler func(*types.Receipt, error)) (*types.Transaction, error) {
tx := types.NewSimpleTx(contract, input, abi, "", "", c.transactor.SMCrypto())
if err := c.transactor.AsyncSendTransaction(ensureContext(opts.Context), tx, handler); err != nil {
return nil, err
}
return nil, nil
Expand Down
4 changes: 2 additions & 2 deletions v3/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ var (
if len(bytecode) == 0 {
return common.Address{}, nil, nil, fmt.Errorf("cannot deploy empty bytecode")
}
address, receipt, contract, err := bind.DeployContract(auth, parsed, bytecode, backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
address, receipt, contract, err := bind.DeployContract(auth, parsed, bytecode, {{.Type}}ABI, backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
if err != nil {
return common.Address{}, nil, nil, err
}
Expand All @@ -179,7 +179,7 @@ var (
if len(bytecode) == 0 {
return nil, fmt.Errorf("cannot deploy empty bytecode")
}
tx, err := bind.AsyncDeployContract(auth, handler, parsed, bytecode, backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
tx, err := bind.AsyncDeployContract(auth, handler, parsed, bytecode, {{.Type}}ABI, backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit d261c90

Please sign in to comment.