Skip to content

Commit e5ba10b

Browse files
committed
feat(utxorpc): add support for searchUtxos by address
Signed-off-by: Ales Verbic <[email protected]>
1 parent b36523d commit e5ba10b

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

internal/utxorpc/query.go

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
connect "connectrpc.com/connect"
2424
"github.com/blinklabs-io/gouroboros/ledger"
25+
"github.com/blinklabs-io/gouroboros/ledger/common"
2526

2627
// ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
2728

@@ -184,19 +185,44 @@ func (s *queryServiceServer) SearchUtxos(
184185
if predicate == nil {
185186
return nil, fmt.Errorf("ERROR: empty predicate: %v", predicate)
186187
}
187-
addresses := []ledger.Address{}
188+
189+
var addresses []common.Address
188190
addressPattern := predicate.GetMatch().GetCardano().GetAddress()
189191
if addressPattern != nil {
190-
if addressPattern.GetExactAddress() != nil {
191-
address, err := ledger.NewAddress(
192-
hex.EncodeToString(addressPattern.GetExactAddress()),
193-
)
192+
// Handle Exact Address
193+
exactAddressBytes := addressPattern.GetExactAddress()
194+
if exactAddressBytes != nil {
195+
var addr common.Address
196+
err := addr.UnmarshalCBOR(exactAddressBytes)
197+
if err != nil {
198+
return nil, fmt.Errorf("failed to decode exact address: %w", err)
199+
}
200+
addresses = append(addresses, addr)
201+
}
202+
203+
// Handle Payment Part
204+
paymentPart := addressPattern.GetPaymentPart()
205+
if paymentPart != nil {
206+
log.Printf("PaymentPart is present, decoding...")
207+
var paymentAddr common.Address
208+
err := paymentAddr.UnmarshalCBOR(paymentPart)
209+
if err != nil {
210+
return nil, fmt.Errorf("failed to decode payment part: %w", err)
211+
}
212+
addresses = append(addresses, paymentAddr)
213+
}
214+
215+
// Handle Delegation Part
216+
delegationPart := addressPattern.GetDelegationPart()
217+
if delegationPart != nil {
218+
log.Printf("DelegationPart is present, decoding...")
219+
var delegationAddr common.Address
220+
err := delegationAddr.UnmarshalCBOR(delegationPart)
194221
if err != nil {
195-
return nil, err
222+
return nil, fmt.Errorf("failed to decode delegation part: %w", err)
196223
}
197-
addresses = append(addresses, address)
224+
addresses = append(addresses, delegationAddr)
198225
}
199-
// TODO: GetPaymentPart() GetDelegationPart()
200226
}
201227

202228
// Connect to node

0 commit comments

Comments
 (0)