Procházet zdrojové kódy

增加合并余额接口

476052856 před 6 roky
rodič
revize
b97c48dddb

+ 1 - 1
coinproxy.toml

@@ -15,5 +15,5 @@ dbpath="/var/"
 
 [cointype]
 type=["DCR"]
-sigkey="coinsapi^&#@(*33"
+sigkey="2017coins%^&#@(*33"
 

binární
coinsapi


+ 8 - 7
httphandler.go

@@ -20,13 +20,14 @@ import (
 //)
 
 var handler = map[string]func(w http.ResponseWriter, r *http.Request, js *simplejson.Json, body []byte) int{
-	CREATEADDR:  commonFunc,
-	TRANSINFO:   commonFunc,
-	COINBALANCE: commonFunc,
-	SENDCOINS:   commonFunc,
-	CHAINHEIGHT: commonFunc,
-	LISTUNSPENT: commonFunc,
-	RAWTRANSFER: commonFunc,
+	CREATEADDR:     commonFunc,
+	TRANSINFO:      commonFunc,
+	COINBALANCE:    commonFunc,
+	SENDCOINS:      commonFunc,
+	CHAINHEIGHT:    commonFunc,
+	LISTUNSPENT:    commonFunc,
+	RAWTRANSFER:    commonFunc,
+	SUMCOINBALANCE: commonFunc,
 }
 
 func commonHandler(w http.ResponseWriter, r *http.Request) {

+ 11 - 12
src/bitcoin/bitcoinmain.go

@@ -9,8 +9,8 @@ import (
 	"time"
 
 	simplejson "github.com/go-simplejson"
-	tml "github.com/toml-master"
 	btc "github.com/piotrnar/gocoin/lib/btc"
+	tml "github.com/toml-master"
 )
 
 var (
@@ -35,7 +35,6 @@ var PubKey string = ""
 var StartCount uint32 = 0
 var EndCount uint32 = 0
 
-
 func (m BitCoin) InitDriver(parm interface{}) bool {
 	if m.initconfig() == false {
 		return false
@@ -146,7 +145,7 @@ func (m BitCoin) TransInfo(parm interface{}) ([]byte, error) {
 		if listtransaction.Blocktime <= endblocktime {
 			requestData := make(map[string]interface{})
 			if listtransaction.Amount < 0 {
-				LOG("DEBUG", "listtransaction.Address:%v,value:%v,txid:%v",listtransaction.Address,listtransaction.Amount,listtransaction.Txid)
+				LOG("DEBUG", "listtransaction.Address:%v,value:%v,txid:%v", listtransaction.Address, listtransaction.Amount, listtransaction.Txid)
 				continue
 			}
 			confirmationheight, err := CoinApi.WalletGetBlockHeight(listtransaction.Blockhash)
@@ -229,7 +228,6 @@ func (m BitCoin) CreateAddress(parm interface{}) ([]byte, error) {
 	return result, err
 }
 
-
 //Create Address From HdWallet  address&key for receiving payments
 func (m BitCoin) CreateAddressFromHdWallet() ([]byte, error) {
 
@@ -295,16 +293,15 @@ func (m BitCoin) CreateAddressFromHdWallet() ([]byte, error) {
 	bitcoindb.Put([]byte(BACKUPPUBKEYINDEX), pubkeyindex)
 
 	//Import the Address in Wallet watche only cannot be used to spend
-	_,err = CoinApi.WalletImportAddress(addr, false)
-	if err != nil{
-		LOG("ERROR", "WalletImportAddress:%v, error:%v",addr, err.Error())
+	_, err = CoinApi.WalletImportAddress(addr, false)
+	if err != nil {
+		LOG("ERROR", "WalletImportAddress:%v, error:%v", addr, err.Error())
 		return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, INNER_ERR, getErrMsg(INNER_ERR, nil))
 	}
 	return jbuf, nil
 
 }
 
-
 //create a new  address&key for receiving payments
 func (m BitCoin) CreateAddressFromWallet() ([]byte, error) {
 
@@ -412,13 +409,12 @@ func (m BitCoin) ChainHeight(parm interface{}) ([]byte, error) {
 	return []byte(sendstr), nil
 }
 
-
 func (m BitCoin) ListUnspent(parm interface{}) ([]byte, error) {
 	pjs := parm.(*simplejson.Json)
-	address,err := pjs.Get("address").StringArray()
-	if err != nil{
+	address, err := pjs.Get("address").StringArray()
+	if err != nil {
 		LOG("ERROR", "  input parm error:%v", err.Error())
-                return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, LISTUNSPENT_ERR, getErrMsg(LISTUNSPENT_ERR, nil))
+		return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, LISTUNSPENT_ERR, getErrMsg(LISTUNSPENT_ERR, nil))
 	}
 
 	unspent, err := CoinApi.Listunspent(address)
@@ -468,6 +464,9 @@ func (m BitCoin) SendRawTransaction(parm interface{}) ([]byte, error) {
 	return jbuf, nil
 }
 
+func (m BitCoin) SumcoinBalance(parm interface{}) ([]byte, error) {
+	return nil, nil
+}
 
 func init() {
 	Register(NameCoin, &BitCoin{})

+ 4 - 0
src/bucash/bucashcoins.go

@@ -360,6 +360,10 @@ func (m Bucash) SendRawTransaction(parm interface{}) ([]byte, error) {
 	return jbuf, nil
 }
 
+func (m Bucash) SumcoinBalance(parm interface{}) ([]byte, error) {
+	return nil, nil
+}
+
 func init() {
 	Register(NameCoin, &Bucash{})
 }

+ 94 - 2
src/dcrcash/dcrcash.go

@@ -84,12 +84,11 @@ func (m *DcrCashApi) WalletInfo() ([]byte, error) {
 	var walletinfoResult WalletinfoResult
 	result, err := dcrcashRpc.RunCall("walletinfo")
 
-	fmt.Println(string(result))
 	if err != nil {
 		fmt.Println("Call walletinfo fail:", err.Error())
 		return nil, err
 	}
-	fmt.Println("WalletInfo->Unmarshal")
+	fmt.Println("walletinfo:", string(result))
 	if err := json.Unmarshal([]byte(result), &walletinfoResult); err != nil {
 		fmt.Println("Unmarshal err :", err.Error())
 		return nil, err
@@ -97,6 +96,8 @@ func (m *DcrCashApi) WalletInfo() ([]byte, error) {
 
 	if len(walletinfoResult.Error.Message) == 0 {
 		var jbuf []byte
+		WalleTxfee = walletinfoResult.Result.TxFee
+		fmt.Println(WalleTxfee)
 		if jbuf, err = json.Marshal(walletinfoResult.Result); err != nil {
 			return nil, err
 		}
@@ -340,6 +341,46 @@ func (m *DcrCashApi) WalleSendTo(toaddress string, amount float64, comment, comm
 	return strconv.Itoa(SendResult.Error.Code), err
 }
 
+func (m *DcrCashApi) WalletSendFrom(fromaccount string, toaddress string, amount float64, minconf int, comment, commentto string) (string, error) {
+
+	var SendResult RpcResult
+
+	if len(toaddress) == 0 {
+		fmt.Println("input toaddress err:")
+		err := errors.New("input toaddress err")
+		return "", err
+	}
+
+	if toaddress == DEFAULTACCOUNT {
+		var err error
+		toaddress, err = m.WalletAddressofaccount(toaddress)
+		if err != nil {
+			fmt.Println("Call getaccountaddress fail:", err.Error())
+			return "", err
+		}
+		//toaddress = "DscoFukRjv6y9C62tsiJG8qPVsA9AbTe9AB"
+	}
+	dcrcashRpc.RunCall("walletpassphrase", Config.Walletpass.Passphrase, 3)
+	result, err := dcrcashRpc.RunCall("sendfrom", fromaccount, toaddress, amount)
+	fmt.Println("WalleSendfrom>>>>>>>>", string(result))
+	if err != nil {
+		fmt.Println("Call sendfrom fail:", err.Error())
+		return "", err
+	}
+
+	if err := json.Unmarshal([]byte(result), &SendResult); err != nil {
+		fmt.Println("Unmarshal err :", err.Error())
+		return "", err
+	}
+
+	// success
+	if len(SendResult.Error.Message) == 0 {
+		return SendResult.Result, nil
+	}
+	err = errors.New(SendResult.Error.Message)
+	return strconv.Itoa(SendResult.Error.Code), err
+}
+
 //list unspent transaction outputs
 func (m DcrCashApi) Listunspent(address []string) ([]map[string]interface{}, error) {
 
@@ -416,3 +457,54 @@ func (m DcrCashApi) SendRawTransaction(hexstring string) (string, error) {
 	err = errors.New(rawtransactioninfo.Error.Message)
 	return "", err
 }
+
+func (m DcrCashApi) ListAccounts() ([]byte, error) {
+	var accountsofValues AccountsOfvaluesResult
+
+	result, err := dcrcashRpc.RunCall("listaccounts")
+	if err != nil {
+		fmt.Println("Call listaccounts fail:", err.Error())
+		return nil, err
+	}
+
+	if err := json.Unmarshal(result, &accountsofValues); err != nil {
+		fmt.Println("unmarshal err:", err.Error())
+		return nil, err
+
+	}
+	if len(accountsofValues.Error.Message) == 0 {
+		var jbuf []byte
+		if jbuf, err = json.Marshal(accountsofValues.Result); err != nil {
+			return nil, err
+		}
+		return jbuf, nil
+	}
+	err = errors.New(accountsofValues.Error.Message)
+	return nil, err
+}
+
+func (m DcrCashApi) WalletAddressofaccount(address string) (string, error) {
+	var oneaddress OneaddressOfaccount
+	if len(address) == 0 {
+		fmt.Println("input para err:")
+		err := errors.New("input para err")
+		return "", err
+	}
+	result, err := dcrcashRpc.RunCall("getaccountaddress", address)
+	if err != nil {
+		fmt.Println("Call getaccountaddress fial:", err.Error())
+		return "", err
+	}
+
+	if err := json.Unmarshal([]byte(result), &oneaddress); err != nil {
+		fmt.Println("Unmarshal err :", err.Error())
+		return "", err
+	}
+	if len(oneaddress.Error.Message) == 0 {
+		return oneaddress.Result, nil
+	}
+
+	err = errors.New(oneaddress.Error.Message)
+	return "", err
+
+}

+ 1 - 1
src/dcrcash/dcrcash.toml

@@ -7,7 +7,7 @@ WalletKey="scrub usual alchemy moon height eskimos palace deity boss runway pres
 passphrase="fuzamei888"
 
 [limit]
-fee="0.00000000"
+fee="0.0010000"
 
 [rpc]
 rpcuser="rpcuser"

+ 36 - 7
src/dcrcash/dcrcash_test.go

@@ -11,7 +11,7 @@ import (
 	"time"
 )
 
-func Test_newaddr(t *testing.T) {
+/*func Test_newaddr(t *testing.T) {
 	client := http.DefaultClient
 	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/createaddr`)
 	//timestamp := fmt.Sprintf("%v", time.Now().Unix())
@@ -42,7 +42,7 @@ func Test_newaddr(t *testing.T) {
 	fmt.Printf("read bytes:%v", string(rbs))
 
 	return
-}
+}*/
 
 func Test_Balance(t *testing.T) {
 	client := http.DefaultClient
@@ -74,7 +74,7 @@ func Test_Balance(t *testing.T) {
 	return
 }
 
-func Test_TransInfo(t *testing.T) {
+/*func Test_TransInfo(t *testing.T) {
 
 	//first get block height then test transinfo
 
@@ -105,7 +105,7 @@ func Test_TransInfo(t *testing.T) {
 
 	t.Logf("read bytes:%v", string(rbs))
 	return
-}
+}*/
 
 func Test_ChainHeight(t *testing.T) {
 	client := http.DefaultClient
@@ -198,14 +198,43 @@ func Test_SendRawTransaction(t *testing.T) {
 	return
 }
 
-func Test_TransferAccounts(t *testing.T) {
+func Test_SumCoinBalance(t *testing.T) {
+	client := http.DefaultClient
+	geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/sumcoinbalance`)
+	t.Logf("post url:%v", geturl)
+
+	//var b []byte
+	postdata := fmt.Sprintf(`{"cointype":"DCR","sumamount":5.0}`)
+	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_TransferAccounts(t *testing.T) {
 	client := http.DefaultClient
 	geturl := fmt.Sprintf(`http://localhost:15741/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.5","address":"Dsk52C4m56pmAnNAhejXypVGBDTi5GDrHpb","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte("/coinproxy/sendcoins"), timestamp))
+	postdata := fmt.Sprintf(`{"cointype":"DCR","amount":"0.002747","address":"DsgbyoXAB2PdsiU3yDpCtBww7FcxhTAV2Vr","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())
@@ -226,7 +255,7 @@ func Test_TransferAccounts(t *testing.T) {
 
 	t.Logf("read bytes:%v", string(rbs))
 	return
-}
+}*/
 
 func Signature(body []byte, timestamp string) string {
 

+ 103 - 11
src/dcrcash/dcrcashcoin.go

@@ -12,9 +12,9 @@ import (
 )
 
 var (
-	Config  config
-	CoinApi DcrCashApi
-	//Walletpass string
+	Config     config
+	CoinApi    DcrCashApi
+	WalleTxfee float64
 )
 
 type DcrCash struct {
@@ -22,8 +22,10 @@ type DcrCash struct {
 }
 
 const (
-	NameCoin    = "DCR"
-	SendToError = "-32603"
+	NameCoin           = "DCR"
+	SendToError        = "-32603"
+	DefaultMaxsumamout = 20.0
+	DEFAULTACCOUNT     = "default"
 )
 
 func (m DcrCash) InitDriver(param interface{}) bool {
@@ -94,21 +96,29 @@ 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 totalUnconfirbalance float64
+	//var totalConfirbalance float64
+	//var totalUnconfirbalance float64
+	var maxConfirbalance float64
+	var maxUnconfirbalance float64
 	for _, vbalance := range balance {
-		if vbalance.Spendable != 0 {
+		/*if vbalance.Spendable != 0 {
 			totalConfirbalance += vbalance.Spendable
 		}
 		if vbalance.Unconfirmed != 0 {
 			totalUnconfirbalance += vbalance.Unconfirmed
+		}*/
+		if vbalance.Spendable > maxConfirbalance {
+			maxConfirbalance = vbalance.Spendable
+		}
+		if vbalance.Unconfirmed > maxUnconfirbalance {
+			maxUnconfirbalance = vbalance.Unconfirmed
 		}
 
 	}
 	var jbuf []byte
 	resp := make(map[string]interface{})
-	resp["confirmedbalance"] = totalConfirbalance
-	resp["unconfirmed"] = totalUnconfirbalance
+	resp["confirmedbalance"] = maxConfirbalance
+	resp["unconfirmed"] = maxUnconfirbalance
 	resp["errcode"] = 0
 	resp["exact"] = 0
 	if jbuf, err = json.Marshal(resp); err != nil {
@@ -154,6 +164,68 @@ 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) {
+	pjs := parm.(*simplejson.Json)
+	//
+	Sumamount := pjs.Get("sumamount").MustFloat64()
+	Minsumamount := pjs.Get("minamount").MustFloat64()
+
+	if Sumamount <= 0.0 {
+		LOG("ERROR", " Summary amount is nil!")
+		Sumamount = DefaultMaxsumamout
+	}
+	if Minsumamount < WalleTxfee {
+		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
+	}
+	//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
+	}
+	var Totalbalance float64
+	transactionsids := make([]string, 0)
+	for account, value := range AccValues {
+		if (value > Minsumamount) && account != DEFAULTACCOUNT {
+			amount := value - WalleTxfee
+			transactionid, err := CoinApi.WalletSendFrom(account, DEFAULTACCOUNT, amount, 1, "", "")
+			if err != nil {
+				LOG("ERROR", " Send coin error:%v", err.Error())
+				//return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, SENDCOINS_ERR, getErrMsg(SENDCOINS_ERR, nil))
+				continue
+			}
+			transactionsids = append(transactionsids, transactionid)
+			Totalbalance += amount
+			if Totalbalance >= Sumamount {
+				break
+			}
+		}
+
+	}
+	if len(transactionsids) != 0 {
+		var jbuf []byte
+		resp := make(map[string]interface{})
+		resp["transcationids"] = transactionsids
+		resp["errcode"] = 0
+		resp["msg"] = "ok"
+
+		if jbuf, err = json.Marshal(resp); err != nil {
+			LOG("ERROR", " inner json error:%v", err.Error())
+			return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, INNER_ERR, getErrMsg(INNER_ERR, nil))
+		}
+		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))
+	//fromaccout = "default"
+}
+
 func (m DcrCash) TransferAccounts(parm interface{}) ([]byte, error) {
 	pjs := parm.(*simplejson.Json)
 	amountTmp := pjs.Get("amount").MustString()
@@ -170,8 +242,28 @@ func (m DcrCash) TransferAccounts(parm interface{}) ([]byte, error) {
 	}
 
 	amount := float64(f)
+	//list Accounts and account of balance
+	accountsofValues, err := CoinApi.ListAccounts()
+	if err != nil {
+		LOG("ERROR", "List accounts 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
+	}
+
+	fromaccout := ""
+	for account, value := range AccValues {
+		if value >= (amount + WalleTxfee) {
+			fromaccout = account
+			break
+		}
+
+	}
 
-	transactionid, err := CoinApi.WalleSendTo(destination, amount, "", "")
+	transactionid, err := CoinApi.WalletSendFrom(fromaccout, destination, amount, 1, "", "")
 	if err != nil {
 		LOG("ERROR", " Send coin error:%v", err.Error())
 		fmt.Println(transactionid)

+ 30 - 13
src/dcrcash/type.go

@@ -7,16 +7,16 @@ type RpcError struct {
 }
 
 //get wallet info result struct
-type OutwalletInfo struct {
-	daemonconnected  bool
-	unlocked         bool
-	txfee            float64
-	ticketfee        float64
-	ticketpurchasing bool
-	votebits         uint64
-	votebitsextended string
-	voteversion      uint64
-	voting           bool
+type WalletInfo struct {
+	DaemonConnected  bool    `json:"daemonconnected"`
+	Unlocked         bool    `json:"unlocked"`
+	TxFee            float64 `json:"txfee"`
+	TicketFee        float64 `json:"ticketfee"`
+	TicketPurchasing bool    `json:"ticketpurchasing"`
+	VoteBits         uint16  `json:"votebits"`
+	VoteBitsExtended string  `json:"votebitsextended"`
+	VoteVersion      uint32  `json:"voteversion"`
+	Voting           bool    `json:"voting"`
 }
 
 //  rpc  common result struct
@@ -34,9 +34,9 @@ type Setfeeresult struct {
 }
 
 type WalletinfoResult struct {
-	Result OutwalletInfo `json:"result"`
-	Error  RpcError      `json:"error"`
-	Id     int           `json:"id"`
+	Result WalletInfo `json:"result"`
+	Error  RpcError   `json:"error"`
+	Id     int        `json:"id"`
 }
 
 //get block count
@@ -209,3 +209,20 @@ type RpcUnspentResult struct {
 	Error  RpcError      `json:"error"`
 	Id     int           `json:"id"`
 }
+
+/*type AccountsOfvalue struct {
+	Account string  `json:"account"`
+	Balance float64 `json:"balance"`
+}*/
+
+type AccountsOfvaluesResult struct {
+	Result map[string]float64 `json:"result"`
+	Error  RpcError           `json:"error"`
+	Id     int                `json:"id"`
+}
+
+type OneaddressOfaccount struct {
+	Result string   `json:"result"`
+	Error  RpcError `json:"error"`
+	Id     int      `json:"id"`
+}

+ 4 - 0
src/lite/litecoins.go

@@ -339,6 +339,10 @@ func (m Lite) SendRawTransaction(parm interface{}) ([]byte, error) {
 	return jbuf, nil
 }
 
+func (m Lite) SumcoinBalance(parm interface{}) ([]byte, error) {
+	return nil, nil
+}
+
 func init() {
 	Register(NameLite, &Lite{})
 }

+ 17 - 14
src/template/template.go

@@ -13,26 +13,29 @@ type Template interface {
 	ChainHeight(parm interface{}) ([]byte, error)
 	ListUnspent(parm interface{}) ([]byte, error)
 	SendRawTransaction(parm interface{}) ([]byte, error)
+	SumcoinBalance(parm interface{}) ([]byte, error)
 }
 
 const (
-	CREATEADDR  = "/coinproxy/createaddr"
-	TRANSINFO   = "/coinproxy/query/transinfo"
-	COINBALANCE = "/coinproxy/coinbalance"
-	SENDCOINS   = "/coinproxy/sendcoins"
-	CHAINHEIGHT = "/coinproxy/blockchain/height"
-	LISTUNSPENT = "/coinproxy/listunspent"
-	RAWTRANSFER = "/coinproxy/sendrawtransaction"
+	CREATEADDR     = "/coinproxy/createaddr"
+	TRANSINFO      = "/coinproxy/query/transinfo"
+	COINBALANCE    = "/coinproxy/coinbalance"
+	SENDCOINS      = "/coinproxy/sendcoins"
+	CHAINHEIGHT    = "/coinproxy/blockchain/height"
+	LISTUNSPENT    = "/coinproxy/listunspent"
+	RAWTRANSFER    = "/coinproxy/sendrawtransaction"
+	SUMCOINBALANCE = "/coinproxy/sumcoinbalance"
 )
 
 var Handler = map[string]func(Template, interface{}) ([]byte, error){
-	CREATEADDR:  Template.CreateAddress,
-	COINBALANCE: Template.CoinBalance,
-	SENDCOINS:   Template.TransferAccounts,
-	TRANSINFO:   Template.TransInfo,
-	CHAINHEIGHT: Template.ChainHeight,
-	LISTUNSPENT: Template.ListUnspent,
-	RAWTRANSFER: Template.SendRawTransaction,
+	CREATEADDR:     Template.CreateAddress,
+	COINBALANCE:    Template.CoinBalance,
+	SENDCOINS:      Template.TransferAccounts,
+	TRANSINFO:      Template.TransInfo,
+	CHAINHEIGHT:    Template.ChainHeight,
+	LISTUNSPENT:    Template.ListUnspent,
+	RAWTRANSFER:    Template.SendRawTransaction,
+	SUMCOINBALANCE: Template.SumcoinBalance,
 }
 var drivers = make(map[string]Template)
 

+ 11 - 8
src/zcash/zcashcoins.go

@@ -70,7 +70,7 @@ func (m Zcash) TransInfo(parm interface{}) ([]byte, error) {
 	endH := pjs.Get("endh").MustUint64()
 
 	if startH < 1 {
-		startH=1
+		startH = 1
 	}
 
 	//get longest block count
@@ -79,7 +79,7 @@ func (m Zcash) TransInfo(parm interface{}) ([]byte, error) {
 		LOG("ERROR", "zcash WalleGetBlockCount  err:%v", err.Error())
 		return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, GETCLOCKCOUNT_ERR, getErrMsg(GETCLOCKCOUNT_ERR, nil))
 	}
-	
+
 	//first get block hash and time by height
 
 	if startH > blockcount {
@@ -93,7 +93,7 @@ func (m Zcash) TransInfo(parm interface{}) ([]byte, error) {
 		LOG("ERROR", "zcash GetBlockinfo startH:%v err:%v", startH, err.Error())
 		return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, GETBLOCKINFO_ERR, getErrMsg(GETBLOCKINFO_ERR, nil))
 	}
-	
+
 	if endH > blockcount {
 		LOG("DEBUG", "zcash endheight:%v >  blockcount:%v", endH, blockcount)
 		endH = blockcount
@@ -127,12 +127,12 @@ func (m Zcash) TransInfo(parm interface{}) ([]byte, error) {
 		// get all transactions from block startHright to endHeight
 		if zcashtransaction.Blocktime <= endblocktime {
 			requestData := make(map[string]interface{})
-			height, err :=zcashOp.WalletGetBlockHeight(zcashtransaction.Blockhash)
+			height, err := zcashOp.WalletGetBlockHeight(zcashtransaction.Blockhash)
 			if err != nil {
 				LOG("ERROR", "zcash WalletGetBlockHeight error:%v", err.Error())
 				return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, GETBLOCKINFO_ERR, getErrMsg(GETBLOCKINFO_ERR, nil))
 			}
-			requestData["confirmationheight"] =height
+			requestData["confirmationheight"] = height
 			requestData["address"] = zcashtransaction.Address
 			requestData["confirmationtimestamp"] = zcashtransaction.Timereceived
 			requestData["value"] = zcashtransaction.Amount
@@ -186,7 +186,7 @@ func (m Zcash) TransferAccounts(parm interface{}) ([]byte, error) {
 	if len(transactionid) != 0 {
 		var jbuf []byte
 		resp := make(map[string]interface{})
-		resp["transactionid"] =[] string{transactionid}
+		resp["transactionid"] = []string{transactionid}
 		resp["errcode"] = 0
 		resp["msg"] = "ok"
 
@@ -259,7 +259,7 @@ func (m Zcash) initconfig() bool {
 	zcashPort := ZecConfig.ZcashRpc.Zcashport
 
 	zcashOp.InitRpcConf(zcashUser, zcashPassword, zcashHost, zcashPort)
-	
+
 	initZcashErr()
 
 	f, err := strconv.ParseFloat(ZecConfig.Limit.Fee, 64)
@@ -288,9 +288,12 @@ func (m Zcash) ListUnspent(parm interface{}) ([]byte, error) {
 	return nil, nil
 }
 func (m Zcash) SendRawTransaction(parm interface{}) ([]byte, error) {
-        return nil, nil
+	return nil, nil
 }
 
+func (m Zcash) SumcoinBalance(parm interface{}) ([]byte, error) {
+	return nil, nil
+}
 
 func init() {
 	Register(NameZcash, &Zcash{})