Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utxorpc): add support for searchUtxos by address #296

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions internal/utxorpc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

connect "connectrpc.com/connect"
"github.com/blinklabs-io/gouroboros/ledger"
"github.com/blinklabs-io/gouroboros/ledger/common"

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

Expand Down Expand Up @@ -184,19 +185,44 @@ func (s *queryServiceServer) SearchUtxos(
if predicate == nil {
return nil, fmt.Errorf("ERROR: empty predicate: %v", predicate)
}
addresses := []ledger.Address{}

var addresses []common.Address
addressPattern := predicate.GetMatch().GetCardano().GetAddress()
if addressPattern != nil {
if addressPattern.GetExactAddress() != nil {
address, err := ledger.NewAddress(
hex.EncodeToString(addressPattern.GetExactAddress()),
)
// Handle Exact Address
exactAddressBytes := addressPattern.GetExactAddress()
if exactAddressBytes != nil {
var addr common.Address
err := addr.UnmarshalCBOR(exactAddressBytes)
if err != nil {
return nil, fmt.Errorf("failed to decode exact address: %w", err)
}
addresses = append(addresses, addr)
}

// Handle Payment Part
paymentPart := addressPattern.GetPaymentPart()
if paymentPart != nil {
log.Printf("PaymentPart is present, decoding...")
var paymentAddr common.Address
err := paymentAddr.UnmarshalCBOR(paymentPart)
if err != nil {
return nil, fmt.Errorf("failed to decode payment part: %w", err)
}
addresses = append(addresses, paymentAddr)
}

// Handle Delegation Part
delegationPart := addressPattern.GetDelegationPart()
if delegationPart != nil {
log.Printf("DelegationPart is present, decoding...")
var delegationAddr common.Address
err := delegationAddr.UnmarshalCBOR(delegationPart)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to decode delegation part: %w", err)
}
addresses = append(addresses, address)
addresses = append(addresses, delegationAddr)
}
// TODO: GetPaymentPart() GetDelegationPart()
}

// Connect to node
Expand Down