mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 22:26:47 +00:00
Wallet parse/send/create commands improvement (#2024)
* Fix wallet parsing of multi tx data * Output wallet msgs to stderr when creating/signing tx * Fix go fmt Co-authored-by: Ori Newman <orinewman1@gmail.com>
This commit is contained in:
parent
b200b77541
commit
24848da895
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
|
||||||
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
|
||||||
@ -29,7 +30,8 @@ func createUnsignedTransaction(conf *createUnsignedTransactionConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Created unsigned transaction")
|
fmt.Fprintln(os.Stderr, "Created unsigned transaction")
|
||||||
fmt.Println(encodeTransactionsToHex(response.UnsignedTransactions))
|
fmt.Println(encodeTransactionsToHex(response.UnsignedTransactions))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -29,55 +29,57 @@ func parse(conf *parseConfig) error {
|
|||||||
transactionHex = strings.TrimSpace(string(transactionHexBytes))
|
transactionHex = strings.TrimSpace(string(transactionHexBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction, err := hex.DecodeString(transactionHex)
|
transactions, err := decodeTransactionsFromHex(transactionHex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
for i, transaction := range transactions {
|
||||||
|
|
||||||
partiallySignedTransaction, err := serialization.DeserializePartiallySignedTransaction(transaction)
|
partiallySignedTransaction, err := serialization.DeserializePartiallySignedTransaction(transaction)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Transaction ID: \t%s\n", consensushashing.TransactionID(partiallySignedTransaction.Tx))
|
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
allInputSompi := uint64(0)
|
|
||||||
for index, input := range partiallySignedTransaction.Tx.Inputs {
|
|
||||||
partiallySignedInput := partiallySignedTransaction.PartiallySignedInputs[index]
|
|
||||||
|
|
||||||
if conf.Verbose {
|
|
||||||
fmt.Printf("Input %d: \tOutpoint: %s:%d \tAmount: %.2f Kaspa\n", index, input.PreviousOutpoint.TransactionID,
|
|
||||||
input.PreviousOutpoint.Index, float64(partiallySignedInput.PrevOutput.Value)/float64(constants.SompiPerKaspa))
|
|
||||||
}
|
|
||||||
|
|
||||||
allInputSompi += partiallySignedInput.PrevOutput.Value
|
|
||||||
}
|
|
||||||
if conf.Verbose {
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
||||||
allOutputSompi := uint64(0)
|
|
||||||
for index, output := range partiallySignedTransaction.Tx.Outputs {
|
|
||||||
scriptPublicKeyType, scriptPublicKeyAddress, err := txscript.ExtractScriptPubKeyAddress(output.ScriptPublicKey, conf.ActiveNetParams)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
addressString := scriptPublicKeyAddress.EncodeAddress()
|
fmt.Printf("Transaction #%d ID: \t%s\n", i+1, consensushashing.TransactionID(partiallySignedTransaction.Tx))
|
||||||
if scriptPublicKeyType == txscript.NonStandardTy {
|
fmt.Println()
|
||||||
scriptPublicKeyHex := hex.EncodeToString(output.ScriptPublicKey.Script)
|
|
||||||
addressString = fmt.Sprintf("<Non-standard transaction script public key: %s>", scriptPublicKeyHex)
|
allInputSompi := uint64(0)
|
||||||
|
for index, input := range partiallySignedTransaction.Tx.Inputs {
|
||||||
|
partiallySignedInput := partiallySignedTransaction.PartiallySignedInputs[index]
|
||||||
|
|
||||||
|
if conf.Verbose {
|
||||||
|
fmt.Printf("Input %d: \tOutpoint: %s:%d \tAmount: %.2f Kaspa\n", index, input.PreviousOutpoint.TransactionID,
|
||||||
|
input.PreviousOutpoint.Index, float64(partiallySignedInput.PrevOutput.Value)/float64(constants.SompiPerKaspa))
|
||||||
|
}
|
||||||
|
|
||||||
|
allInputSompi += partiallySignedInput.PrevOutput.Value
|
||||||
|
}
|
||||||
|
if conf.Verbose {
|
||||||
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Output %d: \tRecipient: %s \tAmount: %.2f Kaspa\n",
|
allOutputSompi := uint64(0)
|
||||||
index, addressString, float64(output.Value)/float64(constants.SompiPerKaspa))
|
for index, output := range partiallySignedTransaction.Tx.Outputs {
|
||||||
|
scriptPublicKeyType, scriptPublicKeyAddress, err := txscript.ExtractScriptPubKeyAddress(output.ScriptPublicKey, conf.ActiveNetParams)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
allOutputSompi += output.Value
|
addressString := scriptPublicKeyAddress.EncodeAddress()
|
||||||
|
if scriptPublicKeyType == txscript.NonStandardTy {
|
||||||
|
scriptPublicKeyHex := hex.EncodeToString(output.ScriptPublicKey.Script)
|
||||||
|
addressString = fmt.Sprintf("<Non-standard transaction script public key: %s>", scriptPublicKeyHex)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Output %d: \tRecipient: %s \tAmount: %.2f Kaspa\n",
|
||||||
|
index, addressString, float64(output.Value)/float64(constants.SompiPerKaspa))
|
||||||
|
|
||||||
|
allOutputSompi += output.Value
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Printf("Fee:\t%d Sompi\n\n", allInputSompi-allOutputSompi)
|
||||||
}
|
}
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
fmt.Printf("Fee:\t%d Sompi\n", allInputSompi-allOutputSompi)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/cmd/kaspawallet/keys"
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/keys"
|
||||||
@ -66,12 +67,11 @@ func sign(conf *signConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if areAllTransactionsFullySigned {
|
if areAllTransactionsFullySigned {
|
||||||
fmt.Println("The transaction is signed and ready to broadcast")
|
fmt.Fprintln(os.Stderr, "The transaction is signed and ready to broadcast")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Successfully signed transaction")
|
fmt.Fprintln(os.Stderr, "Successfully signed transaction")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Transaction: ")
|
|
||||||
fmt.Println(encodeTransactionsToHex(updatedPartiallySignedTransactions))
|
fmt.Println(encodeTransactionsToHex(updatedPartiallySignedTransactions))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user