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
b1f6088c
Unverified
Commit
b1f6088c
authored
Nov 22, 2018
by
vipwzw
Committed by
GitHub
Nov 22, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into fix_ticket_tclose_test
parents
72752a44
40589b8e
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
666 additions
and
319 deletions
+666
-319
ticket_test.go
plugin/consensus/ticket/ticket_test.go
+30
-1
privacy_test.go
plugin/dapp/privacy/crypto/privacy_test.go
+104
-179
ring_signature_test.go
plugin/dapp/privacy/crypto/ring_signature_test.go
+51
-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
+350
-0
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/consensus/ticket/ticket_test.go
View file @
b1f6088c
...
...
@@ -7,9 +7,9 @@ package ticket
import
(
"fmt"
"testing"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/queue"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
...
...
@@ -100,5 +100,34 @@ func TestTicketMap(t *testing.T) {
assert
.
Equal
(
t
,
c
.
getTicketCount
(),
int64
(
4
))
c
.
delTicket
(
"3333"
)
assert
.
Equal
(
t
,
c
.
getTicketCount
(),
int64
(
3
))
}
func
TestProcEvent
(
t
*
testing
.
T
)
{
c
:=
Client
{}
ret
:=
c
.
ProcEvent
(
queue
.
Message
{})
assert
.
Equal
(
t
,
ret
,
true
)
}
func
Test_genPrivHash
(
t
*
testing
.
T
)
{
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
assert
.
NoError
(
t
,
err
)
priv
,
err
:=
c
.
GenKey
()
bt
,
err
:=
genPrivHash
(
priv
,
"AA:BB:CC:DD"
)
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
0
,
len
(
bt
))
bt
,
err
=
genPrivHash
(
priv
,
"111:222:333:444"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
32
,
len
(
bt
))
}
func
Test_getNextRequiredDifficulty
(
t
*
testing
.
T
)
{
c
:=
&
Client
{}
bits
,
bt
,
err
:=
c
.
getNextRequiredDifficulty
(
nil
,
1
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
bt
,
defaultModify
)
assert
.
Equal
(
t
,
bits
,
types
.
GetP
(
0
)
.
PowLimitBits
)
}
plugin/dapp/privacy/crypto/privacy_test.go
View file @
b1f6088c
...
...
@@ -4,182 +4,107 @@
package
privacy
/*
func TestPrivacyOnetimeKey(t *testing.T) {
t.Logf("Begin to do TestPrivacyOnetimeKey\n")
priKey := "BC7621CE84D3D67851326C360B518DB5"
pribyte, _ := common.Hex2Bytes(priKey)
priaddr32 := (*[32]byte)(unsafe.Pointer(&pribyte[0]))
privacyInfo, err := NewPrivacyWithPrivKey(priaddr32)
if err != nil {
t.Errorf("Failed to NewPrivacyWithPrivKey", "err info is", err)
return
}
t.Logf("viewprikey:%X, viewpubkey:%X\n", privacyInfo.ViewPrivKey, privacyInfo.ViewPubkey)
t.Logf("spendprikey:%X, spendpubkey:%X\n", privacyInfo.SpendPrivKey, privacyInfo.SpendPubkey)
viewPublic := (*[32]byte)(unsafe.Pointer(&privacyInfo.ViewPubkey[0]))
spendPublic := (*[32]byte)(unsafe.Pointer(&privacyInfo.SpendPubkey[0]))
pubkeyOnetime, txPublicKey, err := GenerateOneTimeAddr(viewPublic, spendPublic)
if err != nil {
t.Errorf("Failed to GenerateOneTimeAddr")
return
}
t.Logf("The generated pubkeyOnetime: %X \n", pubkeyOnetime[:])
t.Logf("The generated txPublicKey: %X \n", txPublicKey[:])
onetimePriKey, err := RecoverOnetimePriKey(txPublicKey[:], privacyInfo.ViewPrivKey, privacyInfo.SpendPrivKey)
if err != nil {
t.Errorf("Failed to RecoverOnetimePriKey")
return
}
t.Logf("The recovered one time privicy key is:%X", onetimePriKey.Bytes())
recoverPub := onetimePriKey.PubKey().Bytes()[:]
originPub := pubkeyOnetime[:]
t.Logf("****¥¥¥*****The recoverPub key is:%X", recoverPub)
t.Logf("****¥¥¥*****The originPub key is:%X", originPub)
if !bytes.Equal(recoverPub, originPub) {
t.Failed()
t.Errorf("recoverPub is not equal to originPub")
return
} else {
t.Logf("Yea!!! Succeed to do the TestPrivacyOnetimeKey.")
}
t.Logf("End to do TestPrivacyOnetimeKey\n")
}
*/
/*
// TODO: 需要增加隐私签名的UT
func TestPrivacySignWithFixInput(t *testing.T) {
prislice, _ := common.Hex2Bytes("9E0ED368F3DDAA9F472FE7F319F866227A74A2EF16B43410CEB3CE7C1BAAEB09")
var onetimePriKey PrivKeyPrivacy
copy(onetimePriKey[:], prislice)
recoverPub := onetimePriKey.PubKey().Bytes()[:]
data := []byte("Yea!!! Succeed to do the TestPrivacyOnetimeKey")
sig := onetimePriKey.Sign(data)
sign := &types.Signature{
Ty: 4,
Pubkey: recoverPub,
Signature: sig.Bytes(),
}
c := &oneTimeEd25519{}
pub, err := c.PubKeyFromBytes(sign.Pubkey)
if err != nil {
t.Failed()
t.Errorf("Failed to PubKeyFromBytes")
return
}
signbytes, err := c.SignatureFromBytes(sign.Signature)
if err != nil {
t.Failed()
t.Errorf("Failed to SignatureFromBytes")
return
}
if pub.VerifyBytes(data, signbytes) {
t.Logf("Yea!!! Succeed to pass CheckSign.")
} else {
t.Failed()
t.Errorf("Fail the CheckSign")
return
}
t.Logf("End to do TestPrivacyOnetimeKey\n")
}
*/
//func TestPrivacySign(t *testing.T) {
// t.Logf("Begin to do TestPrivacyOnetimeKey\n")
//
// priKey := "BC7621CE84D3D67851326C360B518DB5"
// pribyte, _ := common.Hex2Bytes(priKey)
// priaddr32 := (*[32]byte)(unsafe.Pointer(&pribyte[0]))
// privacyInfo, err := NewPrivacyWithPrivKey(priaddr32)
// if err != nil {
// t.Errorf("Failed to NewPrivacyWithPrivKey", "err info is", err)
// return
// }
//
// t.Logf("viewprikey:%X, viewpubkey:%X\n", privacyInfo.ViewPrivKey, privacyInfo.ViewPubkey)
// t.Logf("spendprikey:%X, spendpubkey:%X\n", privacyInfo.SpendPrivKey, privacyInfo.SpendPubkey)
//
// viewPublic := (*[32]byte)(unsafe.Pointer(&privacyInfo.ViewPubkey[0]))
// spendPublic := (*[32]byte)(unsafe.Pointer(&privacyInfo.SpendPubkey[0]))
// pubkeyOnetime, txPublicKey, err := privacyInfo.GenerateOneTimeAddr(viewPublic, spendPublic)
// if err != nil {
// t.Errorf("Failed to GenerateOneTimeAddr")
// return
// }
// t.Logf("The generated pubkeyOnetime: %X \n", pubkeyOnetime[:])
// t.Logf("The generated txPublicKey: %X \n", txPublicKey[:])
//
// onetimePriKey, err := privacyInfo.RecoverOnetimePriKey(txPublicKey[:], privacyInfo.ViewPrivKey, privacyInfo.SpendPrivKey)
// if err != nil {
// t.Errorf("Failed to RecoverOnetimePriKey")
// return
// }
// t.Logf("The recovered one time privicy key is:%X", onetimePriKey.Bytes())
//
// recoverPub := onetimePriKey.PubKey().Bytes()[:]
// originPub := pubkeyOnetime[:]
// t.Logf("****¥¥¥*****The recoverPub key is:%X", recoverPub)
// t.Logf("****¥¥¥*****The originPub key is:%X", originPub)
//
//
// if !bytes.Equal(recoverPub, originPub) {
// t.Failed()
// t.Errorf("recoverPub is not equal to originPub")
// return
//
// } else {
// t.Logf("Yea!!! Succeed to do the TestPrivacyOnetimeKey.")
// }
// data := []byte("Yea!!! Succeed to do the TestPrivacyOnetimeKey")
// sig := onetimePriKey.Sign(data)
// sign := &types.Signature{
// Ty: 4,
// Pubkey: recoverPub,
// Signature:sig.Bytes(),
// }
//
// c := &oneTimeEd25519{}
//
// pub, err := c.PubKeyFromBytes(sign.Pubkey)
// if err != nil {
// t.Failed()
// t.Errorf("Failed to PubKeyFromBytes")
// return
// }
// signbytes, err := c.SignatureFromBytes(sign.Signature)
// if err != nil {
// t.Failed()
// t.Errorf("Failed to SignatureFromBytes")
// return
// }
//
// if pub.VerifyBytes(data, signbytes) {
// t.Logf("Yea!!! Succeed to pass CheckSign.")
//
// } else {
// t.Failed()
// t.Errorf("Fail the CheckSign")
// return
//
// }
//
// t.Logf("End to do TestPrivacyOnetimeKey\n")
//}
import
(
"testing"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/log"
"github.com/stretchr/testify/assert"
)
type
pubKeyMock
struct
{
}
func
(
*
pubKeyMock
)
Bytes
()
[]
byte
{
return
[]
byte
(
"pubKeyMock"
)
}
func
(
*
pubKeyMock
)
KeyString
()
string
{
return
"pubKeyMock"
}
func
(
*
pubKeyMock
)
VerifyBytes
(
msg
[]
byte
,
sig
crypto
.
Signature
)
bool
{
return
true
}
func
(
*
pubKeyMock
)
Equals
(
crypto
.
PubKey
)
bool
{
return
true
}
type
signatureMock
struct
{
}
func
(
*
signatureMock
)
Bytes
()
[]
byte
{
return
[]
byte
(
"signatureMock"
)
}
func
(
*
signatureMock
)
IsZero
()
bool
{
return
true
}
func
(
*
signatureMock
)
String
()
string
{
return
"signatureMock"
}
func
(
*
signatureMock
)
Equals
(
crypto
.
Signature
)
bool
{
return
true
}
type
privKeyMock
struct
{
}
func
(
mock
*
privKeyMock
)
Bytes
()
[]
byte
{
return
[]
byte
(
"1234"
)
}
func
(
mock
*
privKeyMock
)
Sign
(
msg
[]
byte
)
crypto
.
Signature
{
return
&
signatureMock
{}
}
func
(
mock
*
privKeyMock
)
PubKey
()
crypto
.
PubKey
{
return
&
pubKeyMock
{}
}
func
(
mock
*
privKeyMock
)
Equals
(
crypto
.
PrivKey
)
bool
{
return
true
}
func
init
()
{
log
.
SetLogLevel
(
"crit"
)
}
func
TestNewPrivacy
(
t
*
testing
.
T
)
{
test_NewPrivacy
(
t
)
test_NewPrivacyWithPrivKey
(
t
)
test_GenerateOneTimeAddr
(
t
)
test_RecoverOnetimePriKey
(
t
)
}
func
test_RecoverOnetimePriKey
(
t
*
testing
.
T
)
{
R
:=
[]
byte
(
"1234"
)
pkm
:=
privKeyMock
{}
privKey
,
err
:=
RecoverOnetimePriKey
(
R
,
&
pkm
,
&
pkm
,
0
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
privKey
)
}
func
test_GenerateOneTimeAddr
(
t
*
testing
.
T
)
{
bytes1
:=
[
32
]
byte
{}
pkot
,
err
:=
GenerateOneTimeAddr
(
&
bytes1
,
&
bytes1
,
&
bytes1
,
0
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
pkot
)
}
func
test_NewPrivacy
(
t
*
testing
.
T
)
{
p
:=
NewPrivacy
()
assert
.
NotNil
(
t
,
p
)
}
func
test_NewPrivacyWithPrivKey
(
t
*
testing
.
T
)
{
bytes1
:=
[
KeyLen32
]
byte
{}
p
,
err
:=
NewPrivacyWithPrivKey
(
&
bytes1
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
p
)
}
plugin/dapp/privacy/crypto/ring_signature_test.go
View file @
b1f6088c
...
...
@@ -6,8 +6,11 @@ package privacy
import
(
"bytes"
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
"math/rand"
"time"
...
...
@@ -161,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"
)
...
...
@@ -334,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
)
}
}
}
...
...
@@ -395,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
)
...
...
@@ -458,3 +461,47 @@ func Benchmark_RingSignatureAllStep(b *testing.B) {
}
}
func
TestRingSignatureCrypto
(
t
*
testing
.
T
)
{
{
sig
:=
&
RingSignature
{}
bytes
:=
hex
.
EncodeToString
(
sig
.
Bytes
())
assert
.
Equal
(
t
,
bytes
,
""
)
assert
.
Equal
(
t
,
true
,
sig
.
IsZero
())
assert
.
Equal
(
t
,
sig
.
String
(),
""
)
assert
.
Equal
(
t
,
sig
.
Equals
(
sig
),
true
)
}
{
key
:=
&
RingSignPrivateKey
{}
bytes
:=
hex
.
EncodeToString
(
key
.
Bytes
())
assert
.
Equal
(
t
,
bytes
,
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)
assert
.
NotNil
(
t
,
key
.
PubKey
())
assert
.
Equal
(
t
,
key
.
Equals
(
key
),
true
)
sig
:=
key
.
Sign
([]
byte
(
"Messages"
))
assert
.
NotNil
(
t
,
sig
)
}
{
ringsig
:=
&
RingSignature
{}
key
:=
&
RingSignPublicKey
{}
bytes
:=
hex
.
EncodeToString
(
key
.
Bytes
())
assert
.
Equal
(
t
,
bytes
,
"0000000000000000000000000000000000000000000000000000000000000000"
)
assert
.
Equal
(
t
,
key
.
KeyString
(),
"0000000000000000000000000000000000000000000000000000000000000000"
)
assert
.
Equal
(
t
,
key
.
Equals
(
key
),
true
)
assert
.
Equal
(
t
,
key
.
VerifyBytes
([]
byte
(
"Message"
),
ringsig
),
false
)
}
{
ring
:=
&
RingSignED25519
{}
privKey
,
err
:=
ring
.
GenKey
()
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
privKey
)
privKey
,
err
=
ring
.
PrivKeyFromBytes
([]
byte
(
"00000000000000000000000000000000"
))
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
privKey
)
pubKey
,
err
:=
ring
.
PubKeyFromBytes
([]
byte
(
"00000000000000000000000000000000"
))
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
pubKey
)
sig
,
err
:=
ring
.
SignatureFromBytes
([]
byte
(
"00000000000000000000000000000000"
))
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
sig
)
}
}
plugin/dapp/privacy/executor/exec.go
View file @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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
0 → 100644
View file @
b1f6088c
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package
wallet
import
(
"encoding/json"
"fmt"
"testing"
"github.com/golang/protobuf/proto"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
pt
"github.com/33cn/plugin/plugin/dapp/privacy/types"
"github.com/stretchr/testify/assert"
)
func
createStore
(
t
*
testing
.
T
)
*
privacyStore
{
cfg
,
_
:=
testnode
.
GetDefaultConfig
()
cfgWallet
:=
cfg
.
Wallet
walletStoreDB
:=
dbm
.
NewDB
(
"wallet"
,
cfgWallet
.
Driver
,
cfgWallet
.
DbPath
,
cfgWallet
.
DbCache
)
store
:=
newStore
(
walletStoreDB
)
assert
.
NotNil
(
t
,
store
)
return
store
}
func
TestPrivacyStore
(
t
*
testing
.
T
)
{
testStore_getVersion
(
t
)
testStore_setVersion
(
t
)
testStore_getAccountByPrefix
(
t
)
testStore_getAccountByAddr
(
t
)
testStore_setWalletAccountPrivacy
(
t
)
testStore_listAvailableUTXOs
(
t
)
testStore_listFrozenUTXOs
(
t
)
testStore_getWalletPrivacyTxDetails
(
t
)
testStore_getPrivacyTokenUTXOs
(
t
)
testStore_moveUTXO2FTXO
(
t
)
testStore_getRescanUtxosFlag4Addr
(
t
)
testStore_saveREscanUTXOsAddresses
(
t
)
testStore_setScanPrivacyInputUTXO
(
t
)
testStore_isUTXOExist
(
t
)
testStore_updateScanInputUTXOs
(
t
)
testStore_moveUTXO2STXO
(
t
)
testStore_selectPrivacyTransactionToWallet
(
t
)
testStore_setUTXO
(
t
)
testStore_storeScanPrivacyInputUTXO
(
t
)
testStore_listSpendUTXOs
(
t
)
testStore_getWalletFtxoStxo
(
t
)
testStore_getFTXOlist
(
t
)
testStore_moveFTXO2STXO
(
t
)
testStore_moveFTXO2UTXO
(
t
)
testStore_unsetUTXO
(
t
)
testStore_moveSTXO2FTXO
(
t
)
testStore_moveFTXO2UTXOWhenFTXOExpire
(
t
)
}
func
testStore_moveFTXO2UTXOWhenFTXOExpire
(
t
*
testing
.
T
)
{
}
func
testStore_moveSTXO2FTXO
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
batch
:=
store
.
NewBatch
(
true
)
err
:=
store
.
moveSTXO2FTXO
(
nil
,
"moveSTXO2FTXO"
,
batch
)
assert
.
NotNil
(
t
,
err
)
}
func
testStore_unsetUTXO
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
addr
:=
""
txhash
:=
""
batch
:=
store
.
NewBatch
(
true
)
err
:=
store
.
unsetUTXO
(
&
addr
,
&
txhash
,
0
,
""
,
batch
)
assert
.
NotNil
(
t
,
err
)
addr
=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
txhash
=
"TXHASH"
err
=
store
.
unsetUTXO
(
&
addr
,
&
txhash
,
0
,
"BTY"
,
batch
)
assert
.
NoError
(
t
,
err
)
}
func
testStore_moveFTXO2UTXO
(
t
*
testing
.
T
)
{
}
func
testStore_moveFTXO2STXO
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
batch
:=
store
.
NewBatch
(
true
)
err
:=
store
.
moveFTXO2STXO
(
nil
,
"TXHASH"
,
batch
)
assert
.
NotNil
(
t
,
err
)
}
func
testStore_getFTXOlist
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
txs
,
bts
:=
store
.
getFTXOlist
()
assert
.
Equal
(
t
,
0
,
len
(
bts
))
assert
.
Equal
(
t
,
0
,
len
(
txs
))
}
func
testStore_getWalletFtxoStxo
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
_
,
_
,
err
:=
store
.
getWalletFtxoStxo
(
""
)
assert
.
Nil
(
t
,
err
)
}
func
testStore_listSpendUTXOs
(
t
*
testing
.
T
)
{
}
func
testStore_storeScanPrivacyInputUTXO
(
t
*
testing
.
T
)
{
}
func
testStore_setUTXO
(
t
*
testing
.
T
)
{
var
addr
,
txhash
string
store
:=
createStore
(
t
)
dbbatch
:=
store
.
NewBatch
(
true
)
err
:=
store
.
setUTXO
(
&
addr
,
&
txhash
,
0
,
nil
,
dbbatch
)
assert
.
NotNil
(
t
,
err
)
addr
=
"setUTXO"
txhash
=
"TXHASH"
err
=
store
.
setUTXO
(
&
addr
,
&
txhash
,
0
,
nil
,
dbbatch
)
assert
.
NotNil
(
t
,
err
)
}
func
testStore_selectPrivacyTransactionToWallet
(
t
*
testing
.
T
)
{
}
func
testStore_moveUTXO2STXO
(
t
*
testing
.
T
)
{
}
func
testStore_updateScanInputUTXOs
(
t
*
testing
.
T
)
{
}
func
testStore_isUTXOExist
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
pdbs
,
err
:=
store
.
isUTXOExist
(
""
,
0
)
assert
.
Nil
(
t
,
pdbs
)
assert
.
NotNil
(
t
,
err
)
}
func
testStore_setScanPrivacyInputUTXO
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
utxogls
:=
store
.
setScanPrivacyInputUTXO
(
0
)
assert
.
Nil
(
t
,
utxogls
)
}
func
testStore_saveREscanUTXOsAddresses
(
t
*
testing
.
T
)
{
}
func
testStore_getRescanUtxosFlag4Addr
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
utxos
,
err
:=
store
.
getRescanUtxosFlag4Addr
(
&
pt
.
ReqRescanUtxos
{})
assert
.
Nil
(
t
,
utxos
)
assert
.
NotNil
(
t
,
err
)
}
func
testStore_moveUTXO2FTXO
(
t
*
testing
.
T
)
{
}
func
testStore_getPrivacyTokenUTXOs
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
utxos
,
err
:=
store
.
getPrivacyTokenUTXOs
(
""
,
""
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
utxos
)
token
:=
"BTY"
addr
:=
"getPrivacyTokenUTXOs"
for
n
:=
0
;
n
<
5
;
n
++
{
data
:=
&
pt
.
PrivacyDBStore
{
Txindex
:
int32
(
n
)}
bt
,
err
:=
proto
.
Marshal
(
data
)
assert
.
NoError
(
t
,
err
)
key
:=
fmt
.
Sprintf
(
"Key%d"
,
n
)
err
=
store
.
Set
(
calcUTXOKey4TokenAddr
(
token
,
addr
,
"txhash"
,
n
),
[]
byte
(
key
))
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
([]
byte
(
key
),
bt
)
assert
.
NoError
(
t
,
err
)
}
utxos
,
err
=
store
.
getPrivacyTokenUTXOs
(
token
,
addr
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
5
,
len
(
utxos
.
utxos
))
}
func
testStore_getWalletPrivacyTxDetails
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
wtds
,
err
:=
store
.
getWalletPrivacyTxDetails
(
nil
)
assert
.
Nil
(
t
,
wtds
)
assert
.
NotNil
(
t
,
err
)
wtds
,
err
=
store
.
getWalletPrivacyTxDetails
(
&
pt
.
ReqPrivacyTransactionList
{})
assert
.
Nil
(
t
,
wtds
)
assert
.
NotNil
(
t
,
err
)
}
func
testStore_listFrozenUTXOs
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
token
:=
"BTY"
addr
:=
"26htvcBNSEA7fZhAdLJphDwQRQJaHpyHTq"
txs
,
err
:=
store
.
listFrozenUTXOs
(
""
,
""
)
assert
.
Nil
(
t
,
txs
)
assert
.
NotNil
(
t
,
err
)
txs
,
err
=
store
.
listFrozenUTXOs
(
token
,
addr
)
assert
.
Nil
(
t
,
txs
)
assert
.
Nil
(
t
,
err
)
tx
:=
&
pt
.
FTXOsSTXOsInOneTx
{
Tokenname
:
"BTY"
}
bt
,
err
:=
proto
.
Marshal
(
tx
)
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
(
calcKey4FTXOsInTx
(
token
,
addr
,
"TXHASH"
),
bt
)
assert
.
NoError
(
t
,
err
)
txs
,
err
=
store
.
listFrozenUTXOs
(
token
,
addr
)
assert
.
Nil
(
t
,
txs
)
assert
.
NotNil
(
t
,
err
)
err
=
store
.
Set
(
calcKey4FTXOsInTx
(
token
,
addr
,
"TXHASH"
),
[]
byte
(
"DataKey"
))
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
([]
byte
(
"DataKey"
),
bt
)
assert
.
NoError
(
t
,
err
)
txs
,
err
=
store
.
listFrozenUTXOs
(
token
,
addr
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
txs
))
assert
.
Equal
(
t
,
tx
,
txs
[
0
])
}
func
testStore_listAvailableUTXOs
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
utxos
,
err
:=
store
.
listAvailableUTXOs
(
""
,
""
)
assert
.
Nil
(
t
,
utxos
)
assert
.
Equal
(
t
,
err
,
types
.
ErrInvalidParam
)
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTq"
token
:=
"BTY"
txhash
:=
"123456"
utxo
:=
&
pt
.
PrivacyDBStore
{
Tokenname
:
"BTY"
,
}
key
:=
calcUTXOKey4TokenAddr
(
token
,
addr
,
txhash
,
0
)
bt
,
err
:=
proto
.
Marshal
(
utxo
)
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
(
key
,
[]
byte
(
"AccKey"
))
assert
.
NoError
(
t
,
err
)
utxos
,
err
=
store
.
listAvailableUTXOs
(
token
,
addr
)
assert
.
NotNil
(
t
,
err
)
err
=
store
.
Set
([]
byte
(
"AccKey"
),
bt
)
utxos
,
err
=
store
.
listAvailableUTXOs
(
token
,
addr
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
utxos
))
assert
.
Equal
(
t
,
utxo
,
utxos
[
0
])
}
func
testStore_setWalletAccountPrivacy
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
err
:=
store
.
setWalletAccountPrivacy
(
""
,
nil
)
assert
.
Equal
(
t
,
err
,
types
.
ErrInvalidParam
)
err
=
store
.
setWalletAccountPrivacy
(
addr
,
nil
)
assert
.
Equal
(
t
,
err
,
types
.
ErrInvalidParam
)
err
=
store
.
setWalletAccountPrivacy
(
addr
,
&
pt
.
WalletAccountPrivacy
{})
assert
.
NoError
(
t
,
err
)
}
func
testStore_getAccountByAddr
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTq"
was
,
err
:=
store
.
getAccountByAddr
(
""
)
assert
.
Nil
(
t
,
was
)
assert
.
Equal
(
t
,
err
,
types
.
ErrInvalidParam
)
was
,
err
=
store
.
getAccountByAddr
(
addr
)
assert
.
Nil
(
t
,
was
)
assert
.
Equal
(
t
,
err
,
types
.
ErrAddrNotExist
)
account
:=
&
types
.
WalletAccountStore
{
Label
:
"Label1"
,
}
bt
,
err
:=
proto
.
Marshal
(
account
)
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
(
calcAddrKey
(
addr
),
bt
)
was
,
err
=
store
.
getAccountByAddr
(
addr
)
assert
.
Equal
(
t
,
was
,
account
)
assert
.
NoError
(
t
,
err
)
}
func
testStore_getAccountByPrefix
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
addr
:=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
was
,
err
:=
store
.
getAccountByAddr
(
""
)
assert
.
Nil
(
t
,
was
)
assert
.
Equal
(
t
,
err
,
types
.
ErrInvalidParam
)
was
,
err
=
store
.
getAccountByAddr
(
addr
)
assert
.
Nil
(
t
,
was
)
assert
.
Equal
(
t
,
err
,
types
.
ErrAddrNotExist
)
// 这里始终是成功的,所以不能建立测试
//other := &types.ReqSignRawTx{Expire:"Ex"}
//bt, err := proto.Marshal(other)
//assert.NoError(t, err)
//err = store.Set(calcAddrKey(addr), bt)
//assert.NoError(t, err)
//was, err = store.getAccountByAddr(addr)
//assert.Nil(t, was)
//assert.Equal(t, err, types.ErrUnmarshal)
account
:=
&
types
.
WalletAccountStore
{
Label
:
"Label1"
,
}
bt
,
err
:=
proto
.
Marshal
(
account
)
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
(
calcAddrKey
(
addr
),
bt
)
assert
.
NoError
(
t
,
err
)
was
,
err
=
store
.
getAccountByAddr
(
addr
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
was
,
account
)
}
func
testStore_setVersion
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
err
:=
store
.
setVersion
()
assert
.
NoError
(
t
,
err
)
}
func
testStore_getVersion
(
t
*
testing
.
T
)
{
store
:=
createStore
(
t
)
bt
,
err
:=
json
.
Marshal
(
"this is a string"
)
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
(
calcPrivacyDBVersion
(),
bt
)
assert
.
NoError
(
t
,
err
)
version
:=
store
.
getVersion
()
assert
.
Equal
(
t
,
int64
(
0
),
version
)
bt
,
err
=
json
.
Marshal
(
PRIVACYDBVERSION
)
assert
.
NoError
(
t
,
err
)
err
=
store
.
Set
(
calcPrivacyDBVersion
(),
bt
)
version
=
store
.
getVersion
()
assert
.
Equal
(
t
,
PRIVACYDBVERSION
,
version
)
}
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
View file @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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 @
b1f6088c
...
...
@@ -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