|
@@ -12,9 +12,9 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
var (
|
|
var (
|
|
- Config config
|
|
|
|
- CoinApi DcrCashApi
|
|
|
|
- //Walletpass string
|
|
|
|
|
|
+ Config config
|
|
|
|
+ CoinApi DcrCashApi
|
|
|
|
+ WalleTxfee float64
|
|
)
|
|
)
|
|
|
|
|
|
type DcrCash struct {
|
|
type DcrCash struct {
|
|
@@ -22,8 +22,10 @@ type DcrCash struct {
|
|
}
|
|
}
|
|
|
|
|
|
const (
|
|
const (
|
|
- NameCoin = "DCR"
|
|
|
|
- SendToError = "-32603"
|
|
|
|
|
|
+ NameCoin = "DCR"
|
|
|
|
+ SendToError = "-32603"
|
|
|
|
+ DefaultMaxsumamout = 20.0
|
|
|
|
+ DEFAULTACCOUNT = "default"
|
|
)
|
|
)
|
|
|
|
|
|
func (m DcrCash) InitDriver(param interface{}) bool {
|
|
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())
|
|
LOG("ERROR", " inner json 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"}`, 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 {
|
|
for _, vbalance := range balance {
|
|
- if vbalance.Spendable != 0 {
|
|
|
|
|
|
+ /*if vbalance.Spendable != 0 {
|
|
totalConfirbalance += vbalance.Spendable
|
|
totalConfirbalance += vbalance.Spendable
|
|
}
|
|
}
|
|
if vbalance.Unconfirmed != 0 {
|
|
if vbalance.Unconfirmed != 0 {
|
|
totalUnconfirbalance += vbalance.Unconfirmed
|
|
totalUnconfirbalance += vbalance.Unconfirmed
|
|
|
|
+ }*/
|
|
|
|
+ if vbalance.Spendable > maxConfirbalance {
|
|
|
|
+ maxConfirbalance = vbalance.Spendable
|
|
|
|
+ }
|
|
|
|
+ if vbalance.Unconfirmed > maxUnconfirbalance {
|
|
|
|
+ maxUnconfirbalance = vbalance.Unconfirmed
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
var jbuf []byte
|
|
var jbuf []byte
|
|
resp := make(map[string]interface{})
|
|
resp := make(map[string]interface{})
|
|
- resp["confirmedbalance"] = totalConfirbalance
|
|
|
|
- resp["unconfirmed"] = totalUnconfirbalance
|
|
|
|
|
|
+ resp["confirmedbalance"] = maxConfirbalance
|
|
|
|
+ resp["unconfirmed"] = maxUnconfirbalance
|
|
resp["errcode"] = 0
|
|
resp["errcode"] = 0
|
|
resp["exact"] = 0
|
|
resp["exact"] = 0
|
|
if jbuf, err = json.Marshal(resp); err != nil {
|
|
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))
|
|
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) {
|
|
func (m DcrCash) TransferAccounts(parm interface{}) ([]byte, error) {
|
|
pjs := parm.(*simplejson.Json)
|
|
pjs := parm.(*simplejson.Json)
|
|
amountTmp := pjs.Get("amount").MustString()
|
|
amountTmp := pjs.Get("amount").MustString()
|
|
@@ -170,8 +242,28 @@ func (m DcrCash) TransferAccounts(parm interface{}) ([]byte, error) {
|
|
}
|
|
}
|
|
|
|
|
|
amount := float64(f)
|
|
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 {
|
|
if err != nil {
|
|
LOG("ERROR", " Send coin error:%v", err.Error())
|
|
LOG("ERROR", " Send coin error:%v", err.Error())
|
|
fmt.Println(transactionid)
|
|
fmt.Println(transactionid)
|