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
8c77ec6d
Commit
8c77ec6d
authored
Sep 11, 2019
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
dc450c2e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
313 additions
and
19 deletions
+313
-19
dpos_test.go
plugin/consensus/dpos/dpos_test.go
+311
-17
dposvotedb.go
plugin/dapp/dposvote/executor/dposvotedb.go
+2
-2
No files found.
plugin/consensus/dpos/dpos_test.go
View file @
8c77ec6d
...
@@ -8,18 +8,19 @@ import (
...
@@ -8,18 +8,19 @@ import (
"context"
"context"
"encoding/binary"
"encoding/binary"
"encoding/hex"
"encoding/hex"
"encoding/json"
"errors"
"errors"
"flag"
"flag"
"fmt"
"fmt"
"github.com/33cn/chain33/util"
"math/rand"
"math/rand"
"os"
"os"
"testing"
"testing"
"time"
"time"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/blockchain"
"github.com/33cn/chain33/blockchain"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/limits"
"github.com/33cn/chain33/common/limits"
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/executor"
"github.com/33cn/chain33/executor"
...
@@ -28,15 +29,15 @@ import (
...
@@ -28,15 +29,15 @@ import (
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/rpc"
"github.com/33cn/chain33/rpc"
"github.com/33cn/chain33/store"
"github.com/33cn/chain33/store"
_
"github.com/33cn/chain33/system"
cty
"github.com/33cn/chain33/system/dapp/coins/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
ttypes
"github.com/33cn/plugin/plugin/consensus/dpos/types"
ttypes
"github.com/33cn/plugin/plugin/consensus/dpos/types"
dty
"github.com/33cn/plugin/plugin/dapp/dposvote/types"
dty
"github.com/33cn/plugin/plugin/dapp/dposvote/types"
pty
"github.com/33cn/plugin/plugin/dapp/norm/types"
"google.golang.org/grpc"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/plugin/plugin/dapp/init"
_
"github.com/33cn/plugin/plugin/dapp/init"
pty
"github.com/33cn/plugin/plugin/dapp/norm/types"
_
"github.com/33cn/plugin/plugin/store/init"
_
"github.com/33cn/plugin/plugin/store/init"
"google.golang.org/grpc"
)
)
var
(
var
(
...
@@ -46,6 +47,12 @@ var (
...
@@ -46,6 +47,12 @@ var (
c
types
.
Chain33Client
c
types
.
Chain33Client
strPubkey
=
"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"
strPubkey
=
"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"
pubkey
[]
byte
pubkey
[]
byte
genesisKey
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
validatorKey
=
"5A6A14DA6F5A42835E529D75D87CC8904544F59EEE5387A37D87EEAD194D7EB2"
genesisAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
validatorAddr
=
"15LsTP6tkYGZcN7tc1Xo2iYifQfowxot3b"
)
)
const
fee
=
1e6
const
fee
=
1e6
...
@@ -83,7 +90,35 @@ func DposPerf() {
...
@@ -83,7 +90,35 @@ func DposPerf() {
NormPut
()
NormPut
()
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
}
}
time
.
Sleep
(
10
*
time
.
Second
)
//从创世地址向测试地址转入代币
sendTransferTx
(
genesisKey
,
validatorAddr
,
2000000000000
)
time
.
Sleep
(
3
*
time
.
Second
)
in
:=
&
types
.
ReqBalance
{}
in
.
Addresses
=
append
(
in
.
Addresses
,
validatorAddr
)
acct
,
err
:=
c
.
GetBalance
(
context
.
Background
(),
in
)
if
err
!=
nil
||
len
(
acct
.
Acc
)
==
0
{
fmt
.
Println
(
"no balance for "
,
validatorAddr
)
}
else
{
fmt
.
Println
(
validatorAddr
,
" balance:"
,
acct
.
Acc
[
0
]
.
Balance
,
"frozen:"
,
acct
.
Acc
[
0
]
.
Frozen
)
}
//从测试地址向dos合约转入代币
sendTransferToExecTx
(
validatorKey
,
"dpos"
,
1600000000000
)
time
.
Sleep
(
3
*
time
.
Second
)
in2
:=
&
types
.
ReqBalance
{}
in2
.
Addresses
=
append
(
in2
.
Addresses
,
validatorAddr
)
acct
,
err
=
c
.
GetBalance
(
context
.
Background
(),
in2
)
if
err
!=
nil
||
len
(
acct
.
Acc
)
==
0
{
fmt
.
Println
(
"no balance for "
,
validatorAddr
)
}
else
{
fmt
.
Println
(
validatorAddr
,
" balance:"
,
acct
.
Acc
[
0
]
.
Balance
,
"frozen:"
,
acct
.
Acc
[
0
]
.
Frozen
)
}
sendRegistCandidatorTx
(
strPubkey
,
validatorAddr
,
"127.0.0.1"
,
validatorKey
)
time
.
Sleep
(
3
*
time
.
Second
)
now
:=
time
.
Now
()
.
Unix
()
now
:=
time
.
Now
()
.
Unix
()
task
:=
DecideTaskByTime
(
now
)
task
:=
DecideTaskByTime
(
now
)
...
@@ -105,15 +140,12 @@ func DposPerf() {
...
@@ -105,15 +140,12 @@ func DposPerf() {
time
.
Sleep
(
1
*
time
.
Second
)
time
.
Sleep
(
1
*
time
.
Second
)
info
:=
&
dty
.
DposCBInfo
{
info
:=
&
dty
.
DposCBInfo
{
Cycle
:
task
.
Cycle
,
Cycle
:
task
.
Cycle
,
StopHeight
:
10
,
StopHeight
:
dposClient
.
GetCurrentHeight
()
,
StopHash
:
"absadfafa"
,
StopHash
:
hex
.
EncodeToString
(
dposClient
.
GetCurrentBlock
()
.
Hash
())
,
Pubkey
:
strPubkey
,
Pubkey
:
strPubkey
,
}
}
if
dposClient
.
csState
.
SendCBTx
(
info
)
{
dposClient
.
csState
.
SendCBTx
(
info
)
fmt
.
Println
(
"sendCBTx ok"
)
sendCBTx
(
dposClient
.
csState
,
info
)
}
else
{
fmt
.
Println
(
"sendCBTx failed"
)
}
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
/*
/*
info2 := dposClient.csState.GetCBInfoByCircle(task.Cycle)
info2 := dposClient.csState.GetCBInfoByCircle(task.Cycle)
...
@@ -136,14 +168,17 @@ func DposPerf() {
...
@@ -136,14 +168,17 @@ func DposPerf() {
vrfM
:=
&
dty
.
DposVrfMRegist
{
vrfM
:=
&
dty
.
DposVrfMRegist
{
Pubkey
:
strPubkey
,
Pubkey
:
strPubkey
,
Cycle
:
task
.
Cycle
,
Cycle
:
task
.
Cycle
,
M
:
"
absadfafa
"
,
M
:
"
data1
"
,
}
}
if
dposClient
.
csState
.
SendRegistVrfMTx
(
vrfM
)
{
if
dposClient
.
csState
.
SendRegistVrfMTx
(
vrfM
)
{
fmt
.
Println
(
"SendRegistVrfMTx ok"
)
fmt
.
Println
(
"SendRegistVrfMTx ok"
)
}
else
{
}
else
{
fmt
.
Println
(
"SendRegistVrfMTx failed"
)
fmt
.
Println
(
"SendRegistVrfMTx failed"
)
}
}
sendRegistVrfMTx
(
dposClient
.
csState
,
vrfM
)
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
vrfInfo
,
err
:=
dposClient
.
csState
.
QueryVrf
(
pubkey
,
task
.
Cycle
)
vrfInfo
,
err
:=
dposClient
.
csState
.
QueryVrf
(
pubkey
,
task
.
Cycle
)
if
err
!=
nil
||
vrfInfo
==
nil
{
if
err
!=
nil
||
vrfInfo
==
nil
{
fmt
.
Println
(
"QueryVrf failed"
)
fmt
.
Println
(
"QueryVrf failed"
)
...
@@ -162,15 +197,19 @@ func DposPerf() {
...
@@ -162,15 +197,19 @@ func DposPerf() {
vrfRP
:=
&
dty
.
DposVrfRPRegist
{
vrfRP
:=
&
dty
.
DposVrfRPRegist
{
Pubkey
:
strPubkey
,
Pubkey
:
strPubkey
,
Cycle
:
task
.
Cycle
,
Cycle
:
task
.
Cycle
,
R
:
"
Rabsadfafa
"
,
R
:
"
22a58fbbe8002939b7818184e663e6c57447f4354adba31ad3c7f556e153353c
"
,
P
:
"
Pabsadfafa
"
,
P
:
"
5ed22d8c1cc0ad131c1c9f82daec7b99ff25ae5e717624b4a8cf60e0f3dca2c97096680cd8df0d9ed8662ce6513edf5d1676ad8d72b7e4f0e0de687bd38623f404eb085d28f5631207cf97a02c55f835bd3733241c7e068b80cf75e2afd12fd4c4cb8e6f630afa2b7b2918dff3d279e50acab59da1b25b3ff920b69c443da67320
"
,
}
}
if
dposClient
.
csState
.
SendRegistVrfRPTx
(
vrfRP
)
{
if
dposClient
.
csState
.
SendRegistVrfRPTx
(
vrfRP
)
{
fmt
.
Println
(
"SendRegistVrfRPTx ok"
)
fmt
.
Println
(
"SendRegistVrfRPTx ok"
)
}
else
{
}
else
{
fmt
.
Println
(
"SendRegistVrfRPTx failed"
)
fmt
.
Println
(
"SendRegistVrfRPTx failed"
)
}
}
sendRegistVrfRPTx
(
dposClient
.
csState
,
vrfRP
)
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
vrfInfo
,
err
=
dposClient
.
csState
.
QueryVrf
(
pubkey
,
task
.
Cycle
)
vrfInfo
,
err
=
dposClient
.
csState
.
QueryVrf
(
pubkey
,
task
.
Cycle
)
if
err
!=
nil
||
vrfInfo
==
nil
{
if
err
!=
nil
||
vrfInfo
==
nil
{
fmt
.
Println
(
"QueryVrf failed"
)
fmt
.
Println
(
"QueryVrf failed"
)
...
@@ -203,8 +242,12 @@ func DposPerf() {
...
@@ -203,8 +242,12 @@ func DposPerf() {
}
else
{
}
else
{
fmt
.
Println
(
"SendTopNRegistTx failed"
)
fmt
.
Println
(
"SendTopNRegistTx failed"
)
}
}
sendTopNRegistTx
(
dposClient
.
csState
,
reg
)
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
dposClient
.
QueryTopNCandidators
(
dposClient
.
GetCurrentHeight
()
/
blockNumToUpdateDelegate
)
dposClient
.
QueryTopNCandidators
(
dposClient
.
GetCurrentHeight
()
/
blockNumToUpdateDelegate
)
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
}
}
...
@@ -321,3 +364,254 @@ func NormPut() {
...
@@ -321,3 +364,254 @@ func NormPut() {
return
return
}
}
}
}
// SendCBTx method
func
sendCBTx
(
cs
*
ConsensusState
,
info
*
dty
.
DposCBInfo
)
bool
{
//info.Pubkey = strings.ToUpper(hex.EncodeToString(cs.privValidator.GetPubKey().Bytes()))
canonical
:=
dty
.
CanonicalOnceCBInfo
{
Cycle
:
info
.
Cycle
,
StopHeight
:
info
.
StopHeight
,
StopHash
:
info
.
StopHash
,
Pubkey
:
info
.
Pubkey
,
}
byteCB
,
err
:=
json
.
Marshal
(
&
canonical
)
if
err
!=
nil
{
dposlog
.
Error
(
"marshal CanonicalOnceCBInfo failed"
,
"err"
,
err
)
}
sig
,
err
:=
cs
.
privValidator
.
SignMsg
(
byteCB
)
if
err
!=
nil
{
dposlog
.
Error
(
"SignCBInfo failed."
,
"err"
,
err
)
return
false
}
info
.
Signature
=
hex
.
EncodeToString
(
sig
.
Bytes
())
tx
,
err
:=
cs
.
client
.
CreateRecordCBTx
(
info
)
if
err
!=
nil
{
dposlog
.
Error
(
"CreateRecordCBTx failed."
,
"err"
,
err
)
return
false
}
tx
.
Fee
=
fee
cs
.
privValidator
.
SignTx
(
tx
)
dposlog
.
Info
(
"Sign RecordCBTx ok."
)
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
false
}
if
!
reply
.
IsOk
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
New
(
string
(
reply
.
GetMsg
())))
return
false
}
return
true
}
func
sendRegistVrfMTx
(
cs
*
ConsensusState
,
info
*
dty
.
DposVrfMRegist
)
bool
{
tx
,
err
:=
cs
.
client
.
CreateRegVrfMTx
(
info
)
if
err
!=
nil
{
dposlog
.
Error
(
"CreateRegVrfMTx failed."
,
"err"
,
err
)
return
false
}
tx
.
Fee
=
fee
cs
.
privValidator
.
SignTx
(
tx
)
dposlog
.
Info
(
"Sign RegistVrfMTx ok."
)
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
false
}
if
!
reply
.
IsOk
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
New
(
string
(
reply
.
GetMsg
())))
return
false
}
return
true
}
// SendRegistVrfRPTx method
func
sendRegistVrfRPTx
(
cs
*
ConsensusState
,
info
*
dty
.
DposVrfRPRegist
)
bool
{
tx
,
err
:=
cs
.
client
.
CreateRegVrfRPTx
(
info
)
if
err
!=
nil
{
dposlog
.
Error
(
"CreateRegVrfRPTx failed."
,
"err"
,
err
)
return
false
}
tx
.
Fee
=
fee
cs
.
privValidator
.
SignTx
(
tx
)
dposlog
.
Info
(
"Sign RegVrfRPTx ok."
)
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
false
}
if
!
reply
.
IsOk
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
New
(
string
(
reply
.
GetMsg
())))
return
false
}
return
true
}
func
sendTopNRegistTx
(
cs
*
ConsensusState
,
reg
*
dty
.
TopNCandidatorRegist
)
bool
{
//info.Pubkey = strings.ToUpper(hex.EncodeToString(cs.privValidator.GetPubKey().Bytes()))
obj
:=
dty
.
CanonicalTopNCandidator
(
reg
.
Cand
)
reg
.
Cand
.
Hash
=
obj
.
ID
()
reg
.
Cand
.
SignerPubkey
=
cs
.
privValidator
.
GetPubKey
()
.
Bytes
()
byteCB
,
err
:=
json
.
Marshal
(
reg
.
Cand
)
if
err
!=
nil
{
dposlog
.
Error
(
"marshal TopNCandidator failed"
,
"err"
,
err
)
}
sig
,
err
:=
cs
.
privValidator
.
SignMsg
(
byteCB
)
if
err
!=
nil
{
dposlog
.
Error
(
"TopNCandidator failed."
,
"err"
,
err
)
return
false
}
reg
.
Cand
.
Signature
=
sig
.
Bytes
()
tx
,
err
:=
cs
.
client
.
CreateTopNRegistTx
(
reg
)
if
err
!=
nil
{
dposlog
.
Error
(
"CreateTopNRegistTx failed."
,
"err"
,
err
)
return
false
}
tx
.
Fee
=
fee
cs
.
privValidator
.
SignTx
(
tx
)
dposlog
.
Info
(
"Sign TopNRegistTx ok."
)
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
false
}
if
!
reply
.
IsOk
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
New
(
string
(
reply
.
GetMsg
())))
return
false
}
return
true
}
func
sendTransferTx
(
fromKey
,
to
string
,
amount
int64
)
bool
{
signer
:=
util
.
HexToPrivkey
(
fromKey
)
var
tx
*
types
.
Transaction
transfer
:=
&
cty
.
CoinsAction
{}
v
:=
&
cty
.
CoinsAction_Transfer
{
Transfer
:
&
types
.
AssetsTransfer
{
Amount
:
amount
,
Note
:
[]
byte
(
""
),
To
:
to
}}
transfer
.
Value
=
v
transfer
.
Ty
=
cty
.
CoinsActionTransfer
execer
:=
[]
byte
(
"coins"
)
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
transfer
),
To
:
to
,
Fee
:
fee
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
if
err
!=
nil
{
fmt
.
Println
(
"in sendTransferTx formatTx failed"
)
return
false
}
tx
.
Sign
(
types
.
SECP256K1
,
signer
)
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
fmt
.
Println
(
"in sendTransferTx SendTransaction failed"
)
return
false
}
if
!
reply
.
IsOk
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
New
(
string
(
reply
.
GetMsg
())))
fmt
.
Println
(
"in sendTransferTx SendTransaction failed,reply not ok."
)
return
false
}
fmt
.
Println
(
"sendTransferTx ok"
)
return
true
}
func
sendTransferToExecTx
(
fromKey
,
execName
string
,
amount
int64
)
bool
{
signer
:=
util
.
HexToPrivkey
(
fromKey
)
var
tx
*
types
.
Transaction
transfer
:=
&
cty
.
CoinsAction
{}
execAddr
:=
address
.
ExecAddress
(
execName
)
v
:=
&
cty
.
CoinsAction_TransferToExec
{
TransferToExec
:
&
types
.
AssetsTransferToExec
{
Amount
:
amount
,
Note
:
[]
byte
(
""
),
ExecName
:
execName
,
To
:
execAddr
}}
transfer
.
Value
=
v
transfer
.
Ty
=
cty
.
CoinsActionTransferToExec
execer
:=
[]
byte
(
"coins"
)
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
transfer
),
To
:
address
.
ExecAddress
(
"dpos"
),
Fee
:
fee
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
if
err
!=
nil
{
fmt
.
Println
(
"sendTransferToExecTx formatTx failed."
)
return
false
}
tx
.
Sign
(
types
.
SECP256K1
,
signer
)
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
fmt
.
Println
(
"in sendTransferToExecTx SendTransaction failed"
)
return
false
}
if
!
reply
.
IsOk
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
New
(
string
(
reply
.
GetMsg
())))
fmt
.
Println
(
"in sendTransferToExecTx SendTransaction failed,reply not ok."
)
return
false
}
fmt
.
Println
(
"sendTransferToExecTx ok"
)
return
true
}
func
sendRegistCandidatorTx
(
ppubkey
,
addr
,
ip
,
privKey
string
)
bool
{
signer
:=
util
.
HexToPrivkey
(
privKey
)
var
tx
*
types
.
Transaction
action
:=
&
dty
.
DposVoteAction
{}
v
:=
&
dty
.
DposVoteAction_Regist
{
Regist
:
&
dty
.
DposCandidatorRegist
{
Pubkey
:
ppubkey
,
Address
:
addr
,
IP
:
ip
,
},
}
action
.
Value
=
v
action
.
Ty
=
dty
.
DposVoteActionRegist
execer
:=
[]
byte
(
"dpos"
)
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
if
err
!=
nil
{
fmt
.
Println
(
"sendRegistCandidatorTx formatTx failed."
)
return
false
}
tx
.
Sign
(
types
.
SECP256K1
,
signer
)
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
fmt
.
Println
(
"in sendRegistCandidatorTx SendTransaction failed"
)
return
false
}
if
!
reply
.
IsOk
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
New
(
string
(
reply
.
GetMsg
())))
fmt
.
Println
(
"in sendTransferToExecTx SendTransaction failed,reply not ok."
)
return
false
}
fmt
.
Println
(
"sendRegistCandidatorTx ok"
)
return
true
}
plugin/dapp/dposvote/executor/dposvotedb.go
View file @
8c77ec6d
...
@@ -503,14 +503,14 @@ func (action *Action) readCandicatorInfo(pubkey []byte) (*dty.CandidatorInfo, er
...
@@ -503,14 +503,14 @@ func (action *Action) readCandicatorInfo(pubkey []byte) (*dty.CandidatorInfo, er
strPubkey
:=
hex
.
EncodeToString
(
pubkey
)
strPubkey
:=
hex
.
EncodeToString
(
pubkey
)
data
,
err
:=
action
.
db
.
Get
(
Key
(
strPubkey
))
data
,
err
:=
action
.
db
.
Get
(
Key
(
strPubkey
))
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Error
(
"readCandicator have err:"
,
err
.
Error
())
logger
.
Error
(
"readCandicator have err:"
,
"err"
,
err
.
Error
())
return
nil
,
err
return
nil
,
err
}
}
var
cand
dty
.
CandidatorInfo
var
cand
dty
.
CandidatorInfo
//decode
//decode
err
=
types
.
Decode
(
data
,
&
cand
)
err
=
types
.
Decode
(
data
,
&
cand
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Error
(
"decode candicator have err:"
,
err
.
Error
())
logger
.
Error
(
"decode candicator have err:"
,
"err"
,
err
.
Error
())
return
nil
,
err
return
nil
,
err
}
}
return
&
cand
,
nil
return
&
cand
,
nil
...
...
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