Commit 022f7688 authored by sanghg's avatar sanghg Committed by vipwzw

issues #55

修复make vet 提示错误
parent 2f689e0e
...@@ -164,11 +164,11 @@ func TestCheckRingSignatureAPI1(t *testing.T) { ...@@ -164,11 +164,11 @@ func TestCheckRingSignatureAPI1(t *testing.T) {
publickeys := make([][]byte, maxCount) publickeys := make([][]byte, maxCount)
prefixHash, err := common.FromHex("fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c") prefixHash, err := common.FromHex("fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c")
if err != nil { if err != nil {
t.Errorf("common.FromHex.", err) t.Errorf("common.FromHex. error %v", err)
} }
keyimage, err := common.FromHex("e7d85d6e81512c5650adce0499d6c17a83e2e29a05c1166cd2171b6b9288b3c4") keyimage, err := common.FromHex("e7d85d6e81512c5650adce0499d6c17a83e2e29a05c1166cd2171b6b9288b3c4")
if err != nil { if err != nil {
t.Errorf("common.FromHex.", err) t.Errorf("common.FromHex. error %v", err)
} }
tmp, err := common.FromHex("15e3cc7cdb904d62f7c20d7fa51923fa2839f9e0a92ff0eddf8c12bd09089c15") tmp, err := common.FromHex("15e3cc7cdb904d62f7c20d7fa51923fa2839f9e0a92ff0eddf8c12bd09089c15")
...@@ -337,7 +337,7 @@ func testRingSignatureOncetime(maxCount int, t *testing.T) { ...@@ -337,7 +337,7 @@ func testRingSignatureOncetime(maxCount int, t *testing.T) {
copy(sec[:], privkey.Bytes()) copy(sec[:], privkey.Bytes())
err = generateKeyImage(&pub, &sec, &image) err = generateKeyImage(&pub, &sec, &image)
if err != nil { if err != nil {
t.Errorf("generateKeyImage() failed. error ", err) t.Errorf("generateKeyImage() failed. error %v", err)
} }
} }
} }
...@@ -398,7 +398,7 @@ func TestGenerateRingSignatureAPI(t *testing.T) { ...@@ -398,7 +398,7 @@ func TestGenerateRingSignatureAPI(t *testing.T) {
var signaturedata *types.RingSignatureItem var signaturedata *types.RingSignatureItem
// step2. generate ring signature // step2. generate ring signature
if signaturedata, err = GenerateRingSignature(prefixHash, utxos, sec[:], realUtxoIndex, keyImage); err != nil { if signaturedata, err = GenerateRingSignature(prefixHash, utxos, sec[:], realUtxoIndex, keyImage); err != nil {
t.Errorf("GenerateRingSignature() failed. ", err) t.Errorf("GenerateRingSignature() failed. error %v", err)
} }
publickeys := make([][]byte, maxCount) publickeys := make([][]byte, maxCount)
......
...@@ -34,14 +34,14 @@ func (p *privacy) Exec_Public2Privacy(payload *ty.Public2Privacy, tx *types.Tran ...@@ -34,14 +34,14 @@ func (p *privacy) Exec_Public2Privacy(payload *ty.Public2Privacy, tx *types.Tran
for index, keyOutput := range output { for index, keyOutput := range output {
key := CalcPrivacyOutputKey(payload.Tokenname, keyOutput.Amount, txhash, index) key := CalcPrivacyOutputKey(payload.Tokenname, keyOutput.Amount, txhash, index)
value := types.Encode(keyOutput) value := types.Encode(keyOutput)
receipt.KV = append(receipt.KV, &types.KeyValue{key, value}) receipt.KV = append(receipt.KV, &types.KeyValue{Key: key, Value: value})
} }
receiptPrivacyOutput := &ty.ReceiptPrivacyOutput{ receiptPrivacyOutput := &ty.ReceiptPrivacyOutput{
Token: payload.Tokenname, Token: payload.Tokenname,
Keyoutput: payload.GetOutput().Keyoutput, Keyoutput: payload.GetOutput().Keyoutput,
} }
execlog := &types.ReceiptLog{ty.TyLogPrivacyOutput, types.Encode(receiptPrivacyOutput)} execlog := &types.ReceiptLog{Ty: ty.TyLogPrivacyOutput, Log: types.Encode(receiptPrivacyOutput)}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
//////////////////debug code begin/////////////// //////////////////debug code begin///////////////
...@@ -64,10 +64,10 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr ...@@ -64,10 +64,10 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr
key := calcPrivacyKeyImageKey(payload.Tokenname, keyInput.KeyImage) key := calcPrivacyKeyImageKey(payload.Tokenname, keyInput.KeyImage)
stateDB := p.GetStateDB() stateDB := p.GetStateDB()
stateDB.Set(key, value) stateDB.Set(key, value)
receipt.KV = append(receipt.KV, &types.KeyValue{key, value}) receipt.KV = append(receipt.KV, &types.KeyValue{Key: key, Value: value})
} }
execlog := &types.ReceiptLog{ty.TyLogPrivacyInput, types.Encode(payload.GetInput())} execlog := &types.ReceiptLog{Ty: ty.TyLogPrivacyInput, Log: types.Encode(payload.GetInput())}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
txhash := common.ToHex(tx.Hash()) txhash := common.ToHex(tx.Hash())
...@@ -75,14 +75,14 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr ...@@ -75,14 +75,14 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr
for index, keyOutput := range output { for index, keyOutput := range output {
key := CalcPrivacyOutputKey(payload.Tokenname, keyOutput.Amount, txhash, index) key := CalcPrivacyOutputKey(payload.Tokenname, keyOutput.Amount, txhash, index)
value := types.Encode(keyOutput) value := types.Encode(keyOutput)
receipt.KV = append(receipt.KV, &types.KeyValue{key, value}) receipt.KV = append(receipt.KV, &types.KeyValue{Key: key, Value: value})
} }
receiptPrivacyOutput := &ty.ReceiptPrivacyOutput{ receiptPrivacyOutput := &ty.ReceiptPrivacyOutput{
Token: payload.Tokenname, Token: payload.Tokenname,
Keyoutput: payload.GetOutput().Keyoutput, Keyoutput: payload.GetOutput().Keyoutput,
} }
execlog = &types.ReceiptLog{ty.TyLogPrivacyOutput, types.Encode(receiptPrivacyOutput)} execlog = &types.ReceiptLog{Ty: ty.TyLogPrivacyOutput, Log: types.Encode(receiptPrivacyOutput)}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
receipt.Ty = types.ExecOk receipt.Ty = types.ExecOk
...@@ -111,10 +111,10 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran ...@@ -111,10 +111,10 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
key := calcPrivacyKeyImageKey(payload.Tokenname, keyInput.KeyImage) key := calcPrivacyKeyImageKey(payload.Tokenname, keyInput.KeyImage)
stateDB := p.GetStateDB() stateDB := p.GetStateDB()
stateDB.Set(key, value) stateDB.Set(key, value)
receipt.KV = append(receipt.KV, &types.KeyValue{key, value}) receipt.KV = append(receipt.KV, &types.KeyValue{Key: key, Value: value})
} }
execlog := &types.ReceiptLog{ty.TyLogPrivacyInput, types.Encode(payload.GetInput())} execlog := &types.ReceiptLog{Ty: ty.TyLogPrivacyInput, Log: types.Encode(payload.GetInput())}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
txhash := common.ToHex(tx.Hash()) txhash := common.ToHex(tx.Hash())
...@@ -122,14 +122,14 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran ...@@ -122,14 +122,14 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
for index, keyOutput := range output { for index, keyOutput := range output {
key := CalcPrivacyOutputKey(payload.Tokenname, keyOutput.Amount, txhash, index) key := CalcPrivacyOutputKey(payload.Tokenname, keyOutput.Amount, txhash, index)
value := types.Encode(keyOutput) value := types.Encode(keyOutput)
receipt.KV = append(receipt.KV, &types.KeyValue{key, value}) receipt.KV = append(receipt.KV, &types.KeyValue{Key: key, Value: value})
} }
receiptPrivacyOutput := &ty.ReceiptPrivacyOutput{ receiptPrivacyOutput := &ty.ReceiptPrivacyOutput{
Token: payload.Tokenname, Token: payload.Tokenname,
Keyoutput: payload.GetOutput().Keyoutput, Keyoutput: payload.GetOutput().Keyoutput,
} }
execlog = &types.ReceiptLog{ty.TyLogPrivacyOutput, types.Encode(receiptPrivacyOutput)} execlog = &types.ReceiptLog{Ty: ty.TyLogPrivacyOutput, Log: types.Encode(receiptPrivacyOutput)}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
receipt.Ty = types.ExecOk receipt.Ty = types.ExecOk
......
...@@ -35,7 +35,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt ...@@ -35,7 +35,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt
for m, keyOutput := range receiptPrivacyOutput.Keyoutput { for m, keyOutput := range receiptPrivacyOutput.Keyoutput {
//kv1,添加一个具体的UTXO,方便我们可以查询相应token下特定额度下,不同高度时,不同txhash的UTXO //kv1,添加一个具体的UTXO,方便我们可以查询相应token下特定额度下,不同高度时,不同txhash的UTXO
key := CalcPrivacyUTXOkeyHeight(token, keyOutput.Amount, p.GetHeight(), txhash, i, m) key := CalcPrivacyUTXOkeyHeight(token, keyOutput.Amount, p.GetHeight(), txhash, i, m)
kv := &types.KeyValue{key, nil} kv := &types.KeyValue{Key: key, Value: nil}
dbSet.KV = append(dbSet.KV, kv) dbSet.KV = append(dbSet.KV, kv)
//kv2,添加各种不同额度的kv记录,能让我们很方便的获知本系统存在的所有不同的额度的UTXO //kv2,添加各种不同额度的kv记录,能让我们很方便的获知本系统存在的所有不同的额度的UTXO
...@@ -56,7 +56,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt ...@@ -56,7 +56,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt
} }
value2 := types.Encode(&amountTypes) value2 := types.Encode(&amountTypes)
kv := &types.KeyValue{key2, value2} kv := &types.KeyValue{Key: key2, Value: value2}
dbSet.KV = append(dbSet.KV, kv) dbSet.KV = append(dbSet.KV, kv)
//在本地的query数据库进行设置,这样可以防止相同的新增amout不会被重复生成kv,而进行重复的设置 //在本地的query数据库进行设置,这样可以防止相同的新增amout不会被重复生成kv,而进行重复的设置
localDB.Set(key2, nil) localDB.Set(key2, nil)
...@@ -75,7 +75,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt ...@@ -75,7 +75,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt
if settxhash == txhash { if settxhash == txhash {
delete(tokenNames.TokensMap, token) delete(tokenNames.TokensMap, token)
value3 := types.Encode(&tokenNames) value3 := types.Encode(&tokenNames)
kv := &types.KeyValue{key3, value3} kv := &types.KeyValue{Key: key3, Value: value3}
dbSet.KV = append(dbSet.KV, kv) dbSet.KV = append(dbSet.KV, kv)
localDB.Set(key3, nil) localDB.Set(key3, nil)
} }
......
...@@ -39,7 +39,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio ...@@ -39,7 +39,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
Onetimepubkey: keyOutput.Onetimepubkey, Onetimepubkey: keyOutput.Onetimepubkey,
} }
value := types.Encode(localUTXOItem) value := types.Encode(localUTXOItem)
kv := &types.KeyValue{key, value} kv := &types.KeyValue{Key: key, Value: value}
dbSet.KV = append(dbSet.KV, kv) dbSet.KV = append(dbSet.KV, kv)
//kv2,添加各种不同额度的kv记录,能让我们很方便的获知本系统存在的所有不同的额度的UTXO //kv2,添加各种不同额度的kv记录,能让我们很方便的获知本系统存在的所有不同的额度的UTXO
...@@ -58,7 +58,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio ...@@ -58,7 +58,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
//todo:考虑后续溢出的情况 //todo:考虑后续溢出的情况
amountTypes.AmountMap[keyOutput.Amount] = amount + 1 amountTypes.AmountMap[keyOutput.Amount] = amount + 1
} }
kv := &types.KeyValue{key2, types.Encode(&amountTypes)} kv := &types.KeyValue{Key: key2, Value: types.Encode(&amountTypes)}
dbSet.KV = append(dbSet.KV, kv) dbSet.KV = append(dbSet.KV, kv)
//在本地的query数据库进行设置,这样可以防止相同的新增amout不会被重复生成kv,而进行重复的设置 //在本地的query数据库进行设置,这样可以防止相同的新增amout不会被重复生成kv,而进行重复的设置
localDB.Set(key2, types.Encode(&amountTypes)) localDB.Set(key2, types.Encode(&amountTypes))
...@@ -70,7 +70,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio ...@@ -70,7 +70,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
//如果该种token第一次进行隐私操作 //如果该种token第一次进行隐私操作
amountTypes.AmountMap = make(map[int64]int64) amountTypes.AmountMap = make(map[int64]int64)
amountTypes.AmountMap[keyOutput.Amount] = 1 amountTypes.AmountMap[keyOutput.Amount] = 1
kv := &types.KeyValue{key2, types.Encode(&amountTypes)} kv := &types.KeyValue{Key: key2, Value: types.Encode(&amountTypes)}
dbSet.KV = append(dbSet.KV, kv) dbSet.KV = append(dbSet.KV, kv)
localDB.Set(key2, types.Encode(&amountTypes)) localDB.Set(key2, types.Encode(&amountTypes))
} }
...@@ -84,7 +84,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio ...@@ -84,7 +84,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
if err == nil { if err == nil {
if _, ok := tokenNames.TokensMap[token]; !ok { if _, ok := tokenNames.TokensMap[token]; !ok {
tokenNames.TokensMap[token] = txhash tokenNames.TokensMap[token] = txhash
kv := &types.KeyValue{key3, types.Encode(&tokenNames)} kv := &types.KeyValue{Key: key3, Value: types.Encode(&tokenNames)}
dbSet.KV = append(dbSet.KV, kv) dbSet.KV = append(dbSet.KV, kv)
localDB.Set(key3, types.Encode(&tokenNames)) localDB.Set(key3, types.Encode(&tokenNames))
} }
...@@ -92,7 +92,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio ...@@ -92,7 +92,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
} else { } else {
tokenNames.TokensMap = make(map[string]string) tokenNames.TokensMap = make(map[string]string)
tokenNames.TokensMap[token] = txhash tokenNames.TokensMap[token] = txhash
kv := &types.KeyValue{key3, types.Encode(&tokenNames)} kv := &types.KeyValue{Key: key3, Value: types.Encode(&tokenNames)}
dbSet.KV = append(dbSet.KV, kv) dbSet.KV = append(dbSet.KV, kv)
localDB.Set(key3, types.Encode(&tokenNames)) localDB.Set(key3, types.Encode(&tokenNames))
} }
......
...@@ -45,10 +45,10 @@ func TestRPC_Call(t *testing.T) { ...@@ -45,10 +45,10 @@ func TestRPC_Call(t *testing.T) {
Token: "token", Token: "token",
Displaymode: 3, Displaymode: 3,
} }
var utxo1 = &pty.UTXO{10, &pty.UTXOBasic{&pty.UTXOGlobalIndex{[]byte("hash1"), 1}, []byte("hello")}} var utxo1 = &pty.UTXO{Amount: 10, UtxoBasic: &pty.UTXOBasic{UtxoGlobalIndex: &pty.UTXOGlobalIndex{Txhash: []byte("hash1"), Outindex: 1}, OnetimePubkey: []byte("hello")}}
var utxo2 = &pty.UTXO{11, &pty.UTXOBasic{&pty.UTXOGlobalIndex{[]byte("hash2"), 2}, []byte("world")}} var utxo2 = &pty.UTXO{Amount: 11, UtxoBasic: &pty.UTXOBasic{UtxoGlobalIndex: &pty.UTXOGlobalIndex{Txhash: []byte("hash2"), Outindex: 2}, OnetimePubkey: []byte("world")}}
var res = pty.ReplyPrivacyAccount{ var res = pty.ReplyPrivacyAccount{
Utxos: &pty.UTXOs{[]*pty.UTXO{utxo1, utxo2}}, Utxos: &pty.UTXOs{Utxos: []*pty.UTXO{utxo1, utxo2}},
} }
api.On("ExecWalletFunc", "privacy", "ShowPrivacyAccountInfo", &params).Return(&res, nil) api.On("ExecWalletFunc", "privacy", "ShowPrivacyAccountInfo", &params).Return(&res, nil)
var result pty.ReplyPrivacyAccount var result pty.ReplyPrivacyAccount
......
...@@ -167,7 +167,7 @@ func (policy *privacyPolicy) createUTXOsByPub2Priv(priv crypto.PrivKey, reqCreat ...@@ -167,7 +167,7 @@ func (policy *privacyPolicy) createUTXOsByPub2Priv(priv crypto.PrivKey, reqCreat
} }
action := &privacytypes.PrivacyAction{ action := &privacytypes.PrivacyAction{
Ty: privacytypes.ActionPublic2Privacy, Ty: privacytypes.ActionPublic2Privacy,
Value: &privacytypes.PrivacyAction_Public2Privacy{value}, Value: &privacytypes.PrivacyAction_Public2Privacy{Public2Privacy: value},
} }
tx := &types.Transaction{ tx := &types.Transaction{
...@@ -1013,7 +1013,7 @@ func (policy *privacyPolicy) transPub2PriV2(priv crypto.PrivKey, reqPub2Pri *pri ...@@ -1013,7 +1013,7 @@ func (policy *privacyPolicy) transPub2PriV2(priv crypto.PrivKey, reqPub2Pri *pri
} }
action := &privacytypes.PrivacyAction{ action := &privacytypes.PrivacyAction{
Ty: privacytypes.ActionPublic2Privacy, Ty: privacytypes.ActionPublic2Privacy,
Value: &privacytypes.PrivacyAction_Public2Privacy{value}, Value: &privacytypes.PrivacyAction_Public2Privacy{Public2Privacy: value},
} }
tx := &types.Transaction{ tx := &types.Transaction{
Execer: []byte("privacy"), Execer: []byte("privacy"),
...@@ -1111,7 +1111,7 @@ func (policy *privacyPolicy) transPri2PriV2(privacykeyParirs *privacy.Privacy, r ...@@ -1111,7 +1111,7 @@ func (policy *privacyPolicy) transPri2PriV2(privacykeyParirs *privacy.Privacy, r
} }
action := &privacytypes.PrivacyAction{ action := &privacytypes.PrivacyAction{
Ty: privacytypes.ActionPrivacy2Privacy, Ty: privacytypes.ActionPrivacy2Privacy,
Value: &privacytypes.PrivacyAction_Privacy2Privacy{value}, Value: &privacytypes.PrivacyAction_Privacy2Privacy{Privacy2Privacy: value},
} }
tx := &types.Transaction{ tx := &types.Transaction{
...@@ -1237,7 +1237,7 @@ func (policy *privacyPolicy) transPri2PubV2(privacykeyParirs *privacy.Privacy, r ...@@ -1237,7 +1237,7 @@ func (policy *privacyPolicy) transPri2PubV2(privacykeyParirs *privacy.Privacy, r
} }
action := &privacytypes.PrivacyAction{ action := &privacytypes.PrivacyAction{
Ty: privacytypes.ActionPrivacy2Public, Ty: privacytypes.ActionPrivacy2Public,
Value: &privacytypes.PrivacyAction_Privacy2Public{value}, Value: &privacytypes.PrivacyAction_Privacy2Public{Privacy2Public: value},
} }
tx := &types.Transaction{ tx := &types.Transaction{
......
...@@ -390,15 +390,15 @@ func (store *privacyStore) getRescanUtxosFlag4Addr(req *privacytypes.ReqRescanUt ...@@ -390,15 +390,15 @@ func (store *privacyStore) getRescanUtxosFlag4Addr(req *privacytypes.ReqRescanUt
for _, addr := range storeAddrs { for _, addr := range storeAddrs {
value, err := store.Get(calcRescanUtxosFlagKey(addr)) value, err := store.Get(calcRescanUtxosFlagKey(addr))
if err != nil { if err != nil {
continue
bizlog.Error("getRescanUtxosFlag4Addr", "Failed to get calcRescanUtxosFlagKey(addr) for value", addr) bizlog.Error("getRescanUtxosFlag4Addr", "Failed to get calcRescanUtxosFlagKey(addr) for value", addr)
continue
} }
var data types.Int64 var data types.Int64
err = types.Decode(value, &data) err = types.Decode(value, &data)
if nil != err { if nil != err {
continue
bizlog.Error("getRescanUtxosFlag4Addr", "Failed to decode types.Int64 for value", value) bizlog.Error("getRescanUtxosFlag4Addr", "Failed to decode types.Int64 for value", value)
continue
} }
result := &privacytypes.RepRescanResult{ result := &privacytypes.RepRescanResult{
Addr: addr, Addr: addr,
......
...@@ -187,7 +187,7 @@ func testStore_getPrivacyTokenUTXOs(t *testing.T) { ...@@ -187,7 +187,7 @@ func testStore_getPrivacyTokenUTXOs(t *testing.T) {
data := &pt.PrivacyDBStore{Txindex: int32(n)} data := &pt.PrivacyDBStore{Txindex: int32(n)}
bt, err := proto.Marshal(data) bt, err := proto.Marshal(data)
assert.NoError(t, err) assert.NoError(t, err)
key := fmt.Sprint("Key%d", n) key := fmt.Sprintf("Key%d", n)
err = store.Set(calcUTXOKey4TokenAddr(token, addr, "txhash", n), []byte(key)) err = store.Set(calcUTXOKey4TokenAddr(token, addr, "txhash", n), []byte(key))
assert.NoError(t, err) assert.NoError(t, err)
err = store.Set([]byte(key), bt) err = store.Set([]byte(key), bt)
......
...@@ -297,7 +297,7 @@ func (r *Relayd) syncBlockHeaders() { ...@@ -297,7 +297,7 @@ func (r *Relayd) syncBlockHeaders() {
initIterHeight = breakHeight initIterHeight = breakHeight
log.Info("syncBlockHeaders", "len: ", len(headers)) log.Info("syncBlockHeaders", "len: ", len(headers))
btcHeaders := &ty.BtcHeaders{BtcHeader: headers} btcHeaders := &ty.BtcHeaders{BtcHeader: headers}
relayHeaders := &ty.RelayAction_BtcHeaders{btcHeaders} relayHeaders := &ty.RelayAction_BtcHeaders{BtcHeaders: btcHeaders}
action := &ty.RelayAction{ action := &ty.RelayAction{
Value: relayHeaders, Value: relayHeaders,
Ty: ty.RelayActionRcvBTCHeaders, Ty: ty.RelayActionRcvBTCHeaders,
...@@ -352,7 +352,7 @@ func (r *Relayd) dealOrder() { ...@@ -352,7 +352,7 @@ func (r *Relayd) dealOrder() {
Spv: spv, Spv: spv,
} }
rr := &ty.RelayAction_Verify{ rr := &ty.RelayAction_Verify{
verify, Verify: verify,
} }
action := &ty.RelayAction{ action := &ty.RelayAction{
Value: rr, Value: rr,
......
...@@ -327,7 +327,7 @@ func parseRelayBtcHeadHeightList(res ty.ReplyRelayBtcHeadHeightList) { ...@@ -327,7 +327,7 @@ func parseRelayBtcHeadHeightList(res ty.ReplyRelayBtcHeadHeightList) {
func parseRelayBtcCurHeight(res ty.ReplayRelayQryBTCHeadHeight) { func parseRelayBtcCurHeight(res ty.ReplayRelayQryBTCHeadHeight) {
data, err := json.MarshalIndent(res, "", " ") data, err := json.MarshalIndent(res, "", " ")
if err != nil { if err != nil {
fmt.Println(os.Stderr, err) fmt.Println(err)
return return
} }
......
...@@ -200,20 +200,20 @@ func getCreateOrderKeyValue(kv []*types.KeyValue, order *ty.RelayOrder, status i ...@@ -200,20 +200,20 @@ func getCreateOrderKeyValue(kv []*types.KeyValue, order *ty.RelayOrder, status i
OrderId := []byte(order.Id) OrderId := []byte(order.Id)
key := calcOrderKeyStatus(order, status) key := calcOrderKeyStatus(order, status)
kv = append(kv, &types.KeyValue{key, OrderId}) kv = append(kv, &types.KeyValue{Key: key, Value: OrderId})
key = calcOrderKeyCoin(order, status) key = calcOrderKeyCoin(order, status)
kv = append(kv, &types.KeyValue{key, OrderId}) kv = append(kv, &types.KeyValue{Key: key, Value: OrderId})
key = calcOrderKeyAddrStatus(order, status) key = calcOrderKeyAddrStatus(order, status)
kv = append(kv, &types.KeyValue{key, OrderId}) kv = append(kv, &types.KeyValue{Key: key, Value: OrderId})
key = calcOrderKeyAddrCoin(order, status) key = calcOrderKeyAddrCoin(order, status)
kv = append(kv, &types.KeyValue{key, OrderId}) kv = append(kv, &types.KeyValue{Key: key, Value: OrderId})
key = calcAcceptKeyAddr(order, status) key = calcAcceptKeyAddr(order, status)
if key != nil { if key != nil {
kv = append(kv, &types.KeyValue{key, OrderId}) kv = append(kv, &types.KeyValue{Key: key, Value: OrderId})
} }
return kv return kv
......
...@@ -284,20 +284,20 @@ func (t *trade) replyReplyBuyOrderfromID(key []byte) *pty.ReplyBuyOrder { ...@@ -284,20 +284,20 @@ func (t *trade) replyReplyBuyOrderfromID(key []byte) *pty.ReplyBuyOrder {
func sellOrder2reply(sellOrder *pty.SellOrder) *pty.ReplySellOrder { func sellOrder2reply(sellOrder *pty.SellOrder) *pty.ReplySellOrder {
reply := &pty.ReplySellOrder{ reply := &pty.ReplySellOrder{
sellOrder.TokenSymbol, TokenSymbol: sellOrder.TokenSymbol,
sellOrder.Address, Owner: sellOrder.Address,
sellOrder.AmountPerBoardlot, AmountPerBoardlot: sellOrder.AmountPerBoardlot,
sellOrder.MinBoardlot, MinBoardlot: sellOrder.MinBoardlot,
sellOrder.PricePerBoardlot, PricePerBoardlot: sellOrder.PricePerBoardlot,
sellOrder.TotalBoardlot, TotalBoardlot: sellOrder.TotalBoardlot,
sellOrder.SoldBoardlot, SoldBoardlot: sellOrder.SoldBoardlot,
"", BuyID: "",
sellOrder.Status, Status: sellOrder.Status,
sellOrder.SellID, SellID: sellOrder.SellID,
strings.Replace(sellOrder.SellID, sellIDPrefix, "0x", 1), TxHash: strings.Replace(sellOrder.SellID, sellIDPrefix, "0x", 1),
sellOrder.Height, Height: sellOrder.Height,
sellOrder.SellID, Key: sellOrder.SellID,
sellOrder.AssetExec, AssetExec: sellOrder.AssetExec,
} }
return reply return reply
} }
...@@ -327,20 +327,20 @@ func txResult2sellOrderReply(txResult *types.TxResult) *pty.ReplySellOrder { ...@@ -327,20 +327,20 @@ func txResult2sellOrderReply(txResult *types.TxResult) *pty.ReplySellOrder {
txhash := common.ToHex(txResult.GetTx().Hash()) txhash := common.ToHex(txResult.GetTx().Hash())
reply := &pty.ReplySellOrder{ reply := &pty.ReplySellOrder{
receipt.Base.TokenSymbol, TokenSymbol: receipt.Base.TokenSymbol,
receipt.Base.Owner, Owner: receipt.Base.Owner,
int64(amount * float64(types.TokenPrecision)), AmountPerBoardlot: int64(amount * float64(types.TokenPrecision)),
receipt.Base.MinBoardlot, MinBoardlot: receipt.Base.MinBoardlot,
int64(price * float64(types.Coin)), PricePerBoardlot: int64(price * float64(types.Coin)),
receipt.Base.TotalBoardlot, TotalBoardlot: receipt.Base.TotalBoardlot,
receipt.Base.SoldBoardlot, SoldBoardlot: receipt.Base.SoldBoardlot,
receipt.Base.BuyID, BuyID: receipt.Base.BuyID,
pty.SellOrderStatus2Int[receipt.Base.Status], Status: pty.SellOrderStatus2Int[receipt.Base.Status],
"", SellID: "",
txhash, TxHash: txhash,
receipt.Base.Height, Height: receipt.Base.Height,
txhash, Key: txhash,
receipt.Base.AssetExec, AssetExec: receipt.Base.AssetExec,
} }
tradelog.Debug("txResult2sellOrderReply", "show reply", reply) tradelog.Debug("txResult2sellOrderReply", "show reply", reply)
return reply return reply
...@@ -351,20 +351,20 @@ func txResult2sellOrderReply(txResult *types.TxResult) *pty.ReplySellOrder { ...@@ -351,20 +351,20 @@ func txResult2sellOrderReply(txResult *types.TxResult) *pty.ReplySellOrder {
func buyOrder2reply(buyOrder *pty.BuyLimitOrder) *pty.ReplyBuyOrder { func buyOrder2reply(buyOrder *pty.BuyLimitOrder) *pty.ReplyBuyOrder {
reply := &pty.ReplyBuyOrder{ reply := &pty.ReplyBuyOrder{
buyOrder.TokenSymbol, TokenSymbol: buyOrder.TokenSymbol,
buyOrder.Address, Owner: buyOrder.Address,
buyOrder.AmountPerBoardlot, AmountPerBoardlot: buyOrder.AmountPerBoardlot,
buyOrder.MinBoardlot, MinBoardlot: buyOrder.MinBoardlot,
buyOrder.PricePerBoardlot, PricePerBoardlot: buyOrder.PricePerBoardlot,
buyOrder.TotalBoardlot, TotalBoardlot: buyOrder.TotalBoardlot,
buyOrder.BoughtBoardlot, BoughtBoardlot: buyOrder.BoughtBoardlot,
buyOrder.BuyID, BuyID: buyOrder.BuyID,
buyOrder.Status, Status: buyOrder.Status,
"", SellID: "",
strings.Replace(buyOrder.BuyID, buyIDPrefix, "0x", 1), TxHash: strings.Replace(buyOrder.BuyID, buyIDPrefix, "0x", 1),
buyOrder.Height, Height: buyOrder.Height,
buyOrder.BuyID, Key: buyOrder.BuyID,
buyOrder.AssetExec, AssetExec: buyOrder.AssetExec,
} }
return reply return reply
} }
...@@ -393,20 +393,20 @@ func txResult2buyOrderReply(txResult *types.TxResult) *pty.ReplyBuyOrder { ...@@ -393,20 +393,20 @@ func txResult2buyOrderReply(txResult *types.TxResult) *pty.ReplyBuyOrder {
} }
txhash := common.ToHex(txResult.GetTx().Hash()) txhash := common.ToHex(txResult.GetTx().Hash())
reply := &pty.ReplyBuyOrder{ reply := &pty.ReplyBuyOrder{
receipt.Base.TokenSymbol, TokenSymbol: receipt.Base.TokenSymbol,
receipt.Base.Owner, Owner: receipt.Base.Owner,
int64(amount * float64(types.TokenPrecision)), AmountPerBoardlot: int64(amount * float64(types.TokenPrecision)),
receipt.Base.MinBoardlot, MinBoardlot: receipt.Base.MinBoardlot,
int64(price * float64(types.Coin)), PricePerBoardlot: int64(price * float64(types.Coin)),
receipt.Base.TotalBoardlot, TotalBoardlot: receipt.Base.TotalBoardlot,
receipt.Base.BoughtBoardlot, BoughtBoardlot: receipt.Base.BoughtBoardlot,
"", BuyID: "",
pty.SellOrderStatus2Int[receipt.Base.Status], Status: pty.SellOrderStatus2Int[receipt.Base.Status],
receipt.Base.SellID, SellID: receipt.Base.SellID,
txhash, TxHash: txhash,
receipt.Base.Height, Height: receipt.Base.Height,
txhash, Key: txhash,
receipt.Base.AssetExec, AssetExec: receipt.Base.AssetExec,
} }
tradelog.Debug("txResult2sellOrderReply", "show reply", reply) tradelog.Debug("txResult2sellOrderReply", "show reply", reply)
return reply return reply
...@@ -466,22 +466,22 @@ func buyBase2Order(base *pty.ReceiptBuyBase, txHash string, blockTime int64) *pt ...@@ -466,22 +466,22 @@ func buyBase2Order(base *pty.ReceiptBuyBase, txHash string, blockTime int64) *pt
} }
//txhash := common.ToHex(txResult.GetTx().Hash()) //txhash := common.ToHex(txResult.GetTx().Hash())
reply := &pty.ReplyTradeOrder{ reply := &pty.ReplyTradeOrder{
base.TokenSymbol, TokenSymbol: base.TokenSymbol,
base.Owner, Owner: base.Owner,
int64(amount * float64(types.TokenPrecision)), AmountPerBoardlot: int64(amount * float64(types.TokenPrecision)),
base.MinBoardlot, MinBoardlot: base.MinBoardlot,
int64(price * float64(types.Coin)), PricePerBoardlot: int64(price * float64(types.Coin)),
base.TotalBoardlot, TotalBoardlot: base.TotalBoardlot,
base.BoughtBoardlot, TradedBoardlot: base.BoughtBoardlot,
base.BuyID, BuyID: base.BuyID,
pty.SellOrderStatus2Int[base.Status], Status: pty.SellOrderStatus2Int[base.Status],
base.SellID, SellID: base.SellID,
txHash, TxHash: txHash,
base.Height, Height: base.Height,
key, Key: key,
blockTime, BlockTime: blockTime,
false, IsSellOrder: false,
base.AssetExec, AssetExec: base.AssetExec,
} }
tradelog.Debug("txResult2sellOrderReply", "show reply", reply) tradelog.Debug("txResult2sellOrderReply", "show reply", reply)
return reply return reply
...@@ -504,22 +504,22 @@ func sellBase2Order(base *pty.ReceiptSellBase, txHash string, blockTime int64) * ...@@ -504,22 +504,22 @@ func sellBase2Order(base *pty.ReceiptSellBase, txHash string, blockTime int64) *
key = base.SellID key = base.SellID
} }
reply := &pty.ReplyTradeOrder{ reply := &pty.ReplyTradeOrder{
base.TokenSymbol, TokenSymbol: base.TokenSymbol,
base.Owner, Owner: base.Owner,
int64(amount * float64(types.TokenPrecision)), AmountPerBoardlot: int64(amount * float64(types.TokenPrecision)),
base.MinBoardlot, MinBoardlot: base.MinBoardlot,
int64(price * float64(types.Coin)), PricePerBoardlot: int64(price * float64(types.Coin)),
base.TotalBoardlot, TotalBoardlot: base.TotalBoardlot,
base.SoldBoardlot, TradedBoardlot: base.SoldBoardlot,
base.BuyID, BuyID: base.BuyID,
pty.SellOrderStatus2Int[base.Status], Status: pty.SellOrderStatus2Int[base.Status],
base.SellID, SellID: base.SellID,
txHash, TxHash: txHash,
base.Height, Height: base.Height,
key, Key: key,
blockTime, BlockTime: blockTime,
true, IsSellOrder: true,
base.AssetExec, AssetExec: base.AssetExec,
} }
tradelog.Debug("txResult2sellOrderReply", "show reply", reply) tradelog.Debug("txResult2sellOrderReply", "show reply", reply)
return reply return reply
...@@ -630,15 +630,13 @@ func (t *trade) loadOrderFromKey(key []byte) *pty.ReplyTradeOrder { ...@@ -630,15 +630,13 @@ func (t *trade) loadOrderFromKey(key []byte) *pty.ReplyTradeOrder {
} }
reply.TradedBoardlot = buyOrder.BoughtBoardlot reply.TradedBoardlot = buyOrder.BoughtBoardlot
return reply return reply
} else { // txhash as key
txResult, err := getTx(key, t.GetLocalDB())
tradelog.Debug("loadOrderFromKey ", "load txhash", string(key))
if err != nil {
return nil
}
return txResult2OrderReply(txResult)
} }
return nil txResult, err := getTx(key, t.GetLocalDB())
tradelog.Debug("loadOrderFromKey ", "load txhash", string(key))
if err != nil {
return nil
}
return txResult2OrderReply(txResult)
} }
func (t *trade) GetOnesOrderWithStatus(req *pty.ReqAddrAssets) (types.Message, error) { func (t *trade) GetOnesOrderWithStatus(req *pty.ReqAddrAssets) (types.Message, error) {
......
...@@ -112,7 +112,7 @@ func (t *tradeType) Amount(tx *types.Transaction) (int64, error) { ...@@ -112,7 +112,7 @@ func (t *tradeType) Amount(tx *types.Transaction) (int64, error) {
} }
func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) { func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
var tx *types.Transaction //var tx *types.Transaction
if action == "TradeSellLimit" { if action == "TradeSellLimit" {
var param TradeSellTx var param TradeSellTx
err := json.Unmarshal(message, &param) err := json.Unmarshal(message, &param)
...@@ -161,11 +161,9 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra ...@@ -161,11 +161,9 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
return CreateRawTradeRevokeBuyTx(&param) return CreateRawTradeRevokeBuyTx(&param)
} else {
return nil, types.ErrNotSupport
} }
return tx, nil return nil, types.ErrNotSupport
} }
//CreateRawTradeSellTx : 创建卖单交易 //CreateRawTradeSellTx : 创建卖单交易
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment