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
c1ea3255
Commit
c1ea3255
authored
Nov 26, 2018
by
Hugo
Browse files
Options
Browse Files
Download
Plain Diff
merge upstream
parents
f495782e
0ac1f080
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
910 additions
and
539 deletions
+910
-539
Makefile
Makefile
+2
-2
main.go
main.go
+2
-1
init.go
plugin/consensus/init/init.go
+0
-4
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
exec_local.go
plugin/dapp/cert/executor/exec_local.go
+12
-3
query.go
plugin/dapp/game/executor/query.go
+1
-1
exec_del_local.go
plugin/dapp/hashlock/executor/exec_del_local.go
+12
-3
exec_local.go
plugin/dapp/hashlock/executor/exec_local.go
+12
-3
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
ticket.go
plugin/dapp/ticket/wallet/ticket.go
+8
-1
exec_test.go
plugin/dapp/trade/executor/exec_test.go
+20
-20
kv.go
plugin/dapp/trade/executor/kv.go
+20
-20
query.go
plugin/dapp/trade/executor/query.go
+94
-96
trade_test.go
plugin/dapp/trade/executor/trade_test.go
+42
-42
tradedb.go
plugin/dapp/trade/executor/tradedb.go
+98
-98
rpc.go
plugin/dapp/trade/rpc/rpc.go
+5
-5
trade.go
plugin/dapp/trade/types/trade.go
+2
-4
init.go
plugin/store/init/init.go
+0
-4
No files found.
Makefile
View file @
c1ea3255
...
...
@@ -11,7 +11,7 @@ APP := build/chain33
CHAIN33
=
github.com/33cn/chain33
CHAIN33_PATH
=
vendor/
${
CHAIN33
}
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_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
`
"
...
...
@@ -58,7 +58,7 @@ autotest_tick: autotest ## run with ticket mining
update
:
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
}
/vendor/github.com/apache/thrift/tutorial/erl/
cp
-Rf
vendor/
${
CHAIN33
}
/vendor/
*
vendor/
...
...
main.go
View file @
c1ea3255
...
...
@@ -7,7 +7,8 @@
共识 加密 dapp 存储
这个go 包提供了 官方提供的 插件。
*/
// +build go1.8
// +build go1.9
package
main
...
...
plugin/consensus/init/init.go
View file @
c1ea3255
// 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
import
(
...
...
plugin/consensus/tendermint/tendermint.go
View file @
c1ea3255
...
...
@@ -466,7 +466,8 @@ func (client *TendermintClient) QueryValidatorsByHeight(height int64) (*tmtypes.
tendermintlog
.
Error
(
"QueryValidatorsByHeight"
,
"err"
,
err
)
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
)
msg
,
err
=
client
.
GetQueueClient
()
.
Wait
(
msg
)
if
err
!=
nil
{
...
...
@@ -485,7 +486,8 @@ func (client *TendermintClient) QueryBlockInfoByHeight(height int64) (*tmtypes.T
tendermintlog
.
Error
(
"QueryBlockInfoByHeight"
,
"err"
,
err
)
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
)
msg
,
err
=
client
.
GetQueueClient
()
.
Wait
(
msg
)
if
err
!=
nil
{
...
...
plugin/consensus/tendermint/tendermint_test.go
View file @
c1ea3255
...
...
@@ -147,7 +147,7 @@ func prepareTxList() *types.Transaction {
key
=
generateKey
(
i
,
32
)
value
=
generateValue
(
i
,
180
)
nput
:=
&
pty
.
NormAction_Nput
{
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
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"norm"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
fee
}
tx
.
To
=
address
.
ExecAddress
(
"norm"
)
...
...
plugin/consensus/ticket/ticket_test.go
View file @
c1ea3255
...
...
@@ -7,11 +7,14 @@ package ticket
import
(
"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/util/testnode"
_
"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/stretchr/testify/assert"
)
...
...
@@ -28,8 +31,8 @@ func TestTicket(t *testing.T) {
func
TestTicketMap
(
t
*
testing
.
T
)
{
c
:=
Client
{}
ticketList
:=
&
ty
pes
.
ReplyTicketList
{}
ticketList
.
Tickets
=
[]
*
ty
pes
.
Ticket
{
ticketList
:=
&
ty
.
ReplyTicketList
{}
ticketList
.
Tickets
=
[]
*
ty
.
Ticket
{
{
TicketId
:
"1111"
},
{
TicketId
:
"2222"
},
{
TicketId
:
"3333"
},
...
...
@@ -40,5 +43,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/crypto/init/init.go
View file @
c1ea3255
// 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
import
(
...
...
plugin/dapp/cert/executor/exec_local.go
100644 → 100755
View file @
c1ea3255
...
...
@@ -17,11 +17,14 @@ func calcCertHeightKey(height int64) []byte {
}
// ExecLocal_New 启用证书交易执行
func
(
c
*
Cert
)
ExecLocal_New
(
payload
*
ct
.
CertNew
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
c
*
Cert
)
ExecLocal_New
(
payload
*
ct
.
CertNew
,
tx
*
types
.
Transaction
,
receiptData
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
historityCertdata
:=
&
types
.
HistoryCertStore
{}
...
...
@@ -46,11 +49,14 @@ func (c *Cert) ExecLocal_New(payload *ct.CertNew, tx *types.Transaction, receipt
}
// ExecLocal_Update 更新证书交易执行
func
(
c
*
Cert
)
ExecLocal_Update
(
payload
*
ct
.
CertUpdate
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
c
*
Cert
)
ExecLocal_Update
(
payload
*
ct
.
CertUpdate
,
tx
*
types
.
Transaction
,
receiptData
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
// 写入上一纪录的next-height
...
...
@@ -76,11 +82,14 @@ func (c *Cert) ExecLocal_Update(payload *ct.CertUpdate, tx *types.Transaction, r
}
// ExecLocal_Normal 非证书变更交易执行
func
(
c
*
Cert
)
ExecLocal_Normal
(
payload
*
ct
.
CertNormal
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
c
*
Cert
)
ExecLocal_Normal
(
payload
*
ct
.
CertNormal
,
tx
*
types
.
Transaction
,
receiptData
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
return
&
set
,
nil
...
...
plugin/dapp/game/executor/query.go
View file @
c1ea3255
...
...
@@ -30,5 +30,5 @@ func (g *Game) Query_QueryGameById(in *gt.QueryGameInfo) (types.Message, error)
if
err
!=
nil
{
return
nil
,
err
}
return
&
gt
.
ReplyGame
{
game
},
nil
return
&
gt
.
ReplyGame
{
Game
:
game
},
nil
}
plugin/dapp/hashlock/executor/exec_del_local.go
View file @
c1ea3255
...
...
@@ -11,7 +11,10 @@ import (
)
// ExecDelLocal_Hlock Action
func
(
h
*
Hashlock
)
ExecDelLocal_Hlock
(
hlock
*
pty
.
HashlockLock
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecDelLocal_Hlock
(
hlock
*
pty
.
HashlockLock
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
hlock
.
Time
,
Status
:
hashlockLocked
,
Amount
:
hlock
.
Amount
,
CreateTime
:
h
.
GetBlockTime
(),
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
hlock
.
Hash
,
info
)
if
err
!=
nil
{
...
...
@@ -21,7 +24,10 @@ func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transac
}
// ExecDelLocal_Hsend Action
func
(
h
*
Hashlock
)
ExecDelLocal_Hsend
(
hsend
*
pty
.
HashlockSend
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecDelLocal_Hsend
(
hsend
*
pty
.
HashlockSend
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockSent
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hsend
.
Secret
),
info
)
if
err
!=
nil
{
...
...
@@ -31,7 +37,10 @@ func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transac
}
// ExecDelLocal_Hunlock Action
func
(
h
*
Hashlock
)
ExecDelLocal_Hunlock
(
hunlock
*
pty
.
HashlockUnlock
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecDelLocal_Hunlock
(
hunlock
*
pty
.
HashlockUnlock
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockUnlocked
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hunlock
.
Secret
),
info
)
if
err
!=
nil
{
...
...
plugin/dapp/hashlock/executor/exec_local.go
View file @
c1ea3255
...
...
@@ -11,7 +11,10 @@ import (
)
// ExecLocal_Hlock Action
func
(
h
*
Hashlock
)
ExecLocal_Hlock
(
hlock
*
pty
.
HashlockLock
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecLocal_Hlock
(
hlock
*
pty
.
HashlockLock
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
hlock
.
Time
,
Status
:
hashlockLocked
,
Amount
:
hlock
.
Amount
,
CreateTime
:
h
.
GetBlockTime
(),
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
hlock
.
Hash
,
info
)
...
...
@@ -22,7 +25,10 @@ func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transactio
}
// ExecLocal_Hsend Action
func
(
h
*
Hashlock
)
ExecLocal_Hsend
(
hsend
*
pty
.
HashlockSend
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecLocal_Hsend
(
hsend
*
pty
.
HashlockSend
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockSent
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hsend
.
Secret
),
info
)
...
...
@@ -33,7 +39,10 @@ func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transactio
}
// ExecLocal_Hunlock Action
func
(
h
*
Hashlock
)
ExecLocal_Hunlock
(
hunlock
*
pty
.
HashlockUnlock
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
h
*
Hashlock
)
ExecLocal_Hunlock
(
hunlock
*
pty
.
HashlockUnlock
,
tx
*
types
.
Transaction
,
receipt
types
.
ExecTypeGet
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockUnlocked
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hunlock
.
Secret
),
info
)
...
...
plugin/dapp/init/init.go
View file @
c1ea3255
// 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
import
(
...
...
plugin/dapp/privacy/crypto/privacy_test.go
View file @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
/*
* 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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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 @
c1ea3255
...
...
@@ -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/ticket/wallet/ticket.go
View file @
c1ea3255
...
...
@@ -5,6 +5,7 @@
package
wallet
import
(
"encoding/hex"
"fmt"
"sync"
"sync/atomic"
...
...
@@ -611,17 +612,20 @@ func (policy *ticketPolicy) buyTicket(height int64) ([][]byte, int, error) {
}
count
:=
0
var
hashes
[][]
byte
bizlog
.
Debug
(
"ticketPolicy buyTicket begin"
)
for
_
,
priv
:=
range
privs
{
hash
,
n
,
err
:=
policy
.
buyTicketOne
(
height
,
priv
)
if
err
!=
nil
{
bizlog
.
Error
(
"buyTicketOne"
,
"err"
,
err
)
bizlog
.
Error
(
"
ticketPolicy buyTicket
buyTicketOne"
,
"err"
,
err
)
continue
}
count
+=
n
if
hash
!=
nil
{
hashes
=
append
(
hashes
,
hash
)
}
bizlog
.
Debug
(
"ticketPolicy buyTicket"
,
"Address"
,
address
.
PubKeyToAddress
(
priv
.
PubKey
()
.
Bytes
())
.
String
(),
"txhash"
,
hex
.
EncodeToString
(
hash
),
"n"
,
n
)
}
bizlog
.
Debug
(
"ticketPolicy buyTicket end"
)
return
hashes
,
count
,
nil
}
...
...
@@ -705,6 +709,7 @@ func (policy *ticketPolicy) buyMinerAddrTicket(height int64) ([][]byte, int, err
}
count
:=
0
var
hashes
[][]
byte
bizlog
.
Debug
(
"ticketPolicy buyMinerAddrTicket begin"
)
for
_
,
priv
:=
range
privs
{
hashlist
,
n
,
err
:=
policy
.
buyMinerAddrTicketOne
(
height
,
priv
)
if
err
!=
nil
{
...
...
@@ -717,7 +722,9 @@ func (policy *ticketPolicy) buyMinerAddrTicket(height int64) ([][]byte, int, err
if
hashlist
!=
nil
{
hashes
=
append
(
hashes
,
hashlist
...
)
}
bizlog
.
Debug
(
"ticketPolicy buyMinerAddrTicket"
,
"Address"
,
address
.
PubKeyToAddress
(
priv
.
PubKey
()
.
Bytes
())
.
String
(),
"n"
,
n
)
}
bizlog
.
Debug
(
"ticketPolicy buyMinerAddrTicket end"
)
return
hashes
,
count
,
nil
}
...
...
plugin/dapp/trade/executor/exec_test.go
View file @
c1ea3255
...
...
@@ -88,13 +88,13 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
driver
.
SetStateDB
(
stateDB
)
sell
:=
&
pty
.
TradeSellTx
{
Symbol
,
sellArgs
.
amount
,
sellArgs
.
min
,
sellArgs
.
price
,
sellArgs
.
total
,
0
,
AssetExecToken
,
TokenSymbol
:
Symbol
,
AmountPerBoardlot
:
sellArgs
.
amount
,
MinBoardlot
:
sellArgs
.
min
,
PricePerBoardlot
:
sellArgs
.
price
,
TotalBoardlot
:
sellArgs
.
total
,
Fee
:
0
,
AssetExec
:
AssetExec
Token
,
}
tx
,
_
:=
pty
.
CreateRawTradeSellTx
(
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
...
...
@@ -125,9 +125,9 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
assert
.
Equal
(
t
,
string
(
Nodes
[
0
]),
sellOrder
.
Address
)
buy
:=
&
pty
.
TradeBuyTx
{
sellOrder
.
SellID
,
buyArgs
.
total
,
0
,
SellID
:
sellOrder
.
SellID
,
BoardlotCnt
:
buyArgs
.
total
,
Fee
:
0
,
}
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
...
...
@@ -197,13 +197,13 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
driver
.
SetStateDB
(
stateDB
)
buy
:=
&
pty
.
TradeBuyLimitTx
{
Symbol
,
buyArgs
.
amount
,
buyArgs
.
min
,
buyArgs
.
price
,
buyArgs
.
total
,
0
,
AssetExecPara
,
TokenSymbol
:
Symbol
,
AmountPerBoardlot
:
buyArgs
.
amount
,
MinBoardlot
:
buyArgs
.
min
,
PricePerBoardlot
:
buyArgs
.
price
,
TotalBoardlot
:
buyArgs
.
total
,
Fee
:
0
,
AssetExec
:
AssetExec
Para
,
}
tx
,
_
:=
pty
.
CreateRawTradeBuyLimitTx
(
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
...
...
@@ -234,9 +234,9 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
assert
.
Equal
(
t
,
string
(
Nodes
[
1
]),
buyLimitOrder
.
Address
)
sell
:=
&
pty
.
TradeSellMarketTx
{
buyLimitOrder
.
BuyID
,
sellArgs
.
total
,
0
,
BuyID
:
buyLimitOrder
.
BuyID
,
BoardlotCnt
:
sellArgs
.
total
,
Fee
:
0
,
}
tx
,
_
=
pty
.
CreateRawTradeSellMarketTx
(
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
...
...
plugin/dapp/trade/executor/kv.go
View file @
c1ea3255
...
...
@@ -158,13 +158,13 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenBuyOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
...
...
@@ -180,11 +180,11 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
...
...
@@ -195,13 +195,13 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenSellOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyToken
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
...
...
@@ -217,11 +217,11 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
newkey
=
calcTokensSellOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
...
...
@@ -235,42 +235,42 @@ func calcPriceOfToken(priceBoardlot, AmountPerBoardlot int64) int64 {
func
genBuyLimitOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
newkey
:=
calcTokenBuyOrderKey
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
,
buyOrder
.
Height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcTokensBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
buyOrder
.
PricePerBoardlot
,
buyOrder
.
AmountPerBoardlot
),
buyOrder
.
Address
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
buyOrder
.
Address
,
st
,
ty
,
buyOrder
.
Height
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
func
genSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
newkey
:=
calcTokenSellOrderKey
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
,
sellorder
.
Height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyToken
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcTokensSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
sellorder
.
PricePerBoardlot
,
sellorder
.
AmountPerBoardlot
),
sellorder
.
Address
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
sellorder
.
Address
,
st
,
ty
,
sellorder
.
Height
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
plugin/dapp/trade/executor/query.go
View file @
c1ea3255
...
...
@@ -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/executor/trade_test.go
View file @
c1ea3255
...
...
@@ -15,54 +15,54 @@ import (
var
(
sellorderOnsale
=
pty
.
SellOrder
{
"Tokensymbol"
,
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
pty
.
TradeOrderStatusOnSale
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
TokenSymbol
:
"Tokensymbol"
,
Address
:
"Address"
,
AmountPerBoardlot
:
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
MinBoardlot
:
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
PricePerBoardlot
:
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
SellID
:
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
Status
:
pty
.
TradeOrderStatusOnSale
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
AssetExec
:
"token"
,
}
sellorderSoldOut
=
pty
.
SellOrder
{
"Tokensymbol"
,
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
pty
.
TradeOrderStatusSoldOut
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
TokenSymbol
:
"Tokensymbol"
,
Address
:
"Address"
,
AmountPerBoardlot
:
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
MinBoardlot
:
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
PricePerBoardlot
:
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
SellID
:
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
Status
:
pty
.
TradeOrderStatusSoldOut
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
AssetExec
:
"token"
,
}
sellorderRevoked
=
pty
.
SellOrder
{
"Tokensymbol"
,
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
pty
.
TradeOrderStatusRevoked
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
TokenSymbol
:
"Tokensymbol"
,
Address
:
"Address"
,
AmountPerBoardlot
:
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
MinBoardlot
:
2
,
// Minboardlot int64 `protobuf:"varint,4,opt,name=minboardlot" json:"minboardlot,omitempty"`
PricePerBoardlot
:
1
*
1e8
,
//Priceperboardlot int64 `protobuf:"varint,5,opt,name=priceperboardlot" json:"priceperboardlot,omitempty"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
SellID
:
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
Status
:
pty
.
TradeOrderStatusRevoked
,
//Status int32 `protobuf:"varint,12,opt,name=status" json:"status,omitempty"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
AssetExec
:
"token"
,
}
)
...
...
plugin/dapp/trade/executor/tradedb.go
View file @
c1ea3255
This diff is collapsed.
Click to expand it.
plugin/dapp/trade/rpc/rpc.go
View file @
c1ea3255
...
...
@@ -35,7 +35,7 @@ func (cc *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.Tra
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeBuyMarket
,
Value
:
&
ptypes
.
Trade_BuyMarket
{
in
},
Value
:
&
ptypes
.
Trade_BuyMarket
{
BuyMarket
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
@@ -52,7 +52,7 @@ func (cc *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptypes.
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeRevokeSell
,
Value
:
&
ptypes
.
Trade_RevokeSell
{
in
},
Value
:
&
ptypes
.
Trade_RevokeSell
{
RevokeSell
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
@@ -69,7 +69,7 @@ func (cc *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *ptype
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeBuyLimit
,
Value
:
&
ptypes
.
Trade_BuyLimit
{
in
},
Value
:
&
ptypes
.
Trade_BuyLimit
{
BuyLimit
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
@@ -86,7 +86,7 @@ func (cc *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *pty
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeSellMarket
,
Value
:
&
ptypes
.
Trade_SellMarket
{
in
},
Value
:
&
ptypes
.
Trade_SellMarket
{
SellMarket
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
@@ -103,7 +103,7 @@ func (cc *channelClient) CreateRawTradeRevokeBuyTx(ctx context.Context, in *ptyp
}
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeRevokeBuy
,
Value
:
&
ptypes
.
Trade_RevokeBuy
{
in
},
Value
:
&
ptypes
.
Trade_RevokeBuy
{
RevokeBuy
:
in
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
...
...
plugin/dapp/trade/types/trade.go
View file @
c1ea3255
...
...
@@ -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 : 创建卖单交易
...
...
plugin/store/init/init.go
View file @
c1ea3255
// 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
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