From 0d6d491b6aa243dd99c5b0661ba00cd3e9f97fd8 Mon Sep 17 00:00:00 2001 From: bxq2011hust Date: Thu, 4 Jan 2024 15:37:19 +0800 Subject: [PATCH] add option for console --- .ci/hello/HelloWorld.go | 8 +- .ci/store/Store.go | 8 +- README.md | 8 +- v3/abi/bind/base.go | 2 +- v3/abi/bind/template.go | 8 +- v3/client/config.go | 8 +- v3/client/parse_pem.go | 4 +- v3/cmd/commandline/commands.go | 30 +- v3/cmd/commandline/kvTable.go | 20 +- v3/cmd/commandline/root.go | 49 ++- v3/cmd/commandline/system_config.go | 6 +- v3/examples/KVTableTest.go | 8 +- v3/examples/bn256/EthereumPrecompiled.sol | 134 +++++++ v3/examples/bn256/bn256.go | 358 ++++++++++++++++++ v3/examples/hello_world/manual/main.go | 8 +- v3/examples/hello_world/wrapper/HelloWorld.go | 18 +- v3/examples/hello_world/wrapper/main.go | 9 +- v3/precompiled/auth/CommitteeManager.go | 8 +- .../contract/kvTableTest/KVTableTest.go | 8 +- 19 files changed, 608 insertions(+), 94 deletions(-) create mode 100644 v3/examples/bn256/EthereumPrecompiled.sol create mode 100644 v3/examples/bn256/bn256.go diff --git a/.ci/hello/HelloWorld.go b/.ci/hello/HelloWorld.go index acc9b05f..1393ceee 100644 --- a/.ci/hello/HelloWorld.go +++ b/.ci/hello/HelloWorld.go @@ -299,11 +299,11 @@ type HelloWorldSetValue struct { // WatchSetValue is a free log subscription operation binding the contract event 0x1cede41e194608a414a2e1d67987cf390338e67d0ff22be86dee2f3737c23d53. // // Solidity: event setValue(string v, address indexed from, address indexed to, uint256 value) -func (_HelloWorld *HelloWorldFilterer) WatchSetValue(fromBlock *uint64, handler func(int, []types.Log), from common.Address, to common.Address) (string, error) { +func (_HelloWorld *HelloWorldFilterer) WatchSetValue(fromBlock *int64, handler func(int, []types.Log), from common.Address, to common.Address) (string, error) { return _HelloWorld.contract.WatchLogs(fromBlock, handler, "setValue", from, to) } -func (_HelloWorld *HelloWorldFilterer) WatchAllSetValue(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_HelloWorld *HelloWorldFilterer) WatchAllSetValue(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _HelloWorld.contract.WatchLogs(fromBlock, handler, "setValue") } @@ -321,11 +321,11 @@ func (_HelloWorld *HelloWorldFilterer) ParseSetValue(log types.Log) (*HelloWorld // WatchSetValue is a free log subscription operation binding the contract event 0x1cede41e194608a414a2e1d67987cf390338e67d0ff22be86dee2f3737c23d53. // // Solidity: event setValue(string v, address indexed from, address indexed to, uint256 value) -func (_HelloWorld *HelloWorldSession) WatchSetValue(fromBlock *uint64, handler func(int, []types.Log), from common.Address, to common.Address) (string, error) { +func (_HelloWorld *HelloWorldSession) WatchSetValue(fromBlock *int64, handler func(int, []types.Log), from common.Address, to common.Address) (string, error) { return _HelloWorld.Contract.WatchSetValue(fromBlock, handler, from, to) } -func (_HelloWorld *HelloWorldSession) WatchAllSetValue(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_HelloWorld *HelloWorldSession) WatchAllSetValue(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _HelloWorld.Contract.WatchAllSetValue(fromBlock, handler) } diff --git a/.ci/store/Store.go b/.ci/store/Store.go index ebf8e5ed..01689e97 100644 --- a/.ci/store/Store.go +++ b/.ci/store/Store.go @@ -294,11 +294,11 @@ type StoreItemSet struct { // WatchItemSet is a free log subscription operation binding the contract event 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4. // // Solidity: event ItemSet(bytes32 key, bytes32 value) -func (_Store *StoreFilterer) WatchItemSet(fromBlock *uint64, handler func(int, []types.Log)) error { +func (_Store *StoreFilterer) WatchItemSet(fromBlock *int64, handler func(int, []types.Log)) error { return _Store.contract.WatchLogs(fromBlock, handler, "ItemSet") } -func (_Store *StoreFilterer) WatchAllItemSet(fromBlock *uint64, handler func(int, []types.Log)) error { +func (_Store *StoreFilterer) WatchAllItemSet(fromBlock *int64, handler func(int, []types.Log)) error { return _Store.contract.WatchLogs(fromBlock, handler, "ItemSet") } @@ -316,11 +316,11 @@ func (_Store *StoreFilterer) ParseItemSet(log types.Log) (*StoreItemSet, error) // WatchItemSet is a free log subscription operation binding the contract event 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4. // // Solidity: event ItemSet(bytes32 key, bytes32 value) -func (_Store *StoreSession) WatchItemSet(fromBlock *uint64, handler func(int, []types.Log)) error { +func (_Store *StoreSession) WatchItemSet(fromBlock *int64, handler func(int, []types.Log)) error { return _Store.Contract.WatchItemSet(fromBlock, handler) } -func (_Store *StoreSession) WatchAllItemSet(fromBlock *uint64, handler func(int, []types.Log)) error { +func (_Store *StoreSession) WatchAllItemSet(fromBlock *int64, handler func(int, []types.Log)) error { return _Store.Contract.WatchAllItemSet(fromBlock, handler) } diff --git a/README.md b/README.md index 57cc9af1..fce2d3a6 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ cp .ci/hello/HelloWorld.sol ./hello ```bash # 国密请使用 ./abigen --bin ./hello/HelloWorld.bin --abi ./hello/HelloWorld.abi --pkg hello --type HelloWorld --out ./hello/HelloWorld.go --smcrypto=true +# 注意:国密模式,请使用国密solc编译得到bin ./abigen --bin ./hello/HelloWorld.bin --abi ./hello/HelloWorld.abi --pkg hello --type HelloWorld --out ./hello/HelloWorld.go ``` @@ -243,7 +244,12 @@ func main() { return } done := make(chan bool) - _, err = helloSession.WatchAllSetValue(nil, func(ret int, logs []types.Log) { + currentBlock, err := client.GetBlockNumber(context.Background()) + if err != nil { + fmt.Printf("GetBlockNumber() failed: %v", err) + return + } + _, err = helloSession.WatchAllSetValue(¤tBlock, func(ret int, logs []types.Log) { fmt.Printf("WatchAllSetValue receive statud: %d, logs: %v\n", ret, logs) setValue, err := helloSession.ParseSetValue(logs[0]) if err != nil { diff --git a/v3/abi/bind/base.go b/v3/abi/bind/base.go index 53a8c4f6..4238ad29 100755 --- a/v3/abi/bind/base.go +++ b/v3/abi/bind/base.go @@ -248,7 +248,7 @@ func (c *BoundContract) asyncTransact(opts *TransactOpts, contract *common.Addre // WatchLogs filters subscribes to contract logs for future blocks, returning a // subscription object that can be used to tear down the watcher. -func (c *BoundContract) WatchLogs(fromBlock *uint64, handler func(int, []types.Log), name string, query ...interface{}) (string, error) { +func (c *BoundContract) WatchLogs(fromBlock *int64, handler func(int, []types.Log), name string, query ...interface{}) (string, error) { from := int64(1) to := int64(-1) // Don't crash on a lazy user diff --git a/v3/abi/bind/template.go b/v3/abi/bind/template.go index e61138d6..5e0e7f1b 100644 --- a/v3/abi/bind/template.go +++ b/v3/abi/bind/template.go @@ -400,11 +400,11 @@ var ( // Watch{{.Normalized.Name}} is a free log subscription operation binding the contract event 0x{{printf "%x" .Original.ID}}. // // Solidity: {{formatevent .Original $structs}} - func (_{{$contract.Type}} *{{$contract.Type}}Filterer) Watch{{.Normalized.Name}}(fromBlock *uint64, handler func(int, []types.Log){{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}} {{bindtype .Type $structs}}{{end}}{{end}}) (string, error) { + func (_{{$contract.Type}} *{{$contract.Type}}Filterer) Watch{{.Normalized.Name}}(fromBlock *int64, handler func(int, []types.Log){{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}} {{bindtype .Type $structs}}{{end}}{{end}}) (string, error) { return _{{$contract.Type}}.contract.WatchLogs(fromBlock, handler, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}{{end}}{{end}}) } - func (_{{$contract.Type}} *{{$contract.Type}}Filterer) WatchAll{{.Normalized.Name}}(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { + func (_{{$contract.Type}} *{{$contract.Type}}Filterer) WatchAll{{.Normalized.Name}}(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _{{$contract.Type}}.contract.WatchLogs(fromBlock, handler, "{{.Original.Name}}") } @@ -422,11 +422,11 @@ var ( // Watch{{.Normalized.Name}} is a free log subscription operation binding the contract event 0x{{printf "%x" .Original.ID}}. // // Solidity: {{formatevent .Original $structs}} - func (_{{$contract.Type}} *{{$contract.Type}}Session) Watch{{.Normalized.Name}}(fromBlock *uint64, handler func(int, []types.Log){{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}} {{bindtype .Type $structs}}{{end}}{{end}}) (string, error) { + func (_{{$contract.Type}} *{{$contract.Type}}Session) Watch{{.Normalized.Name}}(fromBlock *int64, handler func(int, []types.Log){{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}} {{bindtype .Type $structs}}{{end}}{{end}}) (string, error) { return _{{$contract.Type}}.Contract.Watch{{.Normalized.Name}}(fromBlock, handler {{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}{{end}}{{end}}) } - func (_{{$contract.Type}} *{{$contract.Type}}Session) WatchAll{{.Normalized.Name}}(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { + func (_{{$contract.Type}} *{{$contract.Type}}Session) WatchAll{{.Normalized.Name}}(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _{{$contract.Type}}.Contract.WatchAll{{.Normalized.Name}}(fromBlock, handler) } diff --git a/v3/client/config.go b/v3/client/config.go index 18a9a142..c4a697eb 100644 --- a/v3/client/config.go +++ b/v3/client/config.go @@ -37,11 +37,11 @@ func ParseConfigOptions(caFile string, key string, cert, keyFile string, groupId if err != nil { return nil, fmt.Errorf("parse private key failed, err: %v", err) } - if config.IsSMCrypto && curve != sm2p256v1 { - return nil, fmt.Errorf("smcrypto must use sm2p256v1 private key, but found %s", curve) + if config.IsSMCrypto && curve != Sm2p256v1 { + return nil, fmt.Errorf("smcrypto should use sm2p256v1 private key, but found %s", curve) } - if !config.IsSMCrypto && curve != secp256k1 { - return nil, fmt.Errorf("must use secp256k1 private key, but found %s", curve) + if !config.IsSMCrypto && curve != Secp256k1 { + return nil, fmt.Errorf("must should secp256k1 private key, but found %s", curve) } config.PrivateKey = keyBytes return &config, nil diff --git a/v3/client/parse_pem.go b/v3/client/parse_pem.go index 6649a969..72cfb708 100644 --- a/v3/client/parse_pem.go +++ b/v3/client/parse_pem.go @@ -11,8 +11,8 @@ import ( ) const ( - secp256k1 = "secp256k1" - sm2p256v1 = "sm2p256v1" + Secp256k1 = "secp256k1" + Sm2p256v1 = "sm2p256v1" ) var ( diff --git a/v3/cmd/commandline/commands.go b/v3/cmd/commandline/commands.go index 5d857dd5..18e287e2 100644 --- a/v3/cmd/commandline/commands.go +++ b/v3/cmd/commandline/commands.go @@ -56,7 +56,7 @@ const ( // and reset your terminal to use autocompletion.`, // Run: func(cmd *cobra.Command, args []string) { // rootCmd.GenZshCompletionFile("_console"); -// fmt.Println("zsh file _console had created on your current diretory successfully.") +// fmt.Println("zsh file _console had created on your current directory successfully.") // }, // } @@ -89,8 +89,8 @@ The block height is encoded in hex`, }, } -var getPbftViewCmd = &cobra.Command{ - Use: "getPbftView", +var getPBFTViewCmd = &cobra.Command{ + Use: "getPBFTView", Short: " Get the latest PBFT view(PBFT consensus only)", Long: `Returns the latest PBFT view in the specified group where the node is located. The PBFT view is encoded in hex`, @@ -376,7 +376,7 @@ For more information please refer: fmt.Printf("block not found: %v\n", err) return } - js, err := json.MarshalIndent(block, "", indent) + js, _ := json.MarshalIndent(block, "", indent) fmt.Printf("Block: \n%s\n", js) }, } @@ -658,7 +658,7 @@ func init() { // add common command rootCmd.AddCommand(completionCmd) // add node command - rootCmd.AddCommand(getGroupIDCmd, getBlockNumberCmd, getPbftViewCmd, getSealerListCmd) + rootCmd.AddCommand(getGroupIDCmd, getBlockNumberCmd, getPBFTViewCmd, getSealerListCmd) rootCmd.AddCommand(getObserverListCmd, getConsensusStatusCmd, getSyncStatusCmd, getPeersCmd, getGroupPeersCmd) rootCmd.AddCommand(getNodeIDListCmd, getGroupListCmd, getNodeInfoCmd, getGroupInfoCmd, getGroupInfoListCmd) // add block access command @@ -671,33 +671,33 @@ func init() { // cobra.OnInitialize(initConfig) - // FIXME: add a custom help command or find a way to make help command work without network - // Here you will define your flags and configuration settings. // Cobra supports persistent flags, which, if defined here, // will be global for your application. - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is the project directory ./config.ini)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - // rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + // rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is the project directory ./config.ini)") + rootCmd.Flags().StringVarP(&cfgFile, "privateKeyPath", "p", "", "private key file path of pem format") + rootCmd.Flags().BoolVarP(&smCrypto, "smCrypto", "s", false, "use smCrypto or not, default is false") + rootCmd.Flags().BoolVarP(&disableSsl, "disableSsl", "d", false, "switch off ssl or not, default use ssl") + rootCmd.PersistentFlags().StringVarP(&groupID, "groupID", "g", "group0", "groupID of FISCO BCOS chain") + rootCmd.PersistentFlags().StringVarP(&nodeEndpoint, "nodeEndpoint", "n", "127.0.0.1:20200", "node endpoint, default is 127.0.0.1:20200") + rootCmd.PersistentFlags().StringVarP(&certPath, "certPath", "c", "./conf", "cert path, default is ./conf, should contain ca.crt, sdk.crt, sdk.key") } func isValidHex(str string) (bool, error) { // starts with "0x" if strings.HasPrefix(str, "0x") { if len(str) == 2 { - return false, fmt.Errorf("not a valid hex string: arguments error: please check your inpunt: %s%s", str, info) + return false, fmt.Errorf("not a valid hex string: arguments error: please check your input: %s%s", str, info) } // is hex string _, err := hexutil.Decode(str) if err != nil { - return false, fmt.Errorf("not a valid hex string: arguments error: please check your inpunt: %s%s: %v", str, info, err) + return false, fmt.Errorf("not a valid hex string: arguments error: please check your input: %s%s: %v", str, info, err) } return true, nil } - return false, fmt.Errorf("arguments error: Not a valid hex string, please check your inpunt: %s%s", str, info) + return false, fmt.Errorf("arguments error: Not a valid hex string, please check your input: %s%s", str, info) } func isBlockNumberOutOfRange(blockNumber int64) (bool, error) { diff --git a/v3/cmd/commandline/kvTable.go b/v3/cmd/commandline/kvTable.go index cd67b66f..24190cdb 100644 --- a/v3/cmd/commandline/kvTable.go +++ b/v3/cmd/commandline/kvTable.go @@ -9,7 +9,7 @@ import ( var createTable = &cobra.Command{ Use: "createTable", - Short: "[tableName] [keyName] [valueName] create table", + Short: " ", Long: `createTable. Arguments: [tableName]: string @@ -18,11 +18,7 @@ Arguments: For example: - [createTable] [table1] [key1] [value1] - -For more information please refer: - - https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/manual/console.html#addobserver`, + createTable table1 key1 value1`, Args: cobra.ExactArgs(3), Run: func(cmd *cobra.Command, args []string) { tableName := args[0] @@ -60,11 +56,7 @@ Arguments: For example: - [set] [table1] [key1] [value1] - -For more information please refer: - - https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/manual/console.html#addsealer`, + set table1 key1 value1`, Args: cobra.ExactArgs(3), Run: func(cmd *cobra.Command, args []string) { tableName := args[0] @@ -104,11 +96,7 @@ Arguments: For example: - [get] [tableName] [key1] - -For more information please refer: - - https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/manual/console.html#removenode`, + [get] [tableName] [key1]`, Args: cobra.ExactArgs(2), Run: func(cmd *cobra.Command, args []string) { tableName := args[0] diff --git a/v3/cmd/commandline/root.go b/v3/cmd/commandline/root.go index 09e927b3..82d15b35 100644 --- a/v3/cmd/commandline/root.go +++ b/v3/cmd/commandline/root.go @@ -5,25 +5,24 @@ import ( "encoding/hex" "fmt" "os" + "strconv" + "strings" "github.com/FISCO-BCOS/go-sdk/v3/client" "github.com/spf13/cobra" ) var cfgFile string +var privateKeyFilePath string +var smCrypto bool +var disableSsl bool +var nodeEndpoint string +var groupID string +var certPath string // RPC is the client connected to the blockchain var RPC *client.Client -// GroupID default -var GroupID uint - -// ChainID default -var ChainID int64 - -// URL default -var URL string - // GetClient is used for test, it will be init by a config file later. func getClient(config *client.Config) *client.Client { // RPC API @@ -39,7 +38,7 @@ func getClient(config *client.Config) *client.Client { var rootCmd = &cobra.Command{ Use: "console", Short: "console is a command line tool for FISCO BCOS 3.0.0", - Version: "0.10.0", + Version: "3.0.0", Long: `console is a Golang client for FISCO BCOS 3.0.0 and it supports the JSON-RPC service and the contract operations(e.g. deploying && writing contracts). @@ -71,8 +70,32 @@ func Execute() { // initConfig reads in config file and ENV variables if set. func initConfig() { - privateKey, _ := hex.DecodeString("145e247e170ba3afd6ae97e88f00dbc976c2345d511b0f6713355d19d8b80b58") - config := &client.Config{IsSMCrypto: false, GroupID: "group0", - PrivateKey: privateKey, Host: "127.0.0.1", Port: 20200, TLSCaFile: "./ca.crt", TLSKeyFile: "./sdk.key", TLSCertFile: "./sdk.crt"} + var privateKey []byte + if len(privateKeyFilePath) != 0 { + _, err := os.Stat(privateKeyFilePath) + if err != nil && os.IsNotExist(err) { + fmt.Println("private key file set but not exist, use default private key") + } + key, curve, err := client.LoadECPrivateKeyFromPEM(privateKeyFilePath) + if err != nil { + fmt.Printf("parse private key failed, err: %v\n", err) + return + } + if smCrypto && curve != client.Sm2p256v1 { + fmt.Printf("smCrypto should use sm2p256v1 private key, but found %s\n", curve) + return + } + if !smCrypto && curve != client.Secp256k1 { + fmt.Printf("should use secp256k1 private key, but found %s\n", curve) + } + privateKey = key + } else { + privateKey, _ = hex.DecodeString("145e247e170ba3afd6ae97e88f00dbc976c2345d511b0f6713355d19d8b80b58") + } + ret := strings.Split(nodeEndpoint, ":") + host := ret[0] + port, _ := strconv.Atoi(ret[1]) + config := &client.Config{IsSMCrypto: smCrypto, GroupID: groupID, DisableSsl: disableSsl, + PrivateKey: privateKey, Host: host, Port: port, TLSCaFile: certPath + "/ca.crt", TLSKeyFile: certPath + "/sdk.key", TLSCertFile: certPath + "/sdk.crt"} RPC = getClient(config) } diff --git a/v3/cmd/commandline/system_config.go b/v3/cmd/commandline/system_config.go index 312c678c..4e8ab391 100644 --- a/v3/cmd/commandline/system_config.go +++ b/v3/cmd/commandline/system_config.go @@ -17,11 +17,7 @@ Arguments: For example: - [setSystemConfigByKey] [tx_count_limit] 10000 - -For more information please refer: - - https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/api.html#`, + [setSystemConfigByKey] [tx_count_limit] 10000`, Args: cobra.ExactArgs(2), Run: func(cmd *cobra.Command, args []string) { //configMap := make(map[string]struct{}) diff --git a/v3/examples/KVTableTest.go b/v3/examples/KVTableTest.go index 2b7d8cfa..c201da6c 100644 --- a/v3/examples/KVTableTest.go +++ b/v3/examples/KVTableTest.go @@ -271,11 +271,11 @@ type KVTableTestInsertResult struct { // WatchInsertResult is a free log subscription operation binding the contract event 0xc57b01fa77f41df77eaab79a0e2623fab2e7ae3e9530d9b1cab225ad65f2b7ce. // // Solidity: event InsertResult(int256 count) -func (_KVTableTest *KVTableTestFilterer) WatchInsertResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_KVTableTest *KVTableTestFilterer) WatchInsertResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _KVTableTest.contract.WatchLogs(fromBlock, handler, "InsertResult") } -func (_KVTableTest *KVTableTestFilterer) WatchAllInsertResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_KVTableTest *KVTableTestFilterer) WatchAllInsertResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _KVTableTest.contract.WatchLogs(fromBlock, handler, "InsertResult") } @@ -293,11 +293,11 @@ func (_KVTableTest *KVTableTestFilterer) ParseInsertResult(log types.Log) (*KVTa // WatchInsertResult is a free log subscription operation binding the contract event 0xc57b01fa77f41df77eaab79a0e2623fab2e7ae3e9530d9b1cab225ad65f2b7ce. // // Solidity: event InsertResult(int256 count) -func (_KVTableTest *KVTableTestSession) WatchInsertResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_KVTableTest *KVTableTestSession) WatchInsertResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _KVTableTest.Contract.WatchInsertResult(fromBlock, handler) } -func (_KVTableTest *KVTableTestSession) WatchAllInsertResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_KVTableTest *KVTableTestSession) WatchAllInsertResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _KVTableTest.Contract.WatchAllInsertResult(fromBlock, handler) } diff --git a/v3/examples/bn256/EthereumPrecompiled.sol b/v3/examples/bn256/EthereumPrecompiled.sol new file mode 100644 index 00000000..06b2e45f --- /dev/null +++ b/v3/examples/bn256/EthereumPrecompiled.sol @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity >=0.6.10 <0.8.20; +pragma experimental ABIEncoderV2; + + +contract EthereumPrecompiled { + constructor() public {} + + function Bn256Add(bytes32 ax, bytes32 ay, bytes32 bx, bytes32 by) + public + returns (bytes32[2] memory result) + { + bytes32[4] memory input; + input[0] = ax; + input[1] = ay; + input[2] = bx; + input[3] = by; + assembly { + let success := call(gas(), 0x06, 0, input, 0x80, result, 0x40) + switch success + case 0 { + revert(0, 0) + } + } + } + + function Bn256ScalarMul(bytes32 x, bytes32 y, bytes32 scalar) + public + returns (bytes32[2] memory result) + { + bytes32[3] memory input; + input[0] = x; + input[1] = y; + input[2] = scalar; + assembly { + let success := call(gas(), 0x07, 0, input, 0x60, result, 0x40) + switch success + case 0 { + revert(0, 0) + } + } + } + + function Bn256Pairing(bytes memory input) public returns (bytes32 result) { + // input is a serialized bytes stream of (a1, b1, a2, b2, ..., ak, bk) from (G_1 x G_2)^k + uint256 len = input.length; + require(len % 192 == 0); + assembly { + let memPtr := mload(0x40) + let success := call( + gas(), + 0x08, + 0, + add(input, 0x20), + len, + memPtr, + 0x20 + ) + switch success + case 0 { + revert(0, 0) + } + default { + result := mload(memPtr) + } + } + } + + function BigModExp(bytes32 base, bytes32 exponent, bytes32 modulus) + public + returns (bytes32 result) + { + assembly { + // free memory pointer + let memPtr := mload(0x40) + // length of base, exponent, modulus + mstore(memPtr, 0x20) + mstore(add(memPtr, 0x20), 0x20) + mstore(add(memPtr, 0x40), 0x20) + // assign base, exponent, modulus + mstore(add(memPtr, 0x60), base) + mstore(add(memPtr, 0x80), exponent) + mstore(add(memPtr, 0xa0), modulus) + // call the precompiled contract BigModExp (0x05) + let success := call(gas(), 0x05, 0x0, memPtr, 0xc0, memPtr, 0x20) + switch success + case 0 { + revert(0x0, 0x0) + } + default { + result := mload(memPtr) + } + } + } + + // https://eips.ethereum.org/EIPS/eip-152 + function F( + uint32 rounds, + bytes32[2] memory h, + bytes32[4] memory m, + bytes8[2] memory t, + bool f + ) public view returns (bytes32[2] memory) { + bytes32[2] memory output; + + bytes memory args = abi.encodePacked( + rounds, + h[0], + h[1], + m[0], + m[1], + m[2], + m[3], + t[0], + t[1], + f + ); + + assembly { + if iszero( + staticcall(not(0), 0x09, add(args, 32), 0xd5, output, 0x40) + ) { + revert(0, 0) + } + } + + return output; + } + + function verify(address addr, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) public pure returns(bool) { + // Use ECRECOVER to verify address + return (ecrecover(msgHash, v, r, s) == (addr)); + } +} diff --git a/v3/examples/bn256/bn256.go b/v3/examples/bn256/bn256.go new file mode 100644 index 00000000..37e786cb --- /dev/null +++ b/v3/examples/bn256/bn256.go @@ -0,0 +1,358 @@ +// Code generated - DO NOT EDIT. +// This file is a generated binding and any manual changes will be lost. + +package Precompiledbn256 + +import ( + "math/big" + "strings" + + "github.com/FISCO-BCOS/go-sdk/v3/abi" + "github.com/FISCO-BCOS/go-sdk/v3/abi/bind" + "github.com/FISCO-BCOS/go-sdk/v3/types" + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" +) + +// Reference imports to suppress errors if they are not otherwise used. +var ( + _ = big.NewInt + _ = strings.NewReader + _ = ethereum.NotFound + _ = abi.U256 + _ = bind.Bind + _ = common.Big1 +) + +// Precompiledbn256ABI is the input ABI used to generate the binding from. +const Precompiledbn256ABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"base\",\"type\":\"bytes32\"},{\"name\":\"exponent\",\"type\":\"bytes32\"},{\"name\":\"modulus\",\"type\":\"bytes32\"}],\"name\":\"BigModExp\",\"outputs\":[{\"name\":\"result\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"bytes32\"},{\"name\":\"y\",\"type\":\"bytes32\"},{\"name\":\"scalar\",\"type\":\"bytes32\"}],\"name\":\"Bn256ScalarMul\",\"outputs\":[{\"name\":\"result\",\"type\":\"bytes32[2]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"rounds\",\"type\":\"uint32\"},{\"name\":\"h\",\"type\":\"bytes32[2]\"},{\"name\":\"m\",\"type\":\"bytes32[4]\"},{\"name\":\"t\",\"type\":\"bytes8[2]\"},{\"name\":\"f\",\"type\":\"bool\"}],\"name\":\"F\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"input\",\"type\":\"bytes\"}],\"name\":\"Bn256Pairing\",\"outputs\":[{\"name\":\"result\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"ax\",\"type\":\"bytes32\"},{\"name\":\"ay\",\"type\":\"bytes32\"},{\"name\":\"bx\",\"type\":\"bytes32\"},{\"name\":\"by\",\"type\":\"bytes32\"}],\"name\":\"Bn256Add\",\"outputs\":[{\"name\":\"result\",\"type\":\"bytes32[2]\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" + +// Precompiledbn256Bin is the compiled bytecode used for deploying new contracts. +var Precompiledbn256Bin = "0x608060405234801561001057600080fd5b50610bce806100206000396000f30060806040526004361061006d576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631aa5d42f146100725780633adf65f5146100af57806372de3cbd146100ec57806390ea88a114610129578063fda5d62614610166575b600080fd5b34801561007e57600080fd5b506100996004803603610094919081019061084c565b6101a3565b6040516100a69190610a2d565b60405180910390f35b3480156100bb57600080fd5b506100d660048036036100d1919081019061084c565b6101f8565b6040516100e39190610a12565b60405180910390f35b3480156100f857600080fd5b50610113600480360361010e919081019061093f565b61029a565b6040516101209190610a12565b60405180910390f35b34801561013557600080fd5b50610150600480360361014b91908101906108fe565b6104c3565b60405161015d9190610a2d565b60405180910390f35b34801561017257600080fd5b5061018d6004803603610188919081019061089b565b610516565b60405161019a9190610a12565b60405180910390f35b600060405160208152602080820152602060408201528460608201528360808201528260a082015260208160c083600060055af180600081146101e957825193506101ee565b600080fd5b5050509392505050565b6102006105dc565b6102086105fe565b8481600060038110151561021857fe5b602002019060001916908160001916815250508381600160038110151561023b57fe5b602002019060001916908160001916815250508281600260038110151561025e57fe5b60200201906000191690816000191681525050604082606083600060075af1806000811461028b57610290565b600080fd5b5050509392505050565b6102a26105dc565b6102aa6105dc565b6060878760006002811015156102bc57fe5b60200201518860016002811015156102d057fe5b60200201518860006004811015156102e457fe5b60200201518960016004811015156102f857fe5b60200201518a600260048110151561030c57fe5b60200201518b600360048110151561032057fe5b60200201518b600060028110151561033457fe5b60200201518c600160028110151561034857fe5b60200201518c604051602001808b63ffffffff1663ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004018a60001916600019168152602001896000191660001916815260200188600019166000191681526020018760001916600019168152602001866000191660001916815260200185600019166000191681526020018477ffffffffffffffffffffffffffffffffffffffffffffffff191677ffffffffffffffffffffffffffffffffffffffffffffffff191681526008018377ffffffffffffffffffffffffffffffffffffffffffffffff191677ffffffffffffffffffffffffffffffffffffffffffffffff1916815260080182151515157f01000000000000000000000000000000000000000000000000000000000000000281526001019a5050505050505050505050604051602081830303815290604052905060408260d5602084016009600019fa15156104b557600080fd5b819250505095945050505050565b60008082519050600060c0828115156104d857fe5b061415156104e557600080fd5b6040516020818360208701600060085af18060008114610508578251945061050d565b600080fd5b50505050919050565b61051e6105dc565b610526610621565b8581600060048110151561053657fe5b602002019060001916908160001916815250508481600160048110151561055957fe5b602002019060001916908160001916815250508381600260048110151561057c57fe5b602002019060001916908160001916815250508281600360048110151561059f57fe5b60200201906000191690816000191681525050604082608083600060065af180600081146105cc576105d1565b600080fd5b505050949350505050565b6040805190810160405280600290602082028038833980820191505090505090565b606060405190810160405280600390602082028038833980820191505090505090565b608060405190810160405280600490602082028038833980820191505090505090565b600082601f830112151561065757600080fd5b600261066a61066582610a75565b610a48565b9150818385602084028201111561068057600080fd5b60005b838110156106b0578161069688826107ba565b845260208401935060208301925050600181019050610683565b5050505092915050565b600082601f83011215156106cd57600080fd5b60046106e06106db82610a97565b610a48565b915081838560208402820111156106f657600080fd5b60005b83811015610726578161070c88826107ba565b8452602084019350602083019250506001810190506106f9565b5050505092915050565b600082601f830112151561074357600080fd5b600261075661075182610ab9565b610a48565b9150818385602084028201111561076c57600080fd5b60005b8381101561079c578161078288826107ce565b84526020840193506020830192505060018101905061076f565b5050505092915050565b60006107b28235610b33565b905092915050565b60006107c68235610b3f565b905092915050565b60006107da8235610b49565b905092915050565b600082601f83011215156107f557600080fd5b813561080861080382610adb565b610a48565b9150808252602083016020830185838301111561082457600080fd5b61082f838284610b85565b50505092915050565b60006108448235610b75565b905092915050565b60008060006060848603121561086157600080fd5b600061086f868287016107ba565b9350506020610880868287016107ba565b9250506040610891868287016107ba565b9150509250925092565b600080600080608085870312156108b157600080fd5b60006108bf878288016107ba565b94505060206108d0878288016107ba565b93505060406108e1878288016107ba565b92505060606108f2878288016107ba565b91505092959194509250565b60006020828403121561091057600080fd5b600082013567ffffffffffffffff81111561092a57600080fd5b610936848285016107e2565b91505092915050565b6000806000806000610140868803121561095857600080fd5b600061096688828901610838565b955050602061097788828901610644565b9450506060610988888289016106ba565b93505060e061099988828901610730565b9250506101206109ab888289016107a6565b9150509295509295909350565b6109c181610b11565b6109ca82610b07565b60005b828110156109fc576109e0858351610a03565b6109e982610b1c565b91506020850194506001810190506109cd565b5050505050565b610a0c81610b29565b82525050565b6000604082019050610a2760008301846109b8565b92915050565b6000602082019050610a426000830184610a03565b92915050565b6000604051905081810181811067ffffffffffffffff82111715610a6b57600080fd5b8060405250919050565b600067ffffffffffffffff821115610a8c57600080fd5b602082029050919050565b600067ffffffffffffffff821115610aae57600080fd5b602082029050919050565b600067ffffffffffffffff821115610ad057600080fd5b602082029050919050565b600067ffffffffffffffff821115610af257600080fd5b601f19601f8301169050602081019050919050565b6000819050919050565b600060029050919050565b6000602082019050919050565b6000819050919050565b60008115159050919050565b6000819050919050565b60007fffffffffffffffff00000000000000000000000000000000000000000000000082169050919050565b600063ffffffff82169050919050565b828183376000838301525050505600a265627a7a72305820ea95aeb035d936acb74e1907ec2cffe0cf526e5993231fe9469c0e8186449e6f6c6578706572696d656e74616cf50037" + +// DeployPrecompiledbn256 deploys a new contract, binding an instance of Precompiledbn256 to it. +func DeployPrecompiledbn256(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Receipt, *Precompiledbn256, error) { + parsed, err := abi.JSON(strings.NewReader(Precompiledbn256ABI)) + if err != nil { + return common.Address{}, nil, nil, err + } + + address, receipt, contract, err := bind.DeployContract(auth, parsed, common.FromHex(Precompiledbn256Bin), backend) + if err != nil { + return common.Address{}, nil, nil, err + } + return address, receipt, &Precompiledbn256{Precompiledbn256Caller: Precompiledbn256Caller{contract: contract}, Precompiledbn256Transactor: Precompiledbn256Transactor{contract: contract}, Precompiledbn256Filterer: Precompiledbn256Filterer{contract: contract}}, nil +} + +func AsyncDeployPrecompiledbn256(auth *bind.TransactOpts, handler func(*types.Receipt, error), backend bind.ContractBackend) (*types.Transaction, error) { + parsed, err := abi.JSON(strings.NewReader(Precompiledbn256ABI)) + if err != nil { + return nil, err + } + + tx, err := bind.AsyncDeployContract(auth, handler, parsed, common.FromHex(Precompiledbn256Bin), backend) + if err != nil { + return nil, err + } + return tx, nil +} + +// Precompiledbn256 is an auto generated Go binding around a Solidity contract. +type Precompiledbn256 struct { + Precompiledbn256Caller // Read-only binding to the contract + Precompiledbn256Transactor // Write-only binding to the contract + Precompiledbn256Filterer // Log filterer for contract events +} + +// Precompiledbn256Caller is an auto generated read-only Go binding around a Solidity contract. +type Precompiledbn256Caller struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// Precompiledbn256Transactor is an auto generated write-only Go binding around a Solidity contract. +type Precompiledbn256Transactor struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// Precompiledbn256Filterer is an auto generated log filtering Go binding around a Solidity contract events. +type Precompiledbn256Filterer struct { + contract *bind.BoundContract // Generic contract wrapper for the low level calls +} + +// Precompiledbn256Session is an auto generated Go binding around a Solidity contract, +// with pre-set call and transact options. +type Precompiledbn256Session struct { + Contract *Precompiledbn256 // Generic contract binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// Precompiledbn256CallerSession is an auto generated read-only Go binding around a Solidity contract, +// with pre-set call options. +type Precompiledbn256CallerSession struct { + Contract *Precompiledbn256Caller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session +} + +// Precompiledbn256TransactorSession is an auto generated write-only Go binding around a Solidity contract, +// with pre-set transact options. +type Precompiledbn256TransactorSession struct { + Contract *Precompiledbn256Transactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session +} + +// Precompiledbn256Raw is an auto generated low-level Go binding around a Solidity contract. +type Precompiledbn256Raw struct { + Contract *Precompiledbn256 // Generic contract binding to access the raw methods on +} + +// Precompiledbn256CallerRaw is an auto generated low-level read-only Go binding around a Solidity contract. +type Precompiledbn256CallerRaw struct { + Contract *Precompiledbn256Caller // Generic read-only contract binding to access the raw methods on +} + +// Precompiledbn256TransactorRaw is an auto generated low-level write-only Go binding around a Solidity contract. +type Precompiledbn256TransactorRaw struct { + Contract *Precompiledbn256Transactor // Generic write-only contract binding to access the raw methods on +} + +// NewPrecompiledbn256 creates a new instance of Precompiledbn256, bound to a specific deployed contract. +func NewPrecompiledbn256(address common.Address, backend bind.ContractBackend) (*Precompiledbn256, error) { + contract, err := bindPrecompiledbn256(address, backend, backend, backend) + if err != nil { + return nil, err + } + return &Precompiledbn256{Precompiledbn256Caller: Precompiledbn256Caller{contract: contract}, Precompiledbn256Transactor: Precompiledbn256Transactor{contract: contract}, Precompiledbn256Filterer: Precompiledbn256Filterer{contract: contract}}, nil +} + +// NewPrecompiledbn256Caller creates a new read-only instance of Precompiledbn256, bound to a specific deployed contract. +func NewPrecompiledbn256Caller(address common.Address, caller bind.ContractCaller) (*Precompiledbn256Caller, error) { + contract, err := bindPrecompiledbn256(address, caller, nil, nil) + if err != nil { + return nil, err + } + return &Precompiledbn256Caller{contract: contract}, nil +} + +// NewPrecompiledbn256Transactor creates a new write-only instance of Precompiledbn256, bound to a specific deployed contract. +func NewPrecompiledbn256Transactor(address common.Address, transactor bind.ContractTransactor) (*Precompiledbn256Transactor, error) { + contract, err := bindPrecompiledbn256(address, nil, transactor, nil) + if err != nil { + return nil, err + } + return &Precompiledbn256Transactor{contract: contract}, nil +} + +// NewPrecompiledbn256Filterer creates a new log filterer instance of Precompiledbn256, bound to a specific deployed contract. +func NewPrecompiledbn256Filterer(address common.Address, filterer bind.ContractFilterer) (*Precompiledbn256Filterer, error) { + contract, err := bindPrecompiledbn256(address, nil, nil, filterer) + if err != nil { + return nil, err + } + return &Precompiledbn256Filterer{contract: contract}, nil +} + +// bindPrecompiledbn256 binds a generic wrapper to an already deployed contract. +func bindPrecompiledbn256(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { + parsed, err := abi.JSON(strings.NewReader(Precompiledbn256ABI)) + if err != nil { + return nil, err + } + return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Precompiledbn256 *Precompiledbn256Raw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _Precompiledbn256.Contract.Precompiledbn256Caller.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Precompiledbn256 *Precompiledbn256Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.Precompiledbn256Transactor.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Precompiledbn256 *Precompiledbn256Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.Precompiledbn256Transactor.contract.Transact(opts, method, params...) +} + +// Call invokes the (constant) contract method with params as input values and +// sets the output to result. The result type might be a single field for simple +// returns, a slice of interfaces for anonymous returns and a struct for named +// returns. +func (_Precompiledbn256 *Precompiledbn256CallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { + return _Precompiledbn256.Contract.contract.Call(opts, result, method, params...) +} + +// Transfer initiates a plain transaction to move funds to the contract, calling +// its default method if one is available. +func (_Precompiledbn256 *Precompiledbn256TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.contract.Transfer(opts) +} + +// Transact invokes the (paid) contract method with params as input values. +func (_Precompiledbn256 *Precompiledbn256TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.contract.Transact(opts, method, params...) +} + +// F is a free data retrieval call binding the contract method 0x72de3cbd. +// +// Solidity: function F(uint32 rounds, bytes32[2] h, bytes32[4] m, bytes8[2] t, bool f) constant returns(bytes32[2]) +func (_Precompiledbn256 *Precompiledbn256Caller) F(opts *bind.CallOpts, rounds uint32, h [2][32]byte, m [4][32]byte, t [2][8]byte, f bool) ([2][32]byte, error) { + var ( + ret0 = new([2][32]byte) + ) + out := ret0 + err := _Precompiledbn256.contract.Call(opts, out, "F", rounds, h, m, t, f) + return *ret0, err +} + +// F is a free data retrieval call binding the contract method 0x72de3cbd. +// +// Solidity: function F(uint32 rounds, bytes32[2] h, bytes32[4] m, bytes8[2] t, bool f) constant returns(bytes32[2]) +func (_Precompiledbn256 *Precompiledbn256Session) F(rounds uint32, h [2][32]byte, m [4][32]byte, t [2][8]byte, f bool) ([2][32]byte, error) { + return _Precompiledbn256.Contract.F(&_Precompiledbn256.CallOpts, rounds, h, m, t, f) +} + +// F is a free data retrieval call binding the contract method 0x72de3cbd. +// +// Solidity: function F(uint32 rounds, bytes32[2] h, bytes32[4] m, bytes8[2] t, bool f) constant returns(bytes32[2]) +func (_Precompiledbn256 *Precompiledbn256CallerSession) F(rounds uint32, h [2][32]byte, m [4][32]byte, t [2][8]byte, f bool) ([2][32]byte, error) { + return _Precompiledbn256.Contract.F(&_Precompiledbn256.CallOpts, rounds, h, m, t, f) +} + +// BigModExp is a paid mutator transaction binding the contract method 0x1aa5d42f. +// +// Solidity: function BigModExp(bytes32 base, bytes32 exponent, bytes32 modulus) returns(bytes32 result) +func (_Precompiledbn256 *Precompiledbn256Transactor) BigModExp(opts *bind.TransactOpts, base [32]byte, exponent [32]byte, modulus [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.contract.Transact(opts, "BigModExp", base, exponent, modulus) +} + +func (_Precompiledbn256 *Precompiledbn256Transactor) AsyncBigModExp(handler func(*types.Receipt, error), opts *bind.TransactOpts, base [32]byte, exponent [32]byte, modulus [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.contract.AsyncTransact(opts, handler, "BigModExp", base, exponent, modulus) +} + +// BigModExp is a paid mutator transaction binding the contract method 0x1aa5d42f. +// +// Solidity: function BigModExp(bytes32 base, bytes32 exponent, bytes32 modulus) returns(bytes32 result) +func (_Precompiledbn256 *Precompiledbn256Session) BigModExp(base [32]byte, exponent [32]byte, modulus [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.BigModExp(&_Precompiledbn256.TransactOpts, base, exponent, modulus) +} + +func (_Precompiledbn256 *Precompiledbn256Session) AsyncBigModExp(handler func(*types.Receipt, error), base [32]byte, exponent [32]byte, modulus [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.Contract.AsyncBigModExp(handler, &_Precompiledbn256.TransactOpts, base, exponent, modulus) +} + +// BigModExp is a paid mutator transaction binding the contract method 0x1aa5d42f. +// +// Solidity: function BigModExp(bytes32 base, bytes32 exponent, bytes32 modulus) returns(bytes32 result) +func (_Precompiledbn256 *Precompiledbn256TransactorSession) BigModExp(base [32]byte, exponent [32]byte, modulus [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.BigModExp(&_Precompiledbn256.TransactOpts, base, exponent, modulus) +} + +func (_Precompiledbn256 *Precompiledbn256TransactorSession) AsyncBigModExp(handler func(*types.Receipt, error), base [32]byte, exponent [32]byte, modulus [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.Contract.AsyncBigModExp(handler, &_Precompiledbn256.TransactOpts, base, exponent, modulus) +} + +// Bn256Add is a paid mutator transaction binding the contract method 0xfda5d626. +// +// Solidity: function Bn256Add(bytes32 ax, bytes32 ay, bytes32 bx, bytes32 by) returns(bytes32[2] result) +func (_Precompiledbn256 *Precompiledbn256Transactor) Bn256Add(opts *bind.TransactOpts, ax [32]byte, ay [32]byte, bx [32]byte, by [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.contract.Transact(opts, "Bn256Add", ax, ay, bx, by) +} + +func (_Precompiledbn256 *Precompiledbn256Transactor) AsyncBn256Add(handler func(*types.Receipt, error), opts *bind.TransactOpts, ax [32]byte, ay [32]byte, bx [32]byte, by [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.contract.AsyncTransact(opts, handler, "Bn256Add", ax, ay, bx, by) +} + +// Bn256Add is a paid mutator transaction binding the contract method 0xfda5d626. +// +// Solidity: function Bn256Add(bytes32 ax, bytes32 ay, bytes32 bx, bytes32 by) returns(bytes32[2] result) +func (_Precompiledbn256 *Precompiledbn256Session) Bn256Add(ax [32]byte, ay [32]byte, bx [32]byte, by [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.Bn256Add(&_Precompiledbn256.TransactOpts, ax, ay, bx, by) +} + +func (_Precompiledbn256 *Precompiledbn256Session) AsyncBn256Add(handler func(*types.Receipt, error), ax [32]byte, ay [32]byte, bx [32]byte, by [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.Contract.AsyncBn256Add(handler, &_Precompiledbn256.TransactOpts, ax, ay, bx, by) +} + +// Bn256Add is a paid mutator transaction binding the contract method 0xfda5d626. +// +// Solidity: function Bn256Add(bytes32 ax, bytes32 ay, bytes32 bx, bytes32 by) returns(bytes32[2] result) +func (_Precompiledbn256 *Precompiledbn256TransactorSession) Bn256Add(ax [32]byte, ay [32]byte, bx [32]byte, by [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.Bn256Add(&_Precompiledbn256.TransactOpts, ax, ay, bx, by) +} + +func (_Precompiledbn256 *Precompiledbn256TransactorSession) AsyncBn256Add(handler func(*types.Receipt, error), ax [32]byte, ay [32]byte, bx [32]byte, by [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.Contract.AsyncBn256Add(handler, &_Precompiledbn256.TransactOpts, ax, ay, bx, by) +} + +// Bn256Pairing is a paid mutator transaction binding the contract method 0x90ea88a1. +// +// Solidity: function Bn256Pairing(bytes input) returns(bytes32 result) +func (_Precompiledbn256 *Precompiledbn256Transactor) Bn256Pairing(opts *bind.TransactOpts, input []byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.contract.Transact(opts, "Bn256Pairing", input) +} + +func (_Precompiledbn256 *Precompiledbn256Transactor) AsyncBn256Pairing(handler func(*types.Receipt, error), opts *bind.TransactOpts, input []byte) (*types.Transaction, error) { + return _Precompiledbn256.contract.AsyncTransact(opts, handler, "Bn256Pairing", input) +} + +// Bn256Pairing is a paid mutator transaction binding the contract method 0x90ea88a1. +// +// Solidity: function Bn256Pairing(bytes input) returns(bytes32 result) +func (_Precompiledbn256 *Precompiledbn256Session) Bn256Pairing(input []byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.Bn256Pairing(&_Precompiledbn256.TransactOpts, input) +} + +func (_Precompiledbn256 *Precompiledbn256Session) AsyncBn256Pairing(handler func(*types.Receipt, error), input []byte) (*types.Transaction, error) { + return _Precompiledbn256.Contract.AsyncBn256Pairing(handler, &_Precompiledbn256.TransactOpts, input) +} + +// Bn256Pairing is a paid mutator transaction binding the contract method 0x90ea88a1. +// +// Solidity: function Bn256Pairing(bytes input) returns(bytes32 result) +func (_Precompiledbn256 *Precompiledbn256TransactorSession) Bn256Pairing(input []byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.Bn256Pairing(&_Precompiledbn256.TransactOpts, input) +} + +func (_Precompiledbn256 *Precompiledbn256TransactorSession) AsyncBn256Pairing(handler func(*types.Receipt, error), input []byte) (*types.Transaction, error) { + return _Precompiledbn256.Contract.AsyncBn256Pairing(handler, &_Precompiledbn256.TransactOpts, input) +} + +// Bn256ScalarMul is a paid mutator transaction binding the contract method 0x3adf65f5. +// +// Solidity: function Bn256ScalarMul(bytes32 x, bytes32 y, bytes32 scalar) returns(bytes32[2] result) +func (_Precompiledbn256 *Precompiledbn256Transactor) Bn256ScalarMul(opts *bind.TransactOpts, x [32]byte, y [32]byte, scalar [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.contract.Transact(opts, "Bn256ScalarMul", x, y, scalar) +} + +func (_Precompiledbn256 *Precompiledbn256Transactor) AsyncBn256ScalarMul(handler func(*types.Receipt, error), opts *bind.TransactOpts, x [32]byte, y [32]byte, scalar [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.contract.AsyncTransact(opts, handler, "Bn256ScalarMul", x, y, scalar) +} + +// Bn256ScalarMul is a paid mutator transaction binding the contract method 0x3adf65f5. +// +// Solidity: function Bn256ScalarMul(bytes32 x, bytes32 y, bytes32 scalar) returns(bytes32[2] result) +func (_Precompiledbn256 *Precompiledbn256Session) Bn256ScalarMul(x [32]byte, y [32]byte, scalar [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.Bn256ScalarMul(&_Precompiledbn256.TransactOpts, x, y, scalar) +} + +func (_Precompiledbn256 *Precompiledbn256Session) AsyncBn256ScalarMul(handler func(*types.Receipt, error), x [32]byte, y [32]byte, scalar [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.Contract.AsyncBn256ScalarMul(handler, &_Precompiledbn256.TransactOpts, x, y, scalar) +} + +// Bn256ScalarMul is a paid mutator transaction binding the contract method 0x3adf65f5. +// +// Solidity: function Bn256ScalarMul(bytes32 x, bytes32 y, bytes32 scalar) returns(bytes32[2] result) +func (_Precompiledbn256 *Precompiledbn256TransactorSession) Bn256ScalarMul(x [32]byte, y [32]byte, scalar [32]byte) (*types.Transaction, *types.Receipt, error) { + return _Precompiledbn256.Contract.Bn256ScalarMul(&_Precompiledbn256.TransactOpts, x, y, scalar) +} + +func (_Precompiledbn256 *Precompiledbn256TransactorSession) AsyncBn256ScalarMul(handler func(*types.Receipt, error), x [32]byte, y [32]byte, scalar [32]byte) (*types.Transaction, error) { + return _Precompiledbn256.Contract.AsyncBn256ScalarMul(handler, &_Precompiledbn256.TransactOpts, x, y, scalar) +} diff --git a/v3/examples/hello_world/manual/main.go b/v3/examples/hello_world/manual/main.go index 5d5aeba3..5f6fae07 100644 --- a/v3/examples/hello_world/manual/main.go +++ b/v3/examples/hello_world/manual/main.go @@ -75,8 +75,12 @@ func main() { address := common.HexToAddress(receipt.ContractAddress) // SubscribeEventLogs hello := bind.NewBoundContract(address, parsed, client, client, client) - fromBlock := uint64(0) - hello.WatchLogs(&fromBlock, func(ret int, logs []types.Log) { + currentBlock, err := client.GetBlockNumber(context.Background()) + if err != nil { + fmt.Printf("GetBlockNumber() failed: %v", err) + return + } + hello.WatchLogs(¤tBlock, func(ret int, logs []types.Log) { setValue := &struct { V string From common.Address diff --git a/v3/examples/hello_world/wrapper/HelloWorld.go b/v3/examples/hello_world/wrapper/HelloWorld.go index f82b9118..8f854f3a 100644 --- a/v3/examples/hello_world/wrapper/HelloWorld.go +++ b/v3/examples/hello_world/wrapper/HelloWorld.go @@ -82,7 +82,7 @@ type HelloWorldFilterer struct { // HelloWorldSession is an auto generated Go binding around a Solidity contract, // with pre-set call and transact options. type HelloWorldSession struct { - Contract *HelloWorld // Generic contract binding to set the session for + Contract *HelloWorld // Generic contract binding to set the session for CallOpts bind.CallOpts // Call options to use throughout this session TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session } @@ -90,15 +90,15 @@ type HelloWorldSession struct { // HelloWorldCallerSession is an auto generated read-only Go binding around a Solidity contract, // with pre-set call options. type HelloWorldCallerSession struct { - Contract *HelloWorldCaller // Generic contract caller binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session + Contract *HelloWorldCaller // Generic contract caller binding to set the session for + CallOpts bind.CallOpts // Call options to use throughout this session } // HelloWorldTransactorSession is an auto generated write-only Go binding around a Solidity contract, // with pre-set transact options. type HelloWorldTransactorSession struct { - Contract *HelloWorldTransactor // Generic contract transactor binding to set the session for - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session + Contract *HelloWorldTransactor // Generic contract transactor binding to set the session for + TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session } // HelloWorldRaw is an auto generated low-level Go binding around a Solidity contract. @@ -301,11 +301,11 @@ type HelloWorldSetValue struct { // WatchSetValue is a free log subscription operation binding the contract event 0xc3bf5911f8e0476e774566ef3fa1259f04156ba5c61ea5ff35c0201390381f96. // // Solidity: event setValue(string v, address indexed from, address indexed to, int256 value) -func (_HelloWorld *HelloWorldFilterer) WatchSetValue(fromBlock *uint64, handler func(int, []types.Log), from common.Address, to common.Address) (string, error) { +func (_HelloWorld *HelloWorldFilterer) WatchSetValue(fromBlock *int64, handler func(int, []types.Log), from common.Address, to common.Address) (string, error) { return _HelloWorld.contract.WatchLogs(fromBlock, handler, "setValue", from, to) } -func (_HelloWorld *HelloWorldFilterer) WatchAllSetValue(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_HelloWorld *HelloWorldFilterer) WatchAllSetValue(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _HelloWorld.contract.WatchLogs(fromBlock, handler, "setValue") } @@ -323,11 +323,11 @@ func (_HelloWorld *HelloWorldFilterer) ParseSetValue(log types.Log) (*HelloWorld // WatchSetValue is a free log subscription operation binding the contract event 0xc3bf5911f8e0476e774566ef3fa1259f04156ba5c61ea5ff35c0201390381f96. // // Solidity: event setValue(string v, address indexed from, address indexed to, int256 value) -func (_HelloWorld *HelloWorldSession) WatchSetValue(fromBlock *uint64, handler func(int, []types.Log), from common.Address, to common.Address) (string, error) { +func (_HelloWorld *HelloWorldSession) WatchSetValue(fromBlock *int64, handler func(int, []types.Log), from common.Address, to common.Address) (string, error) { return _HelloWorld.Contract.WatchSetValue(fromBlock, handler, from, to) } -func (_HelloWorld *HelloWorldSession) WatchAllSetValue(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_HelloWorld *HelloWorldSession) WatchAllSetValue(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _HelloWorld.Contract.WatchAllSetValue(fromBlock, handler) } diff --git a/v3/examples/hello_world/wrapper/main.go b/v3/examples/hello_world/wrapper/main.go index 015fd169..aa44f2b0 100644 --- a/v3/examples/hello_world/wrapper/main.go +++ b/v3/examples/hello_world/wrapper/main.go @@ -13,7 +13,7 @@ import ( func main() { privateKey, _ := hex.DecodeString("145e247e170ba3afd6ae97e88f00dbc976c2345d511b0f6713355d19d8b80b58") // disable ssl of node rpc - config := &client.Config{IsSMCrypto: false, GroupID: "group0", DisableSsl: false, + config := &client.Config{IsSMCrypto: false, GroupID: "group0", DisableSsl: true, PrivateKey: privateKey, Host: "127.0.0.1", Port: 20200, TLSCaFile: "./conf/ca.crt", TLSKeyFile: "./conf/sdk.key", TLSCertFile: "./conf/sdk.crt"} client, err := client.DialContext(context.Background(), config) if err != nil { @@ -51,7 +51,12 @@ func main() { return } done := make(chan bool) - _, err = helloSession.WatchAllSetValue(nil, func(ret int, logs []types.Log) { + currentBlock, err := client.GetBlockNumber(context.Background()) + if err != nil { + fmt.Printf("GetBlockNumber() failed: %v", err) + return + } + _, err = helloSession.WatchAllSetValue(¤tBlock, func(ret int, logs []types.Log) { fmt.Printf("receive event SetValue: %d, logs: %v\n", ret, logs) setValue, err := helloSession.ParseSetValue(logs[0]) if err != nil { diff --git a/v3/precompiled/auth/CommitteeManager.go b/v3/precompiled/auth/CommitteeManager.go index cd038564..60f25ec0 100644 --- a/v3/precompiled/auth/CommitteeManager.go +++ b/v3/precompiled/auth/CommitteeManager.go @@ -726,11 +726,11 @@ type CommitteeManagerExecResult struct { // WatchExecResult is a free log subscription operation binding the contract event 0x7251e13f6f51fdfe60094817f80310366d2e1148fe8a46cb475b582d35bfdea8. // // Solidity: event execResult(int256 ) -func (_CommitteeManager *CommitteeManagerFilterer) WatchExecResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_CommitteeManager *CommitteeManagerFilterer) WatchExecResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _CommitteeManager.contract.WatchLogs(fromBlock, handler, "execResult") } -func (_CommitteeManager *CommitteeManagerFilterer) WatchAllExecResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_CommitteeManager *CommitteeManagerFilterer) WatchAllExecResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _CommitteeManager.contract.WatchLogs(fromBlock, handler, "execResult") } @@ -748,11 +748,11 @@ func (_CommitteeManager *CommitteeManagerFilterer) ParseExecResult(log types.Log // WatchExecResult is a free log subscription operation binding the contract event 0x7251e13f6f51fdfe60094817f80310366d2e1148fe8a46cb475b582d35bfdea8. // // Solidity: event execResult(int256 ) -func (_CommitteeManager *CommitteeManagerSession) WatchExecResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_CommitteeManager *CommitteeManagerSession) WatchExecResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _CommitteeManager.Contract.WatchExecResult(fromBlock, handler) } -func (_CommitteeManager *CommitteeManagerSession) WatchAllExecResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_CommitteeManager *CommitteeManagerSession) WatchAllExecResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _CommitteeManager.Contract.WatchAllExecResult(fromBlock, handler) } diff --git a/v3/test/performanceTest/contract/kvTableTest/KVTableTest.go b/v3/test/performanceTest/contract/kvTableTest/KVTableTest.go index ef37d54d..2e5ce12d 100644 --- a/v3/test/performanceTest/contract/kvTableTest/KVTableTest.go +++ b/v3/test/performanceTest/contract/kvTableTest/KVTableTest.go @@ -271,11 +271,11 @@ type KVTableTestInsertResult struct { // WatchInsertResult is a free log subscription operation binding the contract event 0xc57b01fa77f41df77eaab79a0e2623fab2e7ae3e9530d9b1cab225ad65f2b7ce. // // Solidity: event InsertResult(int256 count) -func (_KVTableTest *KVTableTestFilterer) WatchInsertResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_KVTableTest *KVTableTestFilterer) WatchInsertResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _KVTableTest.contract.WatchLogs(fromBlock, handler, "InsertResult") } -func (_KVTableTest *KVTableTestFilterer) WatchAllInsertResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_KVTableTest *KVTableTestFilterer) WatchAllInsertResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _KVTableTest.contract.WatchLogs(fromBlock, handler, "InsertResult") } @@ -293,11 +293,11 @@ func (_KVTableTest *KVTableTestFilterer) ParseInsertResult(log types.Log) (*KVTa // WatchInsertResult is a free log subscription operation binding the contract event 0xc57b01fa77f41df77eaab79a0e2623fab2e7ae3e9530d9b1cab225ad65f2b7ce. // // Solidity: event InsertResult(int256 count) -func (_KVTableTest *KVTableTestSession) WatchInsertResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_KVTableTest *KVTableTestSession) WatchInsertResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _KVTableTest.Contract.WatchInsertResult(fromBlock, handler) } -func (_KVTableTest *KVTableTestSession) WatchAllInsertResult(fromBlock *uint64, handler func(int, []types.Log)) (string, error) { +func (_KVTableTest *KVTableTestSession) WatchAllInsertResult(fromBlock *int64, handler func(int, []types.Log)) (string, error) { return _KVTableTest.Contract.WatchAllInsertResult(fromBlock, handler) }