Pārlūkot izejas kodu

增加错误验证

476052856 6 gadi atpakaļ
vecāks
revīzija
cc96540454

+ 3 - 4
src/dcrcash/dcrcash.go

@@ -61,7 +61,6 @@ func (m *DcrCashApi) WalletDumpPrivKey(address string) (string, error) {
 
 	//
 	result, err := dcrcashRpc.RunCall("dumpprivkey", address)
-	fmt.Println("WalletDumpPrivKey>>>>>>>:", string(result))
 	if err != nil {
 		fmt.Println("Call dumpprivkey fail:", err.Error())
 		return "", err
@@ -483,14 +482,14 @@ func (m DcrCashApi) ListAccounts() ([]byte, error) {
 	return nil, err
 }
 
-func (m DcrCashApi) WalletAddressofaccount(address string) (string, error) {
+func (m DcrCashApi) WalletAddressofaccount(account string) (string, error) {
 	var oneaddress OneaddressOfaccount
-	if len(address) == 0 {
+	if len(account) == 0 {
 		fmt.Println("input para err:")
 		err := errors.New("input para err")
 		return "", err
 	}
-	result, err := dcrcashRpc.RunCall("getaccountaddress", address)
+	result, err := dcrcashRpc.RunCall("getaccountaddress", account)
 	if err != nil {
 		fmt.Println("Call getaccountaddress fial:", err.Error())
 		return "", err

+ 19 - 11
src/dcrcash/dcrcash_test.go

@@ -46,7 +46,8 @@ import (
 
 func Test_Balance(t *testing.T) {
 	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/coinbalance`)
+	geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/coinbalance`)
+	//geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/coinbalance`)
 	timestamp := fmt.Sprintf("%v", time.Now().Unix())
 	t.Logf("post url:%v", geturl)
 
@@ -79,7 +80,7 @@ func Test_Balance(t *testing.T) {
 	//first get block height then test transinfo
 
 	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/query/transinfo`)
+	geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/query/transinfo`)
 	timestamp := fmt.Sprintf("%v", time.Now().Unix())
 	t.Logf("post url:%v", geturl)
 
@@ -109,6 +110,7 @@ func Test_Balance(t *testing.T) {
 
 func Test_ChainHeight(t *testing.T) {
 	client := http.DefaultClient
+	//geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/blockchain/height`)
 	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/blockchain/height`)
 	timestamp := fmt.Sprintf("%v", time.Now().Unix())
 	t.Logf("post url:%v", geturl)
@@ -138,9 +140,10 @@ func Test_ChainHeight(t *testing.T) {
 	return
 }
 
-func Test_ListUnspent(t *testing.T) {
+/*func Test_ListUnspent(t *testing.T) {
 	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/listunspent`)
+	geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/listunspent`)
+	//geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/listunspent`)
 	timestamp := fmt.Sprintf("%v", time.Now().Unix())
 	t.Logf("post url:%v", geturl)
 
@@ -167,10 +170,11 @@ func Test_ListUnspent(t *testing.T) {
 
 	return
 }
-
+*/
 func Test_SendRawTransaction(t *testing.T) {
 	client := http.DefaultClient
 	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/sendrawtransaction`)
+	//geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/sendrawtransaction`)
 	t.Logf("post url:%v", geturl)
 
 	//var b []byte
@@ -198,13 +202,15 @@ func Test_SendRawTransaction(t *testing.T) {
 	return
 }
 
+/*
 func Test_SumCoinBalance(t *testing.T) {
 	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/sumcoinbalance`)
+	//geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/sumcoinbalance`)
+	geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/sumcoinbalance`)
 	t.Logf("post url:%v", geturl)
 
 	//var b []byte
-	postdata := fmt.Sprintf(`{"cointype":"DCR","sumamount":5.0}`)
+	postdata := fmt.Sprintf(`{"cointype":"DCR","sumamount":600}`)
 	request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
 	if err != nil {
 		t.Errorf("err:%s", err.Error())
@@ -226,15 +232,17 @@ func Test_SumCoinBalance(t *testing.T) {
 	t.Logf("read bytes:%v", string(rbs))
 	return
 }
-
-/*func Test_TransferAccounts(t *testing.T) {
+*/
+/*
+func Test_TransferAccounts(t *testing.T) {
 	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/sendcoins`)
+	//geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/sendcoins`)
+	geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/sendcoins`)
 	timestamp := fmt.Sprintf("%v", time.Now().Unix())
 	t.Logf("post url:%v", geturl)
 
 	//var b []byte
-	postdata := fmt.Sprintf(`{"cointype":"DCR","amount":"0.002747","address":"DsgbyoXAB2PdsiU3yDpCtBww7FcxhTAV2Vr","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte("/coinproxy/sendcoins"), timestamp))
+	postdata := fmt.Sprintf(`{"cointype":"DCR","amount":"0.02","address":"DsctbrcDVEF4g4gqTpRF8ciZMqwe4va32uK","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte("/coinproxy/sendcoins"), timestamp))
 	request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
 	if err != nil {
 		t.Errorf("err:%s", err.Error())

+ 13 - 5
src/dcrcash/dcrcashcoin.go

@@ -96,7 +96,7 @@ func (m DcrCash) CoinBalance(parm interface{}) ([]byte, error) {
 		LOG("ERROR", " inner json error:%v", err.Error())
 		return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, INNER_ERR, getErrMsg(INNER_ERR, nil))
 	}
-	//var totalConfirbalance float64
+	var totalbalance float64
 	//var totalUnconfirbalance float64
 	var maxConfirbalance float64
 	var maxUnconfirbalance float64
@@ -107,6 +107,9 @@ func (m DcrCash) CoinBalance(parm interface{}) ([]byte, error) {
 		if vbalance.Unconfirmed != 0 {
 			totalUnconfirbalance += vbalance.Unconfirmed
 		}*/
+		if vbalance.Total != 0 {
+			totalbalance += vbalance.Total
+		}
 		if vbalance.Spendable > maxConfirbalance {
 			maxConfirbalance = vbalance.Spendable
 		}
@@ -119,6 +122,7 @@ func (m DcrCash) CoinBalance(parm interface{}) ([]byte, error) {
 	resp := make(map[string]interface{})
 	resp["confirmedbalance"] = maxConfirbalance
 	resp["unconfirmed"] = maxUnconfirbalance
+	resp["totalbalance"] = totalbalance
 	resp["errcode"] = 0
 	resp["exact"] = 0
 	if jbuf, err = json.Marshal(resp); err != nil {
@@ -164,13 +168,13 @@ func (m DcrCash) CreateAddress(parm interface{}) ([]byte, error) {
 	return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, INNER_ERR, getErrMsg(INNER_ERR, nil))
 }
 
-func (m DcrCash) SumcoinBalance(parm interface{}) ([]byte, error) {
+func (m *DcrCash) SumcoinBalance(parm interface{}) ([]byte, error) {
 	pjs := parm.(*simplejson.Json)
 	//
 	Sumamount := pjs.Get("sumamount").MustFloat64()
 	Minsumamount := pjs.Get("minamount").MustFloat64()
 
-	if Sumamount <= 0.0 {
+	if Sumamount <= 0 {
 		LOG("ERROR", " Summary amount is nil!")
 		Sumamount = DefaultMaxsumamout
 	}
@@ -190,9 +194,11 @@ func (m DcrCash) SumcoinBalance(parm interface{}) ([]byte, error) {
 		return nil, err
 	}
 	var Totalbalance float64
+	fmt.Println("SumcoinBalance >>>>:", len(AccValues), "Sumamount:", Sumamount, "Minsumamount", Minsumamount)
 	transactionsids := make([]string, 0)
 	for account, value := range AccValues {
 		if (value > Minsumamount) && account != DEFAULTACCOUNT {
+			fmt.Println("SumcoinBalance account:", account, "value:", value)
 			amount := value - WalleTxfee
 			transactionid, err := CoinApi.WalletSendFrom(account, DEFAULTACCOUNT, amount, 1, "", "")
 			if err != nil {
@@ -221,8 +227,7 @@ func (m DcrCash) SumcoinBalance(parm interface{}) ([]byte, error) {
 		}
 		return jbuf, nil
 	}
-	LOG("ERROR", " transactionids is null error:%v", err.Error())
-	return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, INNER_ERR, getErrMsg(INNER_ERR, nil))
+	return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, SUMCOIN_ERR, getErrMsg(SUMCOIN_ERR, nil))
 	//fromaccout = "default"
 }
 
@@ -262,6 +267,9 @@ func (m DcrCash) TransferAccounts(parm interface{}) ([]byte, error) {
 		}
 
 	}
+	if fromaccout == "" {
+		fromaccout = DEFAULTACCOUNT
+	}
 
 	transactionid, err := CoinApi.WalletSendFrom(fromaccout, destination, amount, 1, "", "")
 	if err != nil {

+ 2 - 0
src/dcrcash/dcrcasherr.go

@@ -24,6 +24,7 @@ const (
 	SEND_RAW_TRANSACTION_ERR
 	PARM_ERR
 	INSUFFICIENT_FUNDS_TRANSACTION_ERR
+	SUMCOIN_ERR
 	UNKNOWN_ERR
 )
 
@@ -45,6 +46,7 @@ func initDcrError() {
 	ErrMsg[34] = " 发送原始交易信息出错"
 	ErrMsg[35] = " 传入参数错误"
 	ErrMsg[36] = " 交易的资金不足"
+	ErrMsg[37] = " 合并交易出错"
 
 }