Skip to content

Commit 4b9ba36

Browse files
authored
fix: add nil handling for BabbageTransactionOutput Utxorpc() and include unit tests (#668)
Signed-off-by: Ales Verbic <[email protected]>
1 parent d715aec commit 4b9ba36

File tree

4 files changed

+104
-3
lines changed

4 files changed

+104
-3
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/blinklabs-io/ouroboros-mock v0.3.1
1010
github.com/fxamacker/cbor/v2 v2.7.0
1111
github.com/jinzhu/copier v0.4.0
12+
github.com/stretchr/testify v1.9.0
1213
github.com/utxorpc/go-codegen v0.5.1
1314
go.uber.org/goleak v1.3.0
1415
golang.org/x/crypto v0.25.0
@@ -17,9 +18,10 @@ require (
1718
require (
1819
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1920
github.com/google/go-cmp v0.6.0 // indirect
21+
github.com/kr/text v0.2.0 // indirect
2022
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
21-
github.com/stretchr/testify v1.9.0 // indirect
2223
github.com/x448/float16 v0.8.4 // indirect
2324
golang.org/x/sys v0.22.0 // indirect
2425
google.golang.org/protobuf v1.33.0 // indirect
26+
gopkg.in/yaml.v3 v3.0.1 // indirect
2527
)

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
22
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
33
github.com/blinklabs-io/ouroboros-mock v0.3.1 h1:oQiMgH0VgsJIGy4lJGaySegObq5FsVgFTYXUO2PS2T8=
44
github.com/blinklabs-io/ouroboros-mock v0.3.1/go.mod h1:6DosKZuBZ4mmvky3hXUzGZqqb/KhbwOiKOldwAtNoxc=
5+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
56
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
67
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
78
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
@@ -10,6 +11,10 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1011
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1112
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
1213
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
14+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
15+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
16+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
17+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1318
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
1419
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1520
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
@@ -26,5 +31,8 @@ golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
2631
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2732
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
2833
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
34+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
35+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
36+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2937
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3038
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

ledger/babbage.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,26 @@ func (o BabbageTransactionOutput) Datum() *cbor.LazyValue {
411411
}
412412

413413
func (o BabbageTransactionOutput) Utxorpc() *utxorpc.TxOutput {
414+
var address []byte
415+
if o.OutputAddress.Bytes() == nil {
416+
address = []byte{}
417+
} else {
418+
address = o.OutputAddress.Bytes()
419+
}
420+
421+
var datumHash []byte
422+
if o.DatumHash() == nil {
423+
datumHash = []byte{}
424+
} else {
425+
datumHash = o.DatumHash().Bytes()
426+
}
427+
414428
return &utxorpc.TxOutput{
415-
Address: o.OutputAddress.Bytes(),
429+
Address: address,
416430
Coin: o.Amount(),
417431
// Assets: o.Assets(),
418432
// Datum: o.Datum(),
419-
DatumHash: o.DatumHash().Bytes(),
433+
DatumHash: datumHash,
420434
// Script: o.ScriptRef,
421435
}
422436
}

0 commit comments

Comments
 (0)