From 75a237bc0d34439c4b4a4761aaf46fe53d4d2cd3 Mon Sep 17 00:00:00 2001 From: David Hill Date: Fri, 11 Apr 2014 09:39:08 -0400 Subject: [PATCH] Add support for GetTransactionResult. ok @jcvernaleo --- jsonapi.go | 31 +++++++++++++++++++++++++++++++ jsonapi_test.go | 2 ++ test_coverage.txt | 6 +++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/jsonapi.go b/jsonapi.go index d889e9ec..808f505f 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -113,6 +113,31 @@ type GetRawMempoolResult struct { Depends []string `json:"depends"` } +// GetTransactionDetailsResult models the details data from the gettransaction command. +type GetTransactionDetailsResult struct { + Account string `json:"account"` + Address string `json:"address"` + Category string `json:"category"` + Amount float64 `json:"amount"` + Fee float64 `json:"fee,omitempty"` +} + +// GetTransactionResult models the data from the gettransaction command. +type GetTransactionResult struct { + Amount float64 `json:"amount"` + Fee float64 `json:"fee,omitempty"` + Confirmations int64 `json:"confirmations"` + BlockHash string `json:"blockhash"` + BlockIndex int64 `json:"blockindex"` + BlockTime int64 `json:"blocktime"` + TxID string `json:"txid"` + WalletConflicts []string `json:"walletconflicts"` + Time int64 `json:"time"` + TimeReceived int64 `json:"timereceived"` + Details []GetTransactionDetailsResult `json:"details"` + Hex string `json:"hex"` +} + // ListTransactionsResult models the data from the listtransactions command. type ListTransactionsResult struct { Account string `json:"account"` @@ -1027,6 +1052,12 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) { result.Result = res } } + case "gettransaction": + var res GetTransactionResult + err = json.Unmarshal(objmap["result"], &res) + if err == nil { + result.Result = res + } case "getwork": // getwork can either return a JSON object or a boolean // depending on whether or not data was provided. Choose the diff --git a/jsonapi_test.go b/jsonapi_test.go index a78cbe60..8ceab3eb 100644 --- a/jsonapi_test.go +++ b/jsonapi_test.go @@ -342,6 +342,8 @@ var resulttests = []struct { {"getinfo", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, {"getblock", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, {"getblock", []byte(`{"result":{"hash":"000000","confirmations":16007,"size":325648},"error":null,"id":1}`), false, true}, + {"gettransaction", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, + {"gettransaction", []byte(`{"error":null,"id":1,"result":{"Amount":0.0}}`), false, true}, {"getrawtransaction", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, {"getrawtransaction", []byte(`{"error":null,"id":1,"result":{"hex":"somejunk","version":1}}`), false, true}, {"decoderawtransaction", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, diff --git a/test_coverage.txt b/test_coverage.txt index df9633d6..baeae148 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -436,12 +436,12 @@ github.com/conformal/btcjson/jsoncmd.go VerifyMessageCmd.UnmarshalJSON 68.42% github.com/conformal/btcjson/jsoncmd.go SignRawTransactionCmd.MarshalJSON 66.67% (8/12) github.com/conformal/btcjson/jsoncmd.go NewLockUnspentCmd 66.67% (4/6) github.com/conformal/btcjson/jsoncmd.go NewAddNodeCmd 66.67% (2/3) +github.com/conformal/btcjson/jsoncmd.go GetBlockCmd.MarshalJSON 63.64% (7/11) github.com/conformal/btcjson/jsonfxns.go jsonRpcSend 62.50% (10/16) github.com/conformal/btcjson/jsonapi.go rpcCommand 61.54% (8/13) -github.com/conformal/btcjson/jsoncmd.go GetBlockCmd.MarshalJSON 60.00% (6/10) github.com/conformal/btcjson/jsoncmd.go GetTxOutCmd.UnmarshalJSON 59.09% (13/22) +github.com/conformal/btcjson/jsonapi.go ReadResultCmd 58.73% (74/126) github.com/conformal/btcjson/jsoncmd.go LockUnspentCmd.UnmarshalJSON 57.89% (11/19) -github.com/conformal/btcjson/jsonapi.go ReadResultCmd 57.38% (70/122) github.com/conformal/btcjson/jsonapi.go rpcRawCommand 53.33% (8/15) github.com/conformal/btcjson/jsoncmd.go GetBlockCmd.UnmarshalJSON 50.00% (12/24) github.com/conformal/btcjson/cmdhelp.go GetHelpString 50.00% (3/6) @@ -461,5 +461,5 @@ github.com/conformal/btcjson/jsonapi.go TlsRpcCommand 0.00% (0/1) github.com/conformal/btcjson/jsoncmd.go unparsableCmd.Method 0.00% (0/1) github.com/conformal/btcjson/jsoncmd.go unparsableCmd.Id 0.00% (0/1) github.com/conformal/btcjson/jsoncmd.go newUnparsableCmd 0.00% (0/1) -github.com/conformal/btcjson --------------------------------------- 78.71% (2333/2964) +github.com/conformal/btcjson --------------------------------------- 78.75% (2338/2969)