From 2bec3dd1d58313155052ed5220c2e8ba7a38780a Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 20 Dec 2024 14:14:00 +0200 Subject: [PATCH] added copying methods for meta block. --- go.mod | 1 - go.sum | 42 --- process/outportBlockConverter.go | 575 +++++++++++++++++++++++++------ 3 files changed, 469 insertions(+), 149 deletions(-) diff --git a/go.mod b/go.mod index 1d017a2..4c8be5f 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( ) require ( - github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/denisbrodbeck/machineid v1.0.1 // indirect diff --git a/go.sum b/go.sum index f0f01c2..2392385 100644 --- a/go.sum +++ b/go.sum @@ -1,37 +1,12 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= -github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= -github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= -github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= -github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= -github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= -github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A= -github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE= -github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ= -github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= -github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= -github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= -github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= -github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= -github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= -github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= -github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= -github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= -github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= -github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -68,12 +43,8 @@ github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= @@ -92,15 +63,11 @@ github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= 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/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= -github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= -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/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= @@ -116,33 +83,28 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -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.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d h1:vfofYNRScrDdvS342BElfbETmL1Aiz3i2t0zfRj16Hs= github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/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-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 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/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/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.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -161,8 +123,6 @@ golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/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-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -176,7 +136,6 @@ golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 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.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -211,7 +170,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 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= diff --git a/process/outportBlockConverter.go b/process/outportBlockConverter.go index 21c4a17..2481dab 100644 --- a/process/outportBlockConverter.go +++ b/process/outportBlockConverter.go @@ -43,6 +43,45 @@ func NewOutportBlockConverter( }, nil } +// HandleMetaOutportBlock will convert an outport.OutportBlock to data.MetaOutportBlock. +func (o *outportBlockConverter) HandleMetaOutportBlock(outportBlock *outport.OutportBlock) (*hyperOutportBlocks.MetaOutportBlock, error) { + headerType := outportBlock.BlockData.HeaderType + + // check if the header type is supported by this function. + if headerType != string(core.MetaHeader) { + return nil, fmt.Errorf("cannot convert to meta outport block. header type: %s not supported", outportBlock.BlockData.HeaderType) + } + + // unmarshall into google protobuf. This is the proto that will be used in firehose. + blockData, err := o.handleMetaBlockData(outportBlock.BlockData) + if err != nil { + return nil, fmt.Errorf("cannot handle meta block data: %w", err) + } + + txPool, err := o.handleTransactionPool(outportBlock.TransactionPool) + if err != nil { + return nil, fmt.Errorf("failed to migrate transaction pool: %w", err) + } + + headerGasConsumption := handleHeaderGasConsumption(outportBlock.HeaderGasConsumption) + alteredAccounts := handleAlteredAccounts(outportBlock.AlteredAccounts) + stateChanges := handleStateChanges(outportBlock.StateChanges) + + return &hyperOutportBlocks.MetaOutportBlock{ + ShardID: outportBlock.ShardID, + BlockData: blockData, + TransactionPool: txPool, + HeaderGasConsumption: headerGasConsumption, + AlteredAccounts: alteredAccounts, + NotarizedHeadersHashes: outportBlock.NotarizedHeadersHashes, + NumberOfShards: outportBlock.NumberOfShards, + SignersIndexes: outportBlock.SignersIndexes, + HighestFinalBlockNonce: outportBlock.HighestFinalBlockNonce, + HighestFinalBlockHash: outportBlock.HighestFinalBlockHash, + StateChanges: stateChanges, + }, nil +} + // HandleShardOutportBlockV2 will convert an outport.OutportBlock to hyperOutportBlocks.ShardOutportBlockV2 func (o *outportBlockConverter) HandleShardOutportBlockV2(outportBlock *outport.OutportBlock) (*hyperOutportBlocks.ShardOutportBlockV2, error) { headerType := outportBlock.BlockData.HeaderType @@ -52,68 +91,101 @@ func (o *outportBlockConverter) HandleShardOutportBlockV2(outportBlock *outport. return nil, fmt.Errorf("cannot convert to shard outport block. header type: %s not supported", headerType) } - shardOutportBlock := &hyperOutportBlocks.ShardOutportBlockV2{} - shardOutportBlock.ShardID = outportBlock.ShardID - err := o.handleBlockData(outportBlock.BlockData, shardOutportBlock) + blockData, err := o.handleBlockData(outportBlock.BlockData) if err != nil { return nil, fmt.Errorf("failed to migrate block data: %w", err) } - err = o.handleTransactionPool(outportBlock.TransactionPool, shardOutportBlock) + txPool, err := o.handleTransactionPoolV2(outportBlock.TransactionPool) if err != nil { return nil, fmt.Errorf("failed to migrate transacion pool: %w", err) } - handleHeaderGasConsumption(outportBlock.HeaderGasConsumption, shardOutportBlock) - handleAlteredAccounts(outportBlock.AlteredAccounts, shardOutportBlock) - handleStateChanges(outportBlock.StateChanges, shardOutportBlock) - - shardOutportBlock.NotarizedHeadersHashes = outportBlock.NotarizedHeadersHashes - shardOutportBlock.NumberOfShards = outportBlock.NumberOfShards - shardOutportBlock.SignersIndexes = outportBlock.SignersIndexes - shardOutportBlock.HighestFinalBlockNonce = outportBlock.HighestFinalBlockNonce - shardOutportBlock.HighestFinalBlockHash = outportBlock.HighestFinalBlockHash - - return shardOutportBlock, nil + headerGasConsumption := handleHeaderGasConsumption(outportBlock.HeaderGasConsumption) + alteredAccounts := handleAlteredAccounts(outportBlock.AlteredAccounts) + stateChanges := handleStateChanges(outportBlock.StateChanges) + + return &hyperOutportBlocks.ShardOutportBlockV2{ + ShardID: outportBlock.ShardID, + BlockData: blockData, + TransactionPool: txPool, + HeaderGasConsumption: headerGasConsumption, + AlteredAccounts: alteredAccounts, + NotarizedHeadersHashes: outportBlock.NotarizedHeadersHashes, + NumberOfShards: outportBlock.NumberOfShards, + SignersIndexes: outportBlock.SignersIndexes, + HighestFinalBlockNonce: outportBlock.HighestFinalBlockNonce, + HighestFinalBlockHash: outportBlock.HighestFinalBlockHash, + StateChanges: stateChanges, + }, nil } -func (o *outportBlockConverter) handleBlockData(blockData *outport.BlockData, shardOutportBlock *hyperOutportBlocks.ShardOutportBlockV2) error { - if blockData == nil { - return ErrNilBlockData +func (o *outportBlockConverter) handleBlockData(outportBlockData *outport.BlockData) (*hyperOutportBlocks.BlockData, error) { + if outportBlockData == nil { + return nil, ErrNilBlockData } var miniBlocks []*hyperOutportBlocks.MiniBlock - if blockData.Body != nil { - miniBlocks = copyMiniBlocks(blockData.Body.MiniBlocks) + if outportBlockData.Body != nil { + miniBlocks = copyMiniBlocks(outportBlockData.Body.MiniBlocks) } - intraShardMiniBlocks := copyMiniBlocks(blockData.IntraShardMiniBlocks) + intraShardMiniBlocks := copyMiniBlocks(outportBlockData.IntraShardMiniBlocks) - shardOutportBlock.BlockData = &hyperOutportBlocks.BlockData{ - ShardID: blockData.ShardID, - HeaderType: blockData.HeaderType, - HeaderHash: blockData.HeaderHash, + blockData := &hyperOutportBlocks.BlockData{ + ShardID: outportBlockData.ShardID, + HeaderType: outportBlockData.HeaderType, + HeaderHash: outportBlockData.HeaderHash, Body: &hyperOutportBlocks.Body{ MiniBlocks: miniBlocks, }, IntraShardMiniBlocks: intraShardMiniBlocks, } - switch blockData.HeaderType { + switch outportBlockData.HeaderType { case string(core.ShardHeaderV1): - err := o.handleHeaderV1(blockData.HeaderBytes, shardOutportBlock.BlockData) + err := o.handleHeaderV1(outportBlockData.HeaderBytes, blockData) if err != nil { - return fmt.Errorf("failed to handle header v1: %w", err) + return nil, fmt.Errorf("failed to handle header v1: %w", err) } case string(core.ShardHeaderV2): - err := o.handleHeaderV2(blockData.HeaderBytes, shardOutportBlock.BlockData) + err := o.handleHeaderV2(outportBlockData.HeaderBytes, blockData) if err != nil { - return fmt.Errorf("failed to handle header v2: %w", err) + return nil, fmt.Errorf("failed to handle header v2: %w", err) } default: - return fmt.Errorf("unknown header type [%s]", blockData.HeaderType) + return nil, fmt.Errorf("unknown header type [%s]", outportBlockData.HeaderType) } - return nil + return blockData, nil +} + +func (o *outportBlockConverter) handleMetaBlockData(outportBlockData *outport.BlockData) (*hyperOutportBlocks.MetaBlockData, error) { + if outportBlockData == nil { + return nil, ErrNilBlockData + } + + var miniBlocks []*hyperOutportBlocks.MiniBlock + if outportBlockData.Body != nil { + miniBlocks = copyMiniBlocks(outportBlockData.Body.MiniBlocks) + } + intraShardMiniBlocks := copyMiniBlocks(outportBlockData.IntraShardMiniBlocks) + + blockData := &hyperOutportBlocks.MetaBlockData{ + ShardID: outportBlockData.ShardID, + HeaderType: outportBlockData.HeaderType, + HeaderHash: outportBlockData.HeaderHash, + Body: &hyperOutportBlocks.Body{ + MiniBlocks: miniBlocks, + }, + IntraShardMiniBlocks: intraShardMiniBlocks, + } + + err := o.handleMetaHeader(outportBlockData.HeaderBytes, blockData) + if err != nil { + return nil, fmt.Errorf("failed to handle meta header: %w", err) + } + + return blockData, nil } func (o *outportBlockConverter) handleHeaderV1(headerBytes []byte, shardBlockData *hyperOutportBlocks.BlockData) error { @@ -271,60 +343,121 @@ func (o *outportBlockConverter) handleHeaderV2(headerBytes []byte, shardBlockDat return nil } -func (o *outportBlockConverter) handleTransactionPool(outportTxPool *outport.TransactionPool, shardOutportBlockV2 *hyperOutportBlocks.ShardOutportBlockV2) error { +func (o *outportBlockConverter) handleMetaHeader(headerBytes []byte, metaBlockData *hyperOutportBlocks.MetaBlockData) error { + blockHeader := hyperOutportBlocks.MetaHeader{} + err := o.protoMarshaller.Unmarshal(&blockHeader, headerBytes) + if err != nil { + return fmt.Errorf("failed to unmarshal: %w", err) + } + + metaBlockData.Header = &blockHeader + return nil +} + +func (o *outportBlockConverter) handleTransactionPool(outportTxPool *outport.TransactionPool) (*hyperOutportBlocks.TransactionPool, error) { if outportTxPool == nil { - return nil + return nil, nil + } + if len(outportTxPool.Transactions) == 0 { + return nil, nil + } + + transactions, err := o.copyTransactions(outportTxPool.Transactions) + if err != nil { + return nil, fmt.Errorf("failed to copy transactions: %w", err) } - shardOutportBlockV2.TransactionPool = &hyperOutportBlocks.TransactionPoolV2{} - shardOutportBlockV2.TransactionPool.ScheduledExecutedSCRSHashesPrevBlock = outportTxPool.ScheduledExecutedSCRSHashesPrevBlock - shardOutportBlockV2.TransactionPool.ScheduledExecutedInvalidTxsHashesPrevBlock = outportTxPool.ScheduledExecutedInvalidTxsHashesPrevBlock + scResults, err := o.copySmartContractResults(outportTxPool.SmartContractResults) + if err != nil { + return nil, fmt.Errorf("failed to copy smart contract results: %w", err) + } + + rewards, err := o.copyRewards(outportTxPool.Rewards) + if err != nil { + return nil, fmt.Errorf("failed to copy rewards: %w", err) + } + + receipts, err := o.copyReceipts(outportTxPool.Receipts) + if err != nil { + return nil, fmt.Errorf("failed to copy receipts: %w", err) + } + + invalidTransactions, err := o.copyInvalidTxs(outportTxPool.InvalidTxs) + if err != nil { + return nil, fmt.Errorf("failed to copy invalid txs: %w", err) + } + + logs, err := o.copyLogs(outportTxPool.Logs) + if err != nil { + return nil, fmt.Errorf("failed to copy logs: %w", err) + } + + return &hyperOutportBlocks.TransactionPool{ + Transactions: transactions, + SmartContractResults: scResults, + Rewards: rewards, + Receipts: receipts, + InvalidTxs: invalidTransactions, + Logs: logs, + ScheduledExecutedSCRSHashesPrevBlock: outportTxPool.ScheduledExecutedSCRSHashesPrevBlock, + ScheduledExecutedInvalidTxsHashesPrevBlock: outportTxPool.ScheduledExecutedInvalidTxsHashesPrevBlock, + }, nil +} + +func (o *outportBlockConverter) handleTransactionPoolV2(outportTxPool *outport.TransactionPool) (*hyperOutportBlocks.TransactionPoolV2, error) { + if outportTxPool == nil { + return nil, nil + } + + transactionPool := &hyperOutportBlocks.TransactionPoolV2{} + transactionPool.ScheduledExecutedSCRSHashesPrevBlock = outportTxPool.ScheduledExecutedSCRSHashesPrevBlock + transactionPool.ScheduledExecutedInvalidTxsHashesPrevBlock = outportTxPool.ScheduledExecutedInvalidTxsHashesPrevBlock if len(outportTxPool.Transactions) == 0 { - return nil + return nil, nil } - shardOutportBlockV2.TransactionPool.Transactions = make(map[string]*hyperOutportBlocks.TxInfoV2) - err := o.copyTransactions(outportTxPool.Transactions, shardOutportBlockV2.TransactionPool) + transactionPool.Transactions = make(map[string]*hyperOutportBlocks.TxInfoV2) + err := o.copyTransactionsV2(outportTxPool.Transactions, transactionPool) if err != nil { - return fmt.Errorf("failed to copy transactions: %w", err) + return nil, fmt.Errorf("failed to copy transactions: %w", err) } - err = o.copySmartContractResults(outportTxPool.SmartContractResults, shardOutportBlockV2.TransactionPool) + err = o.copySmartContractResultsV2(outportTxPool.SmartContractResults, transactionPool) if err != nil { - return fmt.Errorf("failed to copy smart contract results: %w", err) + return nil, fmt.Errorf("failed to copy smart contract results: %w", err) } - err = o.copyRewards(outportTxPool.Rewards, shardOutportBlockV2.TransactionPool) + err = o.copyRewardsV2(outportTxPool.Rewards, transactionPool) if err != nil { - return fmt.Errorf("failed to copy rewards: %w", err) + return nil, fmt.Errorf("failed to copy rewards: %w", err) } - err = o.copyReceipts(outportTxPool.Receipts, shardOutportBlockV2.TransactionPool) + err = o.copyReceiptsV2(outportTxPool.Receipts, transactionPool) if err != nil { - return fmt.Errorf("failed to copy receipts: %w", err) + return nil, fmt.Errorf("failed to copy receipts: %w", err) } - err = o.copyInvalidTxs(outportTxPool.InvalidTxs, shardOutportBlockV2.TransactionPool) + err = o.copyInvalidTxsV2(outportTxPool.InvalidTxs, transactionPool) if err != nil { - return fmt.Errorf("failed to copy invalid txs: %w", err) + return nil, fmt.Errorf("failed to copy invalid txs: %w", err) } - err = o.copyLogs(outportTxPool.Logs, shardOutportBlockV2.TransactionPool) + err = o.copyLogsV2(outportTxPool.Logs, transactionPool) if err != nil { - return fmt.Errorf("failed to copy logs: %w", err) + return nil, fmt.Errorf("failed to copy logs: %w", err) } - return nil + return transactionPool, nil } -func handleAlteredAccounts(alteredAccounts map[string]*alteredAccount.AlteredAccount, shardOutportBlock *hyperOutportBlocks.ShardOutportBlockV2) { - if alteredAccounts == nil { - return +func handleAlteredAccounts(outportAlteredAccounts map[string]*alteredAccount.AlteredAccount) map[string]*hyperOutportBlocks.AlteredAccount { + if outportAlteredAccounts == nil { + return nil } - shardAlteredAccounts := make(map[string]*hyperOutportBlocks.AlteredAccount, len(alteredAccounts)) - for key, alteredAcc := range alteredAccounts { + alteredAccounts := make(map[string]*hyperOutportBlocks.AlteredAccount, len(outportAlteredAccounts)) + for key, alteredAcc := range outportAlteredAccounts { tokens := make([]*hyperOutportBlocks.AccountTokenData, len(alteredAcc.Tokens)) for i, tokenData := range alteredAcc.Tokens { var md *hyperOutportBlocks.TokenMetaData @@ -352,12 +485,9 @@ func handleAlteredAccounts(alteredAccounts map[string]*alteredAccount.AlteredAcc } } - shardAlteredAccounts[key] = &hyperOutportBlocks.AlteredAccount{ - Address: alteredAcc.Address, - Nonce: alteredAcc.Nonce, - Balance: alteredAcc.Balance, - Tokens: tokens, - AdditionalData: &hyperOutportBlocks.AdditionalAccountData{ + var additionalAccData *hyperOutportBlocks.AdditionalAccountData + if alteredAcc.AdditionalData != nil { + additionalAccData = &hyperOutportBlocks.AdditionalAccountData{ IsSender: alteredAcc.AdditionalData.IsSender, BalanceChanged: alteredAcc.AdditionalData.BalanceChanged, CurrentOwner: alteredAcc.AdditionalData.CurrentOwner, @@ -366,19 +496,27 @@ func handleAlteredAccounts(alteredAccounts map[string]*alteredAccount.AlteredAcc CodeHash: alteredAcc.AdditionalData.CodeHash, RootHash: alteredAcc.AdditionalData.RootHash, CodeMetadata: alteredAcc.AdditionalData.CodeMetadata, - }, + } + } + + alteredAccounts[key] = &hyperOutportBlocks.AlteredAccount{ + Address: alteredAcc.Address, + Nonce: alteredAcc.Nonce, + Balance: alteredAcc.Balance, + Tokens: tokens, + AdditionalData: additionalAccData, } } - shardOutportBlock.AlteredAccounts = shardAlteredAccounts + return alteredAccounts } -func handleHeaderGasConsumption(consumption *outport.HeaderGasConsumption, shardOutportBlock *hyperOutportBlocks.ShardOutportBlockV2) { +func handleHeaderGasConsumption(consumption *outport.HeaderGasConsumption) *hyperOutportBlocks.HeaderGasConsumption { if consumption == nil { - return + return nil } - shardOutportBlock.HeaderGasConsumption = &hyperOutportBlocks.HeaderGasConsumption{ + return &hyperOutportBlocks.HeaderGasConsumption{ GasProvided: consumption.GasProvided, GasRefunded: consumption.GasRefunded, GasPenalized: consumption.GasPenalized, @@ -386,13 +524,13 @@ func handleHeaderGasConsumption(consumption *outport.HeaderGasConsumption, shard } } -func handleStateChanges(stateChanges map[string]*stateChange.StateChanges, shardOutportBlock *hyperOutportBlocks.ShardOutportBlockV2) { - if stateChanges == nil { - return +func handleStateChanges(outportStateChanges map[string]*stateChange.StateChanges) map[string]*hyperOutportBlocks.StateChanges { + if outportStateChanges == nil { + return nil } - shardStateChangesMap := make(map[string]*hyperOutportBlocks.StateChanges, len(stateChanges)) - for key, scs := range stateChanges { + stateChangesMap := make(map[string]*hyperOutportBlocks.StateChanges, len(outportStateChanges)) + for key, scs := range outportStateChanges { shardStateChanges := make([]*hyperOutportBlocks.StateChange, len(scs.StateChanges)) for i, sc := range scs.StateChanges { @@ -417,10 +555,10 @@ func handleStateChanges(stateChanges map[string]*stateChange.StateChanges, shard } } - shardStateChangesMap[key] = &hyperOutportBlocks.StateChanges{StateChanges: shardStateChanges} + stateChangesMap[key] = &hyperOutportBlocks.StateChanges{StateChanges: shardStateChanges} } - shardOutportBlock.StateChanges = shardStateChangesMap + return stateChangesMap } // HandleShardOutportBlock will convert an outport.OutportBlock to data.ShardOutportBlock. @@ -535,7 +673,71 @@ func (o *outportBlockConverter) HandleShardOutportBlock(outportBlock *outport.Ou return shardOutportBlock, nil } -func (o *outportBlockConverter) copyTransactions(sourceTxs map[string]*outport.TxInfo, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { +func (o *outportBlockConverter) copyTransactions(sourceTxs map[string]*outport.TxInfo) (map[string]*hyperOutportBlocks.TxInfo, error) { + var txInfo map[string]*hyperOutportBlocks.TxInfo + if sourceTxs != nil { + txInfo = make(map[string]*hyperOutportBlocks.TxInfo, len(sourceTxs)) + } + + for txHash, outportTxInfo := range sourceTxs { + // TxInfo - Transaction + if outportTxInfo.Transaction == nil { + continue + } + value, err := o.castBigInt(outportTxInfo.Transaction.Value) + if err != nil { + return nil, fmt.Errorf("failed to cast transaction [%s] value: %w", txHash, err) + } + + transaction := &hyperOutportBlocks.Transaction{ + Nonce: outportTxInfo.Transaction.Nonce, + Value: value, + RcvAddr: outportTxInfo.Transaction.RcvAddr, + RcvUserName: outportTxInfo.Transaction.RcvUserName, + SndAddr: outportTxInfo.Transaction.SndAddr, + SndUserName: outportTxInfo.Transaction.SndUserName, + GasPrice: outportTxInfo.Transaction.GasPrice, + GasLimit: outportTxInfo.Transaction.GasLimit, + Data: outportTxInfo.Transaction.Data, + ChainID: outportTxInfo.Transaction.ChainID, + Version: outportTxInfo.Transaction.Version, + Signature: outportTxInfo.Transaction.Signature, + Options: outportTxInfo.Transaction.Options, + GuardianAddr: outportTxInfo.Transaction.GuardianAddr, + GuardianSignature: outportTxInfo.Transaction.GuardianSignature, + } + + // TxInfo - FeeInfo + var feeInfo *hyperOutportBlocks.FeeInfo + if outportTxInfo.FeeInfo != nil { + fee, err := o.castBigInt(outportTxInfo.FeeInfo.Fee) + if err != nil { + return nil, fmt.Errorf("failed to cast transaction [%s] fee: %w", txHash, err) + } + + initialPaidFee, err := o.castBigInt(outportTxInfo.FeeInfo.InitialPaidFee) + if err != nil { + return nil, fmt.Errorf("failed to cast transaction [%s] initial paid fee: %w", txHash, err) + } + + feeInfo = &hyperOutportBlocks.FeeInfo{ + GasUsed: outportTxInfo.FeeInfo.GasUsed, + Fee: fee, + InitialPaidFee: initialPaidFee, + } + } + + txInfo[txHash] = &hyperOutportBlocks.TxInfo{ + Transaction: transaction, + FeeInfo: feeInfo, + ExecutionOrder: outportTxInfo.ExecutionOrder, + } + } + + return txInfo, nil +} + +func (o *outportBlockConverter) copyTransactionsV2(sourceTxs map[string]*outport.TxInfo, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { for txHash, txInfo := range sourceTxs { destTxInfo := &hyperOutportBlocks.TxInfoV2{} @@ -595,7 +797,64 @@ func (o *outportBlockConverter) copyTransactions(sourceTxs map[string]*outport.T return nil } -func (o *outportBlockConverter) copySmartContractResults(sourceSCRs map[string]*outport.SCRInfo, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { +func (o *outportBlockConverter) copySmartContractResults(sourceSCRs map[string]*outport.SCRInfo) (map[string]*hyperOutportBlocks.SCRInfo, error) { + var scrInfo map[string]*hyperOutportBlocks.SCRInfo + if sourceSCRs != nil { + scrInfo = make(map[string]*hyperOutportBlocks.SCRInfo, len(sourceSCRs)) + } + for scrHash, outportSCRInfo := range sourceSCRs { + value, err := o.castBigInt(outportSCRInfo.SmartContractResult.Value) + if err != nil { + return nil, fmt.Errorf("failed to cast smart contract [%s] value: %w", scrHash, err) + } + + relayedValue, err := o.castBigInt(outportSCRInfo.SmartContractResult.RelayedValue) + if err != nil { + return nil, fmt.Errorf("failed to cast relayed transaction [%s] value: %w", scrHash, err) + } + + fee, err := o.castBigInt(outportSCRInfo.FeeInfo.Fee) + if err != nil { + return nil, fmt.Errorf("failed to cast transaction [%s] fee: %w", scrHash, err) + } + + initialPaidFee, err := o.castBigInt(outportSCRInfo.FeeInfo.InitialPaidFee) + if err != nil { + return nil, fmt.Errorf("failed to cast transaction [%s] initial paid fee: %w", scrHash, err) + } + + scrInfo[scrHash] = &hyperOutportBlocks.SCRInfo{ + SmartContractResult: &hyperOutportBlocks.SmartContractResult{ + Nonce: outportSCRInfo.SmartContractResult.Nonce, + Value: value, + RcvAddr: outportSCRInfo.SmartContractResult.RcvAddr, + SndAddr: outportSCRInfo.SmartContractResult.SndAddr, + RelayerAddr: outportSCRInfo.SmartContractResult.RelayerAddr, + RelayedValue: relayedValue, + Code: outportSCRInfo.SmartContractResult.Code, + Data: outportSCRInfo.SmartContractResult.Data, + PrevTxHash: outportSCRInfo.SmartContractResult.PrevTxHash, + OriginalTxHash: outportSCRInfo.SmartContractResult.OriginalTxHash, + GasLimit: outportSCRInfo.SmartContractResult.GasLimit, + GasPrice: outportSCRInfo.SmartContractResult.GasPrice, + CallType: int64(outportSCRInfo.SmartContractResult.CallType), + CodeMetadata: outportSCRInfo.SmartContractResult.CodeMetadata, + ReturnMessage: outportSCRInfo.SmartContractResult.ReturnMessage, + OriginalSender: outportSCRInfo.SmartContractResult.OriginalSender, + }, + FeeInfo: &hyperOutportBlocks.FeeInfo{ + GasUsed: outportSCRInfo.FeeInfo.GasUsed, + Fee: fee, + InitialPaidFee: initialPaidFee, + }, + ExecutionOrder: outportSCRInfo.ExecutionOrder, + } + } + + return scrInfo, nil +} + +func (o *outportBlockConverter) copySmartContractResultsV2(sourceSCRs map[string]*outport.SCRInfo, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { for scrHash, scrInfo := range sourceSCRs { value, err := o.castBigInt(scrInfo.SmartContractResult.Value) if err != nil { @@ -660,7 +919,32 @@ func (o *outportBlockConverter) copySmartContractResults(sourceSCRs map[string]* return nil } -func (o *outportBlockConverter) copyRewards(sourceRewards map[string]*outport.RewardInfo, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { +func (o *outportBlockConverter) copyRewards(sourceRewards map[string]*outport.RewardInfo) (map[string]*hyperOutportBlocks.RewardInfo, error) { + var rewardInfo map[string]*hyperOutportBlocks.RewardInfo + if sourceRewards != nil { + rewardInfo = make(map[string]*hyperOutportBlocks.RewardInfo, len(sourceRewards)) + } + for rewardHash, outportRewardInfo := range sourceRewards { + value, err := o.castBigInt(outportRewardInfo.Reward.Value) + if err != nil { + return nil, fmt.Errorf("failed to cast smart contract [%s] value: %w", rewardHash, err) + } + + rewardInfo[rewardHash] = &hyperOutportBlocks.RewardInfo{ + Reward: &hyperOutportBlocks.RewardTx{ + Round: outportRewardInfo.Reward.Round, + Epoch: outportRewardInfo.Reward.Epoch, + Value: value, + RcvAddr: outportRewardInfo.Reward.RcvAddr, + }, + ExecutionOrder: outportRewardInfo.ExecutionOrder, + } + } + + return rewardInfo, nil +} + +func (o *outportBlockConverter) copyRewardsV2(sourceRewards map[string]*outport.RewardInfo, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { for hash, reward := range sourceRewards { value, err := o.castBigInt(reward.Reward.Value) if err != nil { @@ -683,7 +967,30 @@ func (o *outportBlockConverter) copyRewards(sourceRewards map[string]*outport.Re return nil } -func (o *outportBlockConverter) copyReceipts(sourceReceipts map[string]*receipt.Receipt, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { +func (o *outportBlockConverter) copyReceipts(sourceReceipts map[string]*receipt.Receipt) (map[string]*hyperOutportBlocks.Receipt, error) { + var receipts map[string]*hyperOutportBlocks.Receipt + if sourceReceipts != nil { + receipts = make(map[string]*hyperOutportBlocks.Receipt, len(sourceReceipts)) + } + + for hash, outportReceipt := range sourceReceipts { + value, err := o.castBigInt(outportReceipt.Value) + if err != nil { + return nil, fmt.Errorf("failed to cast smart contract [%s] value: %w", hash, err) + } + + receipts[hash] = &hyperOutportBlocks.Receipt{ + Value: value, + SndAddr: outportReceipt.SndAddr, + Data: outportReceipt.Data, + TxHash: outportReceipt.TxHash, + } + } + + return receipts, nil +} + +func (o *outportBlockConverter) copyReceiptsV2(sourceReceipts map[string]*receipt.Receipt, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { for hash, r := range sourceReceipts { value, err := o.castBigInt(r.Value) if err != nil { @@ -703,7 +1010,59 @@ func (o *outportBlockConverter) copyReceipts(sourceReceipts map[string]*receipt. return nil } -func (o *outportBlockConverter) copyInvalidTxs(sourceInvalidTxs map[string]*outport.TxInfo, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { +func (o *outportBlockConverter) copyInvalidTxs(sourceInvalidTxs map[string]*outport.TxInfo) (map[string]*hyperOutportBlocks.TxInfo, error) { + var invalidTxs map[string]*hyperOutportBlocks.TxInfo + if sourceInvalidTxs != nil { + invalidTxs = make(map[string]*hyperOutportBlocks.TxInfo, len(sourceInvalidTxs)) + } + + for hash, invalidTx := range sourceInvalidTxs { + value, err := o.castBigInt(invalidTx.Transaction.Value) + if err != nil { + return nil, fmt.Errorf("failed to cast receipt tx value: %w", err) + } + + fee, err := o.castBigInt(invalidTx.FeeInfo.Fee) + if err != nil { + return nil, fmt.Errorf("failed to cast receipt tx fee: %w", err) + } + + initialPaidFee, err := o.castBigInt(invalidTx.FeeInfo.InitialPaidFee) + if err != nil { + return nil, fmt.Errorf("failed to cast receipt tx initial paid fee: %w", err) + } + + invalidTxs[hash] = &hyperOutportBlocks.TxInfo{ + Transaction: &hyperOutportBlocks.Transaction{ + Nonce: invalidTx.Transaction.Nonce, + Value: value, + RcvAddr: invalidTx.Transaction.RcvAddr, + RcvUserName: invalidTx.Transaction.RcvUserName, + SndAddr: invalidTx.Transaction.SndAddr, + SndUserName: invalidTx.Transaction.SndUserName, + GasPrice: invalidTx.Transaction.GasPrice, + GasLimit: invalidTx.Transaction.GasLimit, + Data: invalidTx.Transaction.Data, + ChainID: invalidTx.Transaction.ChainID, + Version: invalidTx.Transaction.Version, + Signature: invalidTx.Transaction.Signature, + Options: invalidTx.Transaction.Options, + GuardianAddr: invalidTx.Transaction.GuardianAddr, + GuardianSignature: invalidTx.Transaction.GuardianSignature, + }, + FeeInfo: &hyperOutportBlocks.FeeInfo{ + GasUsed: invalidTx.FeeInfo.GasUsed, + Fee: fee, + InitialPaidFee: initialPaidFee, + }, + ExecutionOrder: invalidTx.ExecutionOrder, + } + } + + return invalidTxs, nil +} + +func (o *outportBlockConverter) copyInvalidTxsV2(sourceInvalidTxs map[string]*outport.TxInfo, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { for txHash, invalidTx := range sourceInvalidTxs { value, err := o.castBigInt(invalidTx.Transaction.Value) if err != nil { @@ -736,7 +1095,36 @@ func (o *outportBlockConverter) copyInvalidTxs(sourceInvalidTxs map[string]*outp return nil } -func (o *outportBlockConverter) copyLogs(sourceLogs []*outport.LogData, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { +func (o *outportBlockConverter) copyLogs(sourceLogs []*outport.LogData) ([]*hyperOutportBlocks.LogData, error) { + logs := make([]*hyperOutportBlocks.LogData, len(sourceLogs)) + + for i, logData := range sourceLogs { + events := make([]*hyperOutportBlocks.Event, len(logData.Log.Events)) + for j, event := range logData.Log.Events { + e := &hyperOutportBlocks.Event{} + + e.Address = event.Address + e.Identifier = event.Identifier + e.Topics = event.Topics + e.Data = event.Data + e.AdditionalData = event.AdditionalData + + events[j] = e + } + + logs[i] = &hyperOutportBlocks.LogData{ + TxHash: logData.TxHash, + Log: &hyperOutportBlocks.Log{ + Address: logData.Log.Address, + Events: events, + }, + } + } + + return logs, nil +} + +func (o *outportBlockConverter) copyLogsV2(sourceLogs []*outport.LogData, transactionPool *hyperOutportBlocks.TransactionPoolV2) error { for _, logData := range sourceLogs { events := make([]*hyperOutportBlocks.Event, len(logData.Log.Events)) for i, event := range logData.Log.Events { @@ -769,31 +1157,6 @@ func (o *outportBlockConverter) copyLogs(sourceLogs []*outport.LogData, transact return nil } -// HandleMetaOutportBlock will convert an outport.OutportBlock to data.MetaOutportBlock. -func (o *outportBlockConverter) HandleMetaOutportBlock(outportBlock *outport.OutportBlock) (*hyperOutportBlocks.MetaOutportBlock, error) { - headerType := outportBlock.BlockData.HeaderType - - // check if the header type is supported by this function. - if headerType != string(core.MetaHeader) { - return nil, fmt.Errorf("cannot convert to meta outport block. header type: %s not supported", outportBlock.BlockData.HeaderType) - } - - // marshal with gogo, since the outportBlock is gogo protobuf (coming from the node). - bytes, err := o.gogoProtoMarshaller.Marshal(outportBlock) - if err != nil { - return nil, fmt.Errorf("marshal metaBlockCaster error: %w", err) - } - - // unmarshall into google protobuf. This is the proto that will be used in firehose. - metaOutportBlock := &hyperOutportBlocks.MetaOutportBlock{} - err = o.protoMarshaller.Unmarshal(metaOutportBlock, bytes) - if err != nil { - return nil, fmt.Errorf("unmarshal metaBlockCaster error: %w", err) - } - - return metaOutportBlock, nil -} - func (o *outportBlockConverter) castBigInt(i *big.Int) ([]byte, error) { buf := make([]byte, o.bigIntCaster.Size(i)) _, err := o.bigIntCaster.MarshalTo(i, buf)