From 0b767d04df6d8957c7bd387790590d90cdf7ae9d Mon Sep 17 00:00:00 2001 From: james Date: Fri, 8 Sep 2023 10:26:37 +0800 Subject: [PATCH 1/4] fix test --- go.mod | 12 +++++++++++- go.sum | 26 ++++++++++++++++++++++---- testutils/rpcclient_test.go | 14 ++++++-------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 3607231..9526bea 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Qitmeer/qitmeer-wallet -go 1.18 +go 1.19 require ( github.com/BurntSushi/toml v1.2.0 @@ -13,6 +13,7 @@ require ( github.com/julienschmidt/httprouter v1.3.0 github.com/mattn/go-colorable v0.1.13 github.com/peterh/liner v1.2.2 + github.com/quic-go/quic-go v0.33.0 github.com/rakyll/statik v0.1.7 github.com/samuel/go-socks v0.0.0-20130725190102-f6c5f6a06ef6 github.com/shopspring/decimal v1.3.1 @@ -52,12 +53,15 @@ require ( github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/go-stack/stack v1.8.1 // indirect + github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gofrs/flock v0.8.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect github.com/golang-jwt/jwt/v4 v4.3.0 // indirect + github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect + github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/graph-gophers/graphql-go v1.3.0 // indirect @@ -98,6 +102,7 @@ require ( github.com/naoina/go-stringutil v0.1.0 // indirect github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect + github.com/onsi/ginkgo/v2 v2.9.2 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect @@ -106,6 +111,8 @@ require ( github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect + github.com/quic-go/qtls-go1-19 v0.3.2 // indirect + github.com/quic-go/qtls-go1-20 v0.2.2 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect github.com/rs/cors v1.7.0 // indirect @@ -126,11 +133,13 @@ require ( github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect + golang.org/x/mod v0.10.0 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.7.0 // indirect golang.org/x/term v0.6.0 // indirect golang.org/x/text v0.8.0 // indirect golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect + golang.org/x/tools v0.7.0 // indirect gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect @@ -141,4 +150,5 @@ require ( ) replace github.com/ethereum/go-ethereum v1.11.5 => github.com/Qitmeer/go-ethereum v1.11.5-q.3 + replace github.com/karalabe/usb v0.0.2 => github.com/dindinw/karalabe-usb v0.0.0-20230613095851-cd69a62c9c30 diff --git a/go.sum b/go.sum index 4d380c2..0e96c2f 100644 --- a/go.sum +++ b/go.sum @@ -198,6 +198,7 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= @@ -209,6 +210,8 @@ github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= @@ -241,6 +244,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -294,6 +299,8 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b h1:Qcx5LM0fSiks9uCyFZwDBUasd3lxd1RM0GYpL+Li5o4= +github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= @@ -368,8 +375,6 @@ github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= -github.com/karalabe/usb v0.0.2 h1:M6QQBNxF+CQ8OFvxrT90BA0qBOXymndZnk5q235mFc4= -github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8= github.com/kataras/iris/v12 v12.1.8/go.mod h1:LMYy4VlP67TQ3Zgriz8RE2h2kMZV2SgMYbq3UhfoFmE= github.com/kataras/neffos v0.0.14/go.mod h1:8lqADm8PnbeFfL7CLXh1WHw53dG27MC3pgi2R1rmoTE= @@ -497,9 +502,11 @@ github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo/v2 v2.9.2 h1:BA2GMJOtfGAfagzYtrAlufIP0lq6QERkFmHLMLPwFSU= +github.com/onsi/ginkgo/v2 v2.9.2/go.mod h1:WHcJJG2dIlcCqVfBAwUCrJxSPFb6v4azBwgxeMeDuts= 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/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= @@ -544,6 +551,12 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= +github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= +github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= +github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= +github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= +github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= +github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= @@ -608,6 +621,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -722,6 +736,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= +golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -940,12 +956,14 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df h1:5Pf6pFKu98ODmgnpvkJ3kFUOQGGLIzLIkbzUHp47618= gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/gonum v0.6.0/go.mod h1:9mxDZsDKxgMAuccQkewq682L+0eCu4dCN2yonUJTCLU= diff --git a/testutils/rpcclient_test.go b/testutils/rpcclient_test.go index 7060290..e898f8d 100644 --- a/testutils/rpcclient_test.go +++ b/testutils/rpcclient_test.go @@ -5,16 +5,16 @@ package testutils import ( - "github.com/Qitmeer/qng/config" - "github.com/Qitmeer/qng/core/event" - "github.com/Qitmeer/qng/rpc" - "github.com/Qitmeer/qng/services/mempool" - "github.com/Qitmeer/qng/testutils" "io/ioutil" "path/filepath" "reflect" "testing" "time" + + "github.com/Qitmeer/qng/config" + "github.com/Qitmeer/qng/rpc" + "github.com/Qitmeer/qng/services/mempool" + "github.com/Qitmeer/qng/testutils" ) const ( @@ -34,7 +34,6 @@ const ( defaultMiningStateSync = false defaultMaxInboundPeersPerHost = 10 // The default max total of inbound peer for host defaultTrickleInterval = 10 * time.Second - defaultCacheInvalidTx = false defaultSigCacheMaxSize = 100000 ) @@ -74,7 +73,6 @@ var ( DAGType: defaultDAGType, Banning: false, MaxInbound: defaultMaxInboundPeersPerHost, - CacheInvalidTx: defaultCacheInvalidTx, NTP: false, RPCListeners: []string{"127.0.0.1:5555"}, RPCUser: "test", @@ -83,7 +81,7 @@ var ( ) func newTestServer(t *testing.T) *rpc.RpcServer { - server, err := rpc.NewRPCServer(&cfg, &event.Feed{}) + server, err := rpc.NewRPCServer(&cfg, nil) if err != nil { t.Errorf("failed to initialize rpc server: %v", err) } From 9da6c927356f6c2863a81adfd936f9405020f606 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 9 Sep 2023 09:32:23 +0800 Subject: [PATCH 2/4] change qng go compile version --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5b9b1e3..c2f8e43 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 id: go - name: Check out code into the Go module directory From e731a7d478fe9f680c6aecbb6729dde9c8ace341 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 9 Sep 2023 10:03:37 +0800 Subject: [PATCH 3/4] fix test --- wallet/wallet.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index a8c4699..51192d2 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -2186,6 +2186,17 @@ func (w *Wallet) createTx(addrs []types.Address, coin2outputs []*TxOutput, coinI return "", 0, nil, err } payAmount.Value += output.Amount.Value + typ := txscript.PubKeyHashTy + addrD, err := address.DecodeAddress(output.Address) + if err != nil { + return "", 0, nil, err + } + switch addrD.(type) { + case *address.SecpPubKeyAddress: + typ = txscript.PubKeyTy + default: + } + outputs = append(outputs, qx.Output{ TargetLockTime: int64(output.LockHeight), TargetAddress: output.Address, @@ -2193,7 +2204,7 @@ func (w *Wallet) createTx(addrs []types.Address, coin2outputs []*TxOutput, coinI Value: output.Amount.Value, Id: output.Amount.Id, }, - OutputType: txscript.PubKeyHashTy, + OutputType: typ, }) } From 7fcf012196c75f55b78e5d9ac5c7f1e898d8fd82 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 11 Sep 2023 12:27:06 +0800 Subject: [PATCH 4/4] workflow --- .github/workflows/go.yml | 4 +- testutils/wallt_test.go | 7 ++- wallet/wallet.go | 128 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 126 insertions(+), 13 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c2f8e43..4c6a746 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -21,9 +21,9 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 - - name: Get dependencies + - name: Get qng v1.0.24 dependencies run: | - git clone https://github.com/Qitmeer/qng.git + git clone -b v1.0.24 https://github.com/Qitmeer/qng.git cd qng && make && pwd && cp ./build/bin/qng /usr/local/bin/ cd .. go get -v -t -d ./... diff --git a/testutils/wallt_test.go b/testutils/wallt_test.go index 8bf02aa..c11883b 100644 --- a/testutils/wallt_test.go +++ b/testutils/wallt_test.go @@ -3,14 +3,15 @@ package testutils import ( "context" "fmt" + "math/big" + "testing" + "time" + "github.com/Qitmeer/qitmeer-wallet/config" waddrmgr "github.com/Qitmeer/qitmeer-wallet/waddrmgs" "github.com/Qitmeer/qng/core/types" "github.com/Qitmeer/qng/params" "github.com/shopspring/decimal" - "math/big" - "testing" - "time" ) var walletCfg = &config.Config{ diff --git a/wallet/wallet.go b/wallet/wallet.go index 51192d2..17ea19d 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -26,6 +26,7 @@ import ( "github.com/Qitmeer/qng/engine/txscript" "github.com/Qitmeer/qng/meerevm/common" "github.com/Qitmeer/qng/qx" + "github.com/Qitmeer/qng/qx/scriptbasetypes" common2 "github.com/ethereum/go-ethereum/common" wt "github.com/Qitmeer/qitmeer-wallet/types" @@ -60,7 +61,7 @@ const ( InsecurePubPassphrase = "public" webUpdateBlockTicker = 30 defaultNewAddressNumber = 1 - ImportTxID = "0000000000000000000000000000000000000000000000000000000000000000" + ImportTxID = "000000000000000000000000000000000000000000000000000000000000000" ImportTxIndex = types.SupperPrevOutIndex ImportTxSequence = types.TxTypeCrossChainImport ) @@ -2221,6 +2222,11 @@ func (w *Wallet) createTx(addrs []types.Address, coin2outputs []*TxOutput, coinI Value: change, Id: coinId, }, addrScript) + typ := txscript.PubKeyHashTy + switch addr.(type) { + case *address.SecpPubKeyAddress: + typ = txscript.PubKeyTy + } if err := txrules.CheckOutput(changeOut, satPerKb); err == nil { outputs = append(outputs, qx.Output{ TargetLockTime: 0, @@ -2229,7 +2235,7 @@ func (w *Wallet) createTx(addrs []types.Address, coin2outputs []*TxOutput, coinI Id: coinId, }, TargetAddress: uxtoList[0].Address, - OutputType: txscript.PubKeyHashTy, + OutputType: typ, }) } } @@ -2411,11 +2417,13 @@ func (w *Wallet) EVMToUTXO(amounts map[string]types.Amount, /*if check == false { return "", err }*/ - txInputs := []qx.Input{} + txInputs := []Input{} txOutputs := []qx.Output{} - txInputs = append(txInputs, qx.Input{ - TxID: ImportTxID, - OutIndex: ImportTxIndex, + txInputs = append(txInputs, Input{ + TxID: ImportTxID, + OutIndex: ImportTxIndex, + Sequence: uint32(ImportTxSequence), + InputType: scriptbasetypes.SPECIAL_CROSS_VAL, }) var pkhAddr types.Address priKeyList := make([]string, 0) @@ -2448,7 +2456,7 @@ func (w *Wallet) EVMToUTXO(amounts map[string]types.Amount, } priKeyList = append(priKeyList, hex.EncodeToString(priKey.Serialize())) } - raw, err := qx.TxEncode(1, uint32(lockHeight), nil, txInputs, txOutputs) + raw, err := TxEncode(1, uint32(lockHeight), nil, txInputs, txOutputs) if err != nil { return "", err } @@ -2456,7 +2464,6 @@ func (w *Wallet) EVMToUTXO(amounts map[string]types.Amount, if err != nil { return "", err } - log.Trace(fmt.Sprintf("signTx size:%v", len(signedRaw)), "signTx", signedRaw) msg, err := w.HttpClient.SendRawTransaction(signedRaw, true) if err != nil { log.Trace("SendRawTransaction txSign err ", "err", err.Error()) @@ -2536,3 +2543,108 @@ func littleHexToUint64(hexStr string) (uint64, error) { err = binary.Read(bytesBuffer, binary.LittleEndian, &number) return number, err } + +type Input struct { + TxID string + OutIndex uint32 + SignScript []byte + Sequence uint32 + InputType txscript.ScriptClass + LockTime int64 +} + +func TxEncode(version uint32, lockTime uint32, timestamp *time.Time, inputs []Input, outputs []qx.Output) (string, error) { + mtx := types.NewTransaction() + mtx.Version = version + if lockTime != 0 { + mtx.LockTime = lockTime + } + if timestamp != nil { + mtx.Timestamp = *timestamp + } + + txtypes := &qx.ScriptTypeIndex{} + for i, vin := range inputs { + txtypes.InputTypeSet(i, vin.InputType, vin.LockTime) + txHash, err := hash.NewHashFromStr(vin.TxID) + if err != nil { + return "", err + } + prevOut := types.NewOutPoint(txHash, vin.OutIndex) + txIn := types.NewTxInput(prevOut, []byte{}) + if vin.Sequence > 0 { + txIn.Sequence = vin.Sequence + } + + // check sequence and lockTime + // see https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki + if vin.Sequence == types.MaxTxInSequenceNum-1 && lockTime <= 0 { + return "", errors.New("unlock cltvpubkeyhash script,locktime must > 0") + } + mtx.AddTxIn(txIn) + } + + for i := 0; i < len(outputs); i++ { + o := outputs[i] + txtypes.OutputTypeSet(i, o.OutputType) + addr, err := address.DecodeAddress(o.TargetAddress) + if err != nil { + return "", fmt.Errorf("could not decode "+ + "address: %v", err) + } + var pkScript []byte + switch addr.(type) { + case *address.PubKeyHashAddress: + case *address.SecpPubKeyAddress: + case *address.ScriptHashAddress: + default: + return "", fmt.Errorf("unsupport address type: %T", addr) + } + // if coinID is meerB the out address must be SecpPubKeyAddress + if o.Amount.Id == types.MEERB { + if _, ok := addr.(*address.SecpPubKeyAddress); !ok { + return "", fmt.Errorf("out coinid is %v but the out address is: %v , not the SecpPubKeyAddress", o.Amount.Id, addr) + } + } + switch o.OutputType { + case txscript.CLTVPubKeyHashTy: + if o.TargetLockTime <= 0 { + return "", fmt.Errorf("can not set CLTVPubKeyHashTy ADDRESS:AMOUNT:COINID:SCRIPTTYPE:LOCKTIME") + } + if _, ok := addr.(*address.PubKeyHashAddress); !ok { + return "", fmt.Errorf("locktype is %v but the out address is: %v , not the PubKeyHashAddress", o.OutputType.String(), addr) + } + pkScript, err = txscript.PayToCLTVPubKeyHashScript(addr.Script(), o.TargetLockTime) + if err != nil { + return "", err + } + case txscript.PubKeyTy: + if _, ok := addr.(*address.SecpPubKeyAddress); !ok { + return "", fmt.Errorf("locktype is %v but the out address is: %v , not the SecpPubKeyAddress", o.OutputType.String(), addr) + } + pkScript, err = txscript.PayToAddrScript(addr) + if err != nil { + return "", err + } + default: // pubkeyhash standard + if _, ok := addr.(*address.PubKeyHashAddress); !ok { + return "", fmt.Errorf("locktype is %v but the out address is: %v , not the PubKeyHashAddress", o.OutputType.String(), addr) + } + pkScript, err = txscript.PayToAddrScript(addr) + if err != nil { + return "", err + } + } + txOut := types.NewTxOutput(o.Amount, pkScript) + mtx.AddTxOut(txOut) + } + mtxHex, err := mtx.Serialize() + if err != nil { + return "", err + } + typeIndex, err := txtypes.Encode() + if err != nil { + return "", err + } + return hex.EncodeToString(mtxHex) + qx.MTX_STR_SEPERATE + typeIndex, nil +}