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
e56fb37a
Commit
e56fb37a
authored
Nov 23, 2018
by
harrylee2015
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master' into game
parents
39047e9b
40589b8e
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
683 additions
and
346 deletions
+683
-346
Makefile
Makefile
+2
-2
main.go
main.go
+2
-1
init.go
plugin/consensus/init/init.go
+0
-4
peer_set.go
plugin/consensus/tendermint/peer_set.go
+1
-1
tendermint.go
plugin/consensus/tendermint/tendermint.go
+4
-2
tendermint_test.go
plugin/consensus/tendermint/tendermint_test.go
+1
-1
ticket_test.go
plugin/consensus/ticket/ticket_test.go
+35
-3
init.go
plugin/crypto/init/init.go
+0
-4
init.go
plugin/dapp/init/init.go
+0
-4
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
exec.go
plugin/dapp/valnode/executor/exec.go
+2
-2
init.go
plugin/store/init/init.go
+0
-4
No files found.
Makefile
View file @
e56fb37a
...
@@ -11,7 +11,7 @@ APP := build/chain33
...
@@ -11,7 +11,7 @@ APP := build/chain33
CHAIN33
=
github.com/33cn/chain33
CHAIN33
=
github.com/33cn/chain33
CHAIN33_PATH
=
vendor/
${
CHAIN33
}
CHAIN33_PATH
=
vendor/
${
CHAIN33
}
LDFLAGS
:=
-ldflags
"-w -s"
LDFLAGS
:=
-ldflags
"-w -s"
PKG_LIST_VET
:=
`
go list ./... |
grep
-v
"vendor"
`
PKG_LIST_VET
:=
`
go list ./... |
grep
-v
"vendor"
|
grep
-v
plugin/dapp/evm/executor/vm/common/crypto/bn256
`
PKG_LIST
:=
`
go list ./... |
grep
-v
"vendor"
|
grep
-v
"chain33/test"
|
grep
-v
"mocks"
|
grep
-v
"pbft"
`
PKG_LIST
:=
`
go list ./... |
grep
-v
"vendor"
|
grep
-v
"chain33/test"
|
grep
-v
"mocks"
|
grep
-v
"pbft"
`
PKG_LIST_Q
:=
`
go list ./... |
grep
-v
"vendor"
|
grep
-v
"chain33/test"
|
grep
-v
"mocks"
|
grep
-v
"blockchain"
|
grep
-v
"pbft"
`
PKG_LIST_Q
:=
`
go list ./... |
grep
-v
"vendor"
|
grep
-v
"chain33/test"
|
grep
-v
"mocks"
|
grep
-v
"blockchain"
|
grep
-v
"pbft"
`
BUILD_FLAGS
=
-ldflags
"-X github.com/33cn/chain33/common/version.GitCommit=
`
git rev-parse
--short
=
8 HEAD
`
"
BUILD_FLAGS
=
-ldflags
"-X github.com/33cn/chain33/common/version.GitCommit=
`
git rev-parse
--short
=
8 HEAD
`
"
...
@@ -58,7 +58,7 @@ autotest_tick: autotest ## run with ticket mining
...
@@ -58,7 +58,7 @@ autotest_tick: autotest ## run with ticket mining
update
:
update
:
rm
-rf
${
CHAIN33_PATH
}
rm
-rf
${
CHAIN33_PATH
}
git clone
--depth
1
-b
master
https://
${
CHAIN33
}
.git
${
CHAIN33_PATH
}
git clone
--depth
1
-b
${
b
}
https://
${
CHAIN33
}
.git
${
CHAIN33_PATH
}
rm
-rf
vendor/
${
CHAIN33
}
/.git
rm
-rf
vendor/
${
CHAIN33
}
/.git
rm
-rf
vendor/
${
CHAIN33
}
/vendor/github.com/apache/thrift/tutorial/erl/
rm
-rf
vendor/
${
CHAIN33
}
/vendor/github.com/apache/thrift/tutorial/erl/
cp
-Rf
vendor/
${
CHAIN33
}
/vendor/
*
vendor/
cp
-Rf
vendor/
${
CHAIN33
}
/vendor/
*
vendor/
...
...
main.go
View file @
e56fb37a
...
@@ -7,7 +7,8 @@
...
@@ -7,7 +7,8 @@
共识 加密 dapp 存储
共识 加密 dapp 存储
这个go 包提供了 官方提供的 插件。
这个go 包提供了 官方提供的 插件。
*/
*/
// +build go1.8
// +build go1.9
package
main
package
main
...
...
plugin/consensus/init/init.go
View file @
e56fb37a
// 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
init
package
init
import
(
import
(
...
...
plugin/consensus/tendermint/peer_set.go
View file @
e56fb37a
...
@@ -537,7 +537,7 @@ FOR_LOOP:
...
@@ -537,7 +537,7 @@ FOR_LOOP:
tendermintlog
.
Debug
(
"Receiving vote"
,
"vote-height"
,
vote
.
Height
,
"peerip"
,
pc
.
ip
.
String
())
tendermintlog
.
Debug
(
"Receiving vote"
,
"vote-height"
,
vote
.
Height
,
"peerip"
,
pc
.
ip
.
String
())
pc
.
state
.
SetHasVote
(
vote
)
pc
.
state
.
SetHasVote
(
vote
)
}
else
if
pkt
.
TypeID
==
ttypes
.
ProposalBlockID
{
}
else
if
pkt
.
TypeID
==
ttypes
.
ProposalBlockID
{
block
:=
&
ttypes
.
TendermintBlock
{
realMsg
.
(
*
tmtypes
.
TendermintBlock
)}
block
:=
&
ttypes
.
TendermintBlock
{
TendermintBlock
:
realMsg
.
(
*
tmtypes
.
TendermintBlock
)}
tendermintlog
.
Debug
(
"Receiving proposal block"
,
"block-height"
,
block
.
Header
.
Height
,
"peerip"
,
pc
.
ip
.
String
())
tendermintlog
.
Debug
(
"Receiving proposal block"
,
"block-height"
,
block
.
Header
.
Height
,
"peerip"
,
pc
.
ip
.
String
())
pc
.
state
.
SetHasProposalBlock
(
block
)
pc
.
state
.
SetHasProposalBlock
(
block
)
}
}
...
...
plugin/consensus/tendermint/tendermint.go
View file @
e56fb37a
...
@@ -466,7 +466,8 @@ func (client *TendermintClient) QueryValidatorsByHeight(height int64) (*tmtypes.
...
@@ -466,7 +466,8 @@ func (client *TendermintClient) QueryValidatorsByHeight(height int64) (*tmtypes.
tendermintlog
.
Error
(
"QueryValidatorsByHeight"
,
"err"
,
err
)
tendermintlog
.
Error
(
"QueryValidatorsByHeight"
,
"err"
,
err
)
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"execs"
,
types
.
EventBlockChainQuery
,
&
types
.
ChainExecutor
{
"valnode"
,
"GetValNodeByHeight"
,
zeroHash
[
:
],
param
,
nil
})
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"execs"
,
types
.
EventBlockChainQuery
,
&
types
.
ChainExecutor
{
Driver
:
"valnode"
,
FuncName
:
"GetValNodeByHeight"
,
StateHash
:
zeroHash
[
:
],
Param
:
param
})
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
msg
,
err
=
client
.
GetQueueClient
()
.
Wait
(
msg
)
msg
,
err
=
client
.
GetQueueClient
()
.
Wait
(
msg
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -485,7 +486,8 @@ func (client *TendermintClient) QueryBlockInfoByHeight(height int64) (*tmtypes.T
...
@@ -485,7 +486,8 @@ func (client *TendermintClient) QueryBlockInfoByHeight(height int64) (*tmtypes.T
tendermintlog
.
Error
(
"QueryBlockInfoByHeight"
,
"err"
,
err
)
tendermintlog
.
Error
(
"QueryBlockInfoByHeight"
,
"err"
,
err
)
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"execs"
,
types
.
EventBlockChainQuery
,
&
types
.
ChainExecutor
{
"valnode"
,
"GetBlockInfoByHeight"
,
zeroHash
[
:
],
param
,
nil
})
msg
:=
client
.
GetQueueClient
()
.
NewMessage
(
"execs"
,
types
.
EventBlockChainQuery
,
&
types
.
ChainExecutor
{
Driver
:
"valnode"
,
FuncName
:
"GetBlockInfoByHeight"
,
StateHash
:
zeroHash
[
:
],
Param
:
param
})
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
client
.
GetQueueClient
()
.
Send
(
msg
,
true
)
msg
,
err
=
client
.
GetQueueClient
()
.
Wait
(
msg
)
msg
,
err
=
client
.
GetQueueClient
()
.
Wait
(
msg
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/consensus/tendermint/tendermint_test.go
View file @
e56fb37a
...
@@ -147,7 +147,7 @@ func prepareTxList() *types.Transaction {
...
@@ -147,7 +147,7 @@ func prepareTxList() *types.Transaction {
key
=
generateKey
(
i
,
32
)
key
=
generateKey
(
i
,
32
)
value
=
generateValue
(
i
,
180
)
value
=
generateValue
(
i
,
180
)
nput
:=
&
pty
.
NormAction_Nput
{
&
pty
.
NormPut
{
Key
:
key
,
Value
:
[]
byte
(
value
)}}
nput
:=
&
pty
.
NormAction_Nput
{
Nput
:
&
pty
.
NormPut
{
Key
:
key
,
Value
:
[]
byte
(
value
)}}
action
:=
&
pty
.
NormAction
{
Value
:
nput
,
Ty
:
pty
.
NormActionPut
}
action
:=
&
pty
.
NormAction
{
Value
:
nput
,
Ty
:
pty
.
NormActionPut
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"norm"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
fee
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"norm"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
fee
}
tx
.
To
=
address
.
ExecAddress
(
"norm"
)
tx
.
To
=
address
.
ExecAddress
(
"norm"
)
...
...
plugin/consensus/ticket/ticket_test.go
View file @
e56fb37a
...
@@ -7,11 +7,14 @@ package ticket
...
@@ -7,11 +7,14 @@ package ticket
import
(
import
(
"testing"
"testing"
"github.com/33cn/
plugin/plugin/dapp/ticket
/types"
"github.com/33cn/
chain33
/types"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/queue"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/util/testnode"
"github.com/33cn/chain33/util/testnode"
_
"github.com/33cn/plugin/plugin/dapp/init"
_
"github.com/33cn/plugin/plugin/dapp/init"
ty
"github.com/33cn/plugin/plugin/dapp/ticket/types"
_
"github.com/33cn/plugin/plugin/store/init"
_
"github.com/33cn/plugin/plugin/store/init"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)
)
...
@@ -28,8 +31,8 @@ func TestTicket(t *testing.T) {
...
@@ -28,8 +31,8 @@ func TestTicket(t *testing.T) {
func
TestTicketMap
(
t
*
testing
.
T
)
{
func
TestTicketMap
(
t
*
testing
.
T
)
{
c
:=
Client
{}
c
:=
Client
{}
ticketList
:=
&
ty
pes
.
ReplyTicketList
{}
ticketList
:=
&
ty
.
ReplyTicketList
{}
ticketList
.
Tickets
=
[]
*
ty
pes
.
Ticket
{
ticketList
.
Tickets
=
[]
*
ty
.
Ticket
{
{
TicketId
:
"1111"
},
{
TicketId
:
"1111"
},
{
TicketId
:
"2222"
},
{
TicketId
:
"2222"
},
{
TicketId
:
"3333"
},
{
TicketId
:
"3333"
},
...
@@ -40,5 +43,34 @@ func TestTicketMap(t *testing.T) {
...
@@ -40,5 +43,34 @@ func TestTicketMap(t *testing.T) {
assert
.
Equal
(
t
,
c
.
getTicketCount
(),
int64
(
4
))
assert
.
Equal
(
t
,
c
.
getTicketCount
(),
int64
(
4
))
c
.
delTicket
(
"3333"
)
c
.
delTicket
(
"3333"
)
assert
.
Equal
(
t
,
c
.
getTicketCount
(),
int64
(
3
))
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/crypto/init/init.go
View file @
e56fb37a
// 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
init
package
init
import
(
import
(
...
...
plugin/dapp/init/init.go
View file @
e56fb37a
// 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
init
package
init
import
(
import
(
...
...
plugin/dapp/privacy/crypto/privacy_test.go
View file @
e56fb37a
...
@@ -4,182 +4,107 @@
...
@@ -4,182 +4,107 @@
package
privacy
package
privacy
/*
import
(
func TestPrivacyOnetimeKey(t *testing.T) {
"testing"
t.Logf("Begin to do TestPrivacyOnetimeKey\n")
"github.com/33cn/chain33/common/crypto"
priKey := "BC7621CE84D3D67851326C360B518DB5"
"github.com/33cn/chain33/common/log"
pribyte, _ := common.Hex2Bytes(priKey)
priaddr32 := (*[32]byte)(unsafe.Pointer(&pribyte[0]))
"github.com/stretchr/testify/assert"
privacyInfo, err := NewPrivacyWithPrivKey(priaddr32)
)
if err != nil {
t.Errorf("Failed to NewPrivacyWithPrivKey", "err info is", err)
type
pubKeyMock
struct
{
return
}
}
func
(
*
pubKeyMock
)
Bytes
()
[]
byte
{
t.Logf("viewprikey:%X, viewpubkey:%X\n", privacyInfo.ViewPrivKey, privacyInfo.ViewPubkey)
return
[]
byte
(
"pubKeyMock"
)
t.Logf("spendprikey:%X, spendpubkey:%X\n", privacyInfo.SpendPrivKey, privacyInfo.SpendPubkey)
}
viewPublic := (*[32]byte)(unsafe.Pointer(&privacyInfo.ViewPubkey[0]))
func
(
*
pubKeyMock
)
KeyString
()
string
{
spendPublic := (*[32]byte)(unsafe.Pointer(&privacyInfo.SpendPubkey[0]))
return
"pubKeyMock"
pubkeyOnetime, txPublicKey, err := GenerateOneTimeAddr(viewPublic, spendPublic)
}
if err != nil {
t.Errorf("Failed to GenerateOneTimeAddr")
func
(
*
pubKeyMock
)
VerifyBytes
(
msg
[]
byte
,
sig
crypto
.
Signature
)
bool
{
return
return
true
}
}
t.Logf("The generated pubkeyOnetime: %X \n", pubkeyOnetime[:])
t.Logf("The generated txPublicKey: %X \n", txPublicKey[:])
func
(
*
pubKeyMock
)
Equals
(
crypto
.
PubKey
)
bool
{
return
true
onetimePriKey, err := RecoverOnetimePriKey(txPublicKey[:], privacyInfo.ViewPrivKey, privacyInfo.SpendPrivKey)
}
if err != nil {
t.Errorf("Failed to RecoverOnetimePriKey")
type
signatureMock
struct
{
return
}
}
t.Logf("The recovered one time privicy key is:%X", onetimePriKey.Bytes())
func
(
*
signatureMock
)
Bytes
()
[]
byte
{
return
[]
byte
(
"signatureMock"
)
recoverPub := onetimePriKey.PubKey().Bytes()[:]
}
originPub := pubkeyOnetime[:]
t.Logf("****¥¥¥*****The recoverPub key is:%X", recoverPub)
func
(
*
signatureMock
)
IsZero
()
bool
{
t.Logf("****¥¥¥*****The originPub key is:%X", originPub)
return
true
}
if !bytes.Equal(recoverPub, originPub) {
func
(
*
signatureMock
)
String
()
string
{
t.Failed()
return
"signatureMock"
t.Errorf("recoverPub is not equal to originPub")
}
return
func
(
*
signatureMock
)
Equals
(
crypto
.
Signature
)
bool
{
} else {
return
true
t.Logf("Yea!!! Succeed to do the TestPrivacyOnetimeKey.")
}
}
type
privKeyMock
struct
{
t.Logf("End to do TestPrivacyOnetimeKey\n")
}
}
*/
func
(
mock
*
privKeyMock
)
Bytes
()
[]
byte
{
return
[]
byte
(
"1234"
)
/*
}
// TODO: 需要增加隐私签名的UT
func TestPrivacySignWithFixInput(t *testing.T) {
func
(
mock
*
privKeyMock
)
Sign
(
msg
[]
byte
)
crypto
.
Signature
{
prislice, _ := common.Hex2Bytes("9E0ED368F3DDAA9F472FE7F319F866227A74A2EF16B43410CEB3CE7C1BAAEB09")
return
&
signatureMock
{}
var onetimePriKey PrivKeyPrivacy
}
copy(onetimePriKey[:], prislice)
func
(
mock
*
privKeyMock
)
PubKey
()
crypto
.
PubKey
{
recoverPub := onetimePriKey.PubKey().Bytes()[:]
return
&
pubKeyMock
{}
}
data := []byte("Yea!!! Succeed to do the TestPrivacyOnetimeKey")
sig := onetimePriKey.Sign(data)
func
(
mock
*
privKeyMock
)
Equals
(
crypto
.
PrivKey
)
bool
{
sign := &types.Signature{
return
true
Ty: 4,
}
Pubkey: recoverPub,
Signature: sig.Bytes(),
func
init
()
{
}
log
.
SetLogLevel
(
"crit"
)
}
c := &oneTimeEd25519{}
func
TestNewPrivacy
(
t
*
testing
.
T
)
{
pub, err := c.PubKeyFromBytes(sign.Pubkey)
test_NewPrivacy
(
t
)
if err != nil {
test_NewPrivacyWithPrivKey
(
t
)
t.Failed()
test_GenerateOneTimeAddr
(
t
)
t.Errorf("Failed to PubKeyFromBytes")
test_RecoverOnetimePriKey
(
t
)
return
}
}
signbytes, err := c.SignatureFromBytes(sign.Signature)
func
test_RecoverOnetimePriKey
(
t
*
testing
.
T
)
{
if err != nil {
R
:=
[]
byte
(
"1234"
)
t.Failed()
pkm
:=
privKeyMock
{}
t.Errorf("Failed to SignatureFromBytes")
privKey
,
err
:=
RecoverOnetimePriKey
(
R
,
&
pkm
,
&
pkm
,
0
)
return
assert
.
Nil
(
t
,
err
)
}
assert
.
NotNil
(
t
,
privKey
)
}
if pub.VerifyBytes(data, signbytes) {
t.Logf("Yea!!! Succeed to pass CheckSign.")
func
test_GenerateOneTimeAddr
(
t
*
testing
.
T
)
{
bytes1
:=
[
32
]
byte
{}
} else {
pkot
,
err
:=
GenerateOneTimeAddr
(
&
bytes1
,
&
bytes1
,
&
bytes1
,
0
)
t.Failed()
assert
.
Nil
(
t
,
err
)
t.Errorf("Fail the CheckSign")
assert
.
NotNil
(
t
,
pkot
)
return
}
}
func
test_NewPrivacy
(
t
*
testing
.
T
)
{
p
:=
NewPrivacy
()
t.Logf("End to do TestPrivacyOnetimeKey\n")
assert
.
NotNil
(
t
,
p
)
}
}
*/
func
test_NewPrivacyWithPrivKey
(
t
*
testing
.
T
)
{
//func TestPrivacySign(t *testing.T) {
bytes1
:=
[
KeyLen32
]
byte
{}
// t.Logf("Begin to do TestPrivacyOnetimeKey\n")
p
,
err
:=
NewPrivacyWithPrivKey
(
&
bytes1
)
//
assert
.
Nil
(
t
,
err
)
// priKey := "BC7621CE84D3D67851326C360B518DB5"
assert
.
NotNil
(
t
,
p
)
// 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")
//}
plugin/dapp/privacy/crypto/ring_signature_test.go
View file @
e56fb37a
...
@@ -6,8 +6,11 @@ package privacy
...
@@ -6,8 +6,11 @@ package privacy
import
(
import
(
"bytes"
"bytes"
"encoding/hex"
"testing"
"testing"
"github.com/stretchr/testify/assert"
"math/rand"
"math/rand"
"time"
"time"
...
@@ -161,11 +164,11 @@ func TestCheckRingSignatureAPI1(t *testing.T) {
...
@@ -161,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"
)
...
@@ -334,7 +337,7 @@ func testRingSignatureOncetime(maxCount int, t *testing.T) {
...
@@ -334,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
)
}
}
}
}
}
}
...
@@ -395,7 +398,7 @@ func TestGenerateRingSignatureAPI(t *testing.T) {
...
@@ -395,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
)
...
@@ -458,3 +461,47 @@ func Benchmark_RingSignatureAllStep(b *testing.B) {
...
@@ -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 @
e56fb37a
...
@@ -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
...
...
plugin/dapp/privacy/executor/exec_del_local.go
View file @
e56fb37a
...
@@ -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
)
}
}
...
...
plugin/dapp/privacy/executor/exec_local.go
View file @
e56fb37a
...
@@ -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
))
}
}
...
...
plugin/dapp/privacy/rpc/rpc_real_test.go
View file @
e56fb37a
...
@@ -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
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
e56fb37a
...
@@ -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
{
...
...
plugin/dapp/privacy/wallet/privacystore.go
View file @
e56fb37a
...
@@ -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
,
...
...
plugin/dapp/privacy/wallet/privacystore_test.go
0 → 100644
View file @
e56fb37a
/*
* 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 @
e56fb37a
...
@@ -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
,
...
...
plugin/dapp/relay/commands/relay.go
View file @
e56fb37a
...
@@ -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
}
}
...
...
plugin/dapp/relay/executor/relay.go
View file @
e56fb37a
...
@@ -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
...
...
plugin/dapp/trade/executor/query.go
View file @
e56fb37a
...
@@ -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
)
{
...
...
plugin/dapp/trade/types/trade.go
View file @
e56fb37a
...
@@ -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 : 创建卖单交易
...
...
plugin/dapp/valnode/executor/exec.go
View file @
e56fb37a
...
@@ -10,11 +10,11 @@ import (
...
@@ -10,11 +10,11 @@ import (
)
)
func
(
val
*
ValNode
)
Exec_Node
(
node
*
pty
.
ValNode
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
val
*
ValNode
)
Exec_Node
(
node
*
pty
.
ValNode
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
receipt
:=
&
types
.
Receipt
{
types
.
ExecOk
,
nil
,
nil
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
nil
,
Logs
:
nil
}
return
receipt
,
nil
return
receipt
,
nil
}
}
func
(
val
*
ValNode
)
Exec_BlockInfo
(
blockInfo
*
pty
.
TendermintBlockInfo
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
val
*
ValNode
)
Exec_BlockInfo
(
blockInfo
*
pty
.
TendermintBlockInfo
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
receipt
:=
&
types
.
Receipt
{
types
.
ExecOk
,
nil
,
nil
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
nil
,
Logs
:
nil
}
return
receipt
,
nil
return
receipt
,
nil
}
}
plugin/store/init/init.go
View file @
e56fb37a
// 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
init
package
init
import
(
import
(
...
...
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