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
3738bc5d
Commit
3738bc5d
authored
Nov 24, 2018
by
vipwzw
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into Hugo-Huang-branch_dev_hugo
parents
4e195bff
0ac1f080
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
909 additions
and
538 deletions
+909
-538
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
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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
// 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/tendermint.go
View file @
3738bc5d
...
@@ -485,7 +485,8 @@ func (client *Client) QueryValidatorsByHeight(height int64) (*tmtypes.ValNodes,
...
@@ -485,7 +485,8 @@ func (client *Client) QueryValidatorsByHeight(height int64) (*tmtypes.ValNodes,
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
{
...
@@ -505,7 +506,8 @@ func (client *Client) QueryBlockInfoByHeight(height int64) (*tmtypes.TendermintB
...
@@ -505,7 +506,8 @@ func (client *Client) QueryBlockInfoByHeight(height int64) (*tmtypes.TendermintB
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/ticket/ticket_test.go
View file @
3738bc5d
...
@@ -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 @
3738bc5d
// 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/cert/executor/exec_local.go
100644 → 100755
View file @
3738bc5d
...
@@ -17,11 +17,14 @@ func calcCertHeightKey(height int64) []byte {
...
@@ -17,11 +17,14 @@ func calcCertHeightKey(height int64) []byte {
}
}
// ExecLocal_New 启用证书交易执行
// 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
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
return
nil
,
ct
.
ErrInitializeAuthority
}
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
historityCertdata
:=
&
types
.
HistoryCertStore
{}
historityCertdata
:=
&
types
.
HistoryCertStore
{}
...
@@ -46,11 +49,14 @@ func (c *Cert) ExecLocal_New(payload *ct.CertNew, tx *types.Transaction, receipt
...
@@ -46,11 +49,14 @@ func (c *Cert) ExecLocal_New(payload *ct.CertNew, tx *types.Transaction, receipt
}
}
// ExecLocal_Update 更新证书交易执行
// 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
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
return
nil
,
ct
.
ErrInitializeAuthority
}
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
// 写入上一纪录的next-height
// 写入上一纪录的next-height
...
@@ -76,11 +82,14 @@ func (c *Cert) ExecLocal_Update(payload *ct.CertUpdate, tx *types.Transaction, r
...
@@ -76,11 +82,14 @@ func (c *Cert) ExecLocal_Update(payload *ct.CertUpdate, tx *types.Transaction, r
}
}
// ExecLocal_Normal 非证书变更交易执行
// 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
{
if
!
authority
.
IsAuthEnable
{
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
clog
.
Error
(
"Authority is not available. Please check the authority config or authority initialize error logs."
)
return
nil
,
ct
.
ErrInitializeAuthority
return
nil
,
ct
.
ErrInitializeAuthority
}
}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
&
types
.
LocalDBSet
{},
nil
}
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
return
&
set
,
nil
return
&
set
,
nil
...
...
plugin/dapp/game/executor/query.go
View file @
3738bc5d
...
@@ -30,5 +30,5 @@ func (g *Game) Query_QueryGameById(in *gt.QueryGameInfo) (types.Message, error)
...
@@ -30,5 +30,5 @@ func (g *Game) Query_QueryGameById(in *gt.QueryGameInfo) (types.Message, error)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
&
gt
.
ReplyGame
{
game
},
nil
return
&
gt
.
ReplyGame
{
Game
:
game
},
nil
}
}
plugin/dapp/hashlock/executor/exec_del_local.go
View file @
3738bc5d
...
@@ -11,7 +11,10 @@ import (
...
@@ -11,7 +11,10 @@ import (
)
)
// ExecDelLocal_Hlock Action
// 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
}
info
:=
pty
.
Hashlockquery
{
Time
:
hlock
.
Time
,
Status
:
hashlockLocked
,
Amount
:
hlock
.
Amount
,
CreateTime
:
h
.
GetBlockTime
(),
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
hlock
.
Hash
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
hlock
.
Hash
,
info
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -21,7 +24,10 @@ func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transac
...
@@ -21,7 +24,10 @@ func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transac
}
}
// ExecDelLocal_Hsend Action
// 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
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockSent
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hsend
.
Secret
),
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hsend
.
Secret
),
info
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -31,7 +37,10 @@ func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transac
...
@@ -31,7 +37,10 @@ func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transac
}
}
// ExecDelLocal_Hunlock Action
// 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
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockUnlocked
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hunlock
.
Secret
),
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hunlock
.
Secret
),
info
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/dapp/hashlock/executor/exec_local.go
View file @
3738bc5d
...
@@ -11,7 +11,10 @@ import (
...
@@ -11,7 +11,10 @@ import (
)
)
// ExecLocal_Hlock Action
// 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
}
info
:=
pty
.
Hashlockquery
{
Time
:
hlock
.
Time
,
Status
:
hashlockLocked
,
Amount
:
hlock
.
Amount
,
CreateTime
:
h
.
GetBlockTime
(),
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
hlock
.
Hash
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
hlock
.
Hash
,
info
)
...
@@ -22,7 +25,10 @@ func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transactio
...
@@ -22,7 +25,10 @@ func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transactio
}
}
// ExecLocal_Hsend Action
// 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
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockSent
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hsend
.
Secret
),
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
...
@@ -33,7 +39,10 @@ func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transactio
}
}
// ExecLocal_Hunlock Action
// 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
}
info
:=
pty
.
Hashlockquery
{
Time
:
0
,
Status
:
hashlockUnlocked
,
Amount
:
0
,
CreateTime
:
0
,
CurrentTime
:
0
}
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
clog
.
Error
(
"ExecLocal"
,
"info"
,
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hunlock
.
Secret
),
info
)
kv
,
err
:=
UpdateHashReciver
(
h
.
GetLocalDB
(),
common
.
Sha256
(
hunlock
.
Secret
),
info
)
...
...
plugin/dapp/init/init.go
View file @
3738bc5d
// 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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
/*
* 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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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 @
3738bc5d
...
@@ -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/ticket/wallet/ticket.go
View file @
3738bc5d
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
wallet
package
wallet
import
(
import
(
"encoding/hex"
"fmt"
"fmt"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
...
@@ -611,17 +612,20 @@ func (policy *ticketPolicy) buyTicket(height int64) ([][]byte, int, error) {
...
@@ -611,17 +612,20 @@ func (policy *ticketPolicy) buyTicket(height int64) ([][]byte, int, error) {
}
}
count
:=
0
count
:=
0
var
hashes
[][]
byte
var
hashes
[][]
byte
bizlog
.
Debug
(
"ticketPolicy buyTicket begin"
)
for
_
,
priv
:=
range
privs
{
for
_
,
priv
:=
range
privs
{
hash
,
n
,
err
:=
policy
.
buyTicketOne
(
height
,
priv
)
hash
,
n
,
err
:=
policy
.
buyTicketOne
(
height
,
priv
)
if
err
!=
nil
{
if
err
!=
nil
{
bizlog
.
Error
(
"buyTicketOne"
,
"err"
,
err
)
bizlog
.
Error
(
"
ticketPolicy buyTicket
buyTicketOne"
,
"err"
,
err
)
continue
continue
}
}
count
+=
n
count
+=
n
if
hash
!=
nil
{
if
hash
!=
nil
{
hashes
=
append
(
hashes
,
hash
)
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
return
hashes
,
count
,
nil
}
}
...
@@ -705,6 +709,7 @@ func (policy *ticketPolicy) buyMinerAddrTicket(height int64) ([][]byte, int, err
...
@@ -705,6 +709,7 @@ func (policy *ticketPolicy) buyMinerAddrTicket(height int64) ([][]byte, int, err
}
}
count
:=
0
count
:=
0
var
hashes
[][]
byte
var
hashes
[][]
byte
bizlog
.
Debug
(
"ticketPolicy buyMinerAddrTicket begin"
)
for
_
,
priv
:=
range
privs
{
for
_
,
priv
:=
range
privs
{
hashlist
,
n
,
err
:=
policy
.
buyMinerAddrTicketOne
(
height
,
priv
)
hashlist
,
n
,
err
:=
policy
.
buyMinerAddrTicketOne
(
height
,
priv
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -717,7 +722,9 @@ func (policy *ticketPolicy) buyMinerAddrTicket(height int64) ([][]byte, int, err
...
@@ -717,7 +722,9 @@ func (policy *ticketPolicy) buyMinerAddrTicket(height int64) ([][]byte, int, err
if
hashlist
!=
nil
{
if
hashlist
!=
nil
{
hashes
=
append
(
hashes
,
hashlist
...
)
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
return
hashes
,
count
,
nil
}
}
...
...
plugin/dapp/trade/executor/exec_test.go
View file @
3738bc5d
...
@@ -88,13 +88,13 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
...
@@ -88,13 +88,13 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
driver
.
SetStateDB
(
stateDB
)
driver
.
SetStateDB
(
stateDB
)
sell
:=
&
pty
.
TradeSellTx
{
sell
:=
&
pty
.
TradeSellTx
{
Symbol
,
TokenSymbol
:
Symbol
,
sellArgs
.
amount
,
AmountPerBoardlot
:
sellArgs
.
amount
,
sellArgs
.
min
,
MinBoardlot
:
sellArgs
.
min
,
sellArgs
.
price
,
PricePerBoardlot
:
sellArgs
.
price
,
sellArgs
.
total
,
TotalBoardlot
:
sellArgs
.
total
,
0
,
Fee
:
0
,
AssetExecToken
,
AssetExec
:
AssetExec
Token
,
}
}
tx
,
_
:=
pty
.
CreateRawTradeSellTx
(
sell
)
tx
,
_
:=
pty
.
CreateRawTradeSellTx
(
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
...
@@ -125,9 +125,9 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
...
@@ -125,9 +125,9 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
assert
.
Equal
(
t
,
string
(
Nodes
[
0
]),
sellOrder
.
Address
)
assert
.
Equal
(
t
,
string
(
Nodes
[
0
]),
sellOrder
.
Address
)
buy
:=
&
pty
.
TradeBuyTx
{
buy
:=
&
pty
.
TradeBuyTx
{
sellOrder
.
SellID
,
SellID
:
sellOrder
.
SellID
,
buyArgs
.
total
,
BoardlotCnt
:
buyArgs
.
total
,
0
,
Fee
:
0
,
}
}
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
buy
)
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
...
@@ -197,13 +197,13 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
...
@@ -197,13 +197,13 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
driver
.
SetStateDB
(
stateDB
)
driver
.
SetStateDB
(
stateDB
)
buy
:=
&
pty
.
TradeBuyLimitTx
{
buy
:=
&
pty
.
TradeBuyLimitTx
{
Symbol
,
TokenSymbol
:
Symbol
,
buyArgs
.
amount
,
AmountPerBoardlot
:
buyArgs
.
amount
,
buyArgs
.
min
,
MinBoardlot
:
buyArgs
.
min
,
buyArgs
.
price
,
PricePerBoardlot
:
buyArgs
.
price
,
buyArgs
.
total
,
TotalBoardlot
:
buyArgs
.
total
,
0
,
Fee
:
0
,
AssetExecPara
,
AssetExec
:
AssetExec
Para
,
}
}
tx
,
_
:=
pty
.
CreateRawTradeBuyLimitTx
(
buy
)
tx
,
_
:=
pty
.
CreateRawTradeBuyLimitTx
(
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
...
@@ -234,9 +234,9 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
...
@@ -234,9 +234,9 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
assert
.
Equal
(
t
,
string
(
Nodes
[
1
]),
buyLimitOrder
.
Address
)
assert
.
Equal
(
t
,
string
(
Nodes
[
1
]),
buyLimitOrder
.
Address
)
sell
:=
&
pty
.
TradeSellMarketTx
{
sell
:=
&
pty
.
TradeSellMarketTx
{
buyLimitOrder
.
BuyID
,
BuyID
:
buyLimitOrder
.
BuyID
,
sellArgs
.
total
,
BoardlotCnt
:
sellArgs
.
total
,
0
,
Fee
:
0
,
}
}
tx
,
_
=
pty
.
CreateRawTradeSellMarketTx
(
sell
)
tx
,
_
=
pty
.
CreateRawTradeSellMarketTx
(
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
...
...
plugin/dapp/trade/executor/kv.go
View file @
3738bc5d
...
@@ -158,13 +158,13 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
...
@@ -158,13 +158,13 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
keyID
:=
receipt
.
TxHash
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenBuyOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
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
)
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
)
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
)
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -180,11 +180,11 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
...
@@ -180,11 +180,11 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyID
)
price
,
receipt
.
Owner
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyID
)
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
return
kv
}
}
...
@@ -195,13 +195,13 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
...
@@ -195,13 +195,13 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
keyID
:=
receipt
.
TxHash
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenSellOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
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
)
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
)
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
)
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -217,11 +217,11 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
...
@@ -217,11 +217,11 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
newkey
=
calcTokensSellOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
newkey
=
calcTokensSellOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyID
)
price
,
receipt
.
Owner
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyID
)
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
return
kv
}
}
...
@@ -235,42 +235,42 @@ func calcPriceOfToken(priceBoardlot, AmountPerBoardlot int64) int64 {
...
@@ -235,42 +235,42 @@ func calcPriceOfToken(priceBoardlot, AmountPerBoardlot int64) int64 {
func
genBuyLimitOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
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
)
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
)
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
)
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
,
newkey
=
calcTokensBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
buyOrder
.
PricePerBoardlot
,
buyOrder
.
AmountPerBoardlot
),
buyOrder
.
Address
,
buyOrder
.
BuyID
)
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
)
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
buyOrder
.
Address
,
st
,
ty
,
buyOrder
.
Height
,
buyOrder
.
BuyID
)
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
return
kv
}
}
func
genSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
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
)
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
)
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
)
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
,
newkey
=
calcTokensSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
sellorder
.
PricePerBoardlot
,
sellorder
.
AmountPerBoardlot
),
sellorder
.
Address
,
sellorder
.
SellID
)
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
)
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
sellorder
.
Address
,
st
,
ty
,
sellorder
.
Height
,
sellorder
.
SellID
)
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
return
kv
}
}
plugin/dapp/trade/executor/query.go
View file @
3738bc5d
...
@@ -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/executor/trade_test.go
View file @
3738bc5d
...
@@ -15,54 +15,54 @@ import (
...
@@ -15,54 +15,54 @@ import (
var
(
var
(
sellorderOnsale
=
pty
.
SellOrder
{
sellorderOnsale
=
pty
.
SellOrder
{
"Tokensymbol"
,
TokenSymbol
:
"Tokensymbol"
,
"Address"
,
Address
:
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
AmountPerBoardlot
:
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"`
MinBoardlot
:
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"`
PricePerBoardlot
:
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"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
SellID
:
"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"`
Status
:
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"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
AssetExec
:
"token"
,
}
}
sellorderSoldOut
=
pty
.
SellOrder
{
sellorderSoldOut
=
pty
.
SellOrder
{
"Tokensymbol"
,
TokenSymbol
:
"Tokensymbol"
,
"Address"
,
Address
:
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
AmountPerBoardlot
:
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"`
MinBoardlot
:
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"`
PricePerBoardlot
:
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"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
SellID
:
"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"`
Status
:
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"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
AssetExec
:
"token"
,
}
}
sellorderRevoked
=
pty
.
SellOrder
{
sellorderRevoked
=
pty
.
SellOrder
{
"Tokensymbol"
,
TokenSymbol
:
"Tokensymbol"
,
"Address"
,
Address
:
"Address"
,
20
*
1e8
,
// Amountperboardlot int64 `protobuf:"varint,3,opt,name=amountperboardlot" json:"amountperboardlot,omitempty"`
AmountPerBoardlot
:
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"`
MinBoardlot
:
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"`
PricePerBoardlot
:
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"`
TotalBoardlot
:
60
,
// Totalboardlot int64 `protobuf:"varint,6,opt,name=totalboardlot" json:"totalboardlot,omitempty"`
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
SoldBoardlot
:
2
,
// Soldboardlot int64 `protobuf:"varint,7,opt,name=soldboardlot" json:"soldboardlot,omitempty"`
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
Starttime
:
0
,
//Starttime int64 `protobuf:"varint,8,opt,name=starttime" json:"starttime,omitempty"`
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
Stoptime
:
0
,
//Stoptime int64 `protobuf:"varint,9,opt,name=stoptime" json:"stoptime,omitempty"`
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
Crowdfund
:
false
,
//Crowdfund bool `protobuf:"varint,10,opt,name=crowdfund" json:"crowdfund,omitempty"`
"IAMSELLID"
,
// Sellid string `protobuf:"bytes,11,opt,name=sellid" json:"sellid,omitempty"`
SellID
:
"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"`
Status
:
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"`
Height
:
100
,
//Height int64 `protobuf:"varint,13,opt,name=height" json:"height,omitempty"`
"token"
,
AssetExec
:
"token"
,
}
}
)
)
...
...
plugin/dapp/trade/executor/tradedb.go
View file @
3738bc5d
...
@@ -40,29 +40,29 @@ func (selldb *sellDB) getSellLogs(tradeType int32, txhash string) *types.Receipt
...
@@ -40,29 +40,29 @@ func (selldb *sellDB) getSellLogs(tradeType int32, txhash string) *types.Receipt
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
tradeType
log
.
Ty
=
tradeType
base
:=
&
pty
.
ReceiptSellBase
{
base
:=
&
pty
.
ReceiptSellBase
{
selldb
.
TokenSymbol
,
TokenSymbol
:
selldb
.
TokenSymbol
,
selldb
.
Address
,
Owner
:
selldb
.
Address
,
strconv
.
FormatFloat
(
float64
(
selldb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
AmountPerBoardlot
:
strconv
.
FormatFloat
(
float64
(
selldb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
selldb
.
MinBoardlot
,
MinBoardlot
:
selldb
.
MinBoardlot
,
strconv
.
FormatFloat
(
float64
(
selldb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
PricePerBoardlot
:
strconv
.
FormatFloat
(
float64
(
selldb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
selldb
.
TotalBoardlot
,
TotalBoardlot
:
selldb
.
TotalBoardlot
,
selldb
.
SoldBoardlot
,
SoldBoardlot
:
selldb
.
SoldBoardlot
,
selldb
.
Starttime
,
Starttime
:
selldb
.
Starttime
,
selldb
.
Stoptime
,
Stoptime
:
selldb
.
Stoptime
,
selldb
.
Crowdfund
,
Crowdfund
:
selldb
.
Crowdfund
,
selldb
.
SellID
,
SellID
:
selldb
.
SellID
,
pty
.
SellOrderStatus
[
selldb
.
Status
],
Status
:
pty
.
SellOrderStatus
[
selldb
.
Status
],
""
,
BuyID
:
""
,
txhash
,
TxHash
:
txhash
,
selldb
.
Height
,
Height
:
selldb
.
Height
,
selldb
.
AssetExec
,
AssetExec
:
selldb
.
AssetExec
,
}
}
if
pty
.
TyLogTradeSellLimit
==
tradeType
{
if
pty
.
TyLogTradeSellLimit
==
tradeType
{
receiptTrade
:=
&
pty
.
ReceiptTradeSellLimit
{
base
}
receiptTrade
:=
&
pty
.
ReceiptTradeSellLimit
{
Base
:
base
}
log
.
Log
=
types
.
Encode
(
receiptTrade
)
log
.
Log
=
types
.
Encode
(
receiptTrade
)
}
else
if
pty
.
TyLogTradeSellRevoke
==
tradeType
{
}
else
if
pty
.
TyLogTradeSellRevoke
==
tradeType
{
receiptTrade
:=
&
pty
.
ReceiptTradeSellRevoke
{
base
}
receiptTrade
:=
&
pty
.
ReceiptTradeSellRevoke
{
Base
:
base
}
log
.
Log
=
types
.
Encode
(
receiptTrade
)
log
.
Log
=
types
.
Encode
(
receiptTrade
)
}
}
...
@@ -73,22 +73,22 @@ func (selldb *sellDB) getBuyLogs(buyerAddr string, boardlotcnt int64, txhash str
...
@@ -73,22 +73,22 @@ func (selldb *sellDB) getBuyLogs(buyerAddr string, boardlotcnt int64, txhash str
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogTradeBuyMarket
log
.
Ty
=
pty
.
TyLogTradeBuyMarket
base
:=
&
pty
.
ReceiptBuyBase
{
base
:=
&
pty
.
ReceiptBuyBase
{
selldb
.
TokenSymbol
,
TokenSymbol
:
selldb
.
TokenSymbol
,
buyerAddr
,
Owner
:
buyerAddr
,
strconv
.
FormatFloat
(
float64
(
selldb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
AmountPerBoardlot
:
strconv
.
FormatFloat
(
float64
(
selldb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
selldb
.
MinBoardlot
,
MinBoardlot
:
selldb
.
MinBoardlot
,
strconv
.
FormatFloat
(
float64
(
selldb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
PricePerBoardlot
:
strconv
.
FormatFloat
(
float64
(
selldb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
boardlotcnt
,
TotalBoardlot
:
boardlotcnt
,
boardlotcnt
,
BoughtBoardlot
:
boardlotcnt
,
""
,
BuyID
:
""
,
pty
.
SellOrderStatus
[
pty
.
TradeOrderStatusBoughtOut
],
Status
:
pty
.
SellOrderStatus
[
pty
.
TradeOrderStatusBoughtOut
],
selldb
.
SellID
,
SellID
:
selldb
.
SellID
,
txhash
,
TxHash
:
txhash
,
selldb
.
Height
,
Height
:
selldb
.
Height
,
selldb
.
AssetExec
,
AssetExec
:
selldb
.
AssetExec
,
}
}
receipt
:=
&
pty
.
ReceiptTradeBuyMarket
{
base
}
receipt
:=
&
pty
.
ReceiptTradeBuyMarket
{
Base
:
base
}
log
.
Log
=
types
.
Encode
(
receipt
)
log
.
Log
=
types
.
Encode
(
receipt
)
return
log
return
log
}
}
...
@@ -131,7 +131,7 @@ func getTx(txHash []byte, db dbm.KV) (*types.TxResult, error) {
...
@@ -131,7 +131,7 @@ func getTx(txHash []byte, db dbm.KV) (*types.TxResult, error) {
func
(
selldb
*
sellDB
)
getKVSet
()
(
kvset
[]
*
types
.
KeyValue
)
{
func
(
selldb
*
sellDB
)
getKVSet
()
(
kvset
[]
*
types
.
KeyValue
)
{
value
:=
types
.
Encode
(
&
selldb
.
SellOrder
)
value
:=
types
.
Encode
(
&
selldb
.
SellOrder
)
key
:=
[]
byte
(
selldb
.
SellID
)
key
:=
[]
byte
(
selldb
.
SellID
)
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
key
,
value
})
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
return
kvset
return
kvset
}
}
...
@@ -156,7 +156,7 @@ func (buydb *buyDB) save(db dbm.KV) []*types.KeyValue {
...
@@ -156,7 +156,7 @@ func (buydb *buyDB) save(db dbm.KV) []*types.KeyValue {
func
(
buydb
*
buyDB
)
getKVSet
()
(
kvset
[]
*
types
.
KeyValue
)
{
func
(
buydb
*
buyDB
)
getKVSet
()
(
kvset
[]
*
types
.
KeyValue
)
{
value
:=
types
.
Encode
(
&
buydb
.
BuyLimitOrder
)
value
:=
types
.
Encode
(
&
buydb
.
BuyLimitOrder
)
key
:=
[]
byte
(
buydb
.
BuyID
)
key
:=
[]
byte
(
buydb
.
BuyID
)
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
key
,
value
})
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
return
kvset
return
kvset
}
}
...
@@ -164,26 +164,26 @@ func (buydb *buyDB) getBuyLogs(tradeType int32, txhash string) *types.ReceiptLog
...
@@ -164,26 +164,26 @@ func (buydb *buyDB) getBuyLogs(tradeType int32, txhash string) *types.ReceiptLog
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
tradeType
log
.
Ty
=
tradeType
base
:=
&
pty
.
ReceiptBuyBase
{
base
:=
&
pty
.
ReceiptBuyBase
{
buydb
.
TokenSymbol
,
TokenSymbol
:
buydb
.
TokenSymbol
,
buydb
.
Address
,
Owner
:
buydb
.
Address
,
strconv
.
FormatFloat
(
float64
(
buydb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
AmountPerBoardlot
:
strconv
.
FormatFloat
(
float64
(
buydb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
buydb
.
MinBoardlot
,
MinBoardlot
:
buydb
.
MinBoardlot
,
strconv
.
FormatFloat
(
float64
(
buydb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
PricePerBoardlot
:
strconv
.
FormatFloat
(
float64
(
buydb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
buydb
.
TotalBoardlot
,
TotalBoardlot
:
buydb
.
TotalBoardlot
,
buydb
.
BoughtBoardlot
,
BoughtBoardlot
:
buydb
.
BoughtBoardlot
,
buydb
.
BuyID
,
BuyID
:
buydb
.
BuyID
,
pty
.
SellOrderStatus
[
buydb
.
Status
],
Status
:
pty
.
SellOrderStatus
[
buydb
.
Status
],
""
,
SellID
:
""
,
txhash
,
TxHash
:
txhash
,
buydb
.
Height
,
Height
:
buydb
.
Height
,
buydb
.
AssetExec
,
AssetExec
:
buydb
.
AssetExec
,
}
}
if
pty
.
TyLogTradeBuyLimit
==
tradeType
{
if
pty
.
TyLogTradeBuyLimit
==
tradeType
{
receiptTrade
:=
&
pty
.
ReceiptTradeBuyLimit
{
base
}
receiptTrade
:=
&
pty
.
ReceiptTradeBuyLimit
{
Base
:
base
}
log
.
Log
=
types
.
Encode
(
receiptTrade
)
log
.
Log
=
types
.
Encode
(
receiptTrade
)
}
else
if
pty
.
TyLogTradeBuyRevoke
==
tradeType
{
}
else
if
pty
.
TyLogTradeBuyRevoke
==
tradeType
{
receiptTrade
:=
&
pty
.
ReceiptTradeBuyRevoke
{
base
}
receiptTrade
:=
&
pty
.
ReceiptTradeBuyRevoke
{
Base
:
base
}
log
.
Log
=
types
.
Encode
(
receiptTrade
)
log
.
Log
=
types
.
Encode
(
receiptTrade
)
}
}
...
@@ -209,22 +209,22 @@ func (buydb *buyDB) getSellLogs(sellerAddr string, sellID string, boardlotCnt in
...
@@ -209,22 +209,22 @@ func (buydb *buyDB) getSellLogs(sellerAddr string, sellID string, boardlotCnt in
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogTradeSellMarket
log
.
Ty
=
pty
.
TyLogTradeSellMarket
base
:=
&
pty
.
ReceiptSellBase
{
base
:=
&
pty
.
ReceiptSellBase
{
buydb
.
TokenSymbol
,
TokenSymbol
:
buydb
.
TokenSymbol
,
sellerAddr
,
Owner
:
sellerAddr
,
strconv
.
FormatFloat
(
float64
(
buydb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
AmountPerBoardlot
:
strconv
.
FormatFloat
(
float64
(
buydb
.
AmountPerBoardlot
)
/
float64
(
types
.
TokenPrecision
),
'f'
,
8
,
64
),
buydb
.
MinBoardlot
,
MinBoardlot
:
buydb
.
MinBoardlot
,
strconv
.
FormatFloat
(
float64
(
buydb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
PricePerBoardlot
:
strconv
.
FormatFloat
(
float64
(
buydb
.
PricePerBoardlot
)
/
float64
(
types
.
Coin
),
'f'
,
8
,
64
),
boardlotCnt
,
TotalBoardlot
:
boardlotCnt
,
boardlotCnt
,
SoldBoardlot
:
boardlotCnt
,
0
,
Starttime
:
0
,
0
,
Stoptime
:
0
,
false
,
Crowdfund
:
false
,
""
,
SellID
:
""
,
pty
.
SellOrderStatus
[
pty
.
TradeOrderStatusSoldOut
],
Status
:
pty
.
SellOrderStatus
[
pty
.
TradeOrderStatusSoldOut
],
buydb
.
BuyID
,
BuyID
:
buydb
.
BuyID
,
txhash
,
TxHash
:
txhash
,
buydb
.
Height
,
Height
:
buydb
.
Height
,
buydb
.
AssetExec
,
AssetExec
:
buydb
.
AssetExec
,
}
}
receiptSellMarket
:=
&
pty
.
ReceiptSellMarket
{
Base
:
base
}
receiptSellMarket
:=
&
pty
.
ReceiptSellMarket
{
Base
:
base
}
log
.
Log
=
types
.
Encode
(
receiptSellMarket
)
log
.
Log
=
types
.
Encode
(
receiptSellMarket
)
...
@@ -272,20 +272,20 @@ func (action *tradeAction) tradeSell(sell *pty.TradeForSell) (*types.Receipt, er
...
@@ -272,20 +272,20 @@ func (action *tradeAction) tradeSell(sell *pty.TradeForSell) (*types.Receipt, er
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
kv
[]
*
types
.
KeyValue
sellOrder
:=
pty
.
SellOrder
{
sellOrder
:=
pty
.
SellOrder
{
sell
.
GetTokenSymbol
(),
TokenSymbol
:
sell
.
GetTokenSymbol
(),
action
.
fromaddr
,
Address
:
action
.
fromaddr
,
sell
.
GetAmountPerBoardlot
(),
AmountPerBoardlot
:
sell
.
GetAmountPerBoardlot
(),
sell
.
GetMinBoardlot
(),
MinBoardlot
:
sell
.
GetMinBoardlot
(),
sell
.
GetPricePerBoardlot
(),
PricePerBoardlot
:
sell
.
GetPricePerBoardlot
(),
sell
.
GetTotalBoardlot
(),
TotalBoardlot
:
sell
.
GetTotalBoardlot
(),
0
,
SoldBoardlot
:
0
,
sell
.
GetStarttime
(),
Starttime
:
sell
.
GetStarttime
(),
sell
.
GetStoptime
(),
Stoptime
:
sell
.
GetStoptime
(),
sell
.
GetCrowdfund
(),
Crowdfund
:
sell
.
GetCrowdfund
(),
calcTokenSellID
(
action
.
txhash
),
SellID
:
calcTokenSellID
(
action
.
txhash
),
pty
.
TradeOrderStatusOnSale
,
Status
:
pty
.
TradeOrderStatusOnSale
,
action
.
height
,
Height
:
action
.
height
,
sell
.
AssetExec
,
AssetExec
:
sell
.
AssetExec
,
}
}
tokendb
:=
newSellDB
(
sellOrder
)
tokendb
:=
newSellDB
(
sellOrder
)
...
@@ -295,7 +295,7 @@ func (action *tradeAction) tradeSell(sell *pty.TradeForSell) (*types.Receipt, er
...
@@ -295,7 +295,7 @@ func (action *tradeAction) tradeSell(sell *pty.TradeForSell) (*types.Receipt, er
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
receipt
=
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
return
receipt
,
nil
}
}
...
@@ -366,7 +366,7 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
...
@@ -366,7 +366,7 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
kv
=
append
(
kv
,
receiptFromAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
func
(
action
*
tradeAction
)
tradeRevokeSell
(
revoke
*
pty
.
TradeForRevokeSell
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
tradeAction
)
tradeRevokeSell
(
revoke
*
pty
.
TradeForRevokeSell
)
(
*
types
.
Receipt
,
error
)
{
...
@@ -409,7 +409,7 @@ func (action *tradeAction) tradeRevokeSell(revoke *pty.TradeForRevokeSell) (*typ
...
@@ -409,7 +409,7 @@ func (action *tradeAction) tradeRevokeSell(revoke *pty.TradeForRevokeSell) (*typ
logs
=
append
(
logs
,
tokendb
.
getSellLogs
(
pty
.
TyLogTradeSellRevoke
,
action
.
txhash
))
logs
=
append
(
logs
,
tokendb
.
getSellLogs
(
pty
.
TyLogTradeSellRevoke
,
action
.
txhash
))
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
func
(
action
*
tradeAction
)
tradeBuyLimit
(
buy
*
pty
.
TradeForBuyLimit
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
tradeAction
)
tradeBuyLimit
(
buy
*
pty
.
TradeForBuyLimit
)
(
*
types
.
Receipt
,
error
)
{
...
@@ -432,17 +432,17 @@ func (action *tradeAction) tradeBuyLimit(buy *pty.TradeForBuyLimit) (*types.Rece
...
@@ -432,17 +432,17 @@ func (action *tradeAction) tradeBuyLimit(buy *pty.TradeForBuyLimit) (*types.Rece
var
logs
[]
*
types
.
ReceiptLog
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
kv
[]
*
types
.
KeyValue
buyOrder
:=
pty
.
BuyLimitOrder
{
buyOrder
:=
pty
.
BuyLimitOrder
{
buy
.
GetTokenSymbol
(),
TokenSymbol
:
buy
.
GetTokenSymbol
(),
action
.
fromaddr
,
Address
:
action
.
fromaddr
,
buy
.
GetAmountPerBoardlot
(),
AmountPerBoardlot
:
buy
.
GetAmountPerBoardlot
(),
buy
.
GetMinBoardlot
(),
MinBoardlot
:
buy
.
GetMinBoardlot
(),
buy
.
GetPricePerBoardlot
(),
PricePerBoardlot
:
buy
.
GetPricePerBoardlot
(),
buy
.
GetTotalBoardlot
(),
TotalBoardlot
:
buy
.
GetTotalBoardlot
(),
0
,
BoughtBoardlot
:
0
,
calcTokenBuyID
(
action
.
txhash
),
BuyID
:
calcTokenBuyID
(
action
.
txhash
),
pty
.
TradeOrderStatusOnBuy
,
Status
:
pty
.
TradeOrderStatusOnBuy
,
action
.
height
,
Height
:
action
.
height
,
buy
.
AssetExec
,
AssetExec
:
buy
.
AssetExec
,
}
}
tokendb
:=
newBuyDB
(
buyOrder
)
tokendb
:=
newBuyDB
(
buyOrder
)
...
@@ -452,7 +452,7 @@ func (action *tradeAction) tradeBuyLimit(buy *pty.TradeForBuyLimit) (*types.Rece
...
@@ -452,7 +452,7 @@ func (action *tradeAction) tradeBuyLimit(buy *pty.TradeForBuyLimit) (*types.Rece
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
buyOrderKV
...
)
kv
=
append
(
kv
,
buyOrderKV
...
)
receipt
=
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
return
receipt
,
nil
}
}
...
@@ -523,7 +523,7 @@ func (action *tradeAction) tradeSellMarket(sellOrder *pty.TradeForSellMarket) (*
...
@@ -523,7 +523,7 @@ func (action *tradeAction) tradeSellMarket(sellOrder *pty.TradeForSellMarket) (*
kv
=
append
(
kv
,
receiptFromAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
func
(
action
*
tradeAction
)
tradeRevokeBuyLimit
(
revoke
*
pty
.
TradeForRevokeBuy
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
tradeAction
)
tradeRevokeBuyLimit
(
revoke
*
pty
.
TradeForRevokeBuy
)
(
*
types
.
Receipt
,
error
)
{
...
@@ -562,5 +562,5 @@ func (action *tradeAction) tradeRevokeBuyLimit(revoke *pty.TradeForRevokeBuy) (*
...
@@ -562,5 +562,5 @@ func (action *tradeAction) tradeRevokeBuyLimit(revoke *pty.TradeForRevokeBuy) (*
logs
=
append
(
logs
,
tokendb
.
getBuyLogs
(
pty
.
TyLogTradeBuyRevoke
,
action
.
txhash
))
logs
=
append
(
logs
,
tokendb
.
getBuyLogs
(
pty
.
TyLogTradeBuyRevoke
,
action
.
txhash
))
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
receiptFromExecAcc
.
KV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
kv
=
append
(
kv
,
sellOrderKV
...
)
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
plugin/dapp/trade/rpc/rpc.go
View file @
3738bc5d
...
@@ -35,7 +35,7 @@ func (cc *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.Tra
...
@@ -35,7 +35,7 @@ func (cc *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.Tra
}
}
buy
:=
&
ptypes
.
Trade
{
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeBuyMarket
,
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
))
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -52,7 +52,7 @@ func (cc *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptypes.
...
@@ -52,7 +52,7 @@ func (cc *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptypes.
}
}
buy
:=
&
ptypes
.
Trade
{
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeRevokeSell
,
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
))
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -69,7 +69,7 @@ func (cc *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *ptype
...
@@ -69,7 +69,7 @@ func (cc *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *ptype
}
}
buy
:=
&
ptypes
.
Trade
{
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeBuyLimit
,
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
))
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -86,7 +86,7 @@ func (cc *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *pty
...
@@ -86,7 +86,7 @@ func (cc *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *pty
}
}
buy
:=
&
ptypes
.
Trade
{
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeSellMarket
,
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
))
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -103,7 +103,7 @@ func (cc *channelClient) CreateRawTradeRevokeBuyTx(ctx context.Context, in *ptyp
...
@@ -103,7 +103,7 @@ func (cc *channelClient) CreateRawTradeRevokeBuyTx(ctx context.Context, in *ptyp
}
}
buy
:=
&
ptypes
.
Trade
{
buy
:=
&
ptypes
.
Trade
{
Ty
:
ptypes
.
TradeRevokeBuy
,
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
))
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
ptypes
.
TradeX
),
types
.
Encode
(
buy
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/dapp/trade/types/trade.go
View file @
3738bc5d
...
@@ -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/store/init/init.go
View file @
3738bc5d
// 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