diff --git a/cmd/msig.go b/cmd/msig.go index 9ecbe0a..f5475f8 100644 --- a/cmd/msig.go +++ b/cmd/msig.go @@ -569,6 +569,22 @@ var initMsigCmd = &cobra.Command{ fmt.Printf("Couldn't get the multisig's ABI: %s\n", err) return } + + if config.Simulate { + multisigContract, err := msig.NewMultisigContract( + config.To, + config.Network(), + ) + if err != nil { + fmt.Printf("Couldn't interact with the contract: %s\n", err) + return + } + err = multisigContract.SimulateSubmit(config.From, config.MsigTo, FloatToBigInt(config.MsigValue, config.Network().GetNativeTokenDecimal()), data) + if err != nil { + fmt.Printf("Could not simulate interact with the contract: %s\n", err) + return + } + } txdata, err := msigABI.Pack( "submitTransaction", @@ -662,6 +678,7 @@ func init() { initMsigCmd.Flags().Uint64VarP(&config.MethodIndex, "method-index", "M", 0, "Index of the method in alphabeth sorted method list of the contract. Index counts from 1.") initMsigCmd.Flags().BoolVarP(&config.NoFuncCall, "no-func-call", "N", false, "True: will not send any data to multisig destination.") initMsigCmd.Flags().StringVarP(&config.PrefillStr, "prefills", "I", "", "Prefill params string. Each param is separated by | char. If the param is \"?\", user input will be prompted.") + initMsigCmd.Flags().BoolVarP(&config.Simulate, "simulate", "S", false, "True: Simulate execution of underlying call.") initMsigCmd.MarkFlagRequired("msig-to") writeCmds := []*cobra.Command{ diff --git a/config/config.go b/config/config.go index c5ac553..5306207 100644 --- a/config/config.go +++ b/config/config.go @@ -94,4 +94,6 @@ var ( CustomABI string JSONOutputFile string + + Simulate bool ) diff --git a/go.mod b/go.mod index 155acd8..b9c1c26 100644 --- a/go.mod +++ b/go.mod @@ -47,7 +47,9 @@ require ( github.com/google/go-cmp v0.5.8 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.2.4 // indirect + github.com/huin/goupnp v1.3.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/mschoch/smat v0.2.0 // indirect @@ -55,6 +57,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/steveyen/gtreap v0.1.0 // indirect github.com/supranational/blst v0.3.11 // indirect + github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/willf/bitset v1.1.10 // indirect diff --git a/go.sum b/go.sum index bce753d..4b590b1 100644 --- a/go.sum +++ b/go.sum @@ -109,6 +109,7 @@ github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+ne github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= @@ -136,10 +137,13 @@ github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -213,11 +217,19 @@ github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFV github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg= github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= +github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= +github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A= github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU= github.com/openconfig/goyang v0.2.4 h1:xGmGr3zuhq9ASCu5jRdtMFdRnixhbg8TJEQ0nylyvxA= @@ -302,6 +314,7 @@ go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -319,10 +332,15 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -332,8 +350,14 @@ golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -345,10 +369,13 @@ golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -356,6 +383,8 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -368,15 +397,19 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/msig/msig.go b/msig/msig.go index 9bd976d..54313e6 100644 --- a/msig/msig.go +++ b/msig/msig.go @@ -1,11 +1,14 @@ package msig import ( + "fmt" "math/big" "strings" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient/gethclient" . "github.com/tranvictor/jarvis/networks" "github.com/tranvictor/jarvis/util" "github.com/tranvictor/jarvis/util/reader" @@ -13,6 +16,8 @@ import ( const GNOSIS_MULTISIG_ABI string = `[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"owners","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"owner","type":"address"}],"name":"removeOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"transactionId","type":"uint256"}],"name":"revokeConfirmation","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"isOwner","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"address"}],"name":"confirmations","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"calcMaxWithdraw","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"pending","type":"bool"},{"name":"executed","type":"bool"}],"name":"getTransactionCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"dailyLimit","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"lastDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"owner","type":"address"}],"name":"addOwner","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"transactionId","type":"uint256"}],"name":"isConfirmed","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"transactionId","type":"uint256"}],"name":"getConfirmationCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"transactions","outputs":[{"name":"destination","type":"address"},{"name":"value","type":"uint256"},{"name":"data","type":"bytes"},{"name":"executed","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getOwners","outputs":[{"name":"","type":"address[]"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"from","type":"uint256"},{"name":"to","type":"uint256"},{"name":"pending","type":"bool"},{"name":"executed","type":"bool"}],"name":"getTransactionIds","outputs":[{"name":"_transactionIds","type":"uint256[]"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"transactionId","type":"uint256"}],"name":"getConfirmations","outputs":[{"name":"_confirmations","type":"address[]"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"transactionCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_required","type":"uint256"}],"name":"changeRequirement","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"transactionId","type":"uint256"}],"name":"confirmTransaction","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"destination","type":"address"},{"name":"value","type":"uint256"},{"name":"data","type":"bytes"}],"name":"submitTransaction","outputs":[{"name":"transactionId","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_dailyLimit","type":"uint256"}],"name":"changeDailyLimit","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"MAX_OWNER_COUNT","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"required","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"owner","type":"address"},{"name":"newOwner","type":"address"}],"name":"replaceOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"transactionId","type":"uint256"}],"name":"executeTransaction","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"spentToday","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"_owners","type":"address[]"},{"name":"_required","type":"uint256"},{"name":"_dailyLimit","type":"uint256"}],"type":"constructor"},{"payable":true,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"dailyLimit","type":"uint256"}],"name":"DailyLimitChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"sender","type":"address"},{"indexed":true,"name":"transactionId","type":"uint256"}],"name":"Confirmation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"sender","type":"address"},{"indexed":true,"name":"transactionId","type":"uint256"}],"name":"Revocation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"transactionId","type":"uint256"}],"name":"Submission","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"transactionId","type":"uint256"}],"name":"Execution","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"transactionId","type":"uint256"}],"name":"ExecutionFailure","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"sender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"OwnerAddition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"OwnerRemoval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"required","type":"uint256"}],"name":"RequirementChange","type":"event"}]` +var OVERRIDECODE []byte = common.Hex2Bytes(`6080604052600436106101855760003560e01c8063a0e67e2b116100d1578063c64274741161008a578063dc8452cd11610064578063dc8452cd14610a1d578063e20056e614610a48578063ee22610b14610ab9578063f059cf2b14610af4576101e4565b8063c6427474146108b1578063cea08621146109b7578063d74f8edd146109f2576101e4565b8063a0e67e2b14610662578063a8abe69a146106ce578063b5dc40c314610780578063b77bf60014610810578063ba51a6df1461083b578063c01a8c8414610876576101e4565b8063547415251161013e5780637065cb48116101185780637065cb4814610490578063784547a7146104e15780638b51d13f146105325780639ace38c214610581576101e4565b806354741525146103dd57806367eeba0c1461043a5780636b0c932d14610465576101e4565b8063025e7c27146101e9578063173825d91461024e57806320ea8d861461029f5780632f54bf6e146102da5780633411c81c146103415780634bc9fdc2146103b2576101e4565b366101e45760003411156101e2573373ffffffffffffffffffffffffffffffffffffffff167fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c346040518082815260200191505060405180910390a25b005b600080fd5b3480156101f557600080fd5b506102226004803603602081101561020c57600080fd5b8101908080359060200190929190505050610b1f565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561025a57600080fd5b5061029d6004803603602081101561027157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b5b565b005b3480156102ab57600080fd5b506102d8600480360360208110156102c257600080fd5b8101908080359060200190929190505050610edf565b005b3480156102e657600080fd5b50610329600480360360208110156102fd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506111bc565b60405180821515815260200191505060405180910390f35b34801561034d57600080fd5b5061039a6004803603604081101561036457600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506111dc565b60405180821515815260200191505060405180910390f35b3480156103be57600080fd5b506103c761120b565b6040518082815260200191505060405180910390f35b3480156103e957600080fd5b506104246004803603604081101561040057600080fd5b81019080803515159060200190929190803515159060200190929190505050611233565b6040518082815260200191505060405180910390f35b34801561044657600080fd5b5061044f6112c5565b6040518082815260200191505060405180910390f35b34801561047157600080fd5b5061047a6112cb565b6040518082815260200191505060405180910390f35b34801561049c57600080fd5b506104df600480360360208110156104b357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112d1565b005b3480156104ed57600080fd5b5061051a6004803603602081101561050457600080fd5b8101908080359060200190929190505050611685565b60405180821515815260200191505060405180910390f35b34801561053e57600080fd5b5061056b6004803603602081101561055557600080fd5b810190808035906020019092919050505061176b565b6040518082815260200191505060405180910390f35b34801561058d57600080fd5b506105ba600480360360208110156105a457600080fd5b8101908080359060200190929190505050611834565b604051808573ffffffffffffffffffffffffffffffffffffffff168152602001848152602001806020018315158152602001828103825284818151815260200191508051906020019080838360005b83811015610624578082015181840152602081019050610609565b50505050905090810190601f1680156106515780820380516001836020036101000a031916815260200191505b509550505050505060405180910390f35b34801561066e57600080fd5b50610677611929565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156106ba57808201518184015260208101905061069f565b505050509050019250505060405180910390f35b3480156106da57600080fd5b50610729600480360360808110156106f157600080fd5b8101908080359060200190929190803590602001909291908035151590602001909291908035151590602001909291905050506119b7565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561076c578082015181840152602081019050610751565b505050509050019250505060405180910390f35b34801561078c57600080fd5b506107b9600480360360208110156107a357600080fd5b8101908080359060200190929190505050611b45565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156107fc5780820151818401526020810190506107e1565b505050509050019250505060405180910390f35b34801561081c57600080fd5b50610825611d97565b6040518082815260200191505060405180910390f35b34801561084757600080fd5b506108746004803603602081101561085e57600080fd5b8101908080359060200190929190505050611d9d565b005b34801561088257600080fd5b506108af6004803603602081101561089957600080fd5b8101908080359060200190929190505050611f25565b005b3480156108bd57600080fd5b506109a1600480360360608110156108d457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019064010000000081111561091b57600080fd5b82018360208201111561092d57600080fd5b8035906020019184600183028401116401000000008311171561094f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061224d565b6040518082815260200191505060405180910390f35b3480156109c357600080fd5b506109f0600480360360208110156109da57600080fd5b810190808035906020019092919050505061226c565b005b3480156109fe57600080fd5b50610a0761234e565b6040518082815260200191505060405180910390f35b348015610a2957600080fd5b50610a32612353565b6040518082815260200191505060405180910390f35b348015610a5457600080fd5b50610ab760048036036040811015610a6b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612359565b005b348015610ac557600080fd5b50610af260048036036020811015610adc57600080fd5b810190808035906020019092919050505061279b565b005b348015610b0057600080fd5b50610b09612a7c565b6040518082815260200191505060405180910390f35b60038181548110610b2c57fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610bfc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f6e6c792077616c6c65742063616e2063616c6c00000000000000000000000081525060200191505060405180910390fd5b80600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610cbc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f776e657220646f6573206e6f7420657869737400000000000000000000000081525060200191505060405180910390fd5b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060005b600160038054905003811015610e39578273ffffffffffffffffffffffffffffffffffffffff1660038281548110610d4b57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415610e2c57600360016003805490500381548110610da757fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660038281548110610ddf57fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610e39565b8080600101915050610d17565b506003805480610e4557fe5b6001900381819060005260206000200160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905590556003805490506004541115610e9857610e97600380549050611d9d565b5b8173ffffffffffffffffffffffffffffffffffffffff167f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b9060405160405180910390a25050565b33600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610f9f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f776e657220646f6573206e6f7420657869737400000000000000000000000081525060200191505060405180910390fd5b81336001600083815260200190815260200160002060008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611071576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f5472616e73616374696f6e206e6f7420636f6e6669726d65640000000000000081525060200191505060405180910390fd5b8360008082815260200190815260200160002060030160009054906101000a900460ff1615611108576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f5472616e73616374696f6e20616c72656164792065786563757465640000000081525060200191505060405180910390fd5b60006001600087815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550843373ffffffffffffffffffffffffffffffffffffffff167ff6a317157440607f36269043eb55f1287a5a19ba2216afeab88cd46cbcfb88e960405160405180910390a35050505050565b60026020528060005260406000206000915054906101000a900460ff1681565b60016020528160005260406000206020528060005260406000206000915091509054906101000a900460ff1681565b60006201518060075401421115611226576006549050611230565b6008546006540390505b90565b600080600090505b6005548110156112be57838015611272575060008082815260200190815260200160002060030160009054906101000a900460ff16155b806112a557508280156112a4575060008082815260200190815260200160002060030160009054906101000a900460ff165b5b156112b1576001820191505b808060010191505061123b565b5092915050565b60065481565b60075481565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611372576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f6e6c792077616c6c65742063616e2063616c6c00000000000000000000000081525060200191505060405180910390fd5b80600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611433576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f776e657220616c72656164792065786973747300000000000000000000000081525060200191505060405180910390fd5b81600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156114d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f416464726573732063616e6e6f74206265206e756c6c0000000000000000000081525060200191505060405180910390fd5b600160038054905001600454603282111580156114f45750818111155b8015611501575060008114155b801561150e575060008214155b611580576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f496e76616c696420726571756972656d656e740000000000000000000000000081525060200191505060405180910390fd5b6001600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506003859080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508473ffffffffffffffffffffffffffffffffffffffff167ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d60405160405180910390a25050505050565b6000806000905060005b60038054905081101561175f57600160008581526020019081526020016000206000600383815481106116be57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161561173d576001820191505b60045482141561175257600192505050611766565b808060010191505061168f565b5060009150505b919050565b600080600090505b60038054905081101561182e57600160008481526020019081526020016000206000600383815481106117a257fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611821576001820191505b8080600101915050611773565b50919050565b60006020528060005260406000206000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690806001015490806002018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561190c5780601f106118e15761010080835404028352916020019161190c565b820191906000526020600020905b8154815290600101906020018083116118ef57829003601f168201915b5050505050908060030160009054906101000a900460ff16905084565b606060038054806020026020016040519081016040528092919081815260200182805480156119ad57602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019060010190808311611963575b5050505050905090565b60608060055467ffffffffffffffff811180156119d357600080fd5b50604051908082528060200260200182016040528015611a025781602001602082028036833780820191505090505b5090506000805b600554811015611aa557858015611a40575060008082815260200190815260200160002060030160009054906101000a900460ff16155b80611a735750848015611a72575060008082815260200190815260200160002060030160009054906101000a900460ff165b5b15611a985780838381518110611a8557fe5b6020026020010181815250506001820191505b8080600101915050611a09565b5086860367ffffffffffffffff81118015611abf57600080fd5b50604051908082528060200260200182016040528015611aee5781602001602082028036833780820191505090505b50925060008790505b86811015611b3a57828181518110611b0b57fe5b60200260200101518489830381518110611b2157fe5b6020026020010181815250508080600101915050611af7565b505050949350505050565b60608060038054905067ffffffffffffffff81118015611b6457600080fd5b50604051908082528060200260200182016040528015611b935781602001602082028036833780820191505090505b5090506000805b600380549050811015611cd35760016000868152602001908152602001600020600060038381548110611bc957fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615611cc65760038181548110611c4e57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16838381518110611c8557fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250506001820191505b8080600101915050611b9a565b508067ffffffffffffffff81118015611ceb57600080fd5b50604051908082528060200260200182016040528015611d1a5781602001602082028036833780820191505090505b50925060005b81811015611d8f57828181518110611d3457fe5b6020026020010151848281518110611d4857fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508080600101915050611d20565b505050919050565b60055481565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611e3e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f6e6c792077616c6c65742063616e2063616c6c00000000000000000000000081525060200191505060405180910390fd5b6003805490508160328211158015611e565750818111155b8015611e63575060008114155b8015611e70575060008214155b611ee2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f496e76616c696420726571756972656d656e740000000000000000000000000081525060200191505060405180910390fd5b826004819055507fa3f1ee9126a074d9326c682f561767f710e927faa811f7a99829d49dc421797a836040518082815260200191505060405180910390a1505050565b33600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611fe5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f776e657220646f6573206e6f7420657869737400000000000000000000000081525060200191505060405180910390fd5b81600073ffffffffffffffffffffffffffffffffffffffff1660008083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156120be576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f5472616e73616374696f6e20646f6573206e6f7420657869737400000000000081525060200191505060405180910390fd5b82336001600083815260200190815260200160002060008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615612191576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f5472616e73616374696f6e20616c726561647920636f6e6669726d656400000081525060200191505060405180910390fd5b600180600087815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550843373ffffffffffffffffffffffffffffffffffffffff167f4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef60405160405180910390a36122468561279b565b5050505050565b600061225a848484612a82565b905061226581611f25565b9392505050565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461230d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f6e6c792077616c6c65742063616e2063616c6c00000000000000000000000081525060200191505060405180910390fd5b806006819055507fc71bdc6afaf9b1aa90a7078191d4fc1adf3bf680fca3183697df6b0dc226bca2816040518082815260200191505060405180910390a150565b603281565b60045481565b3073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146123fa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f6e6c792077616c6c65742063616e2063616c6c00000000000000000000000081525060200191505060405180910390fd5b81600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166124ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f776e657220646f6573206e6f7420657869737400000000000000000000000081525060200191505060405180910390fd5b81600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161561257b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f4f776e657220616c72656164792065786973747300000000000000000000000081525060200191505060405180910390fd5b60005b60038054905081101561265e578473ffffffffffffffffffffffffffffffffffffffff16600382815481106125af57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561265157836003828154811061260457fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061265e565b808060010191505061257e565b506000600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506001600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508373ffffffffffffffffffffffffffffffffffffffff167f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b9060405160405180910390a28273ffffffffffffffffffffffffffffffffffffffff167ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d60405160405180910390a250505050565b8060008082815260200190815260200160002060030160009054906101000a900460ff1615612832576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f5472616e73616374696f6e20616c72656164792065786563757465640000000081525060200191505060405180910390fd5b61283b82611685565b8061289557506000806000848152602001908152602001600020600201805460018160011615610100020316600290049050148015612894575061289360008084815260200190815260200160002060010154612c50565b5b5b15612a78576000806000848152602001908152602001600020905060018160030160006101000a81548160ff0219169083151502179055506128d683611685565b6128ef5780600101546008600082825401925050819055505b600060608260000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1683600101548460020160405180828054600181600116156101000203166002900480156129925780601f10612970576101008083540402835291820191612992565b820191906000526020600020905b81548152906001019060200180831161297e575b505091505060006040518083038185875af1925050503d80600081146129d4576040519150601f19603f3d011682016040523d82523d6000602084013e6129d9565b606091505b509150915081612a47576000815111156129f65780518082602001fd5b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180612d406023913960400191505060405180910390fd5b847f33e13ecb54c3076d8e8bb8c2881800a4d972b792045ffae98fdf46df365fed7560405160405180910390a25050505b5050565b60085481565b600083600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612b28576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f416464726573732063616e6e6f74206265206e756c6c0000000000000000000081525060200191505060405180910390fd5b600554915060405180608001604052808673ffffffffffffffffffffffffffffffffffffffff1681526020018581526020018481526020016000151581525060008084815260200190815260200160002060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550602082015181600101556040820151816002019080519060200190612be6929190612ca2565b5060608201518160030160006101000a81548160ff0219169083151502179055509050506001600560008282540192505081905550817fc0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e5160405160405180910390a2509392505050565b60006201518060075401421115612c71574260078190555060006008819055505b60065482600854011180612c8a57506008548260085401105b15612c985760009050612c9d565b600190505b919050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10612ce357805160ff1916838001178555612d11565b82800160010185558215612d11579182015b82811115612d10578251825591602001919060010190612cf5565b5b509050612d1e9190612d22565b5090565b5b80821115612d3b576000816000905550600101612d23565b509056fe45787465726e616c2063616c6c206661696c656420776974686f757420726561736f6ea2646970667358221220ff7cc39dc092f31840e4b657ad1e52349e71557ad12ce595c2e37032848ee9e464736f6c634300060c0033`) + type MultisigContract struct { Address string Network Network @@ -144,3 +149,66 @@ func NewMultisigContract(address string, network Network) (*MultisigContract, er &a, }, nil } + +func (self *MultisigContract) SimulateSubmit(from string, to string, value *big.Int, data []byte) error { + owners, err := self.Owners() + if err != nil { + fmt.Printf("Couldn't get owners of the multisig: %s\n", err) + return err + } + transactionID, err := self.NOTransactions() + if err != nil { + fmt.Printf("Couldn't get number of transactions of the multisig: %s\n", err) + return err + } + + stateDiff := make(map[common.Hash]common.Hash) + isOnwner := false + for _, owner := range owners { + if strings.EqualFold(owner, from) { + isOnwner = true + } else { + overrideConfirmation(stateDiff, transactionID, owner) + } + } + if !isOnwner { + return fmt.Errorf("Sender is not owner of the msig") + } + overrides := &map[common.Address]gethclient.OverrideAccount{ + common.HexToAddress(self.Address): { + StateDiff: stateDiff, // override that all owner approve to submit tradeID + Code: OVERRIDECODE, // override contract code to get revert msg if any + }, + } + txdata, err := self.Abi.Pack( + "submitTransaction", + common.HexToAddress(to), + value, + data, + ) + if err != nil { + return err + } + _, err = self.reader.EthCall(from, self.Address, txdata, overrides) + return err +} + +func overrideConfirmation(stateDiff map[common.Hash]common.Hash, transactionID int64, owner string) { + // mapping (uint => mapping (address => bool)) public confirmations + + storageSlot := common.BigToHash(big.NewInt(1)) + transactionHash := common.BigToHash(big.NewInt(int64(transactionID))) + ownerAddress := common.HexToAddress(owner) + addressHash := common.BytesToHash(ownerAddress[:]) + fmt.Println(addressHash) + + mapSlot := crypto.Keccak256Hash( + transactionHash[:], + storageSlot[:], + ) + confirmationSlot := crypto.Keccak256Hash( + addressHash[:], + mapSlot[:], + ) + stateDiff[confirmationSlot] = common.BigToHash(big.NewInt(1)) +} diff --git a/util/reader/ethereum_node.go b/util/reader/ethereum_node.go index dfda4ee..88c54f6 100644 --- a/util/reader/ethereum_node.go +++ b/util/reader/ethereum_node.go @@ -4,7 +4,9 @@ import ( "math/big" "github.com/ethereum/go-ethereum/accounts/abi" + ethereum "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient/gethclient" "github.com/tranvictor/jarvis/common" ) @@ -36,6 +38,7 @@ type EthereumNode interface { method string, args ...interface{}, ) ([]byte, error) + EthCall(from string, to string, data []byte, overrides *map[ethereum.Address]gethclient.OverrideAccount) ([]byte, error) StorageAt(atBlock int64, caddr string, slot string) ([]byte, error) HeaderByNumber(number int64) (*types.Header, error) GetLogs(fromBlock, toBlock int, addresses []string, topic string) ([]types.Log, error) diff --git a/util/reader/one_node_reader.go b/util/reader/one_node_reader.go index 0c18638..fce4fc6 100644 --- a/util/reader/one_node_reader.go +++ b/util/reader/one_node_reader.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" + "github.com/ethereum/go-ethereum/ethclient/gethclient" "github.com/ethereum/go-ethereum/rpc" . "github.com/tranvictor/jarvis/common" @@ -20,20 +21,22 @@ import ( const TIMEOUT time.Duration = 4 * time.Second type OneNodeReader struct { - nodeName string - nodeURL string - client *rpc.Client - ethClient *ethclient.Client - mu sync.Mutex + nodeName string + nodeURL string + client *rpc.Client + ethClient *ethclient.Client + gethClient *gethclient.Client + mu sync.Mutex } func NewOneNodeReader(name, url string) *OneNodeReader { return &OneNodeReader{ - nodeName: name, - nodeURL: url, - client: nil, - ethClient: nil, - mu: sync.Mutex{}, + nodeName: name, + nodeURL: url, + client: nil, + ethClient: nil, + gethClient: nil, + mu: sync.Mutex{}, } } @@ -54,6 +57,7 @@ func (self *OneNodeReader) initConnection() error { } self.client = client self.ethClient = ethclient.NewClient(self.client) + self.gethClient = gethclient.New(self.client) return nil } @@ -73,6 +77,14 @@ func (self *OneNodeReader) EthClient() (*ethclient.Client, error) { return self.ethClient, err } +func (self *OneNodeReader) GEthClient() (*gethclient.Client, error) { + if self.gethClient != nil { + return self.gethClient, nil + } + err := self.initConnection() + return self.gethClient, err +} + func (self *OneNodeReader) EstimateGas(from, to string, priceGwei float64, value *big.Int, data []byte) (uint64, error) { fromAddr := common.HexToAddress(from) var toAddrPtr *common.Address @@ -292,6 +304,26 @@ func (self *OneNodeReader) ReadContractToBytes(atBlock int64, from string, caddr }, blockBig) } +func (self *OneNodeReader) EthCall(from string, to string, data []byte, overrides *map[common.Address]gethclient.OverrideAccount) ([]byte, error) { + gethcli, err := self.GEthClient() + if err != nil { + return nil, err + } + + contract := HexToAddress(to) + + timeout, cancel := context.WithTimeout(context.Background(), 4*time.Second) + defer cancel() + return gethcli.CallContract(timeout, ethereum.CallMsg{ + From: HexToAddress(from), + To: &contract, + Gas: 0, + GasPrice: nil, + Value: nil, + Data: data, + }, nil, overrides) +} + func (self *OneNodeReader) CurrentBlock() (uint64, error) { ethcli, err := self.EthClient() if err != nil { diff --git a/util/reader/reader.go b/util/reader/reader.go index 9fd0dd8..d03a34d 100644 --- a/util/reader/reader.go +++ b/util/reader/reader.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient/gethclient" . "github.com/tranvictor/jarvis/common" . "github.com/tranvictor/jarvis/util/explorers" @@ -372,6 +373,29 @@ func (self *EthReader) ReadContractToBytes( return nil, fmt.Errorf("Couldn't read from any nodes: %s", errorInfo(errs)) } +func (self *EthReader) EthCall(from string, to string, data []byte, overrides *map[common.Address]gethclient.OverrideAccount) ([]byte, error) { + resCh := make(chan readContractToBytesResponse, len(self.nodes)) + for i := range self.nodes { + n := self.nodes[i] + go func() { + data, err := n.EthCall(from, to, data, overrides) + resCh <- readContractToBytesResponse{ + Data: data, + Error: wrapError(err, n.NodeName()), + } + }() + } + errs := []error{} + for i := 0; i < len(self.nodes); i++ { + result := <-resCh + if result.Error == nil { + return result.Data, result.Error + } + errs = append(errs, result.Error) + } + return nil, fmt.Errorf("Couldn't read from any nodes: %s", errorInfo(errs)) +} + func (self *EthReader) ImplementationOfEIP1967( atBlock int64, caddr string,