Skip to content

Commit

Permalink
fix(ReadParams): return protocol parameter values
Browse files Browse the repository at this point in the history
Signed-off-by: Ales Verbic <[email protected]>
  • Loading branch information
verbotenj committed Nov 7, 2024
1 parent 8ac9e73 commit 5607a8d
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions internal/utxorpc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ import (

connect "connectrpc.com/connect"
"github.com/blinklabs-io/gouroboros/ledger"
"github.com/blinklabs-io/gouroboros/ledger/allegra"
"github.com/blinklabs-io/gouroboros/ledger/alonzo"
"github.com/blinklabs-io/gouroboros/ledger/babbage"
"github.com/blinklabs-io/gouroboros/ledger/conway"
"github.com/blinklabs-io/gouroboros/ledger/mary"
"github.com/blinklabs-io/gouroboros/ledger/shelley"

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

"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
query "github.com/utxorpc/go-codegen/utxorpc/v1alpha/query"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/query/queryconnect"

Expand Down Expand Up @@ -63,23 +71,59 @@ func (s *queryServiceServer) ReadParams(
return nil, err
}

log.Printf("Get protoParams type: %T", protoParams)

// TODO: This is currently not working but it would allow polymorphism to work
// CurrentProtocolParameters are union of value types of all protocol parameters
// if pp, ok := protoParams.(common.ProtocolParametersUtxorpc); ok {
// utxoParams := pp.Utxorpc()
// log.Printf("Got Utxorpc protocol parameters: %+v", utxoParams)
// } else {
// log.Printf("ERROR: Utxorpc method not supported")
// return nil, fmt.Errorf("Utxorpc method not supported for current protocol parameters")
// }

// Determine the correct type and call Utxorpc() based on the era
var utxoParams *cardano.PParams
switch p := protoParams.(type) {
case conway.ConwayProtocolParameters:
utxoParams = (&p).Utxorpc()
case babbage.BabbageProtocolParameters:
utxoParams = (&p).Utxorpc()
case alonzo.AlonzoProtocolParameters:
utxoParams = (&p).Utxorpc()
case mary.MaryProtocolParameters:
utxoParams = (&p).Utxorpc()
case allegra.AllegraProtocolParameters:
utxoParams = (&p).Utxorpc()
case shelley.ShelleyProtocolParameters:
utxoParams = (&p).Utxorpc()
default:
log.Printf("ERROR: Utxorpc method not supported for current protocol parameters type: %T", protoParams)
return nil, fmt.Errorf("Utxorpc method not supported for current protocol parameters")
}

log.Printf("Converted protocol parameters to Cardano PParams: %+v", utxoParams)

// Get chain point (slot and hash)
point, err := oConn.LocalStateQuery().Client.GetChainPoint()
if err != nil {
return nil, err
}
var acp query.AnyChainParams
// var acpc query.AnyChainParams_Cardano
acpc := &query.AnyChainParams_Cardano{}
log.Printf("protocol parameters: %v", protoParams)
// acpc.Cardano = protoParams.Utxorpc()

// Set up response parameters
acpc := &query.AnyChainParams_Cardano{
Cardano: utxoParams,
}

resp.LedgerTip = &query.ChainPoint{
Slot: point.Slot,
Hash: point.Hash,
}
// acp.Params = &acpc
acp.Params = acpc
resp.Values = &acp
resp.Values = &query.AnyChainParams{
Params: acpc,
}

return connect.NewResponse(resp), nil
}

Expand Down

0 comments on commit 5607a8d

Please sign in to comment.