Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
022f7688
Commit
022f7688
authored
Nov 22, 2018
by
sanghg
Committed by
vipwzw
Nov 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issues #55
修复make vet 提示错误
parent
2f689e0e
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
136 additions
and
140 deletions
+136
-140
ring_signature_test.go
plugin/dapp/privacy/crypto/ring_signature_test.go
+4
-4
exec.go
plugin/dapp/privacy/executor/exec.go
+10
-10
exec_del_local.go
plugin/dapp/privacy/executor/exec_del_local.go
+3
-3
exec_local.go
plugin/dapp/privacy/executor/exec_local.go
+5
-5
rpc_real_test.go
plugin/dapp/privacy/rpc/rpc_real_test.go
+3
-3
privacy.go
plugin/dapp/privacy/wallet/privacy.go
+4
-4
privacystore.go
plugin/dapp/privacy/wallet/privacystore.go
+2
-2
privacystore_test.go
plugin/dapp/privacy/wallet/privacystore_test.go
+1
-1
relayd.go
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
+2
-2
relay.go
plugin/dapp/relay/commands/relay.go
+1
-1
relay.go
plugin/dapp/relay/executor/relay.go
+5
-5
query.go
plugin/dapp/trade/executor/query.go
+94
-96
trade.go
plugin/dapp/trade/types/trade.go
+2
-4
No files found.
plugin/dapp/privacy/crypto/ring_signature_test.go
View file @
022f7688
...
...
@@ -164,11 +164,11 @@ func TestCheckRingSignatureAPI1(t *testing.T) {
publickeys
:=
make
([][]
byte
,
maxCount
)
prefixHash
,
err
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
if
err
!=
nil
{
t
.
Errorf
(
"common.FromHex."
,
err
)
t
.
Errorf
(
"common.FromHex.
error %v
"
,
err
)
}
keyimage
,
err
:=
common
.
FromHex
(
"e7d85d6e81512c5650adce0499d6c17a83e2e29a05c1166cd2171b6b9288b3c4"
)
if
err
!=
nil
{
t
.
Errorf
(
"common.FromHex."
,
err
)
t
.
Errorf
(
"common.FromHex.
error %v
"
,
err
)
}
tmp
,
err
:=
common
.
FromHex
(
"15e3cc7cdb904d62f7c20d7fa51923fa2839f9e0a92ff0eddf8c12bd09089c15"
)
...
...
@@ -337,7 +337,7 @@ func testRingSignatureOncetime(maxCount int, t *testing.T) {
copy
(
sec
[
:
],
privkey
.
Bytes
())
err
=
generateKeyImage
(
&
pub
,
&
sec
,
&
image
)
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) {
var
signaturedata
*
types
.
RingSignatureItem
// step2. generate ring signature
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
)
...
...
plugin/dapp/privacy/executor/exec.go
View file @
022f7688
...
...
@@ -34,14 +34,14 @@ func (p *privacy) Exec_Public2Privacy(payload *ty.Public2Privacy, tx *types.Tran
for
index
,
keyOutput
:=
range
output
{
key
:=
CalcPrivacyOutputKey
(
payload
.
Tokenname
,
keyOutput
.
Amount
,
txhash
,
index
)
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
{
Token
:
payload
.
Tokenname
,
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
)
//////////////////debug code begin///////////////
...
...
@@ -64,10 +64,10 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr
key
:=
calcPrivacyKeyImageKey
(
payload
.
Tokenname
,
keyInput
.
KeyImage
)
stateDB
:=
p
.
GetStateDB
()
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
)
txhash
:=
common
.
ToHex
(
tx
.
Hash
())
...
...
@@ -75,14 +75,14 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr
for
index
,
keyOutput
:=
range
output
{
key
:=
CalcPrivacyOutputKey
(
payload
.
Tokenname
,
keyOutput
.
Amount
,
txhash
,
index
)
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
{
Token
:
payload
.
Tokenname
,
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
.
Ty
=
types
.
ExecOk
...
...
@@ -111,10 +111,10 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
key
:=
calcPrivacyKeyImageKey
(
payload
.
Tokenname
,
keyInput
.
KeyImage
)
stateDB
:=
p
.
GetStateDB
()
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
)
txhash
:=
common
.
ToHex
(
tx
.
Hash
())
...
...
@@ -122,14 +122,14 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
for
index
,
keyOutput
:=
range
output
{
key
:=
CalcPrivacyOutputKey
(
payload
.
Tokenname
,
keyOutput
.
Amount
,
txhash
,
index
)
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
{
Token
:
payload
.
Tokenname
,
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
.
Ty
=
types
.
ExecOk
...
...
plugin/dapp/privacy/executor/exec_del_local.go
View file @
022f7688
...
...
@@ -35,7 +35,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt
for
m
,
keyOutput
:=
range
receiptPrivacyOutput
.
Keyoutput
{
//kv1,添加一个具体的UTXO,方便我们可以查询相应token下特定额度下,不同高度时,不同txhash的UTXO
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
)
//kv2,添加各种不同额度的kv记录,能让我们很方便的获知本系统存在的所有不同的额度的UTXO
...
...
@@ -56,7 +56,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt
}
value2
:=
types
.
Encode
(
&
amountTypes
)
kv
:=
&
types
.
KeyValue
{
key2
,
value2
}
kv
:=
&
types
.
KeyValue
{
Key
:
key2
,
Value
:
value2
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
//在本地的query数据库进行设置,这样可以防止相同的新增amout不会被重复生成kv,而进行重复的设置
localDB
.
Set
(
key2
,
nil
)
...
...
@@ -75,7 +75,7 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt
if
settxhash
==
txhash
{
delete
(
tokenNames
.
TokensMap
,
token
)
value3
:=
types
.
Encode
(
&
tokenNames
)
kv
:=
&
types
.
KeyValue
{
key3
,
value3
}
kv
:=
&
types
.
KeyValue
{
Key
:
key3
,
Value
:
value3
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
localDB
.
Set
(
key3
,
nil
)
}
...
...
plugin/dapp/privacy/executor/exec_local.go
View file @
022f7688
...
...
@@ -39,7 +39,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
Onetimepubkey
:
keyOutput
.
Onetimepubkey
,
}
value
:=
types
.
Encode
(
localUTXOItem
)
kv
:=
&
types
.
KeyValue
{
key
,
value
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
//kv2,添加各种不同额度的kv记录,能让我们很方便的获知本系统存在的所有不同的额度的UTXO
...
...
@@ -58,7 +58,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
//todo:考虑后续溢出的情况
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
)
//在本地的query数据库进行设置,这样可以防止相同的新增amout不会被重复生成kv,而进行重复的设置
localDB
.
Set
(
key2
,
types
.
Encode
(
&
amountTypes
))
...
...
@@ -70,7 +70,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
//如果该种token第一次进行隐私操作
amountTypes
.
AmountMap
=
make
(
map
[
int64
]
int64
)
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
)
localDB
.
Set
(
key2
,
types
.
Encode
(
&
amountTypes
))
}
...
...
@@ -84,7 +84,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
if
err
==
nil
{
if
_
,
ok
:=
tokenNames
.
TokensMap
[
token
];
!
ok
{
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
)
localDB
.
Set
(
key3
,
types
.
Encode
(
&
tokenNames
))
}
...
...
@@ -92,7 +92,7 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
}
else
{
tokenNames
.
TokensMap
=
make
(
map
[
string
]
string
)
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
)
localDB
.
Set
(
key3
,
types
.
Encode
(
&
tokenNames
))
}
...
...
plugin/dapp/privacy/rpc/rpc_real_test.go
View file @
022f7688
...
...
@@ -45,10 +45,10 @@ func TestRPC_Call(t *testing.T) {
Token
:
"token"
,
Displaymode
:
3
,
}
var
utxo1
=
&
pty
.
UTXO
{
10
,
&
pty
.
UTXOBasic
{
&
pty
.
UTXOGlobalIndex
{[]
byte
(
"hash1"
),
1
},
[]
byte
(
"hello"
)}}
var
utxo2
=
&
pty
.
UTXO
{
11
,
&
pty
.
UTXOBasic
{
&
pty
.
UTXOGlobalIndex
{[]
byte
(
"hash2"
),
2
},
[]
byte
(
"world"
)}}
var
utxo1
=
&
pty
.
UTXO
{
Amount
:
10
,
UtxoBasic
:
&
pty
.
UTXOBasic
{
UtxoGlobalIndex
:
&
pty
.
UTXOGlobalIndex
{
Txhash
:
[]
byte
(
"hash1"
),
Outindex
:
1
},
OnetimePubkey
:
[]
byte
(
"hello"
)}}
var
utxo2
=
&
pty
.
UTXO
{
Amount
:
11
,
UtxoBasic
:
&
pty
.
UTXOBasic
{
UtxoGlobalIndex
:
&
pty
.
UTXOGlobalIndex
{
Txhash
:
[]
byte
(
"hash2"
),
Outindex
:
2
},
OnetimePubkey
:
[]
byte
(
"world"
)}}
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
)
var
result
pty
.
ReplyPrivacyAccount
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
022f7688
...
...
@@ -167,7 +167,7 @@ func (policy *privacyPolicy) createUTXOsByPub2Priv(priv crypto.PrivKey, reqCreat
}
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPublic2Privacy
,
Value
:
&
privacytypes
.
PrivacyAction_Public2Privacy
{
value
},
Value
:
&
privacytypes
.
PrivacyAction_Public2Privacy
{
Public2Privacy
:
value
},
}
tx
:=
&
types
.
Transaction
{
...
...
@@ -1013,7 +1013,7 @@ func (policy *privacyPolicy) transPub2PriV2(priv crypto.PrivKey, reqPub2Pri *pri
}
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPublic2Privacy
,
Value
:
&
privacytypes
.
PrivacyAction_Public2Privacy
{
value
},
Value
:
&
privacytypes
.
PrivacyAction_Public2Privacy
{
Public2Privacy
:
value
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"privacy"
),
...
...
@@ -1111,7 +1111,7 @@ func (policy *privacyPolicy) transPri2PriV2(privacykeyParirs *privacy.Privacy, r
}
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPrivacy2Privacy
,
Value
:
&
privacytypes
.
PrivacyAction_Privacy2Privacy
{
value
},
Value
:
&
privacytypes
.
PrivacyAction_Privacy2Privacy
{
Privacy2Privacy
:
value
},
}
tx
:=
&
types
.
Transaction
{
...
...
@@ -1237,7 +1237,7 @@ func (policy *privacyPolicy) transPri2PubV2(privacykeyParirs *privacy.Privacy, r
}
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPrivacy2Public
,
Value
:
&
privacytypes
.
PrivacyAction_Privacy2Public
{
value
},
Value
:
&
privacytypes
.
PrivacyAction_Privacy2Public
{
Privacy2Public
:
value
},
}
tx
:=
&
types
.
Transaction
{
...
...
plugin/dapp/privacy/wallet/privacystore.go
View file @
022f7688
...
...
@@ -390,15 +390,15 @@ func (store *privacyStore) getRescanUtxosFlag4Addr(req *privacytypes.ReqRescanUt
for
_
,
addr
:=
range
storeAddrs
{
value
,
err
:=
store
.
Get
(
calcRescanUtxosFlagKey
(
addr
))
if
err
!=
nil
{
continue
bizlog
.
Error
(
"getRescanUtxosFlag4Addr"
,
"Failed to get calcRescanUtxosFlagKey(addr) for value"
,
addr
)
continue
}
var
data
types
.
Int64
err
=
types
.
Decode
(
value
,
&
data
)
if
nil
!=
err
{
continue
bizlog
.
Error
(
"getRescanUtxosFlag4Addr"
,
"Failed to decode types.Int64 for value"
,
value
)
continue
}
result
:=
&
privacytypes
.
RepRescanResult
{
Addr
:
addr
,
...
...
plugin/dapp/privacy/wallet/privacystore_test.go
View file @
022f7688
...
...
@@ -187,7 +187,7 @@ func testStore_getPrivacyTokenUTXOs(t *testing.T) {
data
:=
&
pt
.
PrivacyDBStore
{
Txindex
:
int32
(
n
)}
bt
,
err
:=
proto
.
Marshal
(
data
)
assert
.
NoError
(
t
,
err
)
key
:=
fmt
.
Sprint
(
"Key%d"
,
n
)
key
:=
fmt
.
Sprint
f
(
"Key%d"
,
n
)
err
=
store
.
Set
(
calcUTXOKey4TokenAddr
(
token
,
addr
,
"txhash"
,
n
),
[]
byte
(
key
))
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
([]
byte
(
key
),
bt
)
...
...
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
View file @
022f7688
...
...
@@ -297,7 +297,7 @@ func (r *Relayd) syncBlockHeaders() {
initIterHeight
=
breakHeight
log
.
Info
(
"syncBlockHeaders"
,
"len: "
,
len
(
headers
))
btcHeaders
:=
&
ty
.
BtcHeaders
{
BtcHeader
:
headers
}
relayHeaders
:=
&
ty
.
RelayAction_BtcHeaders
{
btcHeaders
}
relayHeaders
:=
&
ty
.
RelayAction_BtcHeaders
{
BtcHeaders
:
btcHeaders
}
action
:=
&
ty
.
RelayAction
{
Value
:
relayHeaders
,
Ty
:
ty
.
RelayActionRcvBTCHeaders
,
...
...
@@ -352,7 +352,7 @@ func (r *Relayd) dealOrder() {
Spv
:
spv
,
}
rr
:=
&
ty
.
RelayAction_Verify
{
verify
,
Verify
:
verify
,
}
action
:=
&
ty
.
RelayAction
{
Value
:
rr
,
...
...
plugin/dapp/relay/commands/relay.go
View file @
022f7688
...
...
@@ -327,7 +327,7 @@ func parseRelayBtcHeadHeightList(res ty.ReplyRelayBtcHeadHeightList) {
func
parseRelayBtcCurHeight
(
res
ty
.
ReplayRelayQryBTCHeadHeight
)
{
data
,
err
:=
json
.
MarshalIndent
(
res
,
""
,
" "
)
if
err
!=
nil
{
fmt
.
Println
(
os
.
Stderr
,
err
)
fmt
.
Println
(
err
)
return
}
...
...
plugin/dapp/relay/executor/relay.go
View file @
022f7688
...
...
@@ -200,20 +200,20 @@ func getCreateOrderKeyValue(kv []*types.KeyValue, order *ty.RelayOrder, status i
OrderId
:=
[]
byte
(
order
.
Id
)
key
:=
calcOrderKeyStatus
(
order
,
status
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
key
,
OrderId
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
OrderId
})
key
=
calcOrderKeyCoin
(
order
,
status
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
key
,
OrderId
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
OrderId
})
key
=
calcOrderKeyAddrStatus
(
order
,
status
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
key
,
OrderId
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
OrderId
})
key
=
calcOrderKeyAddrCoin
(
order
,
status
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
key
,
OrderId
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
OrderId
})
key
=
calcAcceptKeyAddr
(
order
,
status
)
if
key
!=
nil
{
kv
=
append
(
kv
,
&
types
.
KeyValue
{
key
,
OrderId
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
OrderId
})
}
return
kv
...
...
plugin/dapp/trade/executor/query.go
View file @
022f7688
...
...
@@ -284,20 +284,20 @@ func (t *trade) replyReplyBuyOrderfromID(key []byte) *pty.ReplyBuyOrder {
func
sellOrder2reply
(
sellOrder
*
pty
.
SellOrder
)
*
pty
.
ReplySellOrder
{
reply
:=
&
pty
.
ReplySellOrder
{
sellOrder
.
TokenSymbol
,
sellOrder
.
Address
,
sellOrder
.
AmountPerBoardlot
,
sellOrder
.
MinBoardlot
,
sellOrder
.
PricePerBoardlot
,
sellOrder
.
TotalBoardlot
,
sellOrder
.
SoldBoardlot
,
""
,
sellOrder
.
Status
,
sellOrder
.
SellID
,
strings
.
Replace
(
sellOrder
.
SellID
,
sellIDPrefix
,
"0x"
,
1
),
sellOrder
.
Height
,
sellOrder
.
SellID
,
sellOrder
.
AssetExec
,
TokenSymbol
:
sellOrder
.
TokenSymbol
,
Owner
:
sellOrder
.
Address
,
AmountPerBoardlot
:
sellOrder
.
AmountPerBoardlot
,
MinBoardlot
:
sellOrder
.
MinBoardlot
,
PricePerBoardlot
:
sellOrder
.
PricePerBoardlot
,
TotalBoardlot
:
sellOrder
.
TotalBoardlot
,
SoldBoardlot
:
sellOrder
.
SoldBoardlot
,
BuyID
:
""
,
Status
:
sellOrder
.
Status
,
SellID
:
sellOrder
.
SellID
,
TxHash
:
strings
.
Replace
(
sellOrder
.
SellID
,
sellIDPrefix
,
"0x"
,
1
),
Height
:
sellOrder
.
Height
,
Key
:
sellOrder
.
SellID
,
AssetExec
:
sellOrder
.
AssetExec
,
}
return
reply
}
...
...
@@ -327,20 +327,20 @@ func txResult2sellOrderReply(txResult *types.TxResult) *pty.ReplySellOrder {
txhash
:=
common
.
ToHex
(
txResult
.
GetTx
()
.
Hash
())
reply
:=
&
pty
.
ReplySellOrder
{
receipt
.
Base
.
TokenSymbol
,
receipt
.
Base
.
Owner
,
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
receipt
.
Base
.
MinBoardlot
,
int64
(
price
*
float64
(
types
.
Coin
)),
receipt
.
Base
.
TotalBoardlot
,
receipt
.
Base
.
SoldBoardlot
,
receipt
.
Base
.
BuyID
,
pty
.
SellOrderStatus2Int
[
receipt
.
Base
.
Status
],
""
,
txhash
,
receipt
.
Base
.
Height
,
txhash
,
receipt
.
Base
.
AssetExec
,
TokenSymbol
:
receipt
.
Base
.
TokenSymbol
,
Owner
:
receipt
.
Base
.
Owner
,
AmountPerBoardlot
:
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
MinBoardlot
:
receipt
.
Base
.
MinBoardlot
,
PricePerBoardlot
:
int64
(
price
*
float64
(
types
.
Coin
)),
TotalBoardlot
:
receipt
.
Base
.
TotalBoardlot
,
SoldBoardlot
:
receipt
.
Base
.
SoldBoardlot
,
BuyID
:
receipt
.
Base
.
BuyID
,
Status
:
pty
.
SellOrderStatus2Int
[
receipt
.
Base
.
Status
],
SellID
:
""
,
TxHash
:
txhash
,
Height
:
receipt
.
Base
.
Height
,
Key
:
txhash
,
AssetExec
:
receipt
.
Base
.
AssetExec
,
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show reply"
,
reply
)
return
reply
...
...
@@ -351,20 +351,20 @@ func txResult2sellOrderReply(txResult *types.TxResult) *pty.ReplySellOrder {
func
buyOrder2reply
(
buyOrder
*
pty
.
BuyLimitOrder
)
*
pty
.
ReplyBuyOrder
{
reply
:=
&
pty
.
ReplyBuyOrder
{
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
buyOrder
.
AmountPerBoardlot
,
buyOrder
.
MinBoardlot
,
buyOrder
.
PricePerBoardlot
,
buyOrder
.
TotalBoardlot
,
buyOrder
.
BoughtBoardlot
,
buyOrder
.
BuyID
,
buyOrder
.
Status
,
""
,
strings
.
Replace
(
buyOrder
.
BuyID
,
buyIDPrefix
,
"0x"
,
1
),
buyOrder
.
Height
,
buyOrder
.
BuyID
,
buyOrder
.
AssetExec
,
TokenSymbol
:
buyOrder
.
TokenSymbol
,
Owner
:
buyOrder
.
Address
,
AmountPerBoardlot
:
buyOrder
.
AmountPerBoardlot
,
MinBoardlot
:
buyOrder
.
MinBoardlot
,
PricePerBoardlot
:
buyOrder
.
PricePerBoardlot
,
TotalBoardlot
:
buyOrder
.
TotalBoardlot
,
BoughtBoardlot
:
buyOrder
.
BoughtBoardlot
,
BuyID
:
buyOrder
.
BuyID
,
Status
:
buyOrder
.
Status
,
SellID
:
""
,
TxHash
:
strings
.
Replace
(
buyOrder
.
BuyID
,
buyIDPrefix
,
"0x"
,
1
),
Height
:
buyOrder
.
Height
,
Key
:
buyOrder
.
BuyID
,
AssetExec
:
buyOrder
.
AssetExec
,
}
return
reply
}
...
...
@@ -393,20 +393,20 @@ func txResult2buyOrderReply(txResult *types.TxResult) *pty.ReplyBuyOrder {
}
txhash
:=
common
.
ToHex
(
txResult
.
GetTx
()
.
Hash
())
reply
:=
&
pty
.
ReplyBuyOrder
{
receipt
.
Base
.
TokenSymbol
,
receipt
.
Base
.
Owner
,
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
receipt
.
Base
.
MinBoardlot
,
int64
(
price
*
float64
(
types
.
Coin
)),
receipt
.
Base
.
TotalBoardlot
,
receipt
.
Base
.
BoughtBoardlot
,
""
,
pty
.
SellOrderStatus2Int
[
receipt
.
Base
.
Status
],
receipt
.
Base
.
SellID
,
txhash
,
receipt
.
Base
.
Height
,
txhash
,
receipt
.
Base
.
AssetExec
,
TokenSymbol
:
receipt
.
Base
.
TokenSymbol
,
Owner
:
receipt
.
Base
.
Owner
,
AmountPerBoardlot
:
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
MinBoardlot
:
receipt
.
Base
.
MinBoardlot
,
PricePerBoardlot
:
int64
(
price
*
float64
(
types
.
Coin
)),
TotalBoardlot
:
receipt
.
Base
.
TotalBoardlot
,
BoughtBoardlot
:
receipt
.
Base
.
BoughtBoardlot
,
BuyID
:
""
,
Status
:
pty
.
SellOrderStatus2Int
[
receipt
.
Base
.
Status
],
SellID
:
receipt
.
Base
.
SellID
,
TxHash
:
txhash
,
Height
:
receipt
.
Base
.
Height
,
Key
:
txhash
,
AssetExec
:
receipt
.
Base
.
AssetExec
,
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show reply"
,
reply
)
return
reply
...
...
@@ -466,22 +466,22 @@ func buyBase2Order(base *pty.ReceiptBuyBase, txHash string, blockTime int64) *pt
}
//txhash := common.ToHex(txResult.GetTx().Hash())
reply
:=
&
pty
.
ReplyTradeOrder
{
base
.
TokenSymbol
,
base
.
Owner
,
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
base
.
MinBoardlot
,
int64
(
price
*
float64
(
types
.
Coin
)),
base
.
TotalBoardlot
,
base
.
BoughtBoardlot
,
base
.
BuyID
,
pty
.
SellOrderStatus2Int
[
base
.
Status
],
base
.
SellID
,
txHash
,
base
.
Height
,
key
,
blockTime
,
false
,
base
.
AssetExec
,
TokenSymbol
:
base
.
TokenSymbol
,
Owner
:
base
.
Owner
,
AmountPerBoardlot
:
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
MinBoardlot
:
base
.
MinBoardlot
,
PricePerBoardlot
:
int64
(
price
*
float64
(
types
.
Coin
)),
TotalBoardlot
:
base
.
TotalBoardlot
,
TradedBoardlot
:
base
.
BoughtBoardlot
,
BuyID
:
base
.
BuyID
,
Status
:
pty
.
SellOrderStatus2Int
[
base
.
Status
],
SellID
:
base
.
SellID
,
TxHash
:
txHash
,
Height
:
base
.
Height
,
Key
:
key
,
BlockTime
:
blockTime
,
IsSellOrder
:
false
,
AssetExec
:
base
.
AssetExec
,
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show reply"
,
reply
)
return
reply
...
...
@@ -504,22 +504,22 @@ func sellBase2Order(base *pty.ReceiptSellBase, txHash string, blockTime int64) *
key
=
base
.
SellID
}
reply
:=
&
pty
.
ReplyTradeOrder
{
base
.
TokenSymbol
,
base
.
Owner
,
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
base
.
MinBoardlot
,
int64
(
price
*
float64
(
types
.
Coin
)),
base
.
TotalBoardlot
,
base
.
SoldBoardlot
,
base
.
BuyID
,
pty
.
SellOrderStatus2Int
[
base
.
Status
],
base
.
SellID
,
txHash
,
base
.
Height
,
key
,
blockTime
,
true
,
base
.
AssetExec
,
TokenSymbol
:
base
.
TokenSymbol
,
Owner
:
base
.
Owner
,
AmountPerBoardlot
:
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
MinBoardlot
:
base
.
MinBoardlot
,
PricePerBoardlot
:
int64
(
price
*
float64
(
types
.
Coin
)),
TotalBoardlot
:
base
.
TotalBoardlot
,
TradedBoardlot
:
base
.
SoldBoardlot
,
BuyID
:
base
.
BuyID
,
Status
:
pty
.
SellOrderStatus2Int
[
base
.
Status
],
SellID
:
base
.
SellID
,
TxHash
:
txHash
,
Height
:
base
.
Height
,
Key
:
key
,
BlockTime
:
blockTime
,
IsSellOrder
:
true
,
AssetExec
:
base
.
AssetExec
,
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show reply"
,
reply
)
return
reply
...
...
@@ -630,15 +630,13 @@ func (t *trade) loadOrderFromKey(key []byte) *pty.ReplyTradeOrder {
}
reply
.
TradedBoardlot
=
buyOrder
.
BoughtBoardlot
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
)
{
...
...
plugin/dapp/trade/types/trade.go
View file @
022f7688
...
...
@@ -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
)
{
var
tx
*
types
.
Transaction
//
var tx *types.Transaction
if
action
==
"TradeSellLimit"
{
var
param
TradeSellTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -161,11 +161,9 @@ func (t *tradeType) CreateTx(action string, message json.RawMessage) (*types.Tra
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawTradeRevokeBuyTx
(
&
param
)
}
else
{
return
nil
,
types
.
ErrNotSupport
}
return
tx
,
nil
return
nil
,
types
.
ErrNotSupport
}
//CreateRawTradeSellTx : 创建卖单交易
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment