@@ -20,6 +20,8 @@ import (
20
20
"log/slog"
21
21
22
22
"github.com/SundaeSwap-finance/kugo"
23
+ "github.com/blinklabs-io/gouroboros/base58"
24
+ "github.com/blinklabs-io/gouroboros/bech32"
23
25
"github.com/blinklabs-io/gouroboros/cbor"
24
26
"github.com/blinklabs-io/gouroboros/ledger"
25
27
"github.com/blinklabs-io/gouroboros/ledger/common"
@@ -78,9 +80,21 @@ func ExtractAssetDetailsFromMatch(match kugo.Match) (common.MultiAsset[uint64],
78
80
}
79
81
80
82
func NewResolvedTransactionOutput (match kugo.Match ) (ledger.TransactionOutput , error ) {
83
+ // FIXME - This is a patch to fix the issue with the address
84
+ // Attempt to create an address using Bech32
81
85
addr , err := common .NewAddress (match .Address )
82
86
if err != nil {
83
- return nil , fmt .Errorf ("failed to create address from match.Address: %w" , err )
87
+ // If Bech32 fails, try to convert from Base58 to Bech32
88
+ bech32addr , err := ConvertBase58ToBech32 (match .Address , "addr" )
89
+ if err != nil {
90
+ return nil , fmt .Errorf ("failed to convert base58 to bech32: %w" , err )
91
+ }
92
+
93
+ // Try to create the address again with the converted Bech32 address
94
+ addr , err = common .NewAddress (bech32addr )
95
+ if err != nil {
96
+ return nil , fmt .Errorf ("failed to create address from base58-converted bech32 address: %w" , err )
97
+ }
84
98
}
85
99
86
100
assets , amount , err := ExtractAssetDetailsFromMatch (match )
@@ -133,3 +147,19 @@ func (txOut ResolvedTransactionOutput) Utxorpc() *utxorpc.TxOutput {
133
147
// Placeholder for UTXO RPC representation
134
148
return & utxorpc.TxOutput {}
135
149
}
150
+
151
+ // ConvertBase58ToBech32 converts a Base58 string to a Bech32 string
152
+ // using the given human-readable part (hrp) required for Bech32 encoding
153
+ func ConvertBase58ToBech32 (base58Str , hrp string ) (string , error ) {
154
+ data := base58 .Decode (base58Str )
155
+ converted , err := bech32 .ConvertBits (data , 8 , 5 , true )
156
+ if err != nil {
157
+ return "" , fmt .Errorf ("failed to convert bits: %w" , err )
158
+ }
159
+ bech32Str , err := bech32 .Encode (hrp , converted )
160
+ if err != nil {
161
+ return "" , fmt .Errorf ("failed to encode Bech32: %w" , err )
162
+ }
163
+
164
+ return bech32Str , nil
165
+ }
0 commit comments