mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* Copy over the CLI wallet from Kasparov. * Fix trivial compilation errors. * Reimplement the balance command. * Extract isUTXOSpendable to a separate function. * Reimplement the send command. * Fix bad transaction ID parsing. * Add a missing newline in a log. * Don't use msgTx in send(). * Fix isUTXOSpendable not checking whether a UTXO is of a coinbase transaction. * Add --devnet, --testnet, etc. to command line flags. * In `create`, only print the public key of the active network. * Use coinbase maturity in isUTXOSpendable. * Add a readme. * Fix formatting in readme.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/rpcclient"
|
|
|
|
"github.com/kaspanet/kaspad/util"
|
|
)
|
|
|
|
func balance(conf *balanceConfig) error {
|
|
client, err := rpcclient.NewRPCClient(conf.RPCServer)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
getUTXOsByAddressesResponse, err := client.GetUTXOsByAddresses([]string{conf.Address})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
virtualSelectedParentBlueScoreResponse, err := client.GetVirtualSelectedParentBlueScore()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
virtualSelectedParentBlueScore := virtualSelectedParentBlueScoreResponse.BlueScore
|
|
|
|
var availableBalance, pendingBalance uint64
|
|
for _, entry := range getUTXOsByAddressesResponse.Entries {
|
|
if isUTXOSpendable(entry, virtualSelectedParentBlueScore, conf.ActiveNetParams.BlockCoinbaseMaturity) {
|
|
availableBalance += entry.UTXOEntry.Amount
|
|
} else {
|
|
pendingBalance += entry.UTXOEntry.Amount
|
|
}
|
|
}
|
|
|
|
fmt.Printf("Balance:\t\tKAS %f\n", float64(availableBalance)/util.SompiPerKaspa)
|
|
if pendingBalance > 0 {
|
|
fmt.Printf("Pending balance:\tKAS %f\n", float64(pendingBalance)/util.SompiPerKaspa)
|
|
}
|
|
|
|
return nil
|
|
}
|