Sfoglia il codice sorgente

修改全局变量的位置

476052856 6 anni fa
parent
commit
0bfe17037e

+ 36 - 6
bitcointest/bitcoin_test.go

@@ -139,7 +139,8 @@ func Test_TransferAccounts(t *testing.T) {
 */
 func Test_ChainHeight(t *testing.T) {
 	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/blockchain/height`)
+	geturl := fmt.Sprintf(`http://118.31.213.53:6784/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)
 
@@ -168,12 +169,41 @@ func Test_ChainHeight(t *testing.T) {
 	return
 }
 
-func Test_ListUnspent(t *testing.T) {
+func Test_AccountsBalance(t *testing.T) {
 	client := http.DefaultClient
-	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/listunspent`)
-	timestamp := fmt.Sprintf("%v", time.Now().Unix())
+	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)
+	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_ListUnspent(t *testing.T) {
+	client := http.DefaultClient
+	geturl := fmt.Sprintf(`http://118.31.212.137:6784/coinproxy/listunspent`)
+	//geturl := fmt.Sprintf(`http://192.168.1.107:15741/coinproxy/listunspent`)
+	timestamp := fmt.Sprintf("%v", time.Now().Unix())
+	t.Logf("post url:%v", geturl)
 
 	postdata := fmt.Sprintf(`{"cointype":"BTC","address":[],"timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte("/coinproxy/listunspent"), timestamp))
 	request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
@@ -226,8 +256,8 @@ func Test_SendRawTransaction(t *testing.T) {
 
         t.Logf("read bytes:%v", string(rbs))
 
-        return
-}
+	return
+}*/
 
 
 func Signature(body []byte, timestamp string) string {

BIN
coinsapi


+ 2 - 1
src/bitcoin/bitcoinmain.go

@@ -44,6 +44,7 @@ func (m BitCoin) InitDriver(parm interface{}) bool {
 	}
 	go m.getwalletinfo()
 	//缓存当前未花费的
+	m_unspent = make([]map[string]interface{}, 0)
 	go AsyncRoutine()
 	return true
 }
@@ -519,7 +520,7 @@ func AsyncRoutine() {
 func Cachelistunspent() {
 	fmt.Println("cachelistunspent time:", time.Now().Format("2006-01-02 15:04:05"))
 	var address []string
-	m_unspent = make([]map[string]interface{}, 0)
+
 	unspent, err := CoinApi.Listunspent(address)
 	if err != nil {
 		LOG("ERROR", "  get listunspent:%v", err.Error())

+ 2 - 1
src/bucash/bucashcoins.go

@@ -35,6 +35,7 @@ func (m Bucash) InitDriver(parm interface{}) bool {
 	go m.getwalletinfo()
 
 	//缓存当前未花费的
+	m_unspent = make([]map[string]interface{}, 0)
 	go AsyncRoutine()
 	return true
 }
@@ -417,7 +418,7 @@ func AsyncRoutine() {
 func Cachelistunspent() {
 	fmt.Println("cachelistunspent time:", time.Now().Format("2006-01-02 15:04:05"))
 	var address []string
-	m_unspent = make([]map[string]interface{}, 0)
+
 	unspent, err := CoinApi.Listunspent(address)
 	if err != nil {
 		LOG("ERROR", "  get listunspent:%v", err.Error())

+ 2 - 2
src/dcrcash/dcrcash_test.go

@@ -46,8 +46,8 @@ import (
 
 func Test_Balance(t *testing.T) {
 	client := http.DefaultClient
-	//geturl := fmt.Sprintf(`http://118.31.213.53:8803/coinproxy/coinbalance`)
-	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)
 

+ 3 - 2
src/dcrcash/dcrcashcoin.go

@@ -41,6 +41,8 @@ func (m DcrCash) InitDriver(param interface{}) bool {
 	}
 	go m.getwalletinfo()
 	//缓存数据
+	m_balanceparam = make(map[string]float64)
+	m_unspent = make([]map[string]interface{}, 0)
 	go AsyncRoutine()
 	return true
 }
@@ -502,7 +504,6 @@ func (m DcrCash) AccountsBalance(parm interface{}) (jbuf []byte, err error) {
 
 func CacheGetbalance() {
 	fmt.Println("Cachegetbalance time:", time.Now().Format("2006-01-02 15:04:05"))
-	m_balanceparam = make(map[string]float64)
 	acountBalace, err := CoinApi.WalleGetBalance("*")
 	if err != nil {
 		LOG("ERROR", " GetBalance err:%v", err.Error())
@@ -540,7 +541,7 @@ func CacheGetbalance() {
 func Cachelistunspent() {
 	fmt.Println("cachelistunspent time:", time.Now().Format("2006-01-02 15:04:05"))
 	var address []string
-	m_unspent = make([]map[string]interface{}, 0)
+
 	unspent, err := CoinApi.Listunspent(address)
 	if err != nil {
 		LOG("ERROR", "  get listunspent:%v", err.Error())