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

Add grpc command for sync vsp ticket by hash #1951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions internal/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3752,3 +3752,42 @@ func (s *walletServer) SyncVSPFailedTickets(ctx context.Context, req *pb.SyncVSP
}
return &pb.SyncVSPTicketsResponse{}, nil
}

func (s *walletServer) SyncVSPTicketByHash(ctx context.Context, req *pb.SyncVSPTicketByHashRequest) (
*pb.SyncVSPTicketByHashResponse, error) {
vspHost := req.VspHost
vspPubKey := req.VspPubkey
if vspPubKey == "" {
return nil, status.Errorf(codes.InvalidArgument, "vsp pubkey can not be null")
}
if vspHost == "" {
return nil, status.Errorf(codes.InvalidArgument, "vsp host can not be null")
}
cfg := vsp.Config{
URL: vspHost,
PubKey: vspPubKey,
PurchaseAccount: req.Account,
ChangeAccount: req.Account,
MaxFee: 0.1e8,
Dialer: nil,
Wallet: s.wallet,
Params: s.wallet.ChainParams(),
}
vspServer, err := vsp.New(ctx, cfg)
if err != nil {
return nil, status.Errorf(codes.Unknown, "TicketBuyerV3 instance failed to start. Error: %v", err)
}
ticketHash, err := chainhash.NewHash(req.TicketHash)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid transaction hash: %v", err)
}

fmt.Printf("tcikethash: %+v\n", ticketHash)
_, err = vspServer.Process(ctx, *ticketHash, nil)
if err != nil {
// if it fails to process again, we log it and continue with
// the wallet start.
// Not sure we need to log here since it's already warned elsewhere
}
return &pb.SyncVSPTicketByHashResponse{}, nil
}
10 changes: 10 additions & 0 deletions rpc/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ service WalletService {
rpc LockWallet (LockWalletRequest) returns (LockWalletResponse);
rpc SyncVSPFailedTickets(SyncVSPTicketsRequest) returns (SyncVSPTicketsResponse);
rpc GetVSPTicketsByFeeStatus (GetVSPTicketsByFeeStatusRequest) returns (GetVSPTicketsByFeeStatusResponse);
rpc SyncVSPTicketByHash (SyncVSPTicketByHashRequest) returns (SyncVSPTicketByHashResponse);
}

service WalletLoaderService {
Expand Down Expand Up @@ -1272,3 +1273,12 @@ message GetVSPTicketsByFeeStatusRequest {
message GetVSPTicketsByFeeStatusResponse {
repeated bytes tickets_hashes = 1;
}

message SyncVSPTicketByHashRequest {
string vsp_host = 1;
string vsp_pubkey = 2;
uint32 account = 3;
bytes ticket_hash = 4;
}

message SyncVSPTicketByHashResponse {}