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
Kaspawallet daemon: Add Send and Sign commands #2016
Changes from 7 commits
2193041
ac1d789
72f0463
3da960f
62621a3
1f84ffe
0f5b5bb
d9e0c3d
2685c02
869a710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ service kaspawalletd { | |
rpc NewAddress (NewAddressRequest) returns (NewAddressResponse) {} | ||
rpc Shutdown (ShutdownRequest) returns (ShutdownResponse) {} | ||
rpc Broadcast (BroadcastRequest) returns (BroadcastResponse) {} | ||
rpc Send(SendRequest) returns (SendResponse) {} | ||
rpc Sign(SignRequest) returns (SignResponse) {} | ||
} | ||
|
||
message GetBalanceRequest { | ||
|
@@ -51,15 +53,35 @@ message NewAddressResponse { | |
} | ||
|
||
message BroadcastRequest { | ||
bytes transaction = 1; | ||
repeated bytes transactions = 1; | ||
} | ||
|
||
message BroadcastResponse { | ||
string txID = 1; | ||
repeated string txIDs = 1; | ||
} | ||
|
||
message ShutdownRequest { | ||
} | ||
|
||
message ShutdownResponse { | ||
} | ||
|
||
message SendRequest{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment that explains that this should be used only on trusted or secured connection? |
||
string toAddress = 1; | ||
uint64 amount = 2; | ||
|
||
string password = 3; | ||
} | ||
|
||
message SendResponse{ | ||
repeated string txIDs = 1; | ||
} | ||
|
||
message SignRequest{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment that explains that this should be used only on trusted or secured connection? |
||
repeated bytes unsignedTransactions = 1; | ||
string password = 2; | ||
} | ||
|
||
message SignResponse{ | ||
repeated bytes signedTransactions = 1; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb" | ||
) | ||
|
||
func (s *server) Send(_ context.Context, request *pb.SendRequest) (*pb.SendResponse, error) { | ||
unsignedTransactions, err := s.createUnsignedTransactions(request.ToAddress, request.Amount) | ||
if err != nil { | ||
return nil, err | ||
} | ||
signedTransactions, err := s.signTransactions(unsignedTransactions, request.Password) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
txIDs, err := s.broadcast(signedTransactions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &pb.SendResponse{TxIDs: txIDs}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet" | ||
|
||
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb" | ||
) | ||
|
||
func (s *server) Sign(_ context.Context, request *pb.SignRequest) (*pb.SignResponse, error) { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
signedTransactions, err := s.signTransactions(request.UnsignedTransactions, request.Password) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &pb.SignResponse{SignedTransactions: signedTransactions}, nil | ||
} | ||
|
||
func (s *server) signTransactions(unsignedTransactions [][]byte, password string) ([][]byte, error) { | ||
mnemonics, err := s.keysFile.DecryptMnemonics(password) | ||
if err != nil { | ||
return nil, err | ||
} | ||
signedTransactions := make([][]byte, len(unsignedTransactions)) | ||
for i, unsignedTransaction := range unsignedTransactions { | ||
signedTransaction, err := libkaspawallet.Sign(s.params, mnemonics, unsignedTransaction, s.keysFile.ECDSA) | ||
if err != nil { | ||
return nil, err | ||
} | ||
signedTransactions[i] = signedTransaction | ||
} | ||
return signedTransactions, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Transactions were"