dongbo 6 anni fa
parent
commit
eac7bce0a0

+ 3 - 3
bitcointest/bitcoin_test.go

@@ -171,12 +171,13 @@ func Test_ChainHeight(t *testing.T) {
 
 func Test_AccountsBalance(t *testing.T) {
 	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://192.168.1.107:15741/coinproxy/accountsbalance`)
+	geturl := fmt.Sprintf(`http://118.31.213.53:6784/coinproxy/accountsbalance`)
+	//geturl := fmt.Sprintf(`http://192.168.1.107:15741/coinproxy/accountsbalance`)
 	timetamp := fmt.Sprintf("%v", time.Now().Unix())
 
 	t.Logf("post url:%v", geturl)
 
-	posdata := fmt.Sprintf(`{"cointype":"BTC","timestamp":"%v"}`, timetamp)
+	posdata := fmt.Sprintf(`{"cointype":"BTC","timestamp":"%v","signature":"%v"}`, timetamp, Signature([]byte("/coinproxy/accountsbalance"), timetamp))
 	request, err := http.NewRequest("POST", geturl, strings.NewReader(posdata))
 	if err != nil {
 		t.Error("err:%s", err.Error())
@@ -259,7 +260,6 @@ func Test_SendRawTransaction(t *testing.T) {
 	return
 }*/
 
-
 func Signature(body []byte, timestamp string) string {
 
 	sha1Contain := sha1.New()

BIN
coinsapi


+ 0 - 31
src/dcrcash/dcrcashRpc/dcrcashRpc.go

@@ -204,20 +204,6 @@ func InitRpcConf(rpcuser string, rpcpassword string, rpchost string, rpcport int
 }
 
 func Marsha1cmd(method string, args ...interface{}) ([]byte, error) {
-	/*rt := reflect.TypeOf(cmd)
-	method, ok := concreateTypeToMethod[rt]
-	if !ok {
-		str := fmt.Sprintf("%q is not registered", method)
-		return nil, error.Error(str)
-	}
-
-	rv := reflect.ValueOf(cmd)
-	if rv.IsNil() {
-		str := "the specified command is nil"
-		return nil, error.Error(str)
-	}
-
-	params := makeParams(rt.Elem(), rv.Elem())*/
 	if method == "" {
 		str := fmt.Sprintf("%q is not method", method)
 		return nil, errors.New(str)
@@ -254,20 +240,3 @@ func NewRequest(id interface{}, method string, params []interface{}) (*Request,
 		Params:  rawParams,
 	}, nil
 }
-
-/*func makeParams(rt reflect.Type, rv reflect.Value) []interface{} {
-	numFields := rt.NumField()
-	params := make([]interface{}, 0, numFields)
-	for i := 0; i < numFields; i++ {
-		rtf := rt.Field(i)
-		rvf := rv.Field(i)
-		if rtf.Type.Kind() == reflect.Ptr {
-			if rvf.IsNil() {
-				break
-			}
-			rvf.Elem()
-		}
-		params = append(params, rvf.Interface())
-	}
-	return params
-}*/

+ 60 - 61
src/dcrcash/dcrcash_test.go

@@ -147,7 +147,7 @@ func Test_ListUnspent(t *testing.T) {
 	timestamp := fmt.Sprintf("%v", time.Now().Unix())
 	t.Logf("post url:%v", geturl)
 
-	postdata := fmt.Sprintf(`{"cointype":"DCR","Sync":false,"address":[],"timestamp":"%v"}`, timestamp)
+	postdata := fmt.Sprintf(`{"cointype":"DCR","Sync":true,"address":["Dsi95trBH3gjLxf6PB3zLvtRXkSixjMFA1F"],"timestamp":"%v"}`, timestamp)
 	request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
 	if err != nil {
 		t.Errorf("err:%s", err.Error())
@@ -202,66 +202,65 @@ 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://118.31.213.53:8803/coinproxy/sumcoinbalance`)
-	t.Logf("post url:%v", geturl)
-
-	//var b []byte
-	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())
-		return
-	}
-	resp, err := client.Do(request)
-	if err != nil {
-		t.Errorf("err:%s", err.Error())
-		return
-	}
-
-	defer resp.Body.Close()
-	rbs, err := ioutil.ReadAll(resp.Body)
-	if err != nil {
-		t.Errorf("err:%s", err.Error())
-		return
-	}
-
-	t.Logf("read bytes:%v", string(rbs))
-	return
-}
-*/
-
-func Test_AccountsBalance(t *testing.T) {
-	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/accountsbalance`)
-	timetamp := fmt.Sprintf("%v", time.Now().Unix())
-
-	t.Logf("post url:%v", geturl)
-
-	posdata := fmt.Sprintf(`{"cointype":"DCR","timestamp":"%v"}`, timetamp)
-	request, err := http.NewRequest("POST", geturl, strings.NewReader(posdata))
-	if err != nil {
-		t.Error("err:%s", err.Error())
-		return
-	}
-	resp, err := client.Do(request)
-	if err != nil {
-		t.Errorf("err:%s", err.Error())
-		return
-	}
-
-	defer resp.Body.Close()
-	rbs, err := ioutil.ReadAll(resp.Body)
-	if err != nil {
-		t.Errorf("err:%s", err.Error())
-		return
-	}
-
-	t.Logf("read bytes:%v", string(rbs))
-}
+//func Test_SumCoinBalance(t *testing.T) {
+//	client := http.DefaultClient
+//	//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":2000,"minamount":50}`)
+//	request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
+//	if err != nil {
+//		t.Errorf("err:%s", err.Error())
+//		return
+//	}
+//	resp, err := client.Do(request)
+//	if err != nil {
+//		t.Errorf("err:%s", err.Error())
+//		return
+//	}
+
+//	defer resp.Body.Close()
+//	rbs, err := ioutil.ReadAll(resp.Body)
+//	if err != nil {
+//		t.Errorf("err:%s", err.Error())
+//		return
+//	}
+
+//	t.Logf("read bytes:%v", string(rbs))
+//	return
+//}
+
+//func Test_AccountsBalance(t *testing.T) {
+//	client := http.DefaultClient
+//	geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/accountsbalance`)
+//	//geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/accountsbalance`)
+//	timetamp := fmt.Sprintf("%v", time.Now().Unix())
+
+//	t.Logf("post url:%v", geturl)
+
+//	posdata := fmt.Sprintf(`{"cointype":"DCR","timestamp":"%v"}`, timetamp)
+//	request, err := http.NewRequest("POST", geturl, strings.NewReader(posdata))
+//	if err != nil {
+//		t.Error("err:%s", err.Error())
+//		return
+//	}
+//	resp, err := client.Do(request)
+//	if err != nil {
+//		t.Errorf("err:%s", err.Error())
+//		return
+//	}
+
+//	defer resp.Body.Close()
+//	rbs, err := ioutil.ReadAll(resp.Body)
+//	if err != nil {
+//		t.Errorf("err:%s", err.Error())
+//		return
+//	}
+
+//	t.Logf("read bytes:%v", string(rbs))
+//}
 
 /*
 func Test_TransferAccounts(t *testing.T) {

+ 23 - 15
src/dcrcash/dcrcashcoin.go

@@ -31,7 +31,7 @@ type DcrCash struct {
 const (
 	NameCoin           = "DCR"
 	SendToError        = "-32603"
-	DefaultMaxsumamout = 20.0
+	DefaultMaxsumamout = 100.0
 	DEFAULTACCOUNT     = "default"
 )
 
@@ -196,29 +196,36 @@ func (m *DcrCash) SumcoinBalance(parm interface{}) ([]byte, error) {
 		Minsumamount = WalleTxfee
 	}
 	//list Accounts and account of balance
-	accountsofValues, err := CoinApi.ListAccounts()
-	if err != nil {
-		LOG("ERROR", "List accounts error:%v", err.Error())
-		return nil, err
-	}
+	//	accountsofValues, err := CoinApi.ListAccounts()
+	//	if err != nil {
+	//		LOG("ERROR", "List accounts error:%v", err.Error())
+	//		return nil, err
+	//	}
 	//var AccValues []AccountsOfvalue
-	AccValues := map[string]float64{}
-	if err = json.Unmarshal(accountsofValues, &AccValues); err != nil {
-		LOG("ERROR", "Unmarshal error:%v", err.Error())
-		return nil, err
-	}
+	//	AccValues := map[string]float64{}
+	//	if err = json.Unmarshal(accountsofValues, &AccValues); err != nil {
+	//		LOG("ERROR", "Unmarshal error:%v", err.Error())
+	//		return nil, err
+	//	}
 	var Totalbalance float64
-	fmt.Println("SumcoinBalance >>>>:", len(AccValues), "Sumamount:", Sumamount, "Minsumamount", Minsumamount)
+	fmt.Println("SumcoinBalance >>>>:", len(m_AccValues), "Sumamount:", Sumamount, "Minsumamount", Minsumamount)
 	transactionsids := make([]string, 0)
-	for account, value := range AccValues {
+	for account, value := range m_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 {
 				LOG("ERROR", " Send coin error:%v", err.Error())
+				for {
+					amount -= 0.001
+					transactionid, err = CoinApi.WalletSendFrom(account, DEFAULTACCOUNT, amount, 1, "", "")
+					if transactionid != "" || amount <= 0.001 {
+						break
+					}
+				}
 				//return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, SENDCOINS_ERR, getErrMsg(SENDCOINS_ERR, nil))
-				continue
+				//continue
 			}
 			transactionsids = append(transactionsids, transactionid)
 			Totalbalance += amount
@@ -230,6 +237,7 @@ func (m *DcrCash) SumcoinBalance(parm interface{}) ([]byte, error) {
 	}
 	if len(transactionsids) != 0 {
 		var jbuf []byte
+		var err error
 		resp := make(map[string]interface{})
 		resp["transcationids"] = transactionsids
 		resp["errcode"] = 0
@@ -572,7 +580,7 @@ func Cachelistaccount() {
 func AsyncRoutine() {
 	CacheGetbalanceTicker := time.NewTicker(120 * time.Second)
 	CachelistaccountTicker := time.NewTicker(90 * time.Second)
-	CachelistunspentTicker := time.NewTicker(120 * time.Second)
+	CachelistunspentTicker := time.NewTicker(180 * time.Second)
 	for {
 		select {
 		case _ = <-CacheGetbalanceTicker.C: