Vars and fields renaming (#387)

* Rename asp > server

* Rename pool > round

* Consolidate naming for pubkey/prvkey vars and types

* Fix

* Fix

* Fix wasm

* Rename congestionTree > vtxoTree

* Fix wasm

* Rename payment > request

* Rename congestionTree > vtxoTree after syncing with master

* Fix Send API in SDK

* Fix wasm

* Fix wasm

* Fixes

* Fixes after review

* Fix

* Fix naming

* Fix

* Fix e2e tests
This commit is contained in:
Pietralberto Mazza
2024-11-26 15:57:16 +01:00
committed by GitHub
parent 12d666bfdf
commit 7f937e8418
109 changed files with 2292 additions and 2325 deletions

View File

@@ -3,6 +3,7 @@ package handlers
import (
"context"
"fmt"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -14,15 +15,15 @@ import (
type adminHandler struct {
adminService application.AdminService
aspService application.Service
arkService application.Service
noteUriPrefix string
}
func NewAdminHandler(
adminService application.AdminService, aspService application.Service, noteUriPrefix string,
adminService application.AdminService, arkService application.Service, noteUriPrefix string,
) arkv1.AdminServiceServer {
return &adminHandler{adminService, aspService, noteUriPrefix}
return &adminHandler{adminService, arkService, noteUriPrefix}
}
func (a *adminHandler) GetRoundDetails(ctx context.Context, req *arkv1.GetRoundDetailsRequest) (*arkv1.GetRoundDetailsResponse, error) {
@@ -134,7 +135,7 @@ func (a *adminHandler) GetMarketHourConfig(
ctx context.Context,
request *arkv1.GetMarketHourConfigRequest,
) (*arkv1.GetMarketHourConfigResponse, error) {
config, err := a.aspService.GetMarketHourConfig(ctx)
config, err := a.arkService.GetMarketHourConfig(ctx)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -153,7 +154,7 @@ func (a *adminHandler) UpdateMarketHourConfig(
ctx context.Context,
req *arkv1.UpdateMarketHourConfigRequest,
) (*arkv1.UpdateMarketHourConfigResponse, error) {
if err := a.aspService.UpdateMarketHourConfig(
if err := a.arkService.UpdateMarketHourConfig(
ctx,
req.GetConfig().GetStartTime().AsTime(),
req.GetConfig().GetEndTime().AsTime(),

View File

@@ -36,7 +36,7 @@ func NewHandler(service application.Service) arkv1.ArkServiceServer {
}
go h.listenToEvents()
go h.listenToPaymentEvents()
go h.listenToTxEvents()
return h
}
@@ -124,14 +124,14 @@ func (h *handler) RegisterInputsForNextRound(
return nil, status.Error(codes.InvalidArgument, "cannot mix vtxos and notes")
}
paymentID := ""
requestID := ""
if len(vtxosInputs) > 0 {
inputs, err := parseInputs(vtxosInputs)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
paymentID, err = h.svc.SpendVtxos(ctx, inputs)
requestID, err = h.svc.SpendVtxos(ctx, inputs)
if err != nil {
return nil, err
}
@@ -142,7 +142,7 @@ func (h *handler) RegisterInputsForNextRound(
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
paymentID, err = h.svc.SpendNotes(ctx, notes)
requestID, err = h.svc.SpendNotes(ctx, notes)
if err != nil {
return nil, err
}
@@ -150,13 +150,13 @@ func (h *handler) RegisterInputsForNextRound(
pubkey := req.GetEphemeralPubkey()
if len(pubkey) > 0 {
if err := h.svc.RegisterCosignerPubkey(ctx, paymentID, pubkey); err != nil {
if err := h.svc.RegisterCosignerPubkey(ctx, requestID, pubkey); err != nil {
return nil, err
}
}
return &arkv1.RegisterInputsForNextRoundResponse{
Id: paymentID,
RequestId: requestID,
}, nil
}
@@ -168,7 +168,7 @@ func (h *handler) RegisterOutputsForNextRound(
return nil, status.Error(codes.InvalidArgument, err.Error())
}
if err := h.svc.ClaimVtxos(ctx, req.GetId(), receivers); err != nil {
if err := h.svc.ClaimVtxos(ctx, req.GetRequestId(), receivers); err != nil {
return nil, err
}
@@ -199,13 +199,13 @@ func (h *handler) SubmitTreeNonces(
return nil, status.Error(codes.InvalidArgument, "invalid cosigner public key")
}
cosignerPublicKey, err := secp256k1.ParsePubKey(pubkeyBytes)
cosignerPubkey, err := secp256k1.ParsePubKey(pubkeyBytes)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid cosigner public key")
}
if err := h.svc.RegisterCosignerNonces(
ctx, roundID, cosignerPublicKey, encodedNonces,
ctx, roundID, cosignerPubkey, encodedNonces,
); err != nil {
return nil, err
}
@@ -237,13 +237,13 @@ func (h *handler) SubmitTreeSignatures(
return nil, status.Error(codes.InvalidArgument, "invalid cosigner public key")
}
cosignerPublicKey, err := secp256k1.ParsePubKey(pubkeyBytes)
cosignerPubkey, err := secp256k1.ParsePubKey(pubkeyBytes)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid cosigner public key")
}
if err := h.svc.RegisterCosignerSignatures(
ctx, roundID, cosignerPublicKey, encodedSignatures,
ctx, roundID, cosignerPubkey, encodedSignatures,
); err != nil {
return nil, err
}
@@ -299,11 +299,11 @@ func (h *handler) GetEventStream(
func (h *handler) Ping(
ctx context.Context, req *arkv1.PingRequest,
) (*arkv1.PingResponse, error) {
if req.GetPaymentId() == "" {
return nil, status.Error(codes.InvalidArgument, "missing payment id")
if req.GetRequestId() == "" {
return nil, status.Error(codes.InvalidArgument, "missing request id")
}
if err := h.svc.UpdatePaymentStatus(ctx, req.GetPaymentId()); err != nil {
if err := h.svc.UpdateTxRequestStatus(ctx, req.GetRequestId()); err != nil {
return nil, err
}
@@ -344,7 +344,7 @@ func (h *handler) GetRound(
Start: round.StartingTimestamp,
End: round.EndingTimestamp,
RoundTx: round.UnsignedTx,
VtxoTree: congestionTree(round.CongestionTree).toProto(),
VtxoTree: vtxoTree(round.VtxoTree).toProto(),
ForfeitTxs: round.ForfeitTxs,
Connectors: round.Connectors,
Stage: stage(round.Stage).toProto(),
@@ -363,7 +363,7 @@ func (h *handler) GetRound(
Start: round.StartingTimestamp,
End: round.EndingTimestamp,
RoundTx: round.UnsignedTx,
VtxoTree: congestionTree(round.CongestionTree).toProto(),
VtxoTree: vtxoTree(round.VtxoTree).toProto(),
ForfeitTxs: round.ForfeitTxs,
Connectors: round.Connectors,
Stage: stage(round.Stage).toProto(),
@@ -390,7 +390,7 @@ func (h *handler) GetRoundById(
Start: round.StartingTimestamp,
End: round.EndingTimestamp,
RoundTx: round.UnsignedTx,
VtxoTree: congestionTree(round.CongestionTree).toProto(),
VtxoTree: vtxoTree(round.VtxoTree).toProto(),
ForfeitTxs: round.ForfeitTxs,
Connectors: round.Connectors,
Stage: stage(round.Stage).toProto(),
@@ -494,7 +494,7 @@ func (h *handler) listenToEvents() {
RoundFinalization: &arkv1.RoundFinalizationEvent{
Id: e.Id,
RoundTx: e.RoundTx,
VtxoTree: congestionTree(e.CongestionTree).toProto(),
VtxoTree: vtxoTree(e.VtxoTree).toProto(),
Connectors: e.Connectors,
MinRelayFeeRate: e.MinRelayFeeRate,
},
@@ -530,7 +530,7 @@ func (h *handler) listenToEvents() {
RoundSigning: &arkv1.RoundSigningEvent{
Id: e.Id,
CosignersPubkeys: cosignersKeys,
UnsignedVtxoTree: congestionTree(e.UnsignedVtxoTree).toProto(),
UnsignedVtxoTree: vtxoTree(e.UnsignedVtxoTree).toProto(),
UnsignedRoundTx: e.UnsignedRoundTx,
},
},
@@ -563,54 +563,37 @@ func (h *handler) listenToEvents() {
}
}
func (h *handler) listenToPaymentEvents() {
paymentEventsCh := h.svc.GetTransactionEventsChannel(context.Background())
for event := range paymentEventsCh {
var paymentEvent *arkv1.GetTransactionsStreamResponse
func (h *handler) listenToTxEvents() {
eventsCh := h.svc.GetTransactionEventsChannel(context.Background())
for event := range eventsCh {
var txEvent *arkv1.GetTransactionsStreamResponse
switch event.Type() {
case application.RoundTransaction:
paymentEvent = &arkv1.GetTransactionsStreamResponse{
txEvent = &arkv1.GetTransactionsStreamResponse{
Tx: &arkv1.GetTransactionsStreamResponse_Round{
Round: convertRoundPaymentEvent(event.(application.RoundTransactionEvent)),
Round: roundTxEvent(event.(application.RoundTransactionEvent)).toProto(),
},
}
case application.RedeemTransaction:
paymentEvent = &arkv1.GetTransactionsStreamResponse{
txEvent = &arkv1.GetTransactionsStreamResponse{
Tx: &arkv1.GetTransactionsStreamResponse_Redeem{
Redeem: convertAsyncPaymentEvent(event.(application.RedeemTransactionEvent)),
Redeem: redeemTxEvent(event.(application.RedeemTransactionEvent)).toProto(),
},
}
}
if paymentEvent != nil {
if txEvent != nil {
logrus.Debugf("forwarding event to %d listeners", len(h.transactionsListenerHandler.listeners))
for _, l := range h.transactionsListenerHandler.listeners {
go func(l *listener[*arkv1.GetTransactionsStreamResponse]) {
l.ch <- paymentEvent
l.ch <- txEvent
}(l)
}
}
}
}
func convertRoundPaymentEvent(e application.RoundTransactionEvent) *arkv1.RoundTransaction {
return &arkv1.RoundTransaction{
Txid: e.RoundTxID,
SpentVtxos: vtxoKeyList(e.SpentVtxos).toProto(),
SpendableVtxos: vtxoList(e.SpendableVtxos).toProto(),
ClaimedBoardingUtxos: vtxoKeyList(e.ClaimedBoardingInputs).toProto(),
}
}
func convertAsyncPaymentEvent(e application.RedeemTransactionEvent) *arkv1.RedeemTransaction {
return &arkv1.RedeemTransaction{
Txid: e.AsyncTxID,
SpentVtxos: vtxoKeyList(e.SpentVtxos).toProto(),
SpendableVtxos: vtxoList(e.SpendableVtxos).toProto(),
}
}
type listener[T any] struct {
id string
ch chan T

View File

@@ -73,7 +73,7 @@ func parseReceiver(out *arkv1.Output) (domain.Receiver, error) {
return domain.Receiver{
Amount: out.GetAmount(),
Pubkey: hex.EncodeToString(schnorr.SerializePubKey(decodedAddr.VtxoTapKey)),
PubKey: hex.EncodeToString(schnorr.SerializePubKey(decodedAddr.VtxoTapKey)),
}, nil
}
@@ -117,7 +117,7 @@ func (v vtxoList) toProto() []*arkv1.Vtxo {
Swept: vv.Swept,
RedeemTx: vv.RedeemTx,
IsPending: len(vv.RedeemTx) > 0,
Pubkey: vv.Pubkey,
Pubkey: vv.PubKey,
CreatedAt: vv.CreatedAt,
})
}
@@ -138,9 +138,9 @@ func (v vtxoKeyList) toProto() []*arkv1.Outpoint {
return list
}
type congestionTree tree.CongestionTree
type vtxoTree tree.VtxoTree
func (t congestionTree) toProto() *arkv1.Tree {
func (t vtxoTree) toProto() *arkv1.Tree {
levels := make([]*arkv1.TreeLevel, 0, len(t))
for _, level := range t {
levelProto := &arkv1.TreeLevel{
@@ -182,6 +182,27 @@ func (s stage) toProto() arkv1.RoundStage {
}
}
type roundTxEvent application.RoundTransactionEvent
func (e roundTxEvent) toProto() *arkv1.RoundTransaction {
return &arkv1.RoundTransaction{
Txid: e.RoundTxid,
SpentVtxos: vtxoKeyList(e.SpentVtxos).toProto(),
SpendableVtxos: vtxoList(e.SpendableVtxos).toProto(),
ClaimedBoardingUtxos: vtxoKeyList(e.ClaimedBoardingInputs).toProto(),
}
}
type redeemTxEvent application.RedeemTransactionEvent
func (e redeemTxEvent) toProto() *arkv1.RedeemTransaction {
return &arkv1.RedeemTransaction{
Txid: e.RedeemTxid,
SpentVtxos: vtxoKeyList(e.SpentVtxos).toProto(),
SpendableVtxos: vtxoList(e.SpendableVtxos).toProto(),
}
}
func parseSignedVtxoOutpoints(signedVtxoOutpoints []*arkv1.SignedVtxoOutpoint) ([]application.SignedVtxoOutpoint, error) {
if len(signedVtxoOutpoints) <= 0 {
return nil, fmt.Errorf("missing signed vtxo outpoints")