From 9ab209ded6ee6d9e279d99c96139903efc71226d Mon Sep 17 00:00:00 2001 From: Captain Dero Date: Thu, 7 Mar 2019 19:08:54 +0100 Subject: [PATCH] 2.1.6-1.alpha.atlantis+07032019. Minor fixes in rpc api for exchange,remote node option added in wallet. --- build_package.sh | 10 ++++++++ cmd/dero-wallet-cli/main.go | 6 +++-- cmd/derod/main.go | 17 +++++++++++- config/config.go | 4 +++ config/version.go | 2 +- structures/wallet_rpc.go | 2 +- walletapi/daemon_communication.go | 4 +++ walletapi/rpc_get_transfer_by_txid.go | 29 +++++++++++++++++---- walletapi/wallet.go | 37 +++++++++++++++++++-------- 9 files changed, 91 insertions(+), 20 deletions(-) diff --git a/build_package.sh b/build_package.sh index 3c3f2f1..9c7ebbc 100644 --- a/build_package.sh +++ b/build_package.sh @@ -47,6 +47,16 @@ echo mkdir -p $OUTPUT_DIR CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -o $OUTPUT_DIR/${BIN_FILENAME} $package" echo "${CMD}" eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" + + # build docker image for linux amd64 competely static + if [[ "${GOOS}" == "linux" && "${GOARCH}" == "amd64" && "${OUTPUT}" != "explorer" ]]; then + BIN_FILENAME="docker-${OUTPUT}-${GOOS}-${GOARCH}" + CMD="GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -o $OUTPUT_DIR/${BIN_FILENAME} $package" + echo "${CMD}" + eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" + fi + + done # ARM64 builds only for linux diff --git a/cmd/dero-wallet-cli/main.go b/cmd/dero-wallet-cli/main.go index 1b4dee1..89116eb 100644 --- a/cmd/dero-wallet-cli/main.go +++ b/cmd/dero-wallet-cli/main.go @@ -72,7 +72,8 @@ Usage: --restore-deterministic-wallet Restore wallet from previously saved recovery seed --electrum-seed= Seed to use while restoring wallet --socks-proxy= Use a proxy to connect to Daemon. - --daemon-address= Use daemon instance at : + --remote use hard coded remote daemon https://rwallet.dero.live + --daemon-address= Use daemon instance at : or https://domain --rpc-server Run rpc server, so wallet is accessible using api --rpc-bind=<127.0.0.1:20209> Wallet binds on this ip address and port --rpc-login= RPC server will grant access based on these credentials @@ -315,7 +316,8 @@ func main() { continue } } else if err == io.EOF { - break +// break + time.Sleep(time.Second) } // pass command to suitable handler diff --git a/cmd/derod/main.go b/cmd/derod/main.go index 6f745f4..bffd430 100644 --- a/cmd/derod/main.go +++ b/cmd/derod/main.go @@ -26,6 +26,7 @@ import "strings" import "strconv" import "runtime" import "math/big" +import "os/signal" //import "crypto/sha1" import "encoding/hex" @@ -324,6 +325,19 @@ func main() { }) l.Refresh() // refresh the prompt + go func (){ + var gracefulStop = make(chan os.Signal) + signal.Notify(gracefulStop,os.Interrupt) // listen to all signals + for { + sig := <-gracefulStop + fmt.Printf("received signal %s\n", sig) + + if sig.String() == "interrupt" { + close(Exit_In_Progress) + } + } + }() + for { line, err := l.Readline() if err == readline.ErrInterrupt { @@ -335,7 +349,8 @@ func main() { continue } } else if err == io.EOF { - break + <-Exit_In_Progress + break } line = strings.TrimSpace(line) diff --git a/config/config.go b/config/config.go index 26004d7..b993996 100644 --- a/config/config.go +++ b/config/config.go @@ -177,3 +177,7 @@ var Testnet = CHAIN_CONFIG{Name: "testnet", // testnet will always have last 3 b // these are still here for previous emission functions, they are not used directly for atlantis const DYNAMIC_FEE_PER_KB_BASE_FEE_V5 = uint64((2000000000 * 60000) / 300000) const DYNAMIC_FEE_PER_KB_BASE_BLOCK_REWARD = uint64(1000000000000) // 1 * pow(10,12) + + +// mainnet has a remote daemon node, which can be used be default, if user provides a --remote flag +const REMOTE_DAEMON = "https://rwallet.dero.live" diff --git a/config/version.go b/config/version.go index dc82ccb..ec3c23c 100644 --- a/config/version.go +++ b/config/version.go @@ -20,4 +20,4 @@ import "github.com/blang/semver" // right now it has to be manually changed // do we need to include git commitsha?? -var Version = semver.MustParse("2.1.5-1.alpha.atlantis+03112018") +var Version = semver.MustParse("2.1.6-1.alpha.atlantis+07032019") diff --git a/structures/wallet_rpc.go b/structures/wallet_rpc.go index b7ff037..60fe18a 100644 --- a/structures/wallet_rpc.go +++ b/structures/wallet_rpc.go @@ -102,7 +102,7 @@ type ( Amount uint64 `json:"amount"` Fees uint64 `json:"fee,omitempty"` Unlock_time uint64 `json:"unlock_time"` - //Destination_list + Destinations []Destination `json:"destinations"` Note string `json:"note,omitempty"` Type string `json:"type,omitempty"` } diff --git a/walletapi/daemon_communication.go b/walletapi/daemon_communication.go index 0882149..692b113 100644 --- a/walletapi/daemon_communication.go +++ b/walletapi/daemon_communication.go @@ -79,6 +79,10 @@ func buildurl(endpoint string) string { // this will tell whether the wallet can connection successfully to daemon or not func (w *Wallet) IsDaemonOnline() (err error) { + if globals.Arguments["--remote"] == true && globals.IsMainnet() { + w.Daemon_Endpoint = config.REMOTE_DAEMON + } + // if user provided endpoint has error, use default if w.Daemon_Endpoint == "" { w.Daemon_Endpoint = "127.0.0.1:" + fmt.Sprintf("%d", config.Mainnet.RPC_Default_Port) diff --git a/walletapi/rpc_get_transfer_by_txid.go b/walletapi/rpc_get_transfer_by_txid.go index 0b848b1..179b91a 100644 --- a/walletapi/rpc_get_transfer_by_txid.go +++ b/walletapi/rpc_get_transfer_by_txid.go @@ -61,14 +61,33 @@ func (h Get_Transfer_By_TXID_Handler) ServeJSONRPC(c context.Context, params *fa Height: entry.Height, Amount: entry.Amount, Unlock_time: entry.Unlock_Time, + + } + if entry.Height == 0 { + return nil, &jsonrpc.Error{Code: -8, Message: fmt.Sprintf("Transaction not found. TXID %s", p.TXID)} } - // setup in/out - if entry.Amount > 0 { // if we have an amount + for i := range entry.Details.Daddress { + result.Transfer.Destinations = append(result.Transfer.Destinations, + structures.Destination{ + Address: entry.Details.Daddress[i], + Amount: entry.Details.Amount[i], + }) + } + + if len(entry.Details.PaymentID) >= 1 { + result.Transfer.Payment_ID = entry.Details.PaymentID + } + + if entry.Status == 0 { // if we have an amount result.Transfer.Type = "in" - if h.r.w.GetTXKey(entry.TXID) != "" { - result.Transfer.Type = "out" - } + // send the result + return result, nil + + } + // setup in/out + if entry.Status == 1 { // if we have an amount + result.Transfer.Type = "out" // send the result return result, nil diff --git a/walletapi/wallet.go b/walletapi/wallet.go index 7c20482..cf7fabf 100644 --- a/walletapi/wallet.go +++ b/walletapi/wallet.go @@ -440,10 +440,12 @@ func (w *Wallet) Add_Transaction_Record_Funds(txdata *globals.TX_Output_Data) (a err = msgpack.Unmarshal(value_bytes, &tx_wallet_temp) if err == nil { if tx_wallet_temp.TXdata.TXID != txdata.TXID { // transaction mismatch + rlog.Warnf("KICD %s,%s, \n%+v \n%+v",txdata.TXID, tx_wallet_temp.TXdata.TXID, txdata,tx_wallet_temp); return 0, false } if tx_wallet_temp.TXdata.Index_within_tx != txdata.Index_within_tx { // index within tx mismatch + rlog.Warnf("KICD2 %s,%s, \n%+v \n%+v",txdata.TXID, tx_wallet_temp.TXdata.TXID, txdata,tx_wallet_temp); return 0, false } } @@ -706,17 +708,20 @@ func (w *Wallet) Add_Possible_Ring_Member(txdata *globals.TX_Output_Data) { } type Entry struct { - Index_Global uint64 - Height uint64 - TopoHeight int64 - TXID crypto.Hash - Amount uint64 - PaymentID []byte - Status byte - Unlock_Time uint64 - Time time.Time + Index_Global uint64 `json:"index_global"` + Height uint64 `json:"height"` + TopoHeight int64 `json:"topoheight"` + TXID crypto.Hash `json:"txid"` + Amount uint64 `json:"amount"` + PaymentID []byte `json:"payment_id"` + Status byte `json:"status"` + Unlock_Time uint64 `json:"unlock_time"` + Time time.Time `json:"time"` + Secret_TX_Key string `json:"secret_tx_key"` // can be used to prove if available + Details structures.Outgoing_Transfer_Details `json:"details"` // actual details if available } + // finds all inputs which have been received/spent etc // TODO this code can be easily parallelised and need to be parallelised // if only the availble is requested, then the wallet is very fast @@ -840,6 +845,10 @@ func (w *Wallet) Show_Transfers(available bool, in bool, out bool, pool bool, fa duration, _ := time.ParseDuration(fmt.Sprintf("%ds", int64(180*entry.Height))) entry.Time = dero_first_block_time.Add(duration) } + + // fill tx secret_key + entry.Secret_TX_Key = w.GetTXKey(tx.TXdata.TXID) + entry.Details = w.GetTXOutDetails(tx.TXdata.TXID) entry.Status = 1 entries = append(entries, entry) // spend entry @@ -880,6 +889,10 @@ func (w *Wallet) Get_Payments_Payment_ID(payid []byte, min_height uint64) (entri entry.PaymentID = tx.WPaymentID entry.Status = 0 entry.Unlock_Time = tx.TXdata.Unlock_Height + + // fill tx secret_key + entry.Secret_TX_Key = w.GetTXKey(tx.TXdata.TXID) + entry.Details = w.GetTXOutDetails(tx.TXdata.TXID) entries = append(entries, entry) } } @@ -913,6 +926,10 @@ func (w *Wallet) Get_Payments_TXID(txid []byte) (entry Entry) { entry.PaymentID = tx.WPaymentID entry.Status = 0 entry.Unlock_Time = tx.TXdata.Unlock_Height + + // fill tx secret_key + entry.Secret_TX_Key = w.GetTXKey(tx.TXdata.TXID) + entry.Details = w.GetTXOutDetails(tx.TXdata.TXID) } } @@ -965,7 +982,7 @@ func (w *Wallet) Clean() { w.delete_bucket(BLOCKCHAIN_UNIVERSE, []byte(FUNDS_SPENT_WHERE)) w.delete_bucket(BLOCKCHAIN_UNIVERSE, []byte(FUNDS_BUCKET_OUTGOING)) -// w.delete_bucket(BLOCKCHAIN_UNIVERSE, []byte(RING_BUCKET)) //Improves wallet rescan performance. + w.delete_bucket(BLOCKCHAIN_UNIVERSE, []byte(RING_BUCKET)) //Improves wallet rescan performance. w.delete_bucket(BLOCKCHAIN_UNIVERSE, []byte(KEYIMAGE_BUCKET)) w.delete_bucket(BLOCKCHAIN_UNIVERSE, []byte(HEIGHT_TO_BLOCK_BUCKET))