Commit b2638e9d authored by kingwang's avatar kingwang

fix bug amount

parent 78fbea97
...@@ -19,7 +19,7 @@ func (chain *BlockChain) ProcRecvMsg() { ...@@ -19,7 +19,7 @@ func (chain *BlockChain) ProcRecvMsg() {
defer chain.recvwg.Done() defer chain.recvwg.Done()
reqnum := make(chan struct{}, 1000) reqnum := make(chan struct{}, 1000)
for msg := range chain.client.Recv() { for msg := range chain.client.Recv() {
chainlog.Debug("blockchain recv", "msg", types.GetEventName(int(msg.Ty)), "id", msg.Id, "cap", len(reqnum)) chainlog.Debug("blockchain recv", "msg", types.GetEventName(int(msg.Ty)), "id", msg.ID, "cap", len(reqnum))
msgtype := msg.Ty msgtype := msg.Ty
reqnum <- struct{}{} reqnum <- struct{}{}
atomic.AddInt32(&chain.runcount, 1) atomic.AddInt32(&chain.runcount, 1)
......
...@@ -9,7 +9,7 @@ package strategy ...@@ -9,7 +9,7 @@ package strategy
//const //const
const ( const (
// 創建main.go的文件模板 // 創建main.go的文件模板
CPFT_MAIN_GO = `package main CpftMainGo = `package main
import ( import (
_ "github.com/33cn/chain33/system" _ "github.com/33cn/chain33/system"
...@@ -26,7 +26,7 @@ func main() { ...@@ -26,7 +26,7 @@ func main() {
` `
// 生成的配置文件模板 xxx.toml // 生成的配置文件模板 xxx.toml
CPFT_CFG_TOML = ` CpftCfgToml = `
Title="${PROJECTNAME}" Title="${PROJECTNAME}"
FixTime=false FixTime=false
...@@ -102,14 +102,14 @@ enableMVCC=false ...@@ -102,14 +102,14 @@ enableMVCC=false
saveTokenTxList=false saveTokenTxList=false
` `
CPFT_RUNMAIN_BLOCK = `package main CpftRunmainBlock = `package main
var ${PROJECTNAME} = ` var ${PROJECTNAME} = `
// 生成项目运行主程序的模板 xxx.go // 生成项目运行主程序的模板 xxx.go
// 顶部还需要加上package main // 顶部还需要加上package main
//var bityuan = `CPFT_RUNMAIN` //var bityuan = `CPFT_RUNMAIN`
CPFT_RUNMAIN = `TestNet=false CpftRunMain = `TestNet=false
[blockchain] [blockchain]
defCacheSize=128 defCacheSize=128
maxFetchBlockNum=128 maxFetchBlockNum=128
...@@ -248,7 +248,7 @@ ForkTradeAsset= -1 ...@@ -248,7 +248,7 @@ ForkTradeAsset= -1
` `
// 生成项目Makefile文件的模板 Makefile // 生成项目Makefile文件的模板 Makefile
CPFT_MAKEFILE = ` CpftMakefile = `
CHAIN33=github.com/33cn/chain33 CHAIN33=github.com/33cn/chain33
CHAIN33_PATH=vendor/${CHAIN33} CHAIN33_PATH=vendor/${CHAIN33}
all: vendor proto build all: vendor proto build
...@@ -297,7 +297,7 @@ clean: ...@@ -297,7 +297,7 @@ clean:
` `
// 生成 .travis.yml 文件模板 // 生成 .travis.yml 文件模板
CPFT_TRAVIS_YML = ` CpftTravisYml = `
language: go language: go
go: go:
...@@ -306,7 +306,7 @@ go: ...@@ -306,7 +306,7 @@ go:
` `
// 生成 plugin/plugin.toml的文件模板 // 生成 plugin/plugin.toml的文件模板
CPFT_PLUGIN_TOML = ` CpftPluginToml = `
# type字段仅支持 consensus dapp store # type字段仅支持 consensus dapp store
[dapp-ticket] [dapp-ticket]
gitrepo = "github.com/33cn/plugin/plugin/dapp/ticket" gitrepo = "github.com/33cn/plugin/plugin/dapp/ticket"
...@@ -327,7 +327,7 @@ gitrepo = "github.com/33cn/plugin/plugin/dapp/token" ...@@ -327,7 +327,7 @@ gitrepo = "github.com/33cn/plugin/plugin/dapp/token"
gitrepo = "github.com/33cn/plugin/plugin/dapp/trade" gitrepo = "github.com/33cn/plugin/plugin/dapp/trade"
` `
// 项目 cli/main.go 文件模板 // 项目 cli/main.go 文件模板
CPFT_CLI_MAIN = `package main CpftCliMain = `package main
import ( import (
_ "${PROJECTPATH}/plugin" _ "${PROJECTPATH}/plugin"
...@@ -340,7 +340,7 @@ func main() { ...@@ -340,7 +340,7 @@ func main() {
} }
` `
// plugin/dapp/xxxx/commands/cmd.go文件的模板c // plugin/dapp/xxxx/commands/cmd.go文件的模板c
CPFT_DAPP_COMMANDS = `package commands CpftDappCommands = `package commands
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -351,7 +351,7 @@ func Cmd() *cobra.Command { ...@@ -351,7 +351,7 @@ func Cmd() *cobra.Command {
}` }`
// plugin/dapp/xxxx/plugin.go文件的模板 // plugin/dapp/xxxx/plugin.go文件的模板
CPFT_DAPP_PLUGIN = `package ${PROJECTNAME} CpftDappPlugin = `package ${PROJECTNAME}
import ( import (
"github.com/33cn/chain33/pluginmgr" "github.com/33cn/chain33/pluginmgr"
...@@ -372,7 +372,7 @@ func init() { ...@@ -372,7 +372,7 @@ func init() {
` `
// plugin/dapp/xxxx/executor/xxxx.go文件模板 // plugin/dapp/xxxx/executor/xxxx.go文件模板
CPFT_DAPP_EXEC = `package executor CpftDappExec = `package executor
import ( import (
log "github.com/inconshreveable/log15" log "github.com/inconshreveable/log15"
...@@ -425,17 +425,17 @@ func (this *${CLASSNAME}) CheckTx(tx *types.Transaction, index int) error { ...@@ -425,17 +425,17 @@ func (this *${CLASSNAME}) CheckTx(tx *types.Transaction, index int) error {
} }
` `
// plugin/dapp/xxxx/proto/create_protobuf.sh文件模板 // plugin/dapp/xxxx/proto/create_protobuf.sh文件模板
CPFT_DAPP_CREATEPB = `#!/bin/sh CpftDappCreatepb = `#!/bin/sh
protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=. protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=.
` `
// plugin/dapp/xxxx/proto/Makefile 文件模板 // plugin/dapp/xxxx/proto/Makefile 文件模板
CPFT_DAPP_MAKEFILE = `all: CpftDappMakefile = `all:
sh ./create_protobuf.sh sh ./create_protobuf.sh
` `
// plugin/dapp/xxxx/proto/xxxx.proto的文件模板 // plugin/dapp/xxxx/proto/xxxx.proto的文件模板
CPFT_DAPP_PROTO = `syntax = "proto3"; CpftDappProto = `syntax = "proto3";
package types; package types;
message ${ACTIONNAME} { message ${ACTIONNAME} {
...@@ -450,7 +450,7 @@ message ${ACTIONNAME}None { ...@@ -450,7 +450,7 @@ message ${ACTIONNAME}None {
` `
// plugin/dapp/xxxx/types/types.go的文件模板cd // plugin/dapp/xxxx/types/types.go的文件模板cd
CPFT_DAPP_TYPEFILE = `package types CpftDappTypefile = `package types
import ( import (
"gitlab.33.cn/chain33/chain33/types" "gitlab.33.cn/chain33/chain33/types"
......
...@@ -78,7 +78,7 @@ func (c *createPluginStrategy) buildTask() []tasks.Task { ...@@ -78,7 +78,7 @@ func (c *createPluginStrategy) buildTask() []tasks.Task {
taskSlice := make([]tasks.Task, 0) taskSlice := make([]tasks.Task, 0)
taskSlice = append(taskSlice, taskSlice = append(taskSlice,
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_MAIN_GO, SourceStr: CpftMainGo,
OutputFile: fmt.Sprintf("%s/main.go", c.projectPath), OutputFile: fmt.Sprintf("%s/main.go", c.projectPath),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
...@@ -86,15 +86,15 @@ func (c *createPluginStrategy) buildTask() []tasks.Task { ...@@ -86,15 +86,15 @@ func (c *createPluginStrategy) buildTask() []tasks.Task {
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_CFG_TOML, SourceStr: CpftCfgToml,
OutputFile: fmt.Sprintf("%s/%s.toml", c.projectPath, c.projName), OutputFile: fmt.Sprintf("%s/%s.toml", c.projectPath, c.projName),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_RUNMAIN, SourceStr: CpftRunMain,
BlockStrBegin: CPFT_RUNMAIN_BLOCK + "`", BlockStrBegin: CpftRunmainBlock + "`",
BlockStrEnd: "`", BlockStrEnd: "`",
OutputFile: fmt.Sprintf("%s/%s.go", c.projectPath, c.projName), OutputFile: fmt.Sprintf("%s/%s.go", c.projectPath, c.projName),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
...@@ -102,7 +102,7 @@ func (c *createPluginStrategy) buildTask() []tasks.Task { ...@@ -102,7 +102,7 @@ func (c *createPluginStrategy) buildTask() []tasks.Task {
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_MAKEFILE, SourceStr: CpftMakefile,
OutputFile: fmt.Sprintf("%s/Makefile", c.projectPath), OutputFile: fmt.Sprintf("%s/Makefile", c.projectPath),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
...@@ -112,21 +112,21 @@ func (c *createPluginStrategy) buildTask() []tasks.Task { ...@@ -112,21 +112,21 @@ func (c *createPluginStrategy) buildTask() []tasks.Task {
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_TRAVIS_YML, SourceStr: CpftTravisYml,
OutputFile: fmt.Sprintf("%s/.travis.yml", c.projectPath), OutputFile: fmt.Sprintf("%s/.travis.yml", c.projectPath),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_PLUGIN_TOML, SourceStr: CpftPluginToml,
OutputFile: fmt.Sprintf("%s/plugin/plugin.toml", c.projectPath), OutputFile: fmt.Sprintf("%s/plugin/plugin.toml", c.projectPath),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_CLI_MAIN, SourceStr: CpftCliMain,
OutputFile: fmt.Sprintf("%s/cli/main.go", c.projectPath), OutputFile: fmt.Sprintf("%s/cli/main.go", c.projectPath),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
...@@ -134,14 +134,14 @@ func (c *createPluginStrategy) buildTask() []tasks.Task { ...@@ -134,14 +134,14 @@ func (c *createPluginStrategy) buildTask() []tasks.Task {
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_DAPP_COMMANDS, SourceStr: CpftDappCommands,
OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/commands/cmd.go", c.projectPath, c.execName), OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/commands/cmd.go", c.projectPath, c.execName),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_DAPP_PLUGIN, SourceStr: CpftDappPlugin,
OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/plugin.go", c.projectPath, c.projName), OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/plugin.go", c.projectPath, c.projName),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
...@@ -150,7 +150,7 @@ func (c *createPluginStrategy) buildTask() []tasks.Task { ...@@ -150,7 +150,7 @@ func (c *createPluginStrategy) buildTask() []tasks.Task {
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_DAPP_EXEC, SourceStr: CpftDappExec,
OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/executor/%s.go", c.projectPath, c.projName, c.execName), OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/executor/%s.go", c.projectPath, c.projName, c.execName),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagProjectName: c.projName, types.TagProjectName: c.projName,
...@@ -159,24 +159,24 @@ func (c *createPluginStrategy) buildTask() []tasks.Task { ...@@ -159,24 +159,24 @@ func (c *createPluginStrategy) buildTask() []tasks.Task {
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_DAPP_CREATEPB, SourceStr: CpftDappCreatepb,
OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/proto/create_protobuf.sh", c.projectPath, c.projName), OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/proto/create_protobuf.sh", c.projectPath, c.projName),
ReplaceKeyPairs: map[string]string{}, ReplaceKeyPairs: map[string]string{},
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_DAPP_MAKEFILE, SourceStr: CpftDappMakefile,
OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/proto/Makefile", c.projectPath, c.projName), OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/proto/Makefile", c.projectPath, c.projName),
ReplaceKeyPairs: map[string]string{}, ReplaceKeyPairs: map[string]string{},
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_DAPP_PROTO, SourceStr: CpftDappProto,
OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/proto/%s.proto", c.projectPath, c.projName, c.execName), OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/proto/%s.proto", c.projectPath, c.projName, c.execName),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagActionName: c.classActionName, types.TagActionName: c.classActionName,
}, },
}, },
&tasks.CreateFileFromStrTemplateTask{ &tasks.CreateFileFromStrTemplateTask{
SourceStr: CPFT_DAPP_TYPEFILE, SourceStr: CpftDappTypefile,
OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/types/types.go", c.projectPath, c.projName), OutputFile: fmt.Sprintf("%s/plugin/dapp/%s/types/types.go", c.projectPath, c.projName),
ReplaceKeyPairs: map[string]string{ ReplaceKeyPairs: map[string]string{
types.TagExecNameFB: c.execNameFB, types.TagExecNameFB: c.execNameFB,
......
...@@ -21,7 +21,7 @@ const ( ...@@ -21,7 +21,7 @@ const (
KeyUpdateInit = "update_init" KeyUpdateInit = "update_init"
KeyCreatePlugin = "create_plugin" KeyCreatePlugin = "create_plugin"
DEF_CPM_CONFIGFILE = "chain33.cpm.toml" DefCpmConfigfile = "chain33.cpm.toml"
TagGoPath = "${GOPATH}" TagGoPath = "${GOPATH}"
TagProjectName = "${PROJECTNAME}" // 项目名称替换标签 TagProjectName = "${PROJECTNAME}" // 项目名称替换标签
......
...@@ -11,11 +11,12 @@ chain33 是由复杂美科技有限公司开发的区块链链框架 ...@@ -11,11 +11,12 @@ chain33 是由复杂美科技有限公司开发的区块链链框架
3. 创新的 合约 调用和组合方式 3. 创新的 合约 调用和组合方式
*/ */
package chain33 package chain33
//有些包国内需要翻墙才能下载,我们把部分参见的包含在这里 //有些包国内需要翻墙才能下载,我们把部分参见的包含在这里
import ( import (
_ "golang.org/x/crypto/nacl/box" _ "golang.org/x/crypto/nacl/box" //register box package
_ "golang.org/x/crypto/nacl/secretbox" _ "golang.org/x/crypto/nacl/secretbox"
_ "golang.org/x/crypto/ssh" _ "golang.org/x/crypto/ssh"
) )
...@@ -16,6 +16,7 @@ function filterLinter() { ...@@ -16,6 +16,7 @@ function filterLinter() {
--enable=structcheck \ --enable=structcheck \
--enable=goimports \ --enable=goimports \
--enable=misspell \ --enable=misspell \
--enable=golint \
--vendor ./...) --vendor ./...)
# --enable=staticcheck \ # --enable=staticcheck \
# --enable=gocyclo \ # --enable=gocyclo \
......
...@@ -600,7 +600,7 @@ func (mem *Mempool) SetQueueClient(client queue.Client) { ...@@ -600,7 +600,7 @@ func (mem *Mempool) SetQueueClient(client queue.Client) {
defer mlog.Info("mempool message recv quit") defer mlog.Info("mempool message recv quit")
defer mem.wg.Done() defer mem.wg.Done()
for msg := range mem.client.Recv() { for msg := range mem.client.Recv() {
mlog.Debug("mempool recv", "msgid", msg.Id, "msg", types.GetEventName(int(msg.Ty))) mlog.Debug("mempool recv", "msgid", msg.ID, "msg", types.GetEventName(int(msg.Ty)))
beg := types.Now() beg := types.Now()
switch msg.Ty { switch msg.Ty {
case types.EventTx: case types.EventTx:
......
...@@ -16,31 +16,31 @@ import ( ...@@ -16,31 +16,31 @@ import (
func TestStep(t *testing.T) { func TestStep(t *testing.T) {
done := make(chan struct{}) done := make(chan struct{})
in := make(chan queue.Message) in := make(chan queue.Message)
msg := queue.Message{Id: 0} msg := queue.Message{ID: 0}
cb := func(in queue.Message) queue.Message { cb := func(in queue.Message) queue.Message {
in.Id++ in.ID++
time.Sleep(time.Microsecond) time.Sleep(time.Microsecond)
return in return in
} }
out := step(done, in, cb) out := step(done, in, cb)
in <- msg in <- msg
msg2 := <-out msg2 := <-out
assert.Equal(t, msg2.Id, int64(1)) assert.Equal(t, msg2.ID, int64(1))
close(done) close(done)
} }
func TestMutiStep(t *testing.T) { func TestMutiStep(t *testing.T) {
done := make(chan struct{}) done := make(chan struct{})
in := make(chan queue.Message) in := make(chan queue.Message)
msg := queue.Message{Id: 0} msg := queue.Message{ID: 0}
step1 := func(in queue.Message) queue.Message { step1 := func(in queue.Message) queue.Message {
in.Id++ in.ID++
time.Sleep(time.Microsecond) time.Sleep(time.Microsecond)
return in return in
} }
out1 := step(done, in, step1) out1 := step(done, in, step1)
step2 := func(in queue.Message) queue.Message { step2 := func(in queue.Message) queue.Message {
in.Id++ in.ID++
time.Sleep(time.Microsecond) time.Sleep(time.Microsecond)
return in return in
} }
...@@ -50,16 +50,16 @@ func TestMutiStep(t *testing.T) { ...@@ -50,16 +50,16 @@ func TestMutiStep(t *testing.T) {
out3 := mergeList(done, out21, out22) out3 := mergeList(done, out21, out22)
in <- msg in <- msg
msg2 := <-out3 msg2 := <-out3
assert.Equal(t, msg2.Id, int64(2)) assert.Equal(t, msg2.ID, int64(2))
close(done) close(done)
} }
func BenchmarkStep(b *testing.B) { func BenchmarkStep(b *testing.B) {
done := make(chan struct{}) done := make(chan struct{})
in := make(chan queue.Message) in := make(chan queue.Message)
msg := queue.Message{Id: 0} msg := queue.Message{ID: 0}
cb := func(in queue.Message) queue.Message { cb := func(in queue.Message) queue.Message {
in.Id++ in.ID++
time.Sleep(100 * time.Microsecond) time.Sleep(100 * time.Microsecond)
return in return in
} }
...@@ -71,7 +71,7 @@ func BenchmarkStep(b *testing.B) { ...@@ -71,7 +71,7 @@ func BenchmarkStep(b *testing.B) {
}() }()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
msg2 := <-out msg2 := <-out
assert.Equal(b, msg2.Id, int64(1)) assert.Equal(b, msg2.ID, int64(1))
} }
close(done) close(done)
} }
...@@ -79,9 +79,9 @@ func BenchmarkStep(b *testing.B) { ...@@ -79,9 +79,9 @@ func BenchmarkStep(b *testing.B) {
func BenchmarkStepMerge(b *testing.B) { func BenchmarkStepMerge(b *testing.B) {
done := make(chan struct{}) done := make(chan struct{})
in := make(chan queue.Message) in := make(chan queue.Message)
msg := queue.Message{Id: 0} msg := queue.Message{ID: 0}
cb := func(in queue.Message) queue.Message { cb := func(in queue.Message) queue.Message {
in.Id++ in.ID++
time.Sleep(100 * time.Microsecond) time.Sleep(100 * time.Microsecond)
return in return in
} }
...@@ -97,7 +97,7 @@ func BenchmarkStepMerge(b *testing.B) { ...@@ -97,7 +97,7 @@ func BenchmarkStepMerge(b *testing.B) {
}() }()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
msg2 := <-out msg2 := <-out
assert.Equal(b, msg2.Id, int64(1)) assert.Equal(b, msg2.ID, int64(1))
} }
close(done) close(done)
} }
...@@ -39,7 +39,7 @@ func (l *listener) Close() { ...@@ -39,7 +39,7 @@ func (l *listener) Close() {
type listener struct { type listener struct {
server *grpc.Server server *grpc.Server
nodeInfo *NodeInfo nodeInfo *NodeInfo
p2pserver *P2pServer p2pserver *P2pserver
node *Node node *Node
netlistener net.Listener netlistener net.Listener
} }
......
...@@ -219,15 +219,17 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int { ...@@ -219,15 +219,17 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int {
return Teredo return Teredo
} else if o.IP.To4() != nil { } else if o.IP.To4() != nil {
return Ipv4 return Ipv4
} else { // ipv6
return Ipv6Weak
} }
// ipv6
return Ipv6Weak
} else if na.IP.To4() != nil { } else if na.IP.To4() != nil {
if o.Routable() && o.IP.To4() != nil { if o.Routable() && o.IP.To4() != nil {
return Ipv4 return Ipv4
} }
return Default return Default
} else /* ipv6 */ { }
/* ipv6 */
var tunnelled bool var tunnelled bool
// Is our v6 is tunnelled? // Is our v6 is tunnelled?
if o.RFC3964() || o.RFC6052() || o.RFC6145() { if o.RFC3964() || o.RFC6052() || o.RFC6145() {
...@@ -244,7 +246,6 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int { ...@@ -244,7 +246,6 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int {
return Ipv6Weak return Ipv6Weak
} }
return Ipv6Strong return Ipv6Strong
}
} }
// RFC1918: IPv4 Private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12) // RFC1918: IPv4 Private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
......
...@@ -20,8 +20,8 @@ import ( ...@@ -20,8 +20,8 @@ import (
pr "google.golang.org/grpc/peer" pr "google.golang.org/grpc/peer"
) )
// P2pServer object information // P2pserver object information
type P2pServer struct { type P2pserver struct {
imtx sync.Mutex //for inboundpeers imtx sync.Mutex //for inboundpeers
smtx sync.Mutex smtx sync.Mutex
node *Node node *Node
...@@ -39,23 +39,23 @@ type innerpeer struct { ...@@ -39,23 +39,23 @@ type innerpeer struct {
} }
// Start p2pserver start // Start p2pserver start
func (s *P2pServer) Start() { func (s *P2pserver) Start() {
s.manageStream() s.manageStream()
} }
// Close p2pserver close // Close p2pserver close
func (s *P2pServer) Close() { func (s *P2pserver) Close() {
atomic.StoreInt32(&s.closed, 1) atomic.StoreInt32(&s.closed, 1)
} }
// IsClose is p2pserver running // IsClose is p2pserver running
func (s *P2pServer) IsClose() bool { func (s *P2pserver) IsClose() bool {
return atomic.LoadInt32(&s.closed) == 1 return atomic.LoadInt32(&s.closed) == 1
} }
// NewP2pServer produce a p2pserver // NewP2pServer produce a p2pserver
func NewP2pServer() *P2pServer { func NewP2pServer() *P2pserver {
return &P2pServer{ return &P2pserver{
streams: make(map[pb.P2Pgservice_ServerStreamSendServer]chan interface{}), streams: make(map[pb.P2Pgservice_ServerStreamSendServer]chan interface{}),
deleteSChan: make(chan pb.P2Pgservice_ServerStreamSendServer, 1024), deleteSChan: make(chan pb.P2Pgservice_ServerStreamSendServer, 1024),
inboundpeers: make(map[string]*innerpeer), inboundpeers: make(map[string]*innerpeer),
...@@ -64,7 +64,7 @@ func NewP2pServer() *P2pServer { ...@@ -64,7 +64,7 @@ func NewP2pServer() *P2pServer {
} }
// Ping p2pserver ping // Ping p2pserver ping
func (s *P2pServer) Ping(ctx context.Context, in *pb.P2PPing) (*pb.P2PPong, error) { func (s *P2pserver) Ping(ctx context.Context, in *pb.P2PPing) (*pb.P2PPong, error) {
log.Debug("ping") log.Debug("ping")
if !P2pComm.CheckSign(in) { if !P2pComm.CheckSign(in) {
log.Error("Ping", "p2p server", "check sig err") log.Error("Ping", "p2p server", "check sig err")
...@@ -95,7 +95,7 @@ func (s *P2pServer) Ping(ctx context.Context, in *pb.P2PPing) (*pb.P2PPong, erro ...@@ -95,7 +95,7 @@ func (s *P2pServer) Ping(ctx context.Context, in *pb.P2PPing) (*pb.P2PPong, erro
} }
// GetAddr get address // GetAddr get address
func (s *P2pServer) GetAddr(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddr, error) { func (s *P2pserver) GetAddr(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddr, error) {
log.Debug("GETADDR", "RECV ADDR", in, "OutBound Len", s.node.Size()) log.Debug("GETADDR", "RECV ADDR", in, "OutBound Len", s.node.Size())
var addrlist []string var addrlist []string
peers, _ := s.node.GetActivePeers() peers, _ := s.node.GetActivePeers()
...@@ -107,7 +107,7 @@ func (s *P2pServer) GetAddr(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddr ...@@ -107,7 +107,7 @@ func (s *P2pServer) GetAddr(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddr
} }
// GetAddrList get address list , and height of address // GetAddrList get address list , and height of address
func (s *P2pServer) GetAddrList(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddrList, error) { func (s *P2pserver) GetAddrList(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2PAddrList, error) {
_, infos := s.node.GetActivePeers() _, infos := s.node.GetActivePeers()
var peerinfos []*pb.P2PPeerInfo var peerinfos []*pb.P2PPeerInfo
...@@ -121,12 +121,12 @@ func (s *P2pServer) GetAddrList(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2P ...@@ -121,12 +121,12 @@ func (s *P2pServer) GetAddrList(ctx context.Context, in *pb.P2PGetAddr) (*pb.P2P
} }
// Version version // Version version
func (s *P2pServer) Version(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVerAck, error) { func (s *P2pserver) Version(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVerAck, error) {
return &pb.P2PVerAck{Version: s.node.nodeInfo.cfg.Version, Service: 6, Nonce: in.Nonce}, nil return &pb.P2PVerAck{Version: s.node.nodeInfo.cfg.Version, Service: 6, Nonce: in.Nonce}, nil
} }
// Version2 p2pserver version // Version2 p2pserver version
func (s *P2pServer) Version2(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVersion, error) { func (s *P2pserver) Version2(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVersion, error) {
log.Debug("Version2") log.Debug("Version2")
var peerip string var peerip string
var err error var err error
...@@ -163,7 +163,7 @@ func (s *P2pServer) Version2(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVer ...@@ -163,7 +163,7 @@ func (s *P2pServer) Version2(ctx context.Context, in *pb.P2PVersion) (*pb.P2PVer
} }
// SoftVersion software version // SoftVersion software version
func (s *P2pServer) SoftVersion(ctx context.Context, in *pb.P2PPing) (*pb.Reply, error) { func (s *P2pserver) SoftVersion(ctx context.Context, in *pb.P2PPing) (*pb.Reply, error) {
if !P2pComm.CheckSign(in) { if !P2pComm.CheckSign(in) {
log.Error("Ping", "p2p server", "check sig err") log.Error("Ping", "p2p server", "check sig err")
...@@ -175,7 +175,7 @@ func (s *P2pServer) SoftVersion(ctx context.Context, in *pb.P2PPing) (*pb.Reply, ...@@ -175,7 +175,7 @@ func (s *P2pServer) SoftVersion(ctx context.Context, in *pb.P2PPing) (*pb.Reply,
} }
// BroadCastTx broadcast transactions of p2pserver // BroadCastTx broadcast transactions of p2pserver
func (s *P2pServer) BroadCastTx(ctx context.Context, in *pb.P2PTx) (*pb.Reply, error) { func (s *P2pserver) BroadCastTx(ctx context.Context, in *pb.P2PTx) (*pb.Reply, error) {
log.Debug("p2pServer RECV TRANSACTION", "in", in) log.Debug("p2pServer RECV TRANSACTION", "in", in)
client := s.node.nodeInfo.client client := s.node.nodeInfo.client
msg := client.NewMessage("mempool", pb.EventTx, in.Tx) msg := client.NewMessage("mempool", pb.EventTx, in.Tx)
...@@ -184,7 +184,7 @@ func (s *P2pServer) BroadCastTx(ctx context.Context, in *pb.P2PTx) (*pb.Reply, e ...@@ -184,7 +184,7 @@ func (s *P2pServer) BroadCastTx(ctx context.Context, in *pb.P2PTx) (*pb.Reply, e
} }
// GetBlocks get blocks of p2pserver // GetBlocks get blocks of p2pserver
func (s *P2pServer) GetBlocks(ctx context.Context, in *pb.P2PGetBlocks) (*pb.P2PInv, error) { func (s *P2pserver) GetBlocks(ctx context.Context, in *pb.P2PGetBlocks) (*pb.P2PInv, error) {
log.Debug("p2pServer GetBlocks", "P2P Recv", in) log.Debug("p2pServer GetBlocks", "P2P Recv", in)
if !s.checkVersion(in.GetVersion()) { if !s.checkVersion(in.GetVersion()) {
...@@ -215,7 +215,7 @@ func (s *P2pServer) GetBlocks(ctx context.Context, in *pb.P2PGetBlocks) (*pb.P2P ...@@ -215,7 +215,7 @@ func (s *P2pServer) GetBlocks(ctx context.Context, in *pb.P2PGetBlocks) (*pb.P2P
} }
// GetMemPool p2pserver queries the local mempool // GetMemPool p2pserver queries the local mempool
func (s *P2pServer) GetMemPool(ctx context.Context, in *pb.P2PGetMempool) (*pb.P2PInv, error) { func (s *P2pserver) GetMemPool(ctx context.Context, in *pb.P2PGetMempool) (*pb.P2PInv, error) {
log.Debug("p2pServer Recv GetMempool", "version", in) log.Debug("p2pServer Recv GetMempool", "version", in)
if !s.checkVersion(in.GetVersion()) { if !s.checkVersion(in.GetVersion()) {
return nil, pb.ErrVersion return nil, pb.ErrVersion
...@@ -234,7 +234,7 @@ func (s *P2pServer) GetMemPool(ctx context.Context, in *pb.P2PGetMempool) (*pb.P ...@@ -234,7 +234,7 @@ func (s *P2pServer) GetMemPool(ctx context.Context, in *pb.P2PGetMempool) (*pb.P
} }
// GetData get data of p2pserver // GetData get data of p2pserver
func (s *P2pServer) GetData(in *pb.P2PGetData, stream pb.P2Pgservice_GetDataServer) error { func (s *P2pserver) GetData(in *pb.P2PGetData, stream pb.P2Pgservice_GetDataServer) error {
log.Debug("p2pServer Recv GetDataTx", "p2p version", in.GetVersion()) log.Debug("p2pServer Recv GetDataTx", "p2p version", in.GetVersion())
var p2pInvData = make([]*pb.InvData, 0) var p2pInvData = make([]*pb.InvData, 0)
var count = 0 var count = 0
...@@ -306,7 +306,7 @@ func (s *P2pServer) GetData(in *pb.P2PGetData, stream pb.P2Pgservice_GetDataServ ...@@ -306,7 +306,7 @@ func (s *P2pServer) GetData(in *pb.P2PGetData, stream pb.P2Pgservice_GetDataServ
} }
// GetHeaders ger headers of p2pServer // GetHeaders ger headers of p2pServer
func (s *P2pServer) GetHeaders(ctx context.Context, in *pb.P2PGetHeaders) (*pb.P2PHeaders, error) { func (s *P2pserver) GetHeaders(ctx context.Context, in *pb.P2PGetHeaders) (*pb.P2PHeaders, error) {
log.Debug("p2pServer GetHeaders", "p2p version", in.GetVersion()) log.Debug("p2pServer GetHeaders", "p2p version", in.GetVersion())
if !s.checkVersion(in.GetVersion()) { if !s.checkVersion(in.GetVersion()) {
return nil, pb.ErrVersion return nil, pb.ErrVersion
...@@ -333,7 +333,7 @@ func (s *P2pServer) GetHeaders(ctx context.Context, in *pb.P2PGetHeaders) (*pb.P ...@@ -333,7 +333,7 @@ func (s *P2pServer) GetHeaders(ctx context.Context, in *pb.P2PGetHeaders) (*pb.P
} }
// GetPeerInfo get peer information of p2pServer // GetPeerInfo get peer information of p2pServer
func (s *P2pServer) GetPeerInfo(ctx context.Context, in *pb.P2PGetPeerInfo) (*pb.P2PPeerInfo, error) { func (s *P2pserver) GetPeerInfo(ctx context.Context, in *pb.P2PGetPeerInfo) (*pb.P2PPeerInfo, error) {
log.Debug("p2pServer GetPeerInfo", "p2p version", in.GetVersion()) log.Debug("p2pServer GetPeerInfo", "p2p version", in.GetVersion())
if !s.checkVersion(in.GetVersion()) { if !s.checkVersion(in.GetVersion()) {
return nil, pb.ErrVersion return nil, pb.ErrVersion
...@@ -381,7 +381,7 @@ func (s *P2pServer) GetPeerInfo(ctx context.Context, in *pb.P2PGetPeerInfo) (*pb ...@@ -381,7 +381,7 @@ func (s *P2pServer) GetPeerInfo(ctx context.Context, in *pb.P2PGetPeerInfo) (*pb
} }
// BroadCastBlock broadcast block of p2pserver // BroadCastBlock broadcast block of p2pserver
func (s *P2pServer) BroadCastBlock(ctx context.Context, in *pb.P2PBlock) (*pb.Reply, error) { func (s *P2pserver) BroadCastBlock(ctx context.Context, in *pb.P2PBlock) (*pb.Reply, error) {
log.Debug("BroadCastBlock") log.Debug("BroadCastBlock")
client := s.node.nodeInfo.client client := s.node.nodeInfo.client
msg := client.NewMessage("blockchain", pb.EventBroadcastAddBlock, in.GetBlock()) msg := client.NewMessage("blockchain", pb.EventBroadcastAddBlock, in.GetBlock())
...@@ -394,7 +394,7 @@ func (s *P2pServer) BroadCastBlock(ctx context.Context, in *pb.P2PBlock) (*pb.Re ...@@ -394,7 +394,7 @@ func (s *P2pServer) BroadCastBlock(ctx context.Context, in *pb.P2PBlock) (*pb.Re
} }
// ServerStreamSend serverstream send of p2pserver // ServerStreamSend serverstream send of p2pserver
func (s *P2pServer) ServerStreamSend(in *pb.P2PPing, stream pb.P2Pgservice_ServerStreamSendServer) error { func (s *P2pserver) ServerStreamSend(in *pb.P2PPing, stream pb.P2Pgservice_ServerStreamSendServer) error {
if len(s.getInBoundPeers()) > int(s.node.nodeInfo.cfg.InnerBounds) { if len(s.getInBoundPeers()) > int(s.node.nodeInfo.cfg.InnerBounds) {
return fmt.Errorf("beyound max inbound num") return fmt.Errorf("beyound max inbound num")
} }
...@@ -438,7 +438,7 @@ func (s *P2pServer) ServerStreamSend(in *pb.P2PPing, stream pb.P2Pgservice_Serve ...@@ -438,7 +438,7 @@ func (s *P2pServer) ServerStreamSend(in *pb.P2PPing, stream pb.P2Pgservice_Serve
} }
// ServerStreamRead server stream read of p2pserver // ServerStreamRead server stream read of p2pserver
func (s *P2pServer) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServer) error { func (s *P2pserver) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServer) error {
if len(s.getInBoundPeers()) > int(s.node.nodeInfo.cfg.InnerBounds) { if len(s.getInBoundPeers()) > int(s.node.nodeInfo.cfg.InnerBounds) {
return fmt.Errorf("beyound max inbound num:%v>%v", len(s.getInBoundPeers()), int(s.node.nodeInfo.cfg.InnerBounds)) return fmt.Errorf("beyound max inbound num:%v>%v", len(s.getInBoundPeers()), int(s.node.nodeInfo.cfg.InnerBounds))
} }
...@@ -538,7 +538,7 @@ func (s *P2pServer) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServe ...@@ -538,7 +538,7 @@ func (s *P2pServer) ServerStreamRead(stream pb.P2Pgservice_ServerStreamReadServe
} }
// CollectInPeers collect external network nodes of connect their own // CollectInPeers collect external network nodes of connect their own
func (s *P2pServer) CollectInPeers(ctx context.Context, in *pb.P2PPing) (*pb.PeerList, error) { func (s *P2pserver) CollectInPeers(ctx context.Context, in *pb.P2PPing) (*pb.PeerList, error) {
log.Info("CollectInPeers") log.Info("CollectInPeers")
if !P2pComm.CheckSign(in) { if !P2pComm.CheckSign(in) {
log.Info("CollectInPeers", "ping", "signatrue err") log.Info("CollectInPeers", "ping", "signatrue err")
...@@ -562,7 +562,7 @@ func (s *P2pServer) CollectInPeers(ctx context.Context, in *pb.P2PPing) (*pb.Pee ...@@ -562,7 +562,7 @@ func (s *P2pServer) CollectInPeers(ctx context.Context, in *pb.P2PPing) (*pb.Pee
} }
// CollectInPeers2 collect external network nodes of connect their own // CollectInPeers2 collect external network nodes of connect their own
func (s *P2pServer) CollectInPeers2(ctx context.Context, in *pb.P2PPing) (*pb.PeersReply, error) { func (s *P2pserver) CollectInPeers2(ctx context.Context, in *pb.P2PPing) (*pb.PeersReply, error) {
log.Info("CollectInPeers2") log.Info("CollectInPeers2")
if !P2pComm.CheckSign(in) { if !P2pComm.CheckSign(in) {
log.Info("CollectInPeers", "ping", "signatrue err") log.Info("CollectInPeers", "ping", "signatrue err")
...@@ -587,7 +587,7 @@ func (s *P2pServer) CollectInPeers2(ctx context.Context, in *pb.P2PPing) (*pb.Pe ...@@ -587,7 +587,7 @@ func (s *P2pServer) CollectInPeers2(ctx context.Context, in *pb.P2PPing) (*pb.Pe
return &pb.PeersReply{Peers: p2pPeers}, nil return &pb.PeersReply{Peers: p2pPeers}, nil
} }
func (s *P2pServer) checkVersion(version int32) bool { func (s *P2pserver) checkVersion(version int32) bool {
if version < s.node.nodeInfo.cfg.VerMin || version > s.node.nodeInfo.cfg.VerMax { if version < s.node.nodeInfo.cfg.VerMin || version > s.node.nodeInfo.cfg.VerMax {
//版本不支持 //版本不支持
...@@ -596,7 +596,7 @@ func (s *P2pServer) checkVersion(version int32) bool { ...@@ -596,7 +596,7 @@ func (s *P2pServer) checkVersion(version int32) bool {
return true return true
} }
func (s *P2pServer) loadMempool() (map[string]*pb.Transaction, error) { func (s *P2pserver) loadMempool() (map[string]*pb.Transaction, error) {
var txmap = make(map[string]*pb.Transaction) var txmap = make(map[string]*pb.Transaction)
client := s.node.nodeInfo.client client := s.node.nodeInfo.client
...@@ -620,7 +620,7 @@ func (s *P2pServer) loadMempool() (map[string]*pb.Transaction, error) { ...@@ -620,7 +620,7 @@ func (s *P2pServer) loadMempool() (map[string]*pb.Transaction, error) {
return txmap, nil return txmap, nil
} }
func (s *P2pServer) manageStream() { func (s *P2pserver) manageStream() {
go s.deleteDisableStream() go s.deleteDisableStream()
go func() { //发送空的block stream ping go func() { //发送空的block stream ping
ticker := time.NewTicker(StreamPingTimeout) ticker := time.NewTicker(StreamPingTimeout)
...@@ -645,7 +645,7 @@ func (s *P2pServer) manageStream() { ...@@ -645,7 +645,7 @@ func (s *P2pServer) manageStream() {
}() }()
} }
func (s *P2pServer) addStreamHandler(stream pb.P2Pgservice_ServerStreamSendServer) chan interface{} { func (s *P2pserver) addStreamHandler(stream pb.P2Pgservice_ServerStreamSendServer) chan interface{} {
s.smtx.Lock() s.smtx.Lock()
defer s.smtx.Unlock() defer s.smtx.Unlock()
s.streams[stream] = make(chan interface{}, 1024) s.streams[stream] = make(chan interface{}, 1024)
...@@ -653,7 +653,7 @@ func (s *P2pServer) addStreamHandler(stream pb.P2Pgservice_ServerStreamSendServe ...@@ -653,7 +653,7 @@ func (s *P2pServer) addStreamHandler(stream pb.P2Pgservice_ServerStreamSendServe
} }
func (s *P2pServer) addStreamData(data interface{}) { func (s *P2pserver) addStreamData(data interface{}) {
s.smtx.Lock() s.smtx.Lock()
defer s.smtx.Unlock() defer s.smtx.Unlock()
timetikc := time.NewTicker(time.Second * 1) timetikc := time.NewTicker(time.Second * 1)
...@@ -674,32 +674,32 @@ func (s *P2pServer) addStreamData(data interface{}) { ...@@ -674,32 +674,32 @@ func (s *P2pServer) addStreamData(data interface{}) {
} }
func (s *P2pServer) deleteDisableStream() { func (s *P2pserver) deleteDisableStream() {
for stream := range s.deleteSChan { for stream := range s.deleteSChan {
s.deleteStream(stream) s.deleteStream(stream)
} }
} }
func (s *P2pServer) deleteStream(stream pb.P2Pgservice_ServerStreamSendServer) { func (s *P2pserver) deleteStream(stream pb.P2Pgservice_ServerStreamSendServer) {
s.smtx.Lock() s.smtx.Lock()
defer s.smtx.Unlock() defer s.smtx.Unlock()
close(s.streams[stream]) close(s.streams[stream])
delete(s.streams, stream) delete(s.streams, stream)
} }
func (s *P2pServer) addInBoundPeerInfo(peername string, info innerpeer) { func (s *P2pserver) addInBoundPeerInfo(peername string, info innerpeer) {
s.imtx.Lock() s.imtx.Lock()
defer s.imtx.Unlock() defer s.imtx.Unlock()
s.inboundpeers[peername] = &info s.inboundpeers[peername] = &info
} }
func (s *P2pServer) deleteInBoundPeerInfo(peername string) { func (s *P2pserver) deleteInBoundPeerInfo(peername string) {
s.imtx.Lock() s.imtx.Lock()
defer s.imtx.Unlock() defer s.imtx.Unlock()
delete(s.inboundpeers, peername) delete(s.inboundpeers, peername)
} }
func (s *P2pServer) getInBoundPeerInfo(peername string) *innerpeer { func (s *P2pserver) getInBoundPeerInfo(peername string) *innerpeer {
s.imtx.Lock() s.imtx.Lock()
defer s.imtx.Unlock() defer s.imtx.Unlock()
if key, ok := s.inboundpeers[peername]; ok { if key, ok := s.inboundpeers[peername]; ok {
...@@ -709,7 +709,7 @@ func (s *P2pServer) getInBoundPeerInfo(peername string) *innerpeer { ...@@ -709,7 +709,7 @@ func (s *P2pServer) getInBoundPeerInfo(peername string) *innerpeer {
return nil return nil
} }
func (s *P2pServer) getInBoundPeers() []*innerpeer { func (s *P2pserver) getInBoundPeers() []*innerpeer {
s.imtx.Lock() s.imtx.Lock()
defer s.imtx.Unlock() defer s.imtx.Unlock()
var peers []*innerpeer var peers []*innerpeer
......
...@@ -188,7 +188,7 @@ func (client *client) isEnd(data Message, ok bool) bool { ...@@ -188,7 +188,7 @@ func (client *client) isEnd(data Message, ok bool) bool {
if atomic.LoadInt32(&client.isClosed) == 1 { if atomic.LoadInt32(&client.isClosed) == 1 {
return true return true
} }
if data.Data == nil && data.Id == 0 && data.Ty == 0 { if data.Data == nil && data.ID == 0 && data.Ty == 0 {
return true return true
} }
return false return false
......
...@@ -229,14 +229,14 @@ func (q *queue) Client() Client { ...@@ -229,14 +229,14 @@ func (q *queue) Client() Client {
type Message struct { type Message struct {
Topic string Topic string
Ty int64 Ty int64
Id int64 ID int64
Data interface{} Data interface{}
chReply chan Message chReply chan Message
} }
// NewMessage new message // NewMessage new message
func NewMessage(id int64, topic string, ty int64, data interface{}) (msg Message) { func NewMessage(id int64, topic string, ty int64, data interface{}) (msg Message) {
msg.Id = id msg.ID = id
msg.Ty = ty msg.Ty = ty
msg.Data = data msg.Data = data
msg.Topic = topic msg.Topic = topic
...@@ -275,7 +275,7 @@ func (msg Message) Reply(replyMsg Message) { ...@@ -275,7 +275,7 @@ func (msg Message) Reply(replyMsg Message) {
// String print the message information // String print the message information
func (msg Message) String() string { func (msg Message) String() string {
return fmt.Sprintf("{topic:%s, Ty:%s, Id:%d, Err:%v, Ch:%v}", msg.Topic, return fmt.Sprintf("{topic:%s, Ty:%s, Id:%d, Err:%v, Ch:%v}", msg.Topic,
types.GetEventName(int(msg.Ty)), msg.Id, msg.Err(), msg.chReply != nil) types.GetEventName(int(msg.Ty)), msg.ID, msg.Err(), msg.chReply != nil)
} }
// ReplyErr reply error // ReplyErr reply error
......
...@@ -20,8 +20,8 @@ import ( ...@@ -20,8 +20,8 @@ import (
//const //const
const ( const (
SM2_RPIVATEKEY_LENGTH = 32 SM2PrivateKeyLength = 32
SM2_PUBLICKEY_LENGTH = 65 SM2PublicKeyLength = 65
) )
//Driver 驱动 //Driver 驱动
...@@ -29,8 +29,8 @@ type Driver struct{} ...@@ -29,8 +29,8 @@ type Driver struct{}
//GenKey 生成私钥 //GenKey 生成私钥
func (d Driver) GenKey() (crypto.PrivKey, error) { func (d Driver) GenKey() (crypto.PrivKey, error) {
privKeyBytes := [SM2_RPIVATEKEY_LENGTH]byte{} privKeyBytes := [SM2PrivateKeyLength]byte{}
copy(privKeyBytes[:], crypto.CRandBytes(SM2_RPIVATEKEY_LENGTH)) copy(privKeyBytes[:], crypto.CRandBytes(SM2PrivateKeyLength))
priv, _ := privKeyFromBytes(sm2.P256Sm2(), privKeyBytes[:]) priv, _ := privKeyFromBytes(sm2.P256Sm2(), privKeyBytes[:])
copy(privKeyBytes[:], SerializePrivateKey(priv)) copy(privKeyBytes[:], SerializePrivateKey(priv))
return PrivKeySM2(privKeyBytes), nil return PrivKeySM2(privKeyBytes), nil
...@@ -38,11 +38,11 @@ func (d Driver) GenKey() (crypto.PrivKey, error) { ...@@ -38,11 +38,11 @@ func (d Driver) GenKey() (crypto.PrivKey, error) {
//PrivKeyFromBytes 字节转为私钥 //PrivKeyFromBytes 字节转为私钥
func (d Driver) PrivKeyFromBytes(b []byte) (privKey crypto.PrivKey, err error) { func (d Driver) PrivKeyFromBytes(b []byte) (privKey crypto.PrivKey, err error) {
if len(b) != SM2_RPIVATEKEY_LENGTH { if len(b) != SM2PrivateKeyLength {
return nil, errors.New("invalid priv key byte") return nil, errors.New("invalid priv key byte")
} }
privKeyBytes := new([SM2_RPIVATEKEY_LENGTH]byte) privKeyBytes := new([SM2PrivateKeyLength]byte)
copy(privKeyBytes[:], b[:SM2_RPIVATEKEY_LENGTH]) copy(privKeyBytes[:], b[:SM2PrivateKeyLength])
priv, _ := privKeyFromBytes(sm2.P256Sm2(), privKeyBytes[:]) priv, _ := privKeyFromBytes(sm2.P256Sm2(), privKeyBytes[:])
...@@ -52,10 +52,10 @@ func (d Driver) PrivKeyFromBytes(b []byte) (privKey crypto.PrivKey, err error) { ...@@ -52,10 +52,10 @@ func (d Driver) PrivKeyFromBytes(b []byte) (privKey crypto.PrivKey, err error) {
//PubKeyFromBytes 字节转为公钥 //PubKeyFromBytes 字节转为公钥
func (d Driver) PubKeyFromBytes(b []byte) (pubKey crypto.PubKey, err error) { func (d Driver) PubKeyFromBytes(b []byte) (pubKey crypto.PubKey, err error) {
if len(b) != SM2_PUBLICKEY_LENGTH { if len(b) != SM2PublicKeyLength {
return nil, errors.New("invalid pub key byte") return nil, errors.New("invalid pub key byte")
} }
pubKeyBytes := new([SM2_PUBLICKEY_LENGTH]byte) pubKeyBytes := new([SM2PublicKeyLength]byte)
copy(pubKeyBytes[:], b[:]) copy(pubKeyBytes[:], b[:])
return PubKeySM2(*pubKeyBytes), nil return PubKeySM2(*pubKeyBytes), nil
} }
...@@ -76,11 +76,11 @@ func (d Driver) SignatureFromBytes(b []byte) (sig crypto.Signature, err error) { ...@@ -76,11 +76,11 @@ func (d Driver) SignatureFromBytes(b []byte) (sig crypto.Signature, err error) {
} }
//PrivKeySM2 私钥 //PrivKeySM2 私钥
type PrivKeySM2 [SM2_RPIVATEKEY_LENGTH]byte type PrivKeySM2 [SM2PrivateKeyLength]byte
//Bytes 字节格式 //Bytes 字节格式
func (privKey PrivKeySM2) Bytes() []byte { func (privKey PrivKeySM2) Bytes() []byte {
s := make([]byte, SM2_RPIVATEKEY_LENGTH) s := make([]byte, SM2PrivateKeyLength)
copy(s, privKey[:]) copy(s, privKey[:])
return s return s
} }
...@@ -120,11 +120,11 @@ func (privKey PrivKeySM2) String() string { ...@@ -120,11 +120,11 @@ func (privKey PrivKeySM2) String() string {
} }
//PubKeySM2 公钥 //PubKeySM2 公钥
type PubKeySM2 [SM2_PUBLICKEY_LENGTH]byte type PubKeySM2 [SM2PublicKeyLength]byte
//Bytes 字节格式 //Bytes 字节格式
func (pubKey PubKeySM2) Bytes() []byte { func (pubKey PubKeySM2) Bytes() []byte {
s := make([]byte, SM2_PUBLICKEY_LENGTH) s := make([]byte, SM2PublicKeyLength)
copy(s, pubKey[:]) copy(s, pubKey[:])
return s return s
} }
......
...@@ -103,7 +103,7 @@ func parsePubKey(pubKeyStr []byte, curve elliptic.Curve) (key *sm2.PublicKey, er ...@@ -103,7 +103,7 @@ func parsePubKey(pubKeyStr []byte, curve elliptic.Curve) (key *sm2.PublicKey, er
//SerializePublicKey 公钥序列化 //SerializePublicKey 公钥序列化
func SerializePublicKey(p *sm2.PublicKey) []byte { func SerializePublicKey(p *sm2.PublicKey) []byte {
b := make([]byte, 0, SM2_PUBLICKEY_LENGTH) b := make([]byte, 0, SM2PublicKeyLength)
b = append(b, 0x4) b = append(b, 0x4)
b = paddedAppend(32, b, p.X.Bytes()) b = paddedAppend(32, b, p.X.Bytes())
return paddedAppend(32, b, p.Y.Bytes()) return paddedAppend(32, b, p.Y.Bytes())
...@@ -111,8 +111,8 @@ func SerializePublicKey(p *sm2.PublicKey) []byte { ...@@ -111,8 +111,8 @@ func SerializePublicKey(p *sm2.PublicKey) []byte {
//SerializePrivateKey 私钥序列化 //SerializePrivateKey 私钥序列化
func SerializePrivateKey(p *sm2.PrivateKey) []byte { func SerializePrivateKey(p *sm2.PrivateKey) []byte {
b := make([]byte, 0, SM2_RPIVATEKEY_LENGTH) b := make([]byte, 0, SM2PrivateKeyLength)
return paddedAppend(SM2_RPIVATEKEY_LENGTH, b, p.D.Bytes()) return paddedAppend(SM2PrivateKeyLength, b, p.D.Bytes())
} }
func paddedAppend(size uint, dst, src []byte) []byte { func paddedAppend(size uint, dst, src []byte) []byte {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
package system package system
import ( import (
_ "github.com/33cn/chain33/system/consensus/init" _ "github.com/33cn/chain33/system/consensus/init" //register consensus init package
_ "github.com/33cn/chain33/system/crypto/init" _ "github.com/33cn/chain33/system/crypto/init"
_ "github.com/33cn/chain33/system/dapp/init" _ "github.com/33cn/chain33/system/dapp/init"
_ "github.com/33cn/chain33/system/store/init" _ "github.com/33cn/chain33/system/store/init"
......
...@@ -172,23 +172,27 @@ func (store *BaseStore) GetQueueClient() queue.Client { ...@@ -172,23 +172,27 @@ func (store *BaseStore) GetQueueClient() queue.Client {
return store.qclient return store.qclient
} }
func NewStoreListQuery(store SubStore, req *types.StoreList) *StoreListQuery { // NewStoreListQuery new store list query object
func NewStoreListQuery(store SubStore, req *types.StoreList) *StorelistQuery {
reply := &types.StoreListReply{Start: req.Start, End: req.End, Suffix: req.Suffix, Count: req.Count, Mode: req.Mode} reply := &types.StoreListReply{Start: req.Start, End: req.End, Suffix: req.Suffix, Count: req.Count, Mode: req.Mode}
return &StoreListQuery{StoreListReply: reply, req: req, store: store} return &StorelistQuery{StoreListReply: reply, req: req, store: store}
} }
type StoreListQuery struct { // StorelistQuery defines a type store list query
type StorelistQuery struct {
store SubStore store SubStore
req *types.StoreList req *types.StoreList
*types.StoreListReply *types.StoreListReply
} }
func (t *StoreListQuery) Run() *types.StoreListReply { // Run store list query
func (t *StorelistQuery) Run() *types.StoreListReply {
t.store.IterateRangeByStateHash(t.req.StateHash, t.req.Start, t.req.End, true, t.IterateCallBack) t.store.IterateRangeByStateHash(t.req.StateHash, t.req.Start, t.req.End, true, t.IterateCallBack)
return t.StoreListReply return t.StoreListReply
} }
func (t *StoreListQuery) IterateCallBack(key, value []byte) bool { // IterateCallBack store list query iterate callback
func (t *StorelistQuery) IterateCallBack(key, value []byte) bool {
if t.Mode == 1 { //[start, end)模式 if t.Mode == 1 { //[start, end)模式
if t.Num >= t.Count { if t.Num >= t.Count {
t.NextKey = key t.NextKey = key
...@@ -198,7 +202,8 @@ func (t *StoreListQuery) IterateCallBack(key, value []byte) bool { ...@@ -198,7 +202,8 @@ func (t *StoreListQuery) IterateCallBack(key, value []byte) bool {
t.Keys = append(t.Keys, cloneByte(key)) t.Keys = append(t.Keys, cloneByte(key))
t.Values = append(t.Values, cloneByte(value)) t.Values = append(t.Values, cloneByte(value))
return false return false
} else if t.Mode == 2 { //prefix + suffix模式,要对按prefix得到的数据key进行suffix的判断,符合条件的数据才是最终要的数据 }
if t.Mode == 2 { //prefix + suffix模式,要对按prefix得到的数据key进行suffix的判断,符合条件的数据才是最终要的数据
if len(key) > len(t.Suffix) { if len(key) > len(t.Suffix) {
if string(key[len(key)-len(t.Suffix):]) == string(t.Suffix) { if string(key[len(key)-len(t.Suffix):]) == string(t.Suffix) {
t.Num++ t.Num++
...@@ -209,16 +214,16 @@ func (t *StoreListQuery) IterateCallBack(key, value []byte) bool { ...@@ -209,16 +214,16 @@ func (t *StoreListQuery) IterateCallBack(key, value []byte) bool {
return true return true
} }
return false return false
} else { }
return false return false
} }
} else {
return false return false
} }
} else {
slog.Error("StoreListReply.IterateCallBack unsupported mode", "mode", t.Mode) slog.Error("StoreListReply.IterateCallBack unsupported mode", "mode", t.Mode)
return true return true
}
} }
func cloneByte(v []byte) []byte { func cloneByte(v []byte) []byte {
......
...@@ -658,6 +658,7 @@ func deleteOldNode(db dbm.DB, mp map[string][]hashData, curHeight int64, lastKey ...@@ -658,6 +658,7 @@ func deleteOldNode(db dbm.DB, mp map[string][]hashData, curHeight int64, lastKey
pruningHashNode(db, delMp) pruningHashNode(db, delMp)
} }
// PruningTreePrintDB pruning tree print db
func PruningTreePrintDB(db dbm.DB, prefix []byte) { func PruningTreePrintDB(db dbm.DB, prefix []byte) {
it := db.Iterator(prefix, nil, true) it := db.Iterator(prefix, nil, true)
defer it.Close() defer it.Close()
......
...@@ -214,7 +214,7 @@ func genPrefixEdge(prefix []byte) (r []byte) { ...@@ -214,7 +214,7 @@ func genPrefixEdge(prefix []byte) (r []byte) {
i := len(prefix) - 1 i := len(prefix) - 1
for i >= 0 { for i >= 0 {
if r[i] < 0xff { if r[i] < 0xff {
r[i] += 1 r[i]++
break break
} else { } else {
i-- i--
...@@ -294,7 +294,7 @@ func TestIterateCallBack_Mode1(t *testing.T) { ...@@ -294,7 +294,7 @@ func TestIterateCallBack_Mode1(t *testing.T) {
resp1.Count = 5 resp1.Count = 5
resp1.Mode = 1 resp1.Mode = 1
query = &drivers.StoreListQuery{StoreListReply: resp1} query = &drivers.StorelistQuery{StoreListReply: resp1}
store.IterateRangeByStateHash(hash1, resp1.Start, resp1.End, true, query.IterateCallBack) store.IterateRangeByStateHash(hash1, resp1.Start, resp1.End, true, query.IterateCallBack)
tool.AddItem(resp1.Values) tool.AddItem(resp1.Values)
...@@ -314,7 +314,7 @@ func TestIterateCallBack_Mode1(t *testing.T) { ...@@ -314,7 +314,7 @@ func TestIterateCallBack_Mode1(t *testing.T) {
resp0.End = genPrefixEdge([]byte(prefix)) resp0.End = genPrefixEdge([]byte(prefix))
resp0.Count = 5 resp0.Count = 5
resp0.Mode = 1 resp0.Mode = 1
query = &drivers.StoreListQuery{StoreListReply: resp0} query = &drivers.StorelistQuery{StoreListReply: resp0}
store.IterateRangeByStateHash(hash0, resp0.Start, resp0.End, true, query.IterateCallBack) store.IterateRangeByStateHash(hash0, resp0.Start, resp0.End, true, query.IterateCallBack)
tool.AddItem(resp0.Values) tool.AddItem(resp0.Values)
...@@ -334,7 +334,7 @@ func TestIterateCallBack_Mode1(t *testing.T) { ...@@ -334,7 +334,7 @@ func TestIterateCallBack_Mode1(t *testing.T) {
resp.End = genPrefixEdge([]byte(prefix)) resp.End = genPrefixEdge([]byte(prefix))
resp.Count = 1 resp.Count = 1
resp.Mode = 1 resp.Mode = 1
query = &drivers.StoreListQuery{StoreListReply: resp} query = &drivers.StorelistQuery{StoreListReply: resp}
store.IterateRangeByStateHash(hash2, resp.Start, resp.End, true, query.IterateCallBack) store.IterateRangeByStateHash(hash2, resp.Start, resp.End, true, query.IterateCallBack)
tool.AddItem(resp.Values) tool.AddItem(resp.Values)
...@@ -354,7 +354,7 @@ func TestIterateCallBack_Mode1(t *testing.T) { ...@@ -354,7 +354,7 @@ func TestIterateCallBack_Mode1(t *testing.T) {
resp.End = genPrefixEdge([]byte(prefix)) resp.End = genPrefixEdge([]byte(prefix))
resp.Count = 2 resp.Count = 2
resp.Mode = 1 resp.Mode = 1
query = &drivers.StoreListQuery{StoreListReply: resp} query = &drivers.StorelistQuery{StoreListReply: resp}
store.IterateRangeByStateHash(hash2, resp.Start, resp.End, true, query.IterateCallBack) store.IterateRangeByStateHash(hash2, resp.Start, resp.End, true, query.IterateCallBack)
tool.AddItem(resp.Values) tool.AddItem(resp.Values)
...@@ -422,7 +422,7 @@ func TestIterateCallBack_Mode2(t *testing.T) { ...@@ -422,7 +422,7 @@ func TestIterateCallBack_Mode2(t *testing.T) {
resp2.Count = 5 resp2.Count = 5
resp2.Mode = 2 resp2.Mode = 2
query := &drivers.StoreListQuery{StoreListReply: resp2} query := &drivers.StorelistQuery{StoreListReply: resp2}
store.IterateRangeByStateHash(hash2, resp2.Start, nil, true, query.IterateCallBack) store.IterateRangeByStateHash(hash2, resp2.Start, nil, true, query.IterateCallBack)
tool := &StatTool{} tool := &StatTool{}
tool.AddItem(resp2.Values) tool.AddItem(resp2.Values)
...@@ -442,7 +442,7 @@ func TestIterateCallBack_Mode2(t *testing.T) { ...@@ -442,7 +442,7 @@ func TestIterateCallBack_Mode2(t *testing.T) {
resp1.End = genPrefixEdge([]byte(prefix)) resp1.End = genPrefixEdge([]byte(prefix))
resp1.Count = 5 resp1.Count = 5
resp1.Mode = 2 resp1.Mode = 2
query = &drivers.StoreListQuery{StoreListReply: resp1} query = &drivers.StorelistQuery{StoreListReply: resp1}
store.IterateRangeByStateHash(hash1, resp1.Start, resp1.End, true, query.IterateCallBack) store.IterateRangeByStateHash(hash1, resp1.Start, resp1.End, true, query.IterateCallBack)
tool.AddItem(resp1.Values) tool.AddItem(resp1.Values)
...@@ -462,7 +462,7 @@ func TestIterateCallBack_Mode2(t *testing.T) { ...@@ -462,7 +462,7 @@ func TestIterateCallBack_Mode2(t *testing.T) {
resp0.End = genPrefixEdge([]byte(prefix)) resp0.End = genPrefixEdge([]byte(prefix))
resp0.Count = 5 resp0.Count = 5
resp0.Mode = 2 resp0.Mode = 2
query = &drivers.StoreListQuery{StoreListReply: resp0} query = &drivers.StorelistQuery{StoreListReply: resp0}
store.IterateRangeByStateHash(hash0, resp0.Start, nil, true, query.IterateCallBack) store.IterateRangeByStateHash(hash0, resp0.Start, nil, true, query.IterateCallBack)
tool.AddItem(resp0.Values) tool.AddItem(resp0.Values)
...@@ -482,7 +482,7 @@ func TestIterateCallBack_Mode2(t *testing.T) { ...@@ -482,7 +482,7 @@ func TestIterateCallBack_Mode2(t *testing.T) {
resp.End = genPrefixEdge([]byte(prefix)) resp.End = genPrefixEdge([]byte(prefix))
resp.Count = 1 resp.Count = 1
resp.Mode = 2 resp.Mode = 2
query = &drivers.StoreListQuery{StoreListReply: resp} query = &drivers.StorelistQuery{StoreListReply: resp}
store.IterateRangeByStateHash(hash2, resp.Start, nil, true, query.IterateCallBack) store.IterateRangeByStateHash(hash2, resp.Start, nil, true, query.IterateCallBack)
tool.AddItem(resp.Values) tool.AddItem(resp.Values)
...@@ -502,7 +502,7 @@ func TestIterateCallBack_Mode2(t *testing.T) { ...@@ -502,7 +502,7 @@ func TestIterateCallBack_Mode2(t *testing.T) {
resp.End = genPrefixEdge([]byte(prefix)) resp.End = genPrefixEdge([]byte(prefix))
resp.Count = 2 resp.Count = 2
resp.Mode = 2 resp.Mode = 2
query = &drivers.StoreListQuery{StoreListReply: resp} query = &drivers.StorelistQuery{StoreListReply: resp}
store.IterateRangeByStateHash(hash2, resp.Start, nil, true, query.IterateCallBack) store.IterateRangeByStateHash(hash2, resp.Start, nil, true, query.IterateCallBack)
tool.AddItem(resp.Values) tool.AddItem(resp.Values)
...@@ -522,7 +522,7 @@ func TestIterateCallBack_Mode2(t *testing.T) { ...@@ -522,7 +522,7 @@ func TestIterateCallBack_Mode2(t *testing.T) {
resp.End = genPrefixEdge([]byte("mavl-coins-bty-exec-26htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp:")) resp.End = genPrefixEdge([]byte("mavl-coins-bty-exec-26htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp:"))
resp.Count = 1 resp.Count = 1
resp.Mode = 2 resp.Mode = 2
query = &drivers.StoreListQuery{StoreListReply: resp} query = &drivers.StorelistQuery{StoreListReply: resp}
store.IterateRangeByStateHash(hash2, resp.Start, resp.End, true, query.IterateCallBack) store.IterateRangeByStateHash(hash2, resp.Start, resp.End, true, query.IterateCallBack)
tool.AddItem(resp.Values) tool.AddItem(resp.Values)
assert.Equal(t, int64(1), resp.Num) assert.Equal(t, int64(1), resp.Num)
......
...@@ -33,7 +33,7 @@ var ( ...@@ -33,7 +33,7 @@ var (
// coin conversation // coin conversation
const ( const (
Coin int64 = 1e8 Coin int64 = 1e8
MaxCoin int64 = 9e18 MaxCoin int64 = 1e17
MaxTxSize = 100000 //100K MaxTxSize = 100000 //100K
MaxTxGroupSize int32 = 20 MaxTxGroupSize int32 = 20
MaxBlockSize = 20000000 //20M MaxBlockSize = 20000000 //20M
......
...@@ -107,25 +107,25 @@ func defaultResolveAny(typeURL string) (proto.Message, error) { ...@@ -107,25 +107,25 @@ func defaultResolveAny(typeURL string) (proto.Message, error) {
return reflect.New(mt.Elem()).Interface().(proto.Message), nil return reflect.New(mt.Elem()).Interface().(proto.Message), nil
} }
// JSONPBMarshaler is implemented by protobuf messages that customize the // JSONPBmarshaler is implemented by protobuf messages that customize the
// way they are marshaled to JSON. Messages that implement this should // way they are marshaled to JSON. Messages that implement this should
// also implement JSONPBUnmarshaler so that the custom format can be // also implement JSONPBUnmarshaler so that the custom format can be
// parsed. // parsed.
// //
// The JSON marshaling must follow the proto to JSON specification: // The JSON marshaling must follow the proto to JSON specification:
// https://developers.google.com/protocol-buffers/docs/proto3#json // https://developers.google.com/protocol-buffers/docs/proto3#json
type JSONPBMarshaler interface { type JSONPBmarshaler interface {
MarshalJSONPB(*Marshaler) ([]byte, error) MarshalJSONPB(*Marshaler) ([]byte, error)
} }
// JSONPBUnmarshaler is implemented by protobuf messages that customize // JSONPBunmarshaler is implemented by protobuf messages that customize
// the way they are unmarshaled from JSON. Messages that implement this // the way they are unmarshaled from JSON. Messages that implement this
// should also implement JSONPBMarshaler so that the custom format can be // should also implement JSONPBMarshaler so that the custom format can be
// produced. // produced.
// //
// The JSON unmarshaling must follow the JSON to proto specification: // The JSON unmarshaling must follow the JSON to proto specification:
// https://developers.google.com/protocol-buffers/docs/proto3#json // https://developers.google.com/protocol-buffers/docs/proto3#json
type JSONPBUnmarshaler interface { type JSONPBunmarshaler interface {
UnmarshalJSONPB(*Unmarshaler, []byte) error UnmarshalJSONPB(*Unmarshaler, []byte) error
} }
...@@ -171,7 +171,7 @@ type wkt interface { ...@@ -171,7 +171,7 @@ type wkt interface {
// marshalObject writes a struct to the Writer. // marshalObject writes a struct to the Writer.
func (m *Marshaler) marshalObject(out *errWriter, v proto.Message, indent, typeURL string) error { func (m *Marshaler) marshalObject(out *errWriter, v proto.Message, indent, typeURL string) error {
if jsm, ok := v.(JSONPBMarshaler); ok { if jsm, ok := v.(JSONPBmarshaler); ok {
b, err := jsm.MarshalJSONPB(m) b, err := jsm.MarshalJSONPB(m)
if err != nil { if err != nil {
return err return err
...@@ -727,7 +727,7 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe ...@@ -727,7 +727,7 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe
if targetType.Kind() == reflect.Ptr { if targetType.Kind() == reflect.Ptr {
// If input value is "null" and target is a pointer type, then the field should be treated as not set // If input value is "null" and target is a pointer type, then the field should be treated as not set
// UNLESS the target is structpb.Value, in which case it should be set to structpb.NullValue. // UNLESS the target is structpb.Value, in which case it should be set to structpb.NullValue.
_, isJSONPBUnmarshaler := target.Interface().(JSONPBUnmarshaler) _, isJSONPBUnmarshaler := target.Interface().(JSONPBunmarshaler)
if string(inputValue) == "null" && targetType != reflect.TypeOf(&stpb.Value{}) && !isJSONPBUnmarshaler { if string(inputValue) == "null" && targetType != reflect.TypeOf(&stpb.Value{}) && !isJSONPBUnmarshaler {
return nil return nil
} }
...@@ -736,7 +736,7 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe ...@@ -736,7 +736,7 @@ func (u *Unmarshaler) unmarshalValue(target reflect.Value, inputValue json.RawMe
return u.unmarshalValue(target.Elem(), inputValue, prop) return u.unmarshalValue(target.Elem(), inputValue, prop)
} }
if jsu, ok := target.Addr().Interface().(JSONPBUnmarshaler); ok { if jsu, ok := target.Addr().Interface().(JSONPBunmarshaler); ok {
return jsu.UnmarshalJSONPB(u, []byte(inputValue)) return jsu.UnmarshalJSONPB(u, []byte(inputValue))
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
//消息队列本身可插拔,可以支持各种队列 //消息队列本身可插拔,可以支持各种队列
//同时共识模式也是可以插拔的。 //同时共识模式也是可以插拔的。
//rpc 服务也是可以插拔的 //rpc 服务也是可以插拔的
package cli package cli
import ( import (
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// package testnode 提供一个通用的测试节点,用于单元测试和集成测试。 // package testnode 提供一个通用的测试节点,用于单元测试和集成测试。
package testnode package testnode
import ( import (
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
bip39 "github.com/33cn/chain33/wallet/bipwallet/go-bip39" bip39 "github.com/33cn/chain33/wallet/bipwallet/go-bip39"
bip44 "github.com/33cn/chain33/wallet/bipwallet/go-bip44" bip44 "github.com/33cn/chain33/wallet/bipwallet/go-bip44"
"github.com/33cn/chain33/wallet/bipwallet/transformer" "github.com/33cn/chain33/wallet/bipwallet/transformer"
_ "github.com/33cn/chain33/wallet/bipwallet/transformer/btcbase" _ "github.com/33cn/chain33/wallet/bipwallet/transformer/btcbase" //register btcbase package
) )
// https://github.com/satoshilabs/slips/blob/master/slip-0044.md // https://github.com/satoshilabs/slips/blob/master/slip-0044.md
......
...@@ -156,7 +156,9 @@ func GetPrivkeyBySeed(db dbm.DB, seed string) (string, error) { ...@@ -156,7 +156,9 @@ func GetPrivkeyBySeed(db dbm.DB, seed string) (string, error) {
} }
index = backupindex + 1 index = backupindex + 1
} }
if SignType != 1 && SignType != 2 {
return "", types.ErrNotSupport
}
//secp256k1 //secp256k1
if SignType == 1 { if SignType == 1 {
...@@ -204,10 +206,6 @@ func GetPrivkeyBySeed(db dbm.DB, seed string) (string, error) { ...@@ -204,10 +206,6 @@ func GetPrivkeyBySeed(db dbm.DB, seed string) (string, error) {
//seedlog.Error("GetPrivkeyBySeed", "index", index, "secretKey", secretKey, "publicKey", publicKey) //seedlog.Error("GetPrivkeyBySeed", "index", index, "secretKey", secretKey, "publicKey", publicKey)
Hexsubprivkey = secretKey Hexsubprivkey = secretKey
} else if SignType == 3 { //sm2
return "", types.ErrNotSupport
} else {
return "", types.ErrNotSupport
} }
// back up index in db // back up index in db
var pubkeyindex []byte var pubkeyindex []byte
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
func (wallet *Wallet) ProcRecvMsg() { func (wallet *Wallet) ProcRecvMsg() {
defer wallet.wg.Done() defer wallet.wg.Done()
for msg := range wallet.client.Recv() { for msg := range wallet.client.Recv() {
walletlog.Debug("wallet recv", "msg", types.GetEventName(int(msg.Ty)), "Id", msg.Id) walletlog.Debug("wallet recv", "msg", types.GetEventName(int(msg.Ty)), "Id", msg.ID)
beg := types.Now() beg := types.Now()
reply, err := wallet.ExecWallet(&msg) reply, err := wallet.ExecWallet(&msg)
if err != nil { if err != nil {
...@@ -23,7 +23,7 @@ func (wallet *Wallet) ProcRecvMsg() { ...@@ -23,7 +23,7 @@ func (wallet *Wallet) ProcRecvMsg() {
} else { } else {
msg.Reply(wallet.api.NewMessage("", 0, reply)) msg.Reply(wallet.api.NewMessage("", 0, reply))
} }
walletlog.Debug("end process", "msg.id", msg.Id, "cost", types.Since(beg)) walletlog.Debug("end process", "msg.id", msg.ID, "cost", types.Since(beg))
} }
} }
......
...@@ -458,10 +458,10 @@ func (wallet *Wallet) ProcImportPrivKey(PrivKey *types.ReqWalletImportPrivkey) ( ...@@ -458,10 +458,10 @@ func (wallet *Wallet) ProcImportPrivKey(PrivKey *types.ReqWalletImportPrivkey) (
if Account.Privkey == Encrypteredstr { if Account.Privkey == Encrypteredstr {
walletlog.Error("ProcImportPrivKey Privkey is exist in wallet!") walletlog.Error("ProcImportPrivKey Privkey is exist in wallet!")
return nil, types.ErrPrivkeyExist return nil, types.ErrPrivkeyExist
} else { }
walletlog.Error("ProcImportPrivKey!", "Account.Privkey", Account.Privkey, "input Privkey", PrivKey.Privkey) walletlog.Error("ProcImportPrivKey!", "Account.Privkey", Account.Privkey, "input Privkey", PrivKey.Privkey)
return nil, types.ErrPrivkey return nil, types.ErrPrivkey
}
} }
var walletaccount types.WalletAccount var walletaccount types.WalletAccount
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment