diff --git a/app/rpc/rpchandlers/submit_transaction.go b/app/rpc/rpchandlers/submit_transaction.go index 34b0b518b..1ce5b8244 100644 --- a/app/rpc/rpchandlers/submit_transaction.go +++ b/app/rpc/rpchandlers/submit_transaction.go @@ -28,7 +28,8 @@ func HandleSubmitTransaction(context *rpccontext.Context, _ *router.Router, requ } log.Debugf("Rejected transaction %s: %s", transactionID, err) - errorMessage := &appmessage.SubmitTransactionResponseMessage{} + // Return the ID also in the case of error, so that clients can match the response to the correct transaction submit request + errorMessage := appmessage.NewSubmitTransactionResponseMessage(transactionID.String()) errorMessage.Error = appmessage.RPCErrorf("Rejected transaction %s: %s", transactionID, err) return errorMessage, nil } diff --git a/cmd/pyrinwallet/balance.go b/cmd/pyrinwallet/balance.go index 30e420109..bbe0de898 100644 --- a/cmd/pyrinwallet/balance.go +++ b/cmd/pyrinwallet/balance.go @@ -32,12 +32,12 @@ func balance(conf *balanceConfig) error { println("Address Available Pending") println("-----------------------------------------------------------------------------------------------------------") for _, addressBalance := range response.AddressBalances { - fmt.Printf("%s %s %s\n", addressBalance.Address, utils.FormatKas(addressBalance.Available), utils.FormatKas(addressBalance.Pending)) + fmt.Printf("%s %s %s\n", addressBalance.Address, utils.FormatPyi(addressBalance.Available), utils.FormatPyi(addressBalance.Pending)) } println("-----------------------------------------------------------------------------------------------------------") print(" ") } - fmt.Printf("Total balance, PYI %s %s%s\n", utils.FormatKas(response.Available), utils.FormatKas(response.Pending), pendingSuffix) + fmt.Printf("Total balance, PYI %s %s%s\n", utils.FormatPyi(response.Available), utils.FormatPyi(response.Pending), pendingSuffix) return nil } diff --git a/cmd/pyrinwallet/config.go b/cmd/pyrinwallet/config.go index b3990437b..c8e1092c5 100644 --- a/cmd/pyrinwallet/config.go +++ b/cmd/pyrinwallet/config.go @@ -4,9 +4,8 @@ import ( "os" "github.com/Pyrinpyi/pyipad/infrastructure/config" - "github.com/pkg/errors" - "github.com/jessevdk/go-flags" + "github.com/pkg/errors" ) const ( @@ -22,6 +21,8 @@ const ( newAddressSubCmd = "new-address" dumpUnencryptedDataSubCmd = "dump-unencrypted-data" startDaemonSubCmd = "start-daemon" + versionSubCmd = "version" + getDaemonVersionSubCmd = "get-daemon-version" ) const ( @@ -30,6 +31,7 @@ const ( ) type configFlags struct { + ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"` config.NetworkFlags } @@ -57,7 +59,7 @@ type sendConfig struct { DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"` ToAddress string `long:"to-address" short:"t" description:"The public address to send Pyrin to" required:"true"` FromAddresses []string `long:"from-address" short:"a" description:"Specific public address to send Pyrin from. Use multiple times to accept several addresses" required:"false"` - SendAmount float64 `long:"send-amount" short:"v" description:"An amount to send in Pyrin (e.g. 1234.12345678)"` + SendAmount string `long:"send-amount" short:"v" description:"An amount to send in Pyrin (e.g. 1234.12345678)"` IsSendAll bool `long:"send-all" description:"Send all the Pyrin in the wallet (mutually exclusive with --send-amount)"` UseExistingChangeAddress bool `long:"use-existing-change-address" short:"u" description:"Will use an existing change address (in case no change address was ever used, it will use a new one)"` Verbose bool `long:"show-serialized" short:"s" description:"Show a list of hex encoded sent transactions"` @@ -74,7 +76,7 @@ type createUnsignedTransactionConfig struct { DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"` ToAddress string `long:"to-address" short:"t" description:"The public address to send Pyrin to" required:"true"` FromAddresses []string `long:"from-address" short:"a" description:"Specific public address to send Pyrin from. Use multiple times to accept several addresses" required:"false"` - SendAmount float64 `long:"send-amount" short:"v" description:"An amount to send in Pyrin (e.g. 1234.12345678)"` + SendAmount string `long:"send-amount" short:"v" description:"An amount to send in Pyrin (e.g. 1234.12345678)"` IsSendAll bool `long:"send-all" description:"Send all the Pyrin in the wallet (mutually exclusive with --send-amount)"` UseExistingChangeAddress bool `long:"use-existing-change-address" short:"u" description:"Will use an existing change address (in case no change address was ever used, it will use a new one)"` config.NetworkFlags @@ -129,6 +131,13 @@ type dumpUnencryptedDataConfig struct { config.NetworkFlags } +type versionConfig struct { +} + +type getDaemonVersionConfig struct { + DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"` +} + func parseCommandLine() (subCommand string, config interface{}) { cfg := &configFlags{} parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag) @@ -185,6 +194,9 @@ func parseCommandLine() (subCommand string, config interface{}) { Listen: defaultListen, } parser.AddCommand(startDaemonSubCmd, "Start the wallet daemon", "Start the wallet daemon", startDaemonConf) + parser.AddCommand(versionSubCmd, "Get the wallet version", "Get the wallet version", &versionConfig{}) + getDaemonVersionConf := &getDaemonVersionConfig{DaemonAddress: defaultListen} + parser.AddCommand(getDaemonVersionSubCmd, "Get the wallet daemon version", "Get the wallet daemon version", getDaemonVersionConf) _, err := parser.Parse() if err != nil { @@ -290,14 +302,17 @@ func parseCommandLine() (subCommand string, config interface{}) { printErrorAndExit(err) } config = startDaemonConf + case versionSubCmd: + case getDaemonVersionSubCmd: + config = getDaemonVersionConf } return parser.Command.Active.Name, config } func validateCreateUnsignedTransactionConf(conf *createUnsignedTransactionConfig) error { - if (!conf.IsSendAll && conf.SendAmount == 0) || - (conf.IsSendAll && conf.SendAmount > 0) { + if (!conf.IsSendAll && conf.SendAmount == "") || + (conf.IsSendAll && conf.SendAmount != "") { return errors.New("exactly one of '--send-amount' or '--all' must be specified") } @@ -305,8 +320,8 @@ func validateCreateUnsignedTransactionConf(conf *createUnsignedTransactionConfig } func validateSendConfig(conf *sendConfig) error { - if (!conf.IsSendAll && conf.SendAmount == 0) || - (conf.IsSendAll && conf.SendAmount > 0) { + if (!conf.IsSendAll && conf.SendAmount == "") || + (conf.IsSendAll && conf.SendAmount != "") { return errors.New("exactly one of '--send-amount' or '--all' must be specified") } diff --git a/cmd/pyrinwallet/create_unsigned_tx.go b/cmd/pyrinwallet/create_unsigned_tx.go index 0d0899bcd..5aac39da0 100644 --- a/cmd/pyrinwallet/create_unsigned_tx.go +++ b/cmd/pyrinwallet/create_unsigned_tx.go @@ -3,11 +3,11 @@ package main import ( "context" "fmt" + "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/utils" "os" "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/client" "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/pb" - "github.com/Pyrinpyi/pyipad/domain/consensus/utils/constants" ) func createUnsignedTransaction(conf *createUnsignedTransactionConfig) error { @@ -20,7 +20,12 @@ func createUnsignedTransaction(conf *createUnsignedTransactionConfig) error { ctx, cancel := context.WithTimeout(context.Background(), daemonTimeout) defer cancel() - sendAmountLeor := uint64(conf.SendAmount * constants.LeorPerPyrin) + sendAmountLeor, err := utils.PyiToLeor(conf.SendAmount) + + if err != nil { + return err + } + response, err := daemonClient.CreateUnsignedTransactions(ctx, &pb.CreateUnsignedTransactionsRequest{ From: conf.FromAddresses, Address: conf.ToAddress, diff --git a/cmd/pyrinwallet/daemon/pb/pyrinwalletd.pb.go b/cmd/pyrinwallet/daemon/pb/pyrinwalletd.pb.go index 753569c0f..24543e056 100644 --- a/cmd/pyrinwallet/daemon/pb/pyrinwalletd.pb.go +++ b/cmd/pyrinwallet/daemon/pb/pyrinwalletd.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v3.12.3 +// protoc v4.25.2 // source: pyrinwalletd.proto package pb @@ -1242,6 +1242,91 @@ func (x *SignResponse) GetSignedTransactions() [][]byte { return nil } +type GetVersionRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetVersionRequest) Reset() { + *x = GetVersionRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_pyrinwalletd_proto_msgTypes[23] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetVersionRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetVersionRequest) ProtoMessage() {} + +func (x *GetVersionRequest) ProtoReflect() protoreflect.Message { + mi := &file_pyrinwalletd_proto_msgTypes[23] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetVersionRequest.ProtoReflect.Descriptor instead. +func (*GetVersionRequest) Descriptor() ([]byte, []int) { + return file_pyrinwalletd_proto_rawDescGZIP(), []int{23} +} + +type GetVersionResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` +} + +func (x *GetVersionResponse) Reset() { + *x = GetVersionResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_pyrinwalletd_proto_msgTypes[24] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetVersionResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetVersionResponse) ProtoMessage() {} + +func (x *GetVersionResponse) ProtoReflect() protoreflect.Message { + mi := &file_pyrinwalletd_proto_msgTypes[24] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetVersionResponse.ProtoReflect.Descriptor instead. +func (*GetVersionResponse) Descriptor() ([]byte, []int) { + return file_pyrinwalletd_proto_rawDescGZIP(), []int{24} +} + +func (x *GetVersionResponse) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + var File_pyrinwalletd_proto protoreflect.FileDescriptor var file_pyrinwalletd_proto_rawDesc = []byte{ @@ -1371,62 +1456,72 @@ var file_pyrinwalletd_proto_rawDesc = []byte{ 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2e, 0x0a, 0x12, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x12, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x32, 0xb3, 0x06, 0x0a, 0x0c, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, - 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x12, 0x51, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, - 0x6e, 0x63, 0x65, 0x12, 0x1f, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, - 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, - 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x7e, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x45, - 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x61, 0x62, 0x6c, 0x65, - 0x55, 0x54, 0x58, 0x4f, 0x73, 0x12, 0x2e, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, - 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, - 0x53, 0x70, 0x65, 0x6e, 0x64, 0x61, 0x62, 0x6c, 0x65, 0x55, 0x54, 0x58, 0x4f, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, - 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, - 0x53, 0x70, 0x65, 0x6e, 0x64, 0x61, 0x62, 0x6c, 0x65, 0x55, 0x54, 0x58, 0x4f, 0x73, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x81, 0x01, 0x0a, 0x1a, 0x43, 0x72, 0x65, + 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x13, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x2e, 0x0a, 0x12, 0x47, 0x65, 0x74, + 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x32, 0x86, 0x07, 0x0a, 0x0c, 0x70, 0x79, + 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x12, 0x51, 0x0a, 0x0a, 0x47, 0x65, + 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1f, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, + 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, + 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x70, 0x79, 0x72, 0x69, + 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x7e, 0x0a, + 0x19, 0x47, 0x65, 0x74, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 0x70, 0x65, 0x6e, + 0x64, 0x61, 0x62, 0x6c, 0x65, 0x55, 0x54, 0x58, 0x4f, 0x73, 0x12, 0x2e, 0x2e, 0x70, 0x79, 0x72, + 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x78, 0x74, + 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x61, 0x62, 0x6c, 0x65, 0x55, 0x54, + 0x58, 0x4f, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x70, 0x79, 0x72, + 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x78, 0x74, + 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x61, 0x62, 0x6c, 0x65, 0x55, 0x54, + 0x58, 0x4f, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x81, 0x01, + 0x0a, 0x1a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x6e, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2f, 0x2e, 0x70, + 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x55, 0x6e, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 0x2e, + 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x6e, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, - 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2f, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, - 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x6e, 0x73, - 0x69, 0x67, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, - 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x6e, - 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x5a, 0x0a, 0x0d, - 0x53, 0x68, 0x6f, 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x22, 0x2e, - 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x68, 0x6f, - 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x23, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, - 0x2e, 0x53, 0x68, 0x6f, 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0a, 0x4e, 0x65, 0x77, 0x41, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1f, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, - 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x4e, 0x65, 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, - 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x4e, 0x65, 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4b, 0x0a, 0x08, 0x53, - 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x1d, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, - 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, - 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4e, 0x0a, 0x09, 0x42, 0x72, 0x6f, 0x61, - 0x64, 0x63, 0x61, 0x73, 0x74, 0x12, 0x1e, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, - 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, - 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x04, 0x53, 0x65, 0x6e, 0x64, - 0x12, 0x19, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, - 0x53, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x79, - 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x04, 0x53, 0x69, 0x67, - 0x6e, 0x12, 0x19, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, - 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, - 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x69, 0x67, 0x6e, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x50, 0x79, 0x72, 0x69, 0x6e, 0x70, 0x79, - 0x69, 0x2f, 0x70, 0x79, 0x69, 0x70, 0x61, 0x64, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x79, 0x72, - 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x2f, 0x64, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x2f, - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x5a, 0x0a, 0x0d, 0x53, 0x68, 0x6f, 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x65, 0x73, 0x12, 0x22, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, + 0x64, 0x2e, 0x53, 0x68, 0x6f, 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, + 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x68, 0x6f, 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, + 0x73, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, + 0x0a, 0x4e, 0x65, 0x77, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1f, 0x2e, 0x70, 0x79, + 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x4e, 0x65, 0x77, 0x41, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x70, + 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x4e, 0x65, 0x77, 0x41, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x4b, 0x0a, 0x08, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x1d, 0x2e, 0x70, + 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x68, 0x75, 0x74, + 0x64, 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x70, 0x79, + 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x68, 0x75, 0x74, 0x64, + 0x6f, 0x77, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4e, 0x0a, + 0x09, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x12, 0x1e, 0x2e, 0x70, 0x79, 0x72, + 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, + 0x61, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x79, 0x72, + 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, + 0x61, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, + 0x04, 0x53, 0x65, 0x6e, 0x64, 0x12, 0x19, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, + 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1a, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, + 0x53, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, + 0x0a, 0x04, 0x53, 0x69, 0x67, 0x6e, 0x12, 0x19, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, + 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, + 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x51, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x2e, + 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, 0x74, + 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, + 0x2e, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x64, 0x2e, 0x47, 0x65, + 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x50, 0x79, 0x72, 0x69, 0x6e, 0x70, 0x79, 0x69, 0x2f, 0x70, 0x79, 0x69, 0x70, 0x61, 0x64, + 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x79, 0x72, 0x69, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, + 0x2f, 0x64, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -1441,7 +1536,7 @@ func file_pyrinwalletd_proto_rawDescGZIP() []byte { return file_pyrinwalletd_proto_rawDescData } -var file_pyrinwalletd_proto_msgTypes = make([]protoimpl.MessageInfo, 23) +var file_pyrinwalletd_proto_msgTypes = make([]protoimpl.MessageInfo, 25) var file_pyrinwalletd_proto_goTypes = []interface{}{ (*GetBalanceRequest)(nil), // 0: pyrinwalletd.GetBalanceRequest (*GetBalanceResponse)(nil), // 1: pyrinwalletd.GetBalanceResponse @@ -1466,6 +1561,8 @@ var file_pyrinwalletd_proto_goTypes = []interface{}{ (*SendResponse)(nil), // 20: pyrinwalletd.SendResponse (*SignRequest)(nil), // 21: pyrinwalletd.SignRequest (*SignResponse)(nil), // 22: pyrinwalletd.SignResponse + (*GetVersionRequest)(nil), // 23: pyrinwalletd.GetVersionRequest + (*GetVersionResponse)(nil), // 24: pyrinwalletd.GetVersionResponse } var file_pyrinwalletd_proto_depIdxs = []int32{ 2, // 0: pyrinwalletd.GetBalanceResponse.addressBalances:type_name -> pyrinwalletd.AddressBalances @@ -1482,17 +1579,19 @@ var file_pyrinwalletd_proto_depIdxs = []int32{ 9, // 11: pyrinwalletd.pyrinwalletd.Broadcast:input_type -> pyrinwalletd.BroadcastRequest 19, // 12: pyrinwalletd.pyrinwalletd.Send:input_type -> pyrinwalletd.SendRequest 21, // 13: pyrinwalletd.pyrinwalletd.Sign:input_type -> pyrinwalletd.SignRequest - 1, // 14: pyrinwalletd.pyrinwalletd.GetBalance:output_type -> pyrinwalletd.GetBalanceResponse - 18, // 15: pyrinwalletd.pyrinwalletd.GetExternalSpendableUTXOs:output_type -> pyrinwalletd.GetExternalSpendableUTXOsResponse - 4, // 16: pyrinwalletd.pyrinwalletd.CreateUnsignedTransactions:output_type -> pyrinwalletd.CreateUnsignedTransactionsResponse - 6, // 17: pyrinwalletd.pyrinwalletd.ShowAddresses:output_type -> pyrinwalletd.ShowAddressesResponse - 8, // 18: pyrinwalletd.pyrinwalletd.NewAddress:output_type -> pyrinwalletd.NewAddressResponse - 12, // 19: pyrinwalletd.pyrinwalletd.Shutdown:output_type -> pyrinwalletd.ShutdownResponse - 10, // 20: pyrinwalletd.pyrinwalletd.Broadcast:output_type -> pyrinwalletd.BroadcastResponse - 20, // 21: pyrinwalletd.pyrinwalletd.Send:output_type -> pyrinwalletd.SendResponse - 22, // 22: pyrinwalletd.pyrinwalletd.Sign:output_type -> pyrinwalletd.SignResponse - 14, // [14:23] is the sub-list for method output_type - 5, // [5:14] is the sub-list for method input_type + 23, // 14: pyrinwalletd.pyrinwalletd.GetVersion:input_type -> pyrinwalletd.GetVersionRequest + 1, // 15: pyrinwalletd.pyrinwalletd.GetBalance:output_type -> pyrinwalletd.GetBalanceResponse + 18, // 16: pyrinwalletd.pyrinwalletd.GetExternalSpendableUTXOs:output_type -> pyrinwalletd.GetExternalSpendableUTXOsResponse + 4, // 17: pyrinwalletd.pyrinwalletd.CreateUnsignedTransactions:output_type -> pyrinwalletd.CreateUnsignedTransactionsResponse + 6, // 18: pyrinwalletd.pyrinwalletd.ShowAddresses:output_type -> pyrinwalletd.ShowAddressesResponse + 8, // 19: pyrinwalletd.pyrinwalletd.NewAddress:output_type -> pyrinwalletd.NewAddressResponse + 12, // 20: pyrinwalletd.pyrinwalletd.Shutdown:output_type -> pyrinwalletd.ShutdownResponse + 10, // 21: pyrinwalletd.pyrinwalletd.Broadcast:output_type -> pyrinwalletd.BroadcastResponse + 20, // 22: pyrinwalletd.pyrinwalletd.Send:output_type -> pyrinwalletd.SendResponse + 22, // 23: pyrinwalletd.pyrinwalletd.Sign:output_type -> pyrinwalletd.SignResponse + 24, // 24: pyrinwalletd.pyrinwalletd.GetVersion:output_type -> pyrinwalletd.GetVersionResponse + 15, // [15:25] is the sub-list for method output_type + 5, // [5:15] is the sub-list for method input_type 5, // [5:5] is the sub-list for extension type_name 5, // [5:5] is the sub-list for extension extendee 0, // [0:5] is the sub-list for field type_name @@ -1780,6 +1879,30 @@ func file_pyrinwalletd_proto_init() { return nil } } + file_pyrinwalletd_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetVersionRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pyrinwalletd_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetVersionResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1787,7 +1910,7 @@ func file_pyrinwalletd_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_pyrinwalletd_proto_rawDesc, NumEnums: 0, - NumMessages: 23, + NumMessages: 25, NumExtensions: 0, NumServices: 1, }, diff --git a/cmd/pyrinwallet/daemon/pb/pyrinwalletd.proto b/cmd/pyrinwallet/daemon/pb/pyrinwalletd.proto index 744076ed3..4a3146b99 100644 --- a/cmd/pyrinwallet/daemon/pb/pyrinwalletd.proto +++ b/cmd/pyrinwallet/daemon/pb/pyrinwalletd.proto @@ -15,6 +15,7 @@ service pyrinwalletd { rpc Send(SendRequest) returns (SendResponse) {} // Since SignRequest contains a password - this command should only be used on a trusted or secure connection rpc Sign(SignRequest) returns (SignResponse) {} + rpc GetVersion(GetVersionRequest) returns (GetVersionResponse) {} } message GetBalanceRequest { @@ -127,3 +128,10 @@ message SignRequest{ message SignResponse{ repeated bytes signedTransactions = 1; } + +message GetVersionRequest{ +} + +message GetVersionResponse{ + string version = 1; +} diff --git a/cmd/pyrinwallet/daemon/pb/pyrinwalletd_grpc.pb.go b/cmd/pyrinwallet/daemon/pb/pyrinwalletd_grpc.pb.go index a2841d3af..07ee66648 100644 --- a/cmd/pyrinwallet/daemon/pb/pyrinwalletd_grpc.pb.go +++ b/cmd/pyrinwallet/daemon/pb/pyrinwalletd_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v3.12.3 +// - protoc v4.25.2 // source: pyrinwalletd.proto package pb @@ -33,6 +33,7 @@ type PyrinwalletdClient interface { Send(ctx context.Context, in *SendRequest, opts ...grpc.CallOption) (*SendResponse, error) // Since SignRequest contains a password - this command should only be used on a trusted or secure connection Sign(ctx context.Context, in *SignRequest, opts ...grpc.CallOption) (*SignResponse, error) + GetVersion(ctx context.Context, in *GetVersionRequest, opts ...grpc.CallOption) (*GetVersionResponse, error) } type pyrinwalletdClient struct { @@ -124,6 +125,15 @@ func (c *pyrinwalletdClient) Sign(ctx context.Context, in *SignRequest, opts ... return out, nil } +func (c *pyrinwalletdClient) GetVersion(ctx context.Context, in *GetVersionRequest, opts ...grpc.CallOption) (*GetVersionResponse, error) { + out := new(GetVersionResponse) + err := c.cc.Invoke(ctx, "/pyrinwalletd.pyrinwalletd/GetVersion", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // PyrinwalletdServer is the server API for Pyrinwalletd service. // All implementations must embed UnimplementedPyrinwalletdServer // for forward compatibility @@ -139,6 +149,7 @@ type PyrinwalletdServer interface { Send(context.Context, *SendRequest) (*SendResponse, error) // Since SignRequest contains a password - this command should only be used on a trusted or secure connection Sign(context.Context, *SignRequest) (*SignResponse, error) + GetVersion(context.Context, *GetVersionRequest) (*GetVersionResponse, error) mustEmbedUnimplementedPyrinwalletdServer() } @@ -173,6 +184,9 @@ func (UnimplementedPyrinwalletdServer) Send(context.Context, *SendRequest) (*Sen func (UnimplementedPyrinwalletdServer) Sign(context.Context, *SignRequest) (*SignResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Sign not implemented") } +func (UnimplementedPyrinwalletdServer) GetVersion(context.Context, *GetVersionRequest) (*GetVersionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetVersion not implemented") +} func (UnimplementedPyrinwalletdServer) mustEmbedUnimplementedPyrinwalletdServer() {} // UnsafePyrinwalletdServer may be embedded to opt out of forward compatibility for this service. @@ -348,6 +362,24 @@ func _Pyrinwalletd_Sign_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } +func _Pyrinwalletd_GetVersion_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetVersionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PyrinwalletdServer).GetVersion(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pyrinwalletd.pyrinwalletd/GetVersion", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PyrinwalletdServer).GetVersion(ctx, req.(*GetVersionRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Pyrinwalletd_ServiceDesc is the grpc.ServiceDesc for Pyrinwalletd service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -391,6 +423,10 @@ var Pyrinwalletd_ServiceDesc = grpc.ServiceDesc{ MethodName: "Sign", Handler: _Pyrinwalletd_Sign_Handler, }, + { + MethodName: "GetVersion", + Handler: _Pyrinwalletd_GetVersion_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "pyrinwalletd.proto", diff --git a/cmd/pyrinwallet/daemon/server/balance.go b/cmd/pyrinwallet/daemon/server/balance.go index 6cf5c4f48..a0481b1f0 100644 --- a/cmd/pyrinwallet/daemon/server/balance.go +++ b/cmd/pyrinwallet/daemon/server/balance.go @@ -2,6 +2,7 @@ package server import ( "context" + "github.com/pkg/errors" "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/pb" "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/libpyrinwallet" @@ -14,13 +15,15 @@ func (s *server) GetBalance(_ context.Context, _ *pb.GetBalanceRequest) (*pb.Get s.lock.RLock() defer s.lock.RUnlock() + if !s.isSynced() { + return nil, errors.Errorf("wallet daemon is not synced yet, %s", s.formatSyncStateReport()) + } + dagInfo, err := s.rpcClient.GetBlockDAGInfo() if err != nil { return nil, err } daaScore := dagInfo.VirtualDAAScore - maturity := s.params.BlockCoinbaseMaturity - balancesMap := make(balancesMapType, 0) for _, entry := range s.utxosSortedByAmount { amount := entry.UTXOEntry.Amount() @@ -30,7 +33,7 @@ func (s *server) GetBalance(_ context.Context, _ *pb.GetBalanceRequest) (*pb.Get balances = new(balancesType) balancesMap[address] = balances } - if isUTXOSpendable(entry, daaScore, maturity) { + if s.isUTXOSpendable(entry, daaScore) { balances.available += amount } else { balances.pending += amount @@ -55,6 +58,8 @@ func (s *server) GetBalance(_ context.Context, _ *pb.GetBalanceRequest) (*pb.Get pending += balances.pending } + log.Infof("GetBalance request scanned %d UTXOs overall over %d addresses", len(s.utxosSortedByAmount), len(balancesMap)) + return &pb.GetBalanceResponse{ Available: available, Pending: pending, @@ -62,9 +67,9 @@ func (s *server) GetBalance(_ context.Context, _ *pb.GetBalanceRequest) (*pb.Get }, nil } -func isUTXOSpendable(entry *walletUTXO, virtualDAAScore uint64, coinbaseMaturity uint64) bool { +func (s *server) isUTXOSpendable(entry *walletUTXO, virtualDAAScore uint64) bool { if !entry.UTXOEntry.IsCoinbase() { return true } - return entry.UTXOEntry.BlockDAAScore()+coinbaseMaturity < virtualDAAScore + return entry.UTXOEntry.BlockDAAScore()+s.coinbaseMaturity < virtualDAAScore } diff --git a/cmd/pyrinwallet/daemon/server/broadcast.go b/cmd/pyrinwallet/daemon/server/broadcast.go index f325ae710..d94b81f1b 100644 --- a/cmd/pyrinwallet/daemon/server/broadcast.go +++ b/cmd/pyrinwallet/daemon/server/broadcast.go @@ -7,6 +7,7 @@ import ( "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/libpyrinwallet" "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/libpyrinwallet/serialization" "github.com/Pyrinpyi/pyipad/domain/consensus/model/externalapi" + "github.com/Pyrinpyi/pyipad/domain/consensus/utils/consensushashing" "github.com/Pyrinpyi/pyipad/infrastructure/network/rpcclient" "github.com/pkg/errors" "time" @@ -54,16 +55,12 @@ func (s *server) broadcast(transactions [][]byte, isDomain bool) ([]string, erro } } - err = s.refreshUTXOs() - if err != nil { - return nil, err - } - + s.forceSync() return txIDs, nil } func sendTransaction(client *rpcclient.RPCClient, tx *externalapi.DomainTransaction) (string, error) { - submitTransactionResponse, err := client.SubmitTransaction(appmessage.DomainTransactionToRPCTransaction(tx), false) + submitTransactionResponse, err := client.SubmitTransaction(appmessage.DomainTransactionToRPCTransaction(tx), consensushashing.TransactionID(tx).String(), false) if err != nil { return "", errors.Wrapf(err, "error submitting transaction") } diff --git a/cmd/pyrinwallet/daemon/server/create_unsigned_transaction.go b/cmd/pyrinwallet/daemon/server/create_unsigned_transaction.go index 5bab084f0..01126e194 100644 --- a/cmd/pyrinwallet/daemon/server/create_unsigned_transaction.go +++ b/cmd/pyrinwallet/daemon/server/create_unsigned_transaction.go @@ -3,19 +3,21 @@ package server import ( "context" "fmt" - "time" - "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/pb" "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/libpyrinwallet" "github.com/Pyrinpyi/pyipad/domain/consensus/utils/constants" "github.com/Pyrinpyi/pyipad/util" "github.com/pkg/errors" - "golang.org/x/exp/slices" ) // TODO: Implement a better fee estimation mechanism const feePerInput = 10000 +// The minimal change amount to target in order to avoid large storage mass (see KIP9 for more details). +// By having at least 0.2KAS in the change output we make sure that every transaction with send value >= 0.2KAS +// should succeed (at most 50K storage mass for each output, thus overall lower than standard mass upper bound which is 100K gram) +const minChangeTarget = constants.LeorPerPyrin / 5 + func (s *server) CreateUnsignedTransactions(_ context.Context, request *pb.CreateUnsignedTransactionsRequest) ( *pb.CreateUnsignedTransactionsResponse, error, ) { @@ -43,11 +45,6 @@ func (s *server) createUnsignedTransactions(address string, amount uint64, isSen return nil, err } - err = s.refreshUTXOs() - if err != nil { - return nil, err - } - var fromAddresses []*walletAddress for _, from := range fromAddressesString { fromAddress, exists := s.addressSet[from] @@ -106,19 +103,14 @@ func (s *server) selectUTXOs(spendAmount uint64, isSendAll bool, feePerInput uin return nil, 0, 0, err } - coinbaseMaturity := s.params.BlockCoinbaseMaturity - if dagInfo.NetworkName == "pyrin-testnet-10" { - coinbaseMaturity = 1000 - } - for _, utxo := range s.utxosSortedByAmount { - if (fromAddresses != nil && !slices.Contains(fromAddresses, utxo.address)) || - !isUTXOSpendable(utxo, dagInfo.VirtualDAAScore, coinbaseMaturity) { + if (fromAddresses != nil && !walletAddressesContain(fromAddresses, utxo.address)) || + !s.isUTXOSpendable(utxo, dagInfo.VirtualDAAScore) { continue } if broadcastTime, ok := s.usedOutpoints[*utxo.Outpoint]; ok { - if time.Since(broadcastTime) > time.Minute { + if s.usedOutpointHasExpired(broadcastTime) { delete(s.usedOutpoints, *utxo.Outpoint) } else { continue @@ -135,7 +127,12 @@ func (s *server) selectUTXOs(spendAmount uint64, isSendAll bool, feePerInput uin fee := feePerInput * uint64(len(selectedUTXOs)) totalSpend := spendAmount + fee - if !isSendAll && totalValue >= totalSpend { + // Two break cases (if not send all): + // 1. totalValue == totalSpend, so there's no change needed -> number of outputs = 1, so a single input is sufficient + // 2. totalValue > totalSpend, so there will be change and 2 outputs, therefor in order to not struggle with -- + // 2.1 go-nodes dust patch we try and find at least 2 inputs (even though the next one is not necessary in terms of spend value) + // 2.2 KIP9 we try and make sure that the change amount is not too small + if !isSendAll && (totalValue == totalSpend || (totalValue >= totalSpend+minChangeTarget && len(selectedUTXOs) > 1)) { break } } @@ -156,3 +153,13 @@ func (s *server) selectUTXOs(spendAmount uint64, isSendAll bool, feePerInput uin return selectedUTXOs, totalReceived, totalValue - totalSpend, nil } + +func walletAddressesContain(addresses []*walletAddress, contain *walletAddress) bool { + for _, address := range addresses { + if *address == *contain { + return true + } + } + + return false +} diff --git a/cmd/pyrinwallet/daemon/server/server.go b/cmd/pyrinwallet/daemon/server/server.go index 7379ace52..34cd4fe4a 100644 --- a/cmd/pyrinwallet/daemon/server/server.go +++ b/cmd/pyrinwallet/daemon/server/server.go @@ -2,9 +2,11 @@ package server import ( "fmt" + "github.com/Pyrinpyi/pyipad/version" "net" "os" "sync" + "sync/atomic" "time" "github.com/Pyrinpyi/pyipad/domain/consensus/model/externalapi" @@ -27,17 +29,22 @@ import ( type server struct { pb.UnimplementedPyrinwalletdServer - rpcClient *rpcclient.RPCClient - params *dagconfig.Params - - lock sync.RWMutex - utxosSortedByAmount []*walletUTXO - nextSyncStartIndex uint32 - keysFile *keys.File - shutdown chan struct{} - addressSet walletAddressSet - txMassCalculator *txmass.Calculator - usedOutpoints map[externalapi.DomainOutpoint]time.Time + rpcClient *rpcclient.RPCClient // RPC client for ongoing user requests + backgroundRPCClient *rpcclient.RPCClient // RPC client dedicated for address and UTXO background fetching + params *dagconfig.Params + coinbaseMaturity uint64 // Is different from default if we use testnet-11 + + lock sync.RWMutex + utxosSortedByAmount []*walletUTXO + nextSyncStartIndex uint32 + keysFile *keys.File + shutdown chan struct{} + forceSyncChan chan struct{} + startTimeOfLastCompletedRefresh time.Time + addressSet walletAddressSet + txMassCalculator *txmass.Calculator + usedOutpoints map[externalapi.DomainOutpoint]time.Time + firstSyncDone atomic.Bool isLogFinalProgressLineShown bool maxUsedAddressesForLog uint32 @@ -59,6 +66,7 @@ func Start(params *dagconfig.Params, listen, rpcServer string, keysFilePath stri profiling.Start(profile, log) } + log.Infof("Version %s", version.Version()) listener, err := net.Listen("tcp", listen) if err != nil { return (errors.Wrapf(err, "Error listening to TCP on %s", listen)) @@ -70,6 +78,10 @@ func Start(params *dagconfig.Params, listen, rpcServer string, keysFilePath stri if err != nil { return (errors.Wrapf(err, "Error connecting to RPC server %s", rpcServer)) } + backgroundRPCClient, err := connectToRPC(params, rpcServer, timeout) + if err != nil { + return (errors.Wrapf(err, "Error making a second connection to RPC server %s", rpcServer)) + } log.Infof("Connected, reading keys file %s...", keysFilePath) keysFile, err := keys.ReadKeysFile(params, keysFilePath) @@ -82,13 +94,26 @@ func Start(params *dagconfig.Params, listen, rpcServer string, keysFilePath stri return err } + dagInfo, err := rpcClient.GetBlockDAGInfo() + if err != nil { + return nil + } + + coinbaseMaturity := params.BlockCoinbaseMaturity + if dagInfo.NetworkName == "kaspa-testnet-11" { + coinbaseMaturity = 1000 + } + serverInstance := &server{ rpcClient: rpcClient, + backgroundRPCClient: backgroundRPCClient, params: params, + coinbaseMaturity: coinbaseMaturity, utxosSortedByAmount: []*walletUTXO{}, nextSyncStartIndex: 0, keysFile: keysFile, shutdown: make(chan struct{}), + forceSyncChan: make(chan struct{}), addressSet: make(walletAddressSet), txMassCalculator: txmass.NewCalculator(params.MassPerTxByte, params.MassPerScriptPubKeyByte, params.MassPerSigOp), usedOutpoints: map[externalapi.DomainOutpoint]time.Time{}, @@ -98,8 +123,8 @@ func Start(params *dagconfig.Params, listen, rpcServer string, keysFilePath stri } log.Infof("Read, syncing the wallet...") - spawn("serverInstance.sync", func() { - err := serverInstance.sync() + spawn("serverInstance.syncLoop", func() { + err := serverInstance.syncLoop() if err != nil { printErrorAndExit(errors.Wrap(err, "error syncing the wallet")) } diff --git a/cmd/pyrinwallet/daemon/server/split_transaction.go b/cmd/pyrinwallet/daemon/server/split_transaction.go index c049a6573..65a16b988 100644 --- a/cmd/pyrinwallet/daemon/server/split_transaction.go +++ b/cmd/pyrinwallet/daemon/server/split_transaction.go @@ -264,7 +264,7 @@ func (s *server) moreUTXOsForMergeTransaction(alreadySelectedUTXOs []*libpyrinwa if _, ok := alreadySelectedUTXOsMap[*utxo.Outpoint]; ok { continue } - if !isUTXOSpendable(utxo, dagInfo.VirtualDAAScore, s.params.BlockCoinbaseMaturity) { + if !s.isUTXOSpendable(utxo, dagInfo.VirtualDAAScore) { continue } additionalUTXOs = append(additionalUTXOs, &libpyrinwallet.UTXO{ diff --git a/cmd/pyrinwallet/daemon/server/sync.go b/cmd/pyrinwallet/daemon/server/sync.go index f00f6da45..51e240d43 100644 --- a/cmd/pyrinwallet/daemon/server/sync.go +++ b/cmd/pyrinwallet/daemon/server/sync.go @@ -23,7 +23,7 @@ func (was walletAddressSet) strings() []string { return addresses } -func (s *server) sync() error { +func (s *server) syncLoop() error { ticker := time.NewTicker(time.Second) defer ticker.Stop() @@ -32,29 +32,39 @@ func (s *server) sync() error { return err } - err = s.refreshExistingUTXOsWithLock() + err = s.refreshUTXOs() if err != nil { return err } - for range ticker.C { - err = s.collectFarAddresses() - if err != nil { - return err - } + s.firstSyncDone.Store(true) + log.Infof("Wallet is synced and ready for operation") - err = s.collectRecentAddresses() - if err != nil { - return err + for { + select { + case <-ticker.C: + case <-s.forceSyncChan: } - err = s.refreshExistingUTXOsWithLock() + err := s.sync() if err != nil { return err } } +} - return nil +func (s *server) sync() error { + err := s.collectFarAddresses() + if err != nil { + return err + } + + err = s.collectRecentAddresses() + if err != nil { + return err + } + + return s.refreshUTXOs() } const ( @@ -158,7 +168,7 @@ func (s *server) collectAddresses(start, end uint32) error { return err } - getBalancesByAddressesResponse, err := s.rpcClient.GetBalancesByAddresses(addressSet.strings()) + getBalancesByAddressesResponse, err := s.backgroundRPCClient.GetBalancesByAddresses(addressSet.strings()) if err != nil { return err } @@ -208,15 +218,17 @@ func (s *server) updateAddressesAndLastUsedIndexes(requestedAddressSet walletAdd return s.keysFile.SetLastUsedInternalIndex(lastUsedInternalIndex) } -func (s *server) refreshExistingUTXOsWithLock() error { - s.lock.Lock() - defer s.lock.Unlock() - - return s.refreshUTXOs() +func (s *server) usedOutpointHasExpired(outpointBroadcastTime time.Time) bool { + // If the node returns a UTXO we previously attempted to spend and enough time has passed, we assume + // that the network rejected or lost the previous transaction and allow a reuse. We set this time + // interval to a minute. + // We also verify that a full refresh UTXO operation started after this time point and has already + // completed, in order to make sure that indeed this state reflects a state obtained following the required wait time. + return s.startTimeOfLastCompletedRefresh.After(outpointBroadcastTime.Add(time.Minute)) } // updateUTXOSet clears the current UTXO set, and re-fills it with the given entries -func (s *server) updateUTXOSet(entries []*appmessage.UTXOsByAddressesEntry, mempoolEntries []*appmessage.MempoolEntryByAddress) error { +func (s *server) updateUTXOSet(entries []*appmessage.UTXOsByAddressesEntry, mempoolEntries []*appmessage.MempoolEntryByAddress, refreshStart time.Time) error { utxos := make([]*walletUTXO, 0, len(entries)) exclude := make(map[appmessage.RPCOutpoint]struct{}) @@ -243,6 +255,7 @@ func (s *server) updateUTXOSet(entries []*appmessage.UTXOsByAddressesEntry, memp return err } + // No need to lock for reading since the only writer of this set is on `syncLoop` on the same goroutine. address, ok := s.addressSet[entry.Address] if !ok { return errors.Errorf("Got result from address %s even though it wasn't requested", entry.Address) @@ -256,32 +269,56 @@ func (s *server) updateUTXOSet(entries []*appmessage.UTXOsByAddressesEntry, memp sort.Slice(utxos, func(i, j int) bool { return utxos[i].UTXOEntry.Amount() > utxos[j].UTXOEntry.Amount() }) + s.lock.Lock() + s.startTimeOfLastCompletedRefresh = refreshStart s.utxosSortedByAmount = utxos + // Cleanup expired used outpoints to avoid a memory leak + for outpoint, broadcastTime := range s.usedOutpoints { + if s.usedOutpointHasExpired(broadcastTime) { + delete(s.usedOutpoints, outpoint) + } + } + s.lock.Unlock() + return nil } func (s *server) refreshUTXOs() error { + refreshStart := time.Now() + + // No need to lock for reading since the only writer of this set is on `syncLoop` on the same goroutine. + addresses := s.addressSet.strings() // It's important to check the mempool before calling `GetUTXOsByAddresses`: // If we would do it the other way around an output can be spent in the mempool // and not in consensus, and between the calls its spending transaction will be // added to consensus and removed from the mempool, so `getUTXOsByAddressesResponse` // will include an obsolete output. - mempoolEntriesByAddresses, err := s.rpcClient.GetMempoolEntriesByAddresses(s.addressSet.strings(), true, true) + mempoolEntriesByAddresses, err := s.backgroundRPCClient.GetMempoolEntriesByAddresses(addresses, true, true) if err != nil { return err } - getUTXOsByAddressesResponse, err := s.rpcClient.GetUTXOsByAddresses(s.addressSet.strings()) + getUTXOsByAddressesResponse, err := s.backgroundRPCClient.GetUTXOsByAddresses(addresses) if err != nil { return err } - return s.updateUTXOSet(getUTXOsByAddressesResponse.Entries, mempoolEntriesByAddresses.Entries) + return s.updateUTXOSet(getUTXOsByAddressesResponse.Entries, mempoolEntriesByAddresses.Entries, refreshStart) +} + +func (s *server) forceSync() { + // Technically if two callers check the `if` simultaneously they will both spawn a + // goroutine, but we don't care about the small redundancy in such a rare case. + if len(s.forceSyncChan) == 0 { + go func() { + s.forceSyncChan <- struct{}{} + }() + } } func (s *server) isSynced() bool { - return s.nextSyncStartIndex > s.maxUsedIndex() + return s.nextSyncStartIndex > s.maxUsedIndex() && s.firstSyncDone.Load() } func (s *server) formatSyncStateReport() string { @@ -291,8 +328,11 @@ func (s *server) formatSyncStateReport() string { maxUsedIndex = s.nextSyncStartIndex } - return fmt.Sprintf("scanned %d out of %d addresses (%.2f%%)", - s.nextSyncStartIndex, maxUsedIndex, float64(s.nextSyncStartIndex)*100.0/float64(maxUsedIndex)) + if s.nextSyncStartIndex < s.maxUsedIndex() { + return fmt.Sprintf("scanned %d out of %d addresses (%.2f%%)", + s.nextSyncStartIndex, maxUsedIndex, float64(s.nextSyncStartIndex)*100.0/float64(maxUsedIndex)) + } + return "loading the wallet UTXO set" } func (s *server) updateSyncingProgressLog(currProcessedAddresses, currMaxUsedAddresses uint32) { @@ -311,7 +351,7 @@ func (s *server) updateSyncingProgressLog(currProcessedAddresses, currMaxUsedAdd if s.maxProcessedAddressesForLog >= s.maxUsedAddressesForLog { if !s.isLogFinalProgressLineShown { - log.Infof("Wallet is synced, ready for queries") + log.Infof("Finished scanning recent addresses") s.isLogFinalProgressLineShown = true } } else { diff --git a/cmd/pyrinwallet/daemon/server/version.go b/cmd/pyrinwallet/daemon/server/version.go new file mode 100644 index 000000000..c0db9bff0 --- /dev/null +++ b/cmd/pyrinwallet/daemon/server/version.go @@ -0,0 +1,16 @@ +package server + +import ( + "context" + "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/pb" + "github.com/Pyrinpyi/pyipad/version" +) + +func (s *server) GetVersion(_ context.Context, _ *pb.GetVersionRequest) (*pb.GetVersionResponse, error) { + s.lock.RLock() + defer s.lock.RUnlock() + + return &pb.GetVersionResponse{ + Version: version.Version(), + }, nil +} diff --git a/cmd/pyrinwallet/get_daemon_version.go b/cmd/pyrinwallet/get_daemon_version.go new file mode 100644 index 000000000..6e9cf48b6 --- /dev/null +++ b/cmd/pyrinwallet/get_daemon_version.go @@ -0,0 +1,26 @@ +package main + +import ( + "context" + "fmt" + "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/client" + "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/pb" +) + +func getDaemonVersion(conf *getDaemonVersionConfig) error { + daemonClient, tearDown, err := client.Connect(conf.DaemonAddress) + if err != nil { + return err + } + defer tearDown() + + ctx, cancel := context.WithTimeout(context.Background(), daemonTimeout) + defer cancel() + response, err := daemonClient.GetVersion(ctx, &pb.GetVersionRequest{}) + if err != nil { + return err + } + fmt.Println(response.Version) + + return nil +} diff --git a/cmd/pyrinwallet/main.go b/cmd/pyrinwallet/main.go index 48995925b..afe44cadc 100644 --- a/cmd/pyrinwallet/main.go +++ b/cmd/pyrinwallet/main.go @@ -1,10 +1,11 @@ package main -import "github.com/pkg/errors" +import ( + "github.com/pkg/errors" +) func main() { subCmd, config := parseCommandLine() - var err error switch subCmd { case createSubCmd: @@ -31,6 +32,10 @@ func main() { err = startDaemon(config.(*startDaemonConfig)) case sweepSubCmd: err = sweep(config.(*sweepConfig)) + case versionSubCmd: + showVersion() + case getDaemonVersionSubCmd: + err = getDaemonVersion(config.(*getDaemonVersionConfig)) default: err = errors.Errorf("Unknown sub-command '%s'\n", subCmd) } diff --git a/cmd/pyrinwallet/send.go b/cmd/pyrinwallet/send.go index 36f059f8e..52d331b04 100644 --- a/cmd/pyrinwallet/send.go +++ b/cmd/pyrinwallet/send.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/utils" "os" "strings" @@ -10,7 +11,6 @@ import ( "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/daemon/pb" "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/keys" "github.com/Pyrinpyi/pyipad/cmd/pyrinwallet/libpyrinwallet" - "github.com/Pyrinpyi/pyipad/domain/consensus/utils/constants" "github.com/pkg/errors" ) @@ -35,7 +35,11 @@ func send(conf *sendConfig) error { var sendAmountLeor uint64 if !conf.IsSendAll { - sendAmountLeor = uint64(conf.SendAmount * constants.LeorPerPyrin) + sendAmountLeor, err = utils.PyiToLeor(conf.SendAmount) + + if err != nil { + return err + } } createUnsignedTransactionsResponse, err := @@ -71,23 +75,29 @@ func send(conf *sendConfig) error { signedTransactions[i] = signedTransaction } - if len(signedTransactions) > 1 { - fmt.Printf("Broadcasting %d transactions\n", len(signedTransactions)) - } - + fmt.Printf("Broadcasting %d transaction(s)\n", len(signedTransactions)) // Since we waited for user input when getting the password, which could take unbound amount of time - // create a new context for broadcast, to reset the timeout. broadcastCtx, broadcastCancel := context.WithTimeout(context.Background(), daemonTimeout) defer broadcastCancel() - response, err := daemonClient.Broadcast(broadcastCtx, &pb.BroadcastRequest{Transactions: signedTransactions}) - if err != nil { - return err - } - fmt.Println("Transactions were sent successfully") - fmt.Println("Transaction ID(s): ") - for _, txID := range response.TxIDs { - fmt.Printf("\t%s\n", txID) + const chunkSize = 100 // To avoid sending a message bigger than the gRPC max message size, we split it to chunks + for offset := 0; offset < len(signedTransactions); offset += chunkSize { + end := len(signedTransactions) + if offset+chunkSize <= len(signedTransactions) { + end = offset + chunkSize + } + + chunk := signedTransactions[offset:end] + response, err := daemonClient.Broadcast(broadcastCtx, &pb.BroadcastRequest{Transactions: chunk}) + if err != nil { + return err + } + fmt.Printf("Broadcasted %d transaction(s) (broadcasted %.2f%% of the transactions so far)\n", len(chunk), 100*float64(end)/float64(len(signedTransactions))) + fmt.Println("Broadcasted Transaction ID(s): ") + for _, txID := range response.TxIDs { + fmt.Printf("\t%s\n", txID) + } } if conf.Verbose { diff --git a/cmd/pyrinwallet/sweep.go b/cmd/pyrinwallet/sweep.go index 389db2756..0c74e5c56 100644 --- a/cmd/pyrinwallet/sweep.go +++ b/cmd/pyrinwallet/sweep.go @@ -116,12 +116,12 @@ func sweep(conf *sweepConfig) error { fmt.Println("\nTransaction ID(s):") for i, txID := range response.TxIDs { fmt.Printf("\t%s\n", txID) - fmt.Println("\tSwept:\t", utils.FormatKas(splitTransactions[i].Outputs[0].Value), " PYI") + fmt.Println("\tSwept:\t", utils.FormatPyi(splitTransactions[i].Outputs[0].Value), " PYI") totalExtracted = totalExtracted + splitTransactions[i].Outputs[0].Value } fmt.Println("\nTotal Funds swept (including transaction fees):") - fmt.Println("\t", utils.FormatKas(totalExtracted), " PYI") + fmt.Println("\t", utils.FormatPyi(totalExtracted), " PYI") return nil } diff --git a/cmd/pyrinwallet/utils/format_kas.go b/cmd/pyrinwallet/utils/format_kas.go index 92e9b27a3..18b69f901 100644 --- a/cmd/pyrinwallet/utils/format_kas.go +++ b/cmd/pyrinwallet/utils/format_kas.go @@ -2,15 +2,67 @@ package utils import ( "fmt" + "math" + "regexp" + "strconv" + "strings" "github.com/Pyrinpyi/pyipad/domain/consensus/utils/constants" + "github.com/pkg/errors" ) -// FormatKas takes the amount of leors as uint64, and returns amount of PYI with 8 decimal places -func FormatKas(amount uint64) string { +// FormatPyi takes the amount of leors as uint64, and returns amount of PYI with 8 decimal places +func FormatPyi(amount uint64) string { res := " " if amount > 0 { res = fmt.Sprintf("%19.8f", float64(amount)/constants.LeorPerPyrin) } return res } + +// PyiToLeor takes in a string representation of the Kas value to convert to Sompi +func PyiToLeor(amount string) (uint64, error) { + err := validateKASAmountFormat(amount) + + if err != nil { + return 0, err + } + + // after validation, amount can only be either an int OR + // a float with an int component and decimal places + parts := strings.Split(amount, ".") + amountStr := "" + + if constants.LeorPerPyrin%10 != 0 { + return 0, errors.Errorf("Unable to convert to leor when LeorPerPyrin is not a multiple of 10") + } + + decimalPlaces := int(math.Log10(constants.LeorPerPyrin)) + decimalStr := "" + + if len(parts) == 2 { + decimalStr = parts[1] + } + + amountStr = fmt.Sprintf("%s%-*s", parts[0], decimalPlaces, decimalStr) // Padded with spaces at the end to fill for missing decimals: Sample "0.01234 " + amountStr = strings.ReplaceAll(amountStr, " ", "0") // Make the spaces be 0s. Sample "0.012340000" + + convertedAmount, err := strconv.ParseUint(amountStr, 10, 64) + + return convertedAmount, err +} + +func validateKASAmountFormat(amount string) error { + // Check whether it's an integer, or a float with max 8 digits + match, err := regexp.MatchString("^([1-9]\\d{0,11}|0)(\\.\\d{0,8})?$", amount) + + if !match { + return errors.Errorf("Invalid amount") + } + + if err != nil { + return err + } + + return nil +} diff --git a/cmd/pyrinwallet/version.go b/cmd/pyrinwallet/version.go new file mode 100644 index 000000000..c7b20060d --- /dev/null +++ b/cmd/pyrinwallet/version.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "github.com/Pyrinpyi/pyipad/version" + "os" + "path/filepath" + "strings" +) + +func showVersion() { + appName := filepath.Base(os.Args[0]) + appName = strings.TrimSuffix(appName, filepath.Ext(appName)) + fmt.Println(appName, "version", version.Version()) +} diff --git a/infrastructure/network/rpcclient/rpc_send_raw_transaction.go b/infrastructure/network/rpcclient/rpc_send_raw_transaction.go index b958a0e41..f3e8d2509 100644 --- a/infrastructure/network/rpcclient/rpc_send_raw_transaction.go +++ b/infrastructure/network/rpcclient/rpc_send_raw_transaction.go @@ -1,23 +1,44 @@ package rpcclient import ( + "strings" + "github.com/Pyrinpyi/pyipad/app/appmessage" ) // SubmitTransaction sends an RPC request respective to the function's name and returns the RPC server's response -func (c *RPCClient) SubmitTransaction(transaction *appmessage.RPCTransaction, allowOrphan bool) (*appmessage.SubmitTransactionResponseMessage, error) { +func (c *RPCClient) SubmitTransaction(transaction *appmessage.RPCTransaction, transactionID string, allowOrphan bool) (*appmessage.SubmitTransactionResponseMessage, error) { err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewSubmitTransactionRequestMessage(transaction, allowOrphan)) if err != nil { return nil, err } - response, err := c.route(appmessage.CmdSubmitTransactionResponseMessage).DequeueWithTimeout(c.timeout) - if err != nil { - return nil, err - } - submitTransactionResponse := response.(*appmessage.SubmitTransactionResponseMessage) - if submitTransactionResponse.Error != nil { - return nil, c.convertRPCError(submitTransactionResponse.Error) - } + for { + response, err := c.route(appmessage.CmdSubmitTransactionResponseMessage).DequeueWithTimeout(c.timeout) + if err != nil { + return nil, err + } + submitTransactionResponse := response.(*appmessage.SubmitTransactionResponseMessage) + // Match the response to the expected ID. If they are different it means we got an old response which we + // previously timed-out on, so we log and continue waiting for the correct current response. + if submitTransactionResponse.TransactionID != transactionID { + if submitTransactionResponse.Error != nil { + // A non-updated Kaspad might return an empty ID in the case of error, so in + // such a case we fallback to checking if the error contains the expected ID + if submitTransactionResponse.TransactionID != "" || !strings.Contains(submitTransactionResponse.Error.Message, transactionID) { + log.Warnf("SubmitTransaction: received an error response for previous request: %s", submitTransactionResponse.Error) + continue + } + + } else { + log.Warnf("SubmitTransaction: received a successful response for previous request with ID %s", + submitTransactionResponse.TransactionID) + continue + } + } + if submitTransactionResponse.Error != nil { + return nil, c.convertRPCError(submitTransactionResponse.Error) + } - return submitTransactionResponse, nil + return submitTransactionResponse, nil + } } diff --git a/stability-tests/mempool-limits/transactions.go b/stability-tests/mempool-limits/transactions.go index b614202d1..524d58eaa 100644 --- a/stability-tests/mempool-limits/transactions.go +++ b/stability-tests/mempool-limits/transactions.go @@ -86,7 +86,7 @@ func submitAnAmountOfTransactionsToTheMempool(t *testing.T, rpcClient *rpcclient for i, transaction := range transactions { rpcTransaction := appmessage.DomainTransactionToRPCTransaction(transaction) - _, err := rpcClient.SubmitTransaction(rpcTransaction, false) + _, err := rpcClient.SubmitTransaction(rpcTransaction, consensushashing.TransactionID(transaction).String(), false) if err != nil { if ignoreOrphanRejects && strings.Contains(err.Error(), "orphan") { continue diff --git a/testing/integration/tx_relay_test.go b/testing/integration/tx_relay_test.go index 892df0238..1d8eb5de4 100644 --- a/testing/integration/tx_relay_test.go +++ b/testing/integration/tx_relay_test.go @@ -53,7 +53,7 @@ func TestTxRelay(t *testing.T) { msgTx := generateTx(t, secondBlock.Transactions[transactionhelper.CoinbaseTransactionIndex], payer, payee) domainTransaction := appmessage.MsgTxToDomainTransaction(msgTx) rpcTransaction := appmessage.DomainTransactionToRPCTransaction(domainTransaction) - response, err := payer.rpcClient.SubmitTransaction(rpcTransaction, false) + response, err := payer.rpcClient.SubmitTransaction(rpcTransaction, consensushashing.TransactionID(domainTransaction).String(), false) if err != nil { t.Fatalf("Error submitting transaction: %+v", err) }