Skip to content

Commit ae7cacf

Browse files
authored
feat: add support for Kupo (#256)
Signed-off-by: Ales Verbic <[email protected]>
1 parent 14a5c00 commit ae7cacf

File tree

8 files changed

+358
-19
lines changed

8 files changed

+358
-19
lines changed

go.mod

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ go 1.21
55
toolchain go1.21.6
66

77
require (
8-
github.com/blinklabs-io/gouroboros v0.96.0
8+
github.com/SundaeSwap-finance/kugo v1.0.5
9+
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20231128043329-e8ced51013a1
10+
github.com/blinklabs-io/gouroboros v0.99.0
911
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd
1012
github.com/gin-gonic/gin v1.10.0
1113
github.com/kelseyhightower/envconfig v1.4.0
1214
github.com/stretchr/testify v1.9.0
1315
github.com/swaggo/files v1.0.1
1416
github.com/swaggo/gin-swagger v1.6.0
1517
github.com/swaggo/swag v1.16.3
18+
github.com/utxorpc/go-codegen v0.10.0
1619
go.uber.org/automaxprocs v1.6.0
1720
golang.org/x/oauth2 v0.23.0
1821
gopkg.in/yaml.v2 v2.4.0
@@ -25,6 +28,8 @@ require (
2528
cloud.google.com/go/compute/metadata v0.3.0 // indirect
2629
filippo.io/edwards25519 v1.1.0 // indirect
2730
github.com/KyleBanks/depth v1.2.1 // indirect
31+
github.com/aws/aws-sdk-go v1.48.7 // indirect
32+
github.com/buger/jsonparser v1.1.1 // indirect
2833
github.com/bytedance/sonic v1.11.6 // indirect
2934
github.com/bytedance/sonic/loader v0.1.1 // indirect
3035
github.com/cloudwego/base64x v0.1.4 // indirect
@@ -43,7 +48,9 @@ require (
4348
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
4449
github.com/goccy/go-json v0.10.2 // indirect
4550
github.com/godbus/dbus/v5 v5.1.0 // indirect
51+
github.com/gorilla/websocket v1.5.1 // indirect
4652
github.com/jinzhu/copier v0.4.0 // indirect
53+
github.com/jmespath/go-jmespath v0.4.0 // indirect
4754
github.com/josharian/intern v1.0.0 // indirect
4855
github.com/json-iterator/go v1.1.12 // indirect
4956
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
@@ -59,13 +66,13 @@ require (
5966
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
6067
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
6168
github.com/ugorji/go/codec v1.2.12 // indirect
62-
github.com/utxorpc/go-codegen v0.9.0 // indirect
6369
github.com/x448/float16 v0.8.4 // indirect
6470
golang.org/x/arch v0.8.0 // indirect
65-
golang.org/x/crypto v0.27.0 // indirect
71+
golang.org/x/crypto v0.28.0 // indirect
6672
golang.org/x/net v0.25.0 // indirect
67-
golang.org/x/sys v0.25.0 // indirect
68-
golang.org/x/text v0.18.0 // indirect
73+
golang.org/x/sync v0.8.0 // indirect
74+
golang.org/x/sys v0.26.0 // indirect
75+
golang.org/x/text v0.19.0 // indirect
6976
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
7077
google.golang.org/protobuf v1.34.2 // indirect
7178
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
44
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
55
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
66
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
7-
github.com/blinklabs-io/gouroboros v0.96.0 h1:UYF2fwOo9MT6uHrpwHz+1krVib6SZ9sDkZ/C5KQxwdA=
8-
github.com/blinklabs-io/gouroboros v0.96.0/go.mod h1:lfvV4sV5tNz/qkaLiR85pKpKqPlHfAa5wFhWGbgsXZ0=
9-
github.com/blinklabs-io/ouroboros-mock v0.3.3 h1:c6jN9qcLzNQSVh3zjPE61gF33UkkRRIiNqSGBkZ10cY=
10-
github.com/blinklabs-io/ouroboros-mock v0.3.3/go.mod h1:UXkR/8qA5w/WtkzffOIdXudgOndN99DEorgRwy4ynN8=
7+
github.com/SundaeSwap-finance/kugo v1.0.5 h1:GWUbHkAIIMh1SmGMCw5r0rpOvriRsEoLpp5ofufWRvs=
8+
github.com/SundaeSwap-finance/kugo v1.0.5/go.mod h1:jkNGTmwLRdUPKVzkOOQjxqkpPTDw5gJ2hkJi3zUF9tA=
9+
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20231128043329-e8ced51013a1 h1:Lfw4vCNhm5Ik5wdbPsCK8k4gphhCB2/jtLxY5s/EifA=
10+
github.com/SundaeSwap-finance/ogmigo/v6 v6.0.0-20231128043329-e8ced51013a1/go.mod h1:CsDGcgbkKoz6S4h0RJ30go7oXG+KhGE2KLhBpRFnEqA=
11+
github.com/aws/aws-sdk-go v1.48.7 h1:gDcOhmkohlNk20j0uWpko5cLBbwSkB+xpkshQO45F7Y=
12+
github.com/aws/aws-sdk-go v1.48.7/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
13+
github.com/blinklabs-io/gouroboros v0.99.0 h1:tGiti2mPjQM/rVOYi1ZrCSlKh8Qt3iQUkDdsOeWKuvw=
14+
github.com/blinklabs-io/gouroboros v0.99.0/go.mod h1:gU9pBcL1h584sVqYF8H7JJcB2x0n1HdWcmWP11VYxPE=
15+
github.com/blinklabs-io/ouroboros-mock v0.3.4 h1:codPfiI5vLeD6YdhKL5VwYSzy2N3Dsgx6xjcLsqFaJQ=
16+
github.com/blinklabs-io/ouroboros-mock v0.3.4/go.mod h1:e/wgG1ZYVenroN2XEMXy7DgEfdmP7KXVRHIQKuh8E/0=
17+
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
18+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
1119
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
1220
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
1321
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
@@ -65,8 +73,14 @@ github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
6573
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
6674
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
6775
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
76+
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
77+
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
6878
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
6979
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
80+
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
81+
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
82+
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
83+
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
7084
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
7185
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
7286
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -100,6 +114,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
100114
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
101115
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
102116
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
117+
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 h1:NHrXEjTNQY7P0Zfx1aMrNhpgxHmow66XQtm0aQLY0AE=
118+
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249/go.mod h1:mpRZBD8SJ55OIICQ3iWH0Yz3cjzA61JdqMLoWXeB2+8=
103119
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
104120
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
105121
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
@@ -132,12 +148,14 @@ github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg=
132148
github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk=
133149
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
134150
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
151+
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
152+
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
135153
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
136154
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
137155
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
138156
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
139-
github.com/utxorpc/go-codegen v0.9.0 h1:sV5vK/QiQs3WvKynRVo+U+5n2tmKU7yMz5y3rEX90Hg=
140-
github.com/utxorpc/go-codegen v0.9.0/go.mod h1:+npvJc9wftIf8JMtWaRXxwjX0YlOCpNp1OlZVioNEO0=
157+
github.com/utxorpc/go-codegen v0.10.0 h1:EVRNc136CThXbbGeYV/oIy6NKfcZGLH2QSRmLTPE6TQ=
158+
github.com/utxorpc/go-codegen v0.10.0/go.mod h1:+npvJc9wftIf8JMtWaRXxwjX0YlOCpNp1OlZVioNEO0=
141159
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
142160
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
143161
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
@@ -150,8 +168,8 @@ golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
150168
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
151169
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
152170
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
153-
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
154-
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
171+
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
172+
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
155173
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
156174
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
157175
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
@@ -174,17 +192,17 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
174192
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
175193
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
176194
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
177-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
178-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
195+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
196+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
179197
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
180198
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
181199
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
182200
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
183201
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
184202
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
185203
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
186-
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
187-
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
204+
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
205+
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
188206
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
189207
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
190208
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
@@ -199,6 +217,7 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
199217
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
200218
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
201219
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
220+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
202221
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
203222
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
204223
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

input/chainsync/chainsync.go

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@
1515
package chainsync
1616

1717
import (
18+
"context"
1819
"encoding/hex"
1920
"fmt"
21+
"log/slog"
22+
"net/http"
23+
"strings"
2024
"time"
2125

26+
"github.com/SundaeSwap-finance/kugo"
27+
28+
"github.com/SundaeSwap-finance/ogmigo/v6/ouroboros/chainsync"
2229
"github.com/blinklabs-io/adder/event"
2330
"github.com/blinklabs-io/adder/plugin"
2431

@@ -59,6 +66,8 @@ type ChainSync struct {
5966
cursorCache []ocommon.Point
6067
dialAddress string
6168
dialFamily string
69+
kupoUrl string
70+
kupoClient *kugo.Client
6271
}
6372

6473
type ChainSyncStatus struct {
@@ -318,7 +327,12 @@ func (c *ChainSync) handleRollForward(
318327
blockEvt := event.New("chainsync.block", time.Now(), NewBlockHeaderContext(v), NewBlockEvent(block, c.includeCbor))
319328
c.eventChan <- blockEvt
320329
for t, transaction := range block.Transactions() {
321-
txEvt := event.New("chainsync.transaction", time.Now(), NewTransactionContext(block, transaction, uint32(t), c.networkMagic), NewTransactionEvent(block, transaction, c.includeCbor))
330+
resolvedInputs, err := resolveTransactionInputs(transaction, c)
331+
if err != nil {
332+
return err
333+
}
334+
txEvt := event.New("chainsync.transaction", time.Now(), NewTransactionContext(block, transaction, uint32(t), c.networkMagic),
335+
NewTransactionEvent(block, transaction, c.includeCbor, resolvedInputs))
322336
c.eventChan <- txEvt
323337
}
324338
c.updateStatus(v.SlotNumber(), v.BlockNumber(), v.Hash(), tip.Point.Slot, hex.EncodeToString(tip.Point.Hash))
@@ -339,6 +353,10 @@ func (c *ChainSync) handleBlockFetchBlock(
339353
)
340354
c.eventChan <- blockEvt
341355
for t, transaction := range block.Transactions() {
356+
resolvedInputs, err := resolveTransactionInputs(transaction, c)
357+
if err != nil {
358+
return err
359+
}
342360
txEvt := event.New(
343361
"chainsync.transaction",
344362
time.Now(),
@@ -348,7 +366,7 @@ func (c *ChainSync) handleBlockFetchBlock(
348366
uint32(t),
349367
c.networkMagic,
350368
),
351-
NewTransactionEvent(block, transaction, c.includeCbor),
369+
NewTransactionEvent(block, transaction, c.includeCbor, resolvedInputs),
352370
)
353371
c.eventChan <- txEvt
354372
}
@@ -403,3 +421,76 @@ func (c *ChainSync) updateStatus(
403421
c.statusUpdateFunc(*(c.status))
404422
}
405423
}
424+
425+
func getKupoClient(c *ChainSync) (*kugo.Client, error) {
426+
if c.kupoClient != nil {
427+
return c.kupoClient, nil
428+
}
429+
430+
k := kugo.New(kugo.WithEndpoint(c.kupoUrl))
431+
432+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
433+
defer cancel()
434+
435+
healthUrl := strings.TrimRight(c.kupoUrl, "/") + "/v1/health"
436+
req, err := http.NewRequestWithContext(ctx, "GET", healthUrl, nil)
437+
if err != nil {
438+
return nil, fmt.Errorf("failed to create health check request: %w", err)
439+
}
440+
441+
client := &http.Client{}
442+
resp, err := client.Do(req)
443+
if err != nil {
444+
return nil, fmt.Errorf("failed to perform health check: %w", err)
445+
}
446+
defer resp.Body.Close()
447+
448+
if resp.StatusCode != http.StatusOK {
449+
return nil, fmt.Errorf("health check failed with status code: %d", resp.StatusCode)
450+
}
451+
452+
c.kupoClient = k
453+
454+
return k, nil
455+
}
456+
457+
// resolveTransactionInputs resolves the transaction inputs by using the
458+
// Kupo client and fetching the corresponding transaction outputs.
459+
func resolveTransactionInputs(transaction ledger.Transaction, c *ChainSync) ([]ledger.TransactionOutput, error) {
460+
var resolvedInputs []ledger.TransactionOutput
461+
462+
// Use Kupo client to resolve inputs if available
463+
if c.kupoUrl != "" {
464+
k, err := getKupoClient(c)
465+
if err != nil {
466+
return nil, fmt.Errorf("failed to get Kupo client: %w", err)
467+
}
468+
469+
for _, input := range transaction.Inputs() {
470+
// Extract transaction ID and index from the input
471+
txId := input.Id().String()
472+
txIndex := int(input.Index())
473+
matches, err := k.Matches(context.Background(),
474+
kugo.TxOut(chainsync.NewTxID(txId, txIndex)),
475+
)
476+
if err != nil {
477+
return nil, fmt.Errorf("Error fetching matches for input TxId: %s, Index: %d. Error: %w\n", txId, txIndex, err)
478+
}
479+
480+
if len(matches) == 0 {
481+
slog.Info("No matches found for input TxId: %s, Index: %d, could be due to Kupo not in sync\n", txId, txIndex)
482+
} else {
483+
slog.Debug(fmt.Sprintf("Found matches %d for input TxId: %s, Index: %d\n", len(matches), txId, txIndex))
484+
for _, match := range matches {
485+
slog.Debug(fmt.Sprintf("Match: %#v\n", match))
486+
transactionOutput, err := NewResolvedTransactionOutput(match)
487+
if err != nil {
488+
return nil, err
489+
}
490+
resolvedInputs = append(resolvedInputs, transactionOutput)
491+
}
492+
}
493+
}
494+
}
495+
return resolvedInputs, nil
496+
}

input/chainsync/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,9 @@ func WithBulkMode(bulkMode bool) ChainSyncOptionFunc {
107107
c.bulkMode = bulkMode
108108
}
109109
}
110+
111+
func WithKupoUrl(kupoUrl string) ChainSyncOptionFunc {
112+
return func(c *ChainSync) {
113+
c.kupoUrl = kupoUrl
114+
}
115+
}

input/chainsync/plugin.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var cmdlineOptions struct {
3636
intersectPoint string
3737
includeCbor bool
3838
autoReconnect bool
39+
kupoUrl string
3940
}
4041

4142
func init() {
@@ -118,6 +119,13 @@ func init() {
118119
DefaultValue: true,
119120
Dest: &(cmdlineOptions.autoReconnect),
120121
},
122+
{
123+
Name: "kupo-url",
124+
Type: plugin.PluginOptionTypeString,
125+
Description: "kupo-url address",
126+
DefaultValue: "",
127+
Dest: &(cmdlineOptions.kupoUrl),
128+
},
121129
},
122130
},
123131
)
@@ -136,6 +144,7 @@ func NewFromCmdlineOptions() plugin.Plugin {
136144
WithBulkMode(cmdlineOptions.bulkMode),
137145
WithIncludeCbor(cmdlineOptions.includeCbor),
138146
WithAutoReconnect(cmdlineOptions.autoReconnect),
147+
WithKupoUrl(cmdlineOptions.kupoUrl),
139148
}
140149
if cmdlineOptions.intersectPoint != "" {
141150
intersectPoints := []ocommon.Point{}

0 commit comments

Comments
 (0)