Unverified Commit 2dae7da6 authored by pengjun's avatar pengjun Committed by GitHub

Merge pull request #7 from 33cn/master

update
parents c8145960 97383193
......@@ -73,7 +73,7 @@ linter_test: ## Use gometalinter check code, for local test
@find . -name '*.sh' -not -path "./vendor/*" | xargs shellcheck
ineffassign:
@golangci-lint run --no-config --issues-exit-code=1 --deadline=2m --disable-all --enable=ineffassign -n ./...
@golangci-lint run --no-config --issues-exit-code=1 --deadline=2m --disable-all --enable=ineffassign ./...
race: ## Run data race detector
@go test -parallel=8 -race -short `go list ./... | grep -v "pbft"`
......
......@@ -14,7 +14,7 @@ https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/6874
### 环境
```
需要安装golang1.12 or latest
需要安装golang1.13 or latest
```
......
......@@ -6,29 +6,40 @@ DAPP_TEST_COMMON=dapp-test-common.sh
function dapp_test_rpc() {
local ip=$1
local node3=$2
echo "============ # dapp rpc test begin ============="
if [ -d dapptest ]; then
cp "$DAPP_TEST_COMMON" dapptest/
cd dapptest || return
rm -f "jobs.log"
rm -f "jobsTicket.log"
rm -rf "outdir"
dapps=$(find . -maxdepth 1 -type d ! -name dapptest ! -name autonomy ! -name . | sed 's/^\.\///' | sort)
dapps=$(find . -maxdepth 1 -type d ! -name dapptest ! -name ticket ! -name x2ethereum ! -name . | sed 's/^\.\///' | sort)
echo "dapps list: $dapps"
set +e
parallel -k --jobs 40 --results outdir --joblog ./jobs.log ./{}/"${RPC_TESTFILE}" "$ip" ::: "$dapps"
parallel -k --jobs 40 --results outdir --joblog ./jobs.log ./{}/"${RPC_TESTFILE}" "$ip" "$node3" ::: "$dapps"
local ret=$?
parallel -k --jobs 1 --results outdir --joblog ./jobsTicket.log ./{}/"${RPC_TESTFILE}" "$ip" ::: "ticket"
local retTicket=$?
if [ $ret -ne 0 ]; then
wrongdapps=$(awk '{print $7,$9 }' jobs.log | grep -a 1 | awk -F '/' '{print $2}')
parallel -k 'cat ./outdir/1/{}/stderr; cat ./outdir/1/{}/stdout' ::: "$wrongdapps"
fi
if [ $retTicket -ne 0 ]; then
wrongdapps=$(awk '{print $7,$9 }' jobsTicket.log | grep -a 1 | awk -F '/' '{print $2}')
parallel -k 'cat ./outdir/1/{}/stderr; cat ./outdir/1/{}/stdout' ::: "$wrongdapps"
fi
echo "============ # check dapps test log: ============="
cat ./jobs.log
cat ./jobsTicket.log
set -e
if [ $ret -ne 0 ]; then
if [ $ret -ne 0 ] || [ $retTicket -ne 0 ]; then
exit 1
fi
fi
echo "============ # dapp rpc test end ============="
}
......@@ -101,7 +101,7 @@ function main() {
echo "============ run main end ================="
find . -maxdepth 1 -type d -name "*-ci" -exec rm -rf {} \;
dir=$(find . -maxdepth 1 -type d ! -name system ! -name . | sed 's/^\.\///')
dir=$(find . -maxdepth 1 -type d ! -name system ! -name x2ethereum ! -name . | sed 's/^\.\///')
for app in $dir; do
run_single_app "${app}" "$TESTCASEFILE" "down"
done
......
......@@ -469,7 +469,7 @@ function rpc_test() {
if [ "$DAPP" == "" ]; then
system_test_rpc "http://${1}:8801"
dapp_test_address "${CLI}"
dapp_test_rpc "http://${1}:8801"
dapp_test_rpc "http://${1}:8801" "${NODE3}"
fi
if [ "$DAPP" == "paracross" ]; then
system_test_rpc "http://${1}:8901"
......
......@@ -44,6 +44,15 @@ enableReExecLocal=true
enableReduceLocaldb=true
enablePushSubscribe=false
# 关闭分片存储,默认false为开启分片存储;平行链不需要分片需要修改此默认参数为true
disableShard=false
# 分片存储中每个大块包含的区块数
chunkblockNum=1000
# 使能从P2pStore中获取数据
enableFetchP2pstore=false
# 使能假设已删除已归档数据后,获取数据情况
enableIfDelLocalChunk=false
[p2p]
# p2p类型
types=["dht", "gossip"]
......@@ -70,6 +79,16 @@ useGithub=true
innerBounds=300
[p2p.sub.dht]
seeds=[]
port=13803
maxConnectNum=100
# 禁止通过局域网发现节点
disableFindLANPeers=false
# 配置为全节点模式,全节点保存所有分片数据
isFullNode=true
# 若本节点不是全节点,则需要配置全节点地址,当在分片网络中查不到数据时,会到全节点上获取数据
# 格式: "/ip4/139.196.46.175/tcp/13803/p2p/16Uiu2HAkvnDRF8HQTTU5Uu5GmtbLDrgPxCwgVsn2QQ9VEU7Eiwjw"
fullNodes=[]
......
......@@ -3,7 +3,7 @@ module github.com/33cn/plugin
go 1.12
require (
github.com/33cn/chain33 v0.0.0-20200703030312-6b32b7a3906e
github.com/33cn/chain33 v0.0.0-20200729032621-0fbd543868cf
github.com/BurntSushi/toml v0.3.1
github.com/NebulousLabs/Sia v1.3.7
github.com/NebulousLabs/errors v0.0.0-20181203160057-9f787ce8f69e // indirect
......
......@@ -3,6 +3,10 @@ github.com/33cn/chain33 v0.0.0-20200701103614-378175ebb161 h1:z2I+MDFv6MVtOoXIgc
github.com/33cn/chain33 v0.0.0-20200701103614-378175ebb161/go.mod h1:O/rG4/H1wdbLOTrlyIub2DJ5AOx7K0nTTlMKjUigQs0=
github.com/33cn/chain33 v0.0.0-20200703030312-6b32b7a3906e h1:xlToOWpjGdHZOIdU4IwQeT9/MlARIZVfuoUbjWSHhoY=
github.com/33cn/chain33 v0.0.0-20200703030312-6b32b7a3906e/go.mod h1:O/rG4/H1wdbLOTrlyIub2DJ5AOx7K0nTTlMKjUigQs0=
github.com/33cn/chain33 v0.0.0-20200722112403-3023e3680a1c h1:MG8my11GnT5QoYsxQAcR9kQy6jexKGKSurlNhidOUgs=
github.com/33cn/chain33 v0.0.0-20200722112403-3023e3680a1c/go.mod h1:O/rG4/H1wdbLOTrlyIub2DJ5AOx7K0nTTlMKjUigQs0=
github.com/33cn/chain33 v0.0.0-20200729032621-0fbd543868cf h1:eoI7Y5DTbRkK3yE6d5lLSDw6sKl/FBwnhGWbRJjSF9M=
github.com/33cn/chain33 v0.0.0-20200729032621-0fbd543868cf/go.mod h1:O/rG4/H1wdbLOTrlyIub2DJ5AOx7K0nTTlMKjUigQs0=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 h1:HD8gA2tkByhMAwYaFAX9w2l7vxvBQ5NMoxDrkhqhtn4=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
......
......@@ -7,7 +7,7 @@ path="${2}"
function filterLinter() {
res=$(
golangci-lint run --no-config --issues-exit-code=1 --deadline=2m --disable-all \
golangci-lint run --no-config --issues-exit-code=0 --deadline=2m --disable-all \
--enable=gofmt \
--enable=gosimple \
--enable=deadcode \
......@@ -18,7 +18,8 @@ function filterLinter() {
--enable=goimports \
--enable=misspell \
--enable=golint \
--exclude=underscores
--exclude=underscores \
--exclude-use-default=false
)
if [[ ${#res} -gt "0" ]]; then
echo -e "${res}"
......
......@@ -785,7 +785,7 @@ func (client *Client) GetNode() *Node {
return client.node
}
//比较newBlock是不是最优区块
//CmpBestBlock 比较newBlock是不是最优区块
func (client *Client) CmpBestBlock(newBlock *types.Block, cmpBlock *types.Block) bool {
return false
}
......@@ -109,6 +109,12 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
subcfg.WriteBlockSeconds = poolMainBlockSec
}
//最初平行链toml GenesisBlockTime=1514533394,但是未被使用,一直使用的内置的1514533390,最新版本开始适配cfg.GenesisBlockTime,并且
//时间也缺省改为1514533390,支持修改时间, 如果有以前的旧的配置未修改,panic强制修改
if cfg.GenesisBlockTime == 1514533394 {
panic("para chain GenesisBlockTime need be modified to 1514533390 or other")
}
emptyInterval, err := parseEmptyBlockInterval(subcfg.EmptyBlockInterval)
if err != nil {
panic("para EmptyBlockInterval config not correct")
......@@ -240,6 +246,7 @@ func (client *client) InitBlock() {
if client.cfg.GenesisBlockTime > 0 {
newblock.BlockTime = client.cfg.GenesisBlockTime
}
newblock.ParentHash = zeroHash[:]
newblock.MainHash = mainHash
......@@ -327,14 +334,14 @@ func (client *client) ProcEvent(msg *queue.Message) bool {
plog.Error("paracross ProcEvent decode", "ty", types.EventReceiveSubData)
return true
}
plog.Info("paracross ProcEvent from", "from", req.GetFrom(), "topic:", req.GetTopic(), "ty", sub.GetTy())
plog.Info("paracross ProcEvent", "from", req.GetFrom(), "topic:", req.GetTopic(), "ty", sub.GetTy())
switch sub.GetTy() {
case P2pSubCommitTx:
go client.blsSignCli.rcvCommitTx(sub.GetCommitTx())
case P2pSubLeaderSyncMsg:
err := client.blsSignCli.rcvLeaderSyncTx(sub.GetSyncMsg())
if err != nil {
plog.Info("paracross ProcEvent leader sync msg", "err", err)
plog.Error("paracross ProcEvent leader sync msg", "err", err)
}
default:
plog.Error("paracross ProcEvent not support", "ty", sub.GetTy())
......
......@@ -13,6 +13,7 @@ import (
const (
P2pSubCommitTx = 1
P2pSubLeaderSyncMsg = 2
moduleName = "consensus"
)
func (client *client) sendP2PMsg(ty int64, data interface{}) ([]byte, error) {
......@@ -40,14 +41,29 @@ func (client *client) SendPubP2PMsg(topic string, msg []byte) error {
}
func (client *client) SendSubP2PTopic(topic string) error {
data := &types.SubTopic{Topic: topic, Module: "consensus"}
data := &types.SubTopic{Topic: topic, Module: moduleName}
_, err := client.sendP2PMsg(types.EventSubTopic, data)
return err
}
func (client *client) SendRmvP2PTopic(topic string) error {
data := &types.RemoveTopic{Topic: topic, Module: "consensus"}
data := &types.RemoveTopic{Topic: topic, Module: moduleName}
_, err := client.sendP2PMsg(types.EventRemoveTopic, data)
return err
}
func (client *client) SendFetchP2PTopic() (*types.TopicList, error) {
data := &types.FetchTopicList{Module: moduleName}
msg, err := client.sendP2PMsg(types.EventFetchTopics, data)
if err != nil {
return nil, errors.Wrap(err, "reply fail")
}
var reply types.TopicList
err = types.Decode(msg, &reply)
if err != nil {
return nil, errors.Wrap(err, "decode fail")
}
return &reply, err
}
......@@ -314,15 +314,15 @@ func TestParseEmptyBlockInterval(t *testing.T) {
assert.Equal(t, defaultEmptyBlockInterval, ret[0].interval)
cfg = []string{"10:50", "20-30"}
ret, err = parseEmptyBlockInterval(cfg)
_, err = parseEmptyBlockInterval(cfg)
assert.NotNil(t, err)
cfg = []string{"10:50", "20:"}
ret, err = parseEmptyBlockInterval(cfg)
_, err = parseEmptyBlockInterval(cfg)
assert.NotNil(t, err)
cfg = []string{"10:50", ":20"}
ret, err = parseEmptyBlockInterval(cfg)
_, err = parseEmptyBlockInterval(cfg)
assert.NotNil(t, err)
//mess sequence
......
......@@ -101,6 +101,11 @@ out:
}
case <-watchDogTicker:
//排除不在Nodegroup里面的Node
if !b.isValidNodes(b.selfID) {
plog.Info("procLeaderSync watchdog, not in nodegroup", "self", b.selfID)
continue
}
//至少1分钟内要收到leader喂狗消息,否则认为leader挂了,index++
if atomic.LoadUint32(&b.feedDog) == 0 {
nodes, leader, _, off, _ := b.getLeaderInfo()
......@@ -140,10 +145,10 @@ func (b *blsClient) rcvLeaderSyncTx(sync *pt.LeaderSyncInfo) error {
}
//如果leader节点冲突,取大者
if isLeader && off > sync.Offset {
return errors.Wrapf(types.ErrNotSync, "self leader off=%d bigger than sync=%d", off, sync.Offset)
return errors.Wrapf(types.ErrNotSync, "self is leader, off=%d bigger than peer sync=%d", off, sync.Offset)
}
//更新同步过来的最新offset 高度
atomic.StoreInt32(&b.leaderOffset, sync.Offset)
atomic.CompareAndSwapInt32(&b.leaderOffset, b.leaderOffset, sync.Offset)
//两节点不同步则不喂狗,以防止非同步或作恶节点喂狗
atomic.StoreUint32(&b.feedDog, 1)
......@@ -151,6 +156,10 @@ func (b *blsClient) rcvLeaderSyncTx(sync *pt.LeaderSyncInfo) error {
}
func (b *blsClient) getLeaderInfo() ([]string, int32, int32, int32, bool) {
//在未同步前 不处理聚合消息
if !b.paraClient.commitMsgClient.isSync() {
return nil, 0, 0, 0, false
}
nodes, _ := b.getSuperNodes()
if len(nodes) <= 0 {
return nil, 0, 0, 0, false
......@@ -538,8 +547,15 @@ func (b *blsClient) showTxBuffInfo() *pt.ParaBlsSignSumInfo {
b.mutex.Lock()
defer b.mutex.Unlock()
var seq []int64
var ret pt.ParaBlsSignSumInfo
reply, err := b.paraClient.SendFetchP2PTopic()
if err != nil {
plog.Error("fetch p2p topic", "err", err)
}
ret.Topics = append(ret.Topics, reply.Topics...)
var seq []int64
for k := range b.commitsPool {
seq = append(seq, k)
}
......
......@@ -149,6 +149,10 @@ func (client *commitMsgClient) updateChainHeightNotify(height int64, isDel bool)
client.createCommitTx()
}
func (client *commitMsgClient) setInitChainHeight(height int64) {
atomic.StoreInt64(&client.chainHeight, height)
}
// reset notify 提供重设发送参数,发送tx的入口
func (client *commitMsgClient) resetNotify() {
client.resetCh <- 1
......@@ -831,7 +835,7 @@ func (client *commitMsgClient) getSelfConsensus() (*pt.ParacrossStatus, error) {
Param: types.Encode(&types.Int64{Data: block.Height}),
})
if err != nil {
plog.Error("getSelfConsensusStatus.GetSelfConsOneStage ", "err", err.Error())
plog.Debug("getSelfConsensusStatus.GetSelfConsOneStage ", "err", err.Error())
return nil, err
}
stage, ok := ret.(*pt.SelfConsensStage)
......@@ -987,10 +991,14 @@ func (client *commitMsgClient) fetchPriKey() error {
req := &types.ReqString{Data: client.authAccount}
resp, err := client.paraClient.GetAPI().ExecWalletFunc("wallet", "DumpPrivkey", req)
if err != nil {
plog.Error("para fetchPriKey dump priKey", "err", err)
return err
}
str := resp.(*types.ReplyString).Data
priKey, err := getSecpPriKey(str)
if err != nil {
plog.Error("para commit msg get priKey", "err", err)
plog.Error("para fetchPriKey get priKey", "err", err)
return err
}
......
......@@ -573,4 +573,14 @@ func (client *blockSyncClient) syncInit() {
if err != nil {
client.printError(err)
}
//设置初始chainHeight,及时发送共识,不然需要等到再产生一个新块才发送
lastBlock, err := client.paraClient.getLastBlockInfo()
if err != nil {
//取已执行最新区块发生错误,不做任何操作
plog.Info("Para sync init", "err", err)
} else {
client.paraClient.commitMsgClient.setInitChainHeight(lastBlock.Height)
}
}
......@@ -147,7 +147,7 @@ func (client *Client) readReply() {
}
//比较newBlock是不是最优区块
//CmpBestBlock 比较newBlock是不是最优区块
func (client *Client) CmpBestBlock(newBlock *types.Block, cmpBlock *types.Block) bool {
return false
}
......@@ -95,13 +95,19 @@ func (client *Client) SetQueueClient(c queue.Client) {
client.InitBlock()
})
go client.EventLoop()
if !client.IsMining() {
rlog.Info("enter sync mode")
return
}
go client.readCommits(client.commitC, client.errorC)
go client.pollingTask()
}
// Close method
func (client *Client) Close() {
client.cancel()
if client.cancel != nil {
client.cancel()
}
rlog.Info("consensus raft closed")
}
......@@ -253,7 +259,7 @@ func (client *Client) pollingTask() {
}
}
//比较newBlock是不是最优区块
//CmpBestBlock 比较newBlock是不是最优区块
func (client *Client) CmpBestBlock(newBlock *types.Block, cmpBlock *types.Block) bool {
return false
}
......@@ -71,8 +71,9 @@ poolCacheSize=10240
[consensus]
# 共识驱动名,支持solo/raft/ticket/tendermint/pbft
name="raft"
minerstart=false
minerstart=true
genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
genesisBlockTime=1514533394
[mver.consensus]
fundKeyAddr = "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
......
......@@ -11,6 +11,7 @@ import (
log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/queue"
drivers "github.com/33cn/chain33/system/consensus"
"github.com/33cn/chain33/types"
"github.com/coreos/etcd/raft/raftpb"
)
......@@ -50,6 +51,15 @@ func init() {
// NewRaftCluster create raft cluster
func NewRaftCluster(cfg *types.Consensus, sub []byte) queue.Module {
genesis = cfg.Genesis
genesisBlockTime = cfg.GenesisBlockTime
if !cfg.Minerstart {
rlog.Info("node only sync block")
c := drivers.NewBaseClient(cfg)
client := &Client{BaseClient: c}
c.SetChild(client)
return client
}
rlog.Info("Start to create raft cluster")
var subcfg subConfig
if sub != nil {
......
......@@ -68,6 +68,7 @@ type raftNode struct {
restartC chan struct{}
}
//Node ...
type Node struct {
*raftNode
}
......
......@@ -133,7 +133,7 @@ func (cs *ConsensusState) SetBroadcastChannel(broadcastChannel chan<- MsgInfo) {
cs.broadcastChannel = broadcastChannel
}
// SetBroadcastChannel method
// SetUnicastChannel method
func (cs *ConsensusState) SetUnicastChannel(unicastChannel chan<- MsgInfo) {
cs.unicastChannel = unicastChannel
}
......
......@@ -316,7 +316,7 @@ func (node *Node) BroadcastRoutine() {
}
}
// BroadcastRoutine receive to broadcast
// UnicastRoutine receive to broadcast
func (node *Node) UnicastRoutine() {
for {
msg, ok := <-node.unicastChannel
......
......@@ -17,6 +17,7 @@ var (
stateKey = []byte("stateKey")
)
//ConsensusStore ...
type ConsensusStore struct {
db dbm.DB
}
......@@ -30,7 +31,7 @@ func NewConsensusStore() *ConsensusStore {
}
}
// LoadStateFromStore
// LoadStateFromStore ...
func (cs *ConsensusStore) LoadStateFromStore() *tmtypes.State {
buf, err := cs.db.Get(stateKey)
if err != nil {
......@@ -45,7 +46,7 @@ func (cs *ConsensusStore) LoadStateFromStore() *tmtypes.State {
return state
}
// LoadStateHeight
// LoadStateHeight ...
func (cs *ConsensusStore) LoadStateHeight() int64 {
state := cs.LoadStateFromStore()
if state == nil {
......
......@@ -12,6 +12,7 @@ import (
"github.com/33cn/chain33/types"
)
//authbls register
const (
AuthBLS = 259
)
......@@ -31,9 +32,10 @@ var (
var (
ttlog = log15.New("module", "tendermint-types")
// ConsensusCrypto define
//ConsensusCrypto define
ConsensusCrypto crypto.Crypto
CryptoName string
//CryptoName ...
CryptoName string
// SignMap define sign type
SignMap = map[string]int{
"secp256k1": types.SECP256K1,
......
......@@ -796,7 +796,7 @@ func getTxHashes(txs []*types.Transaction) (hashes [][]byte) {
return hashes
}
//比较newBlock是不是最优区块,目前ticket主要是比较挖矿交易的难度系数
//CmpBestBlock 比较newBlock是不是最优区块,目前ticket主要是比较挖矿交易的难度系数
func (client *Client) CmpBestBlock(newBlock *types.Block, cmpBlock *types.Block) bool {
cfg := client.GetAPI().GetConfig()
......
......@@ -14,6 +14,7 @@ import (
"github.com/phoreproject/bls/g1pubs"
)
//setting
const (
BLSPrivateKeyLength = 32
BLSPublicKeyLength = 48
......
......@@ -120,9 +120,11 @@ func TestAccountManager(t *testing.T) {
_, err = Exec_QueryAccountByAddr(Nodes[1], stateDB, kvdb)
assert.Equal(t, err, nil)
tx2, err := CreateRegister(&et.Register{AccountID: "harrylee2015"}, PrivKeyC)
assert.Nil(t, err)
err = Exec_Block(t, stateDB, kvdb, env, tx2)
assert.Equal(t, err, et.ErrAccountIDExist)
tx3, err := CreateRegister(&et.Register{AccountID: "harrylee2020"}, PrivKeyC)
assert.Nil(t, err)
Exec_Block(t, stateDB, kvdb, env, tx3)
//转账
tx4, err := CreateTransfer(&et.Transfer{FromAccountID: "harrylee2015", ToAccountID: "harrylee2020", Asset: &types.Asset{Exec: "coins", Symbol: "bty", Amount: 1e8}}, PrivKeyB)
......@@ -133,6 +135,7 @@ func TestAccountManager(t *testing.T) {
tx5, err := CreateReset(&et.ResetKey{Addr: "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs", AccountID: "harrylee2015"}, PrivKeyA)
assert.Equal(t, err, nil)
err = Exec_Block(t, stateDB, kvdb, env, tx5)
assert.Nil(t, err)
//在锁定期内撤回请求
tx6, err := CreateApply(&et.Apply{Op: et.RevokeReset, AccountID: "harrylee2015"}, PrivKeyB)
assert.Equal(t, err, nil)
......@@ -142,11 +145,13 @@ func TestAccountManager(t *testing.T) {
tx5, err = CreateReset(&et.ResetKey{Addr: "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs", AccountID: "harrylee2015"}, PrivKeyA)
assert.Equal(t, err, nil)
err = Exec_Block(t, stateDB, kvdb, env, tx5)
assert.Nil(t, err)
time.Sleep(time.Second)
//过了锁定期,申请生效
tx6, err = CreateApply(&et.Apply{Op: et.EnforceReset, AccountID: "harrylee2015"}, PrivKeyD)
assert.Equal(t, err, nil)
err = Exec_Block(t, stateDB, kvdb, env, tx6)
assert.Nil(t, err)
tx7, _ := CreateTransfer(&et.Transfer{FromAccountID: "harrylee2015", ToAccountID: "harrylee2015", Asset: &types.Asset{Exec: "coins", Symbol: "bty", Amount: 1e8}}, PrivKeyD)
err = Exec_Block(t, stateDB, kvdb, env, tx7)
......
......@@ -42,6 +42,7 @@ type Action struct {
api client.QueueProtocolAPI
}
//NewAction ...
func NewAction(e *Accountmanager, tx *types.Transaction, index int) *Action {
hash := tx.Hash()
fromaddr := tx.From()
......@@ -60,6 +61,7 @@ func (a *Action) GetKVSet(account *et.Account) (kvset []*types.KeyValue) {
return kvset
}
//Register ...
func (a *Action) Register(payload *et.Register) (*types.Receipt, error) {
var logs []*types.ReceiptLog
account1, err := findAccountByID(a.localDB, payload.AccountID)
......@@ -90,7 +92,7 @@ func (a *Action) Register(payload *et.Register) (*types.Receipt, error) {
return receipts, nil
}
//为了避免别人恶意重置别人的帐号,这个操作仅有系统管理员有权限去操作
//Reset 为了避免别人恶意重置别人的帐号,这个操作仅有系统管理员有权限去操作
func (a *Action) Reset(payload *et.ResetKey) (*types.Receipt, error) {
var logs []*types.ReceiptLog
cfg := a.api.GetConfig()
......@@ -116,6 +118,8 @@ func (a *Action) Reset(payload *et.ResetKey) (*types.Receipt, error) {
receipts := &types.Receipt{Ty: types.ExecOk, KV: nil, Logs: logs}
return receipts, nil
}
//Transfer ...
func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kvs []*types.KeyValue
......@@ -193,6 +197,7 @@ func (a *Action) Transfer(payload *et.Transfer) (*types.Receipt, error) {
return receipts, nil
}
//Supervise ...
func (a *Action) Supervise(payload *et.Supervise) (*types.Receipt, error) {
//鉴权,看一下地址是否时管理员地址
cfg := a.api.GetConfig()
......@@ -235,6 +240,7 @@ func (a *Action) Supervise(payload *et.Supervise) (*types.Receipt, error) {
return receipts, nil
}
//Apply ...
func (a *Action) Apply(payload *et.Apply) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kvs []*types.KeyValue
......
......@@ -31,6 +31,7 @@ func InitExecType() {
ety.InitFuncList(types.ListMethod(&Accountmanager{}))
}
//Accountmanager ...
type Accountmanager struct {
drivers.DriverBase
}
......@@ -47,6 +48,7 @@ func GetName() string {
return newAccountmanager().GetName()
}
//GetDriverName ...
func (a *Accountmanager) GetDriverName() string {
return driverName
}
......@@ -82,6 +84,7 @@ func (a *Accountmanager) CheckTx(tx *types.Transaction, index int) error {
return nil
}
//CheckAccountIDIsExist ...
func (a *Accountmanager) CheckAccountIDIsExist(accountID string) bool {
_, err := findAccountByID(a.GetLocalDB(), accountID)
return err != types.ErrNotFound
......
......@@ -10,26 +10,31 @@ import (
* 关键数据上链(statedb)并生成交易回执(log)
*/
//Exec_Register ...
func (a *Accountmanager) Exec_Register(payload *aty.Register, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(a, tx, index)
return action.Register(payload)
}
//Exec_ResetKey ...
func (a *Accountmanager) Exec_ResetKey(payload *aty.ResetKey, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(a, tx, index)
return action.Reset(payload)
}
//Exec_Transfer ...
func (a *Accountmanager) Exec_Transfer(payload *aty.Transfer, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(a, tx, index)
return action.Transfer(payload)
}
//Exec_Supervise ...
func (a *Accountmanager) Exec_Supervise(payload *aty.Supervise, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(a, tx, index)
return action.Supervise(payload)
}
//Exec_Apply ...
func (a *Accountmanager) Exec_Apply(payload *aty.Apply, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(a, tx, index)
return action.Apply(payload)
......
......@@ -10,6 +10,7 @@ import (
* 非关键数据,本地存储(localDB), 用于辅助查询,效率高
*/
//ExecLocal_Register ...
func (a *Accountmanager) ExecLocal_Register(payload *et.Register, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.Ty == types.ExecOk {
......@@ -36,6 +37,8 @@ func (a *Accountmanager) ExecLocal_Register(payload *et.Register, tx *types.Tran
}
return a.addAutoRollBack(tx, dbSet.KV), nil
}
//ExecLocal_ResetKey ...
func (a *Accountmanager) ExecLocal_ResetKey(payload *et.ResetKey, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.Ty == types.ExecOk {
......@@ -62,6 +65,7 @@ func (a *Accountmanager) ExecLocal_ResetKey(payload *et.ResetKey, tx *types.Tran
return a.addAutoRollBack(tx, dbSet.KV), nil
}
//ExecLocal_Apply ...
func (a *Accountmanager) ExecLocal_Apply(payload *et.Apply, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.Ty == types.ExecOk {
......@@ -88,6 +92,7 @@ func (a *Accountmanager) ExecLocal_Apply(payload *et.Apply, tx *types.Transactio
return a.addAutoRollBack(tx, dbSet.KV), nil
}
//ExecLocal_Transfer ...
func (a *Accountmanager) ExecLocal_Transfer(payload *et.Transfer, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.Ty == types.ExecOk {
......@@ -114,6 +119,7 @@ func (a *Accountmanager) ExecLocal_Transfer(payload *et.Transfer, tx *types.Tran
return a.addAutoRollBack(tx, dbSet.KV), nil
}
//ExecLocal_Supervise ...
func (a *Accountmanager) ExecLocal_Supervise(payload *et.Supervise, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
if receiptData.Ty == types.ExecOk {
......
......@@ -5,27 +5,27 @@ import (
et "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
//根据ID查询账户信息
//Query_QueryAccountByID 根据ID查询账户信息
func (a *Accountmanager) Query_QueryAccountByID(in *et.QueryAccountByID) (types.Message, error) {
return findAccountByID(a.GetLocalDB(), in.AccountID)
}
//根据ID查询账户信息
//Query_QueryAccountByAddr 根据ID查询账户信息
func (a *Accountmanager) Query_QueryAccountByAddr(in *et.QueryAccountByAddr) (types.Message, error) {
return findAccountByAddr(a.GetLocalDB(), in.Addr)
}
//根据状态查询账户列表|| 账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
//Query_QueryAccountsByStatus 根据状态查询账户列表|| 账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
func (a *Accountmanager) Query_QueryAccountsByStatus(in *et.QueryAccountsByStatus) (types.Message, error) {
return findAccountListByStatus(a.GetLocalDB(), in.Status, in.Direction, in.PrimaryKey)
}
//查询逾期注销的账户列表
//Query_QueryExpiredAccounts 查询逾期注销的账户列表
func (a *Accountmanager) Query_QueryExpiredAccounts(in *et.QueryExpiredAccounts) (types.Message, error) {
return findAccountListByIndex(a.GetLocalDB(), in.ExpiredTime, in.PrimaryKey)
}
//根据ID查询账户余额
//Query_QueryBalanceByID 根据ID查询账户余额
func (a *Accountmanager) Query_QueryBalanceByID(in *et.QueryBalanceByID) (types.Message, error) {
return queryBalanceByID(a.GetStateDB(), a.GetLocalDB(), a.GetAPI().GetConfig(), a.GetName(), in)
}
......@@ -35,6 +35,7 @@ func calcAccountKey(accountID string) []byte {
return []byte(key)
}
//NewAccountTable ...
func NewAccountTable(kvdb db.KV) *table.Table {
rowmeta := NewAccountRow()
table, err := table.NewTable(rowmeta, kvdb, opt_account)
......@@ -44,7 +45,7 @@ func NewAccountTable(kvdb db.KV) *table.Table {
return table
}
//account table meta 结构
//AccountRow account table meta 结构
type AccountRow struct {
*aty.Account
}
......
......@@ -67,13 +67,15 @@ const (
RevokeReset
EnforceReset
)
//list ...
const (
ListDESC = int32(0)
ListASC = int32(1)
ListSeek = int32(2)
)
const (
//单次list还回条数
//Count 单次list还回条数
Count = int32(10)
)
......@@ -117,10 +119,12 @@ func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(AccountmanagerX, NewType(cfg))
}
//AccountmanagerType ...
type AccountmanagerType struct {
types.ExecTypeBase
}
//NewType ...
func NewType(cfg *types.Chain33Config) *AccountmanagerType {
c := &AccountmanagerType{}
c.SetChild(c)
......@@ -133,7 +137,7 @@ func (a *AccountmanagerType) GetPayload() types.Message {
return &AccountmanagerAction{}
}
// GeTypeMap 获取合约action的id和name信息
// GetTypeMap 获取合约action的id和name信息
func (a *AccountmanagerType) GetTypeMap() map[string]int32 {
return actionMap
}
......
......@@ -36,6 +36,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Autonomy{}))
......
......@@ -19,10 +19,12 @@ func init() {
types.RegExec(name, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(AutonomyX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(AutonomyX, NewType(cfg))
}
......
......@@ -30,6 +30,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Blackwhite{}))
......
......@@ -28,11 +28,13 @@ func init() {
types.RegExec(BlackwhiteX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(BlackwhiteX, "ForkBlackWhiteV2", 900000)
cfg.RegisterDappFork(BlackwhiteX, "Enable", 850000)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(BlackwhiteX, NewType(cfg))
}
......
......@@ -23,10 +23,12 @@ func init() {
types.RegExec(CertX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(CertX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(CertX, NewType(cfg))
}
......
......@@ -49,6 +49,7 @@ func addCollateralizeCreateFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("balance")
}
//CollateralizeCreate ...
func CollateralizeCreate(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -88,6 +89,7 @@ func addCollateralizeBorrowFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("value")
}
//CollateralizeBorrow ...
func CollateralizeBorrow(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -130,6 +132,7 @@ func addCollateralizeAppendFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("value")
}
//CollateralizeAppend ...
func CollateralizeAppend(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -171,6 +174,7 @@ func addCollateralizeRepayFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("recordID")
}
//CollateralizeRepay ...
func CollateralizeRepay(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -211,6 +215,7 @@ func addCollateralizePriceFeedFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("volume")
}
//CollateralizePriceFeed ...
func CollateralizePriceFeed(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -233,7 +238,7 @@ func CollateralizePriceFeed(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
// CollateralizeCloseRawTxCmd 生成开始交易命令行
// CollateralizeRetrieveRawTxCmd 生成开始交易命令行
func CollateralizeRetrieveRawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "retrieve",
......@@ -251,6 +256,7 @@ func addCollateralizeRetrieveFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("balance")
}
//CollateralizeRetrieve ...
func CollateralizeRetrieve(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -292,6 +298,7 @@ func addCollateralizeManageFlags(cmd *cobra.Command) {
cmd.Flags().Float64P("totalBalance", "t", 0, "totalBalance")
}
//CollateralizeManage ...
func CollateralizeManage(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -318,6 +325,7 @@ func CollateralizeManage(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
//CollateralizeQueryCfgCmd ...
func CollateralizeQueryCfgCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "config",
......@@ -327,6 +335,7 @@ func CollateralizeQueryCfgCmd() *cobra.Command {
return cmd
}
//CollateralizeQueryConfig ...
func CollateralizeQueryConfig(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
......@@ -339,6 +348,7 @@ func CollateralizeQueryConfig(cmd *cobra.Command, args []string) {
ctx.Run()
}
//CollateralizeQueryPriceCmd ...
func CollateralizeQueryPriceCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "price",
......@@ -348,6 +358,7 @@ func CollateralizeQueryPriceCmd() *cobra.Command {
return cmd
}
//CollateralizeQueryPrice ...
func CollateralizeQueryPrice(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
......@@ -360,6 +371,7 @@ func CollateralizeQueryPrice(cmd *cobra.Command, args []string) {
ctx.Run()
}
//CollateralizeQueryUserBalanceCmd ...
func CollateralizeQueryUserBalanceCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "balance",
......@@ -375,6 +387,7 @@ func addCollateralizeQueryBalanceFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("address")
}
//CollateralizeQueryUserBalance ...
func CollateralizeQueryUserBalance(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
addr, _ := cmd.Flags().GetString("address")
......@@ -417,6 +430,7 @@ func addCollateralizeQueryFlags(cmd *cobra.Command) {
cmd.Flags().StringP("borrowID", "b", "", "borrow ID")
}
//CollateralizeQuery ...
func CollateralizeQuery(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
collateralizeID, _ := cmd.Flags().GetString("collateralizeID")
......
......@@ -14,6 +14,7 @@ import (
var clog = log.New("module", "execs.collateralize")
var driverName = pty.CollateralizeX
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Collateralize{}))
......
......@@ -499,6 +499,7 @@ func TestCollateralize(t *testing.T) {
res, err = exec.Query("CollateralizeRecordByStatus",
types.Encode(&pkt.ReqCollateralizeRecordByStatus{CollateralizeId: common.ToHex(collateralizeID), Status: 4}))
assert.Nil(t, res)
assert.NotNil(t, err)
p81 := &pkt.CollateralizeFeedTx{}
p81.Price = append(p81.Price, 0.5)
......@@ -566,9 +567,11 @@ func TestCollateralize(t *testing.T) {
res, err = exec.Query("CollateralizeRecordByStatus",
types.Encode(&pkt.ReqCollateralizeRecordByStatus{CollateralizeId: common.ToHex(collateralizeID), Status: 4}))
assert.Nil(t, res)
assert.NotNil(t, err)
res, err = exec.Query("CollateralizeRecordByStatus",
types.Encode(&pkt.ReqCollateralizeRecordByStatus{CollateralizeId: common.ToHex(collateralizeID), Status: 1}))
assert.Nil(t, res)
assert.NotNil(t, err)
// expire liquidate
p10 := &pkt.CollateralizeBorrowTx{
......
......@@ -25,6 +25,7 @@ const (
MaxCount = int32(100) // 最多取100条
)
//setting
const (
Coin = types.Coin // 1e8
DefaultDebtCeiling = 10000 * Coin // 默认借贷限额
......@@ -63,19 +64,19 @@ func Key(id string) (key []byte) {
return key
}
// Key for CollateralizeConfig
//ConfigKey Key for CollateralizeConfig
func ConfigKey() (key []byte) {
key = append(key, []byte("mavl-"+pty.CollateralizeX+"-config")...)
return key
}
// Key for CollateralizeAddrConfig
//AddrKey Key for CollateralizeAddrConfig
func AddrKey() (key []byte) {
key = append(key, []byte("mavl-"+issuanceE.IssuanceX+"-addr")...)
return key
}
// Key for IssuancePriceFeed
//PriceKey Key for IssuancePriceFeed
func PriceKey() (key []byte) {
key = append(key, []byte("mavl-"+pty.CollateralizeX+"-price")...)
return key
......@@ -193,7 +194,7 @@ func (action *Action) GetFeedReceiptLog(collateralize *pty.Collateralize, record
return log
}
// GetCloseReceiptLog generate logs for Collateralize close action
// GetRetrieveReceiptLog generate logs for Collateralize close action
func (action *Action) GetRetrieveReceiptLog(collateralize *pty.Collateralize) *types.ReceiptLog {
log := &types.ReceiptLog{}
log.Ty = pty.TyLogCollateralizeRetrieve
......@@ -236,7 +237,7 @@ func getLatestExpireTime(coll *pty.Collateralize) int64 {
return latest
}
// CollateralizeConfig 设置全局借贷参数(管理员权限)
// CollateralizeManage 设置全局借贷参数(管理员权限)
func (action *Action) CollateralizeManage(manage *pty.CollateralizeManage) (*types.Receipt, error) {
var kv []*types.KeyValue
var receipt *types.Receipt
......@@ -505,7 +506,7 @@ func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActiv
return false
}
// CheckExecAccount 检查账户token余额
// CheckExecTokenAccount 检查账户token余额
func (action *Action) CheckExecTokenAccount(addr string, amount int64, isFrozen bool) bool {
acc := action.tokenAccount.LoadExecAccount(addr, action.execaddr)
if isFrozen {
......
......@@ -27,7 +27,7 @@ func (c *Collateralize) Exec_Repay(payload *pty.CollateralizeRepay, tx *types.Tr
return actiondb.CollateralizeRepay(payload)
}
// Exec_Repay Action
// Exec_Append Action
func (c *Collateralize) Exec_Append(payload *pty.CollateralizeAppend, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewCollateralizeAction(c, tx, index)
return actiondb.CollateralizeAppend(payload)
......@@ -45,7 +45,7 @@ func (c *Collateralize) Exec_Retrieve(payload *pty.CollateralizeRetrieve, tx *ty
return actiondb.CollateralizeRetrieve(payload)
}
// Exec_Close Action
// Exec_Manage Action
func (c *Collateralize) Exec_Manage(payload *pty.CollateralizeManage, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewCollateralizeAction(c, tx, index)
return actiondb.CollateralizeManage(payload)
......
......@@ -86,7 +86,7 @@ func (c *Collateralize) ExecLocal_Repay(payload *pty.CollateralizeRepay, tx *typ
return c.execLocal(tx, receiptData)
}
// ExecLocal_Repay Action
// ExecLocal_Append Action
func (c *Collateralize) ExecLocal_Append(payload *pty.CollateralizeAppend, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return c.execLocal(tx, receiptData)
}
......
......@@ -9,6 +9,7 @@ import (
pty "github.com/33cn/plugin/plugin/dapp/collateralize/types"
)
//Query_CollateralizeInfoByID ...
func (c *Collateralize) Query_CollateralizeInfoByID(req *pty.ReqCollateralizeInfo) (types.Message, error) {
coll, err := queryCollateralizeByID(c.GetStateDB(), req.CollateralizeId)
if err != nil {
......@@ -34,6 +35,7 @@ func (c *Collateralize) Query_CollateralizeInfoByID(req *pty.ReqCollateralizeInf
return info, nil
}
//Query_CollateralizeInfoByIDs ...
func (c *Collateralize) Query_CollateralizeInfoByIDs(req *pty.ReqCollateralizeInfos) (types.Message, error) {
infos := &pty.RepCollateralizeCurrentInfos{}
for _, id := range req.CollateralizeIds {
......@@ -64,6 +66,7 @@ func (c *Collateralize) Query_CollateralizeInfoByIDs(req *pty.ReqCollateralizeIn
return infos, nil
}
//Query_CollateralizeByStatus ...
func (c *Collateralize) Query_CollateralizeByStatus(req *pty.ReqCollateralizeByStatus) (types.Message, error) {
ids := &pty.RepCollateralizeIDs{}
collIDRecords, err := queryCollateralizeByStatus(c.GetLocalDB(), req.Status, req.CollID)
......@@ -76,6 +79,7 @@ func (c *Collateralize) Query_CollateralizeByStatus(req *pty.ReqCollateralizeByS
return ids, nil
}
//Query_CollateralizeByAddr ...
func (c *Collateralize) Query_CollateralizeByAddr(req *pty.ReqCollateralizeByAddr) (types.Message, error) {
ids := &pty.RepCollateralizeIDs{}
collIDRecords, err := queryCollateralizeByAddr(c.GetLocalDB(), req.Addr, req.Status, req.CollID)
......@@ -88,6 +92,7 @@ func (c *Collateralize) Query_CollateralizeByAddr(req *pty.ReqCollateralizeByAdd
return ids, nil
}
//Query_CollateralizeRecordByID ...
func (c *Collateralize) Query_CollateralizeRecordByID(req *pty.ReqCollateralizeRecord) (types.Message, error) {
ret := &pty.RepCollateralizeRecord{}
issuRecord, err := queryCollateralizeRecordByID(c.GetStateDB(), req.CollateralizeId, req.RecordId)
......@@ -100,6 +105,7 @@ func (c *Collateralize) Query_CollateralizeRecordByID(req *pty.ReqCollateralizeR
return ret, nil
}
//Query_CollateralizeRecordByAddr ...
func (c *Collateralize) Query_CollateralizeRecordByAddr(req *pty.ReqCollateralizeRecordByAddr) (types.Message, error) {
ret := &pty.RepCollateralizeRecords{}
records, err := queryCollateralizeRecordByAddr(c.GetStateDB(), c.GetLocalDB(), req.Addr, req.Status, req.CollateralizeId, req.RecordId)
......@@ -120,6 +126,7 @@ func (c *Collateralize) Query_CollateralizeRecordByAddr(req *pty.ReqCollateraliz
return ret, nil
}
//Query_CollateralizeRecordByStatus ...
func (c *Collateralize) Query_CollateralizeRecordByStatus(req *pty.ReqCollateralizeRecordByStatus) (types.Message, error) {
ret := &pty.RepCollateralizeRecords{}
records, err := queryCollateralizeRecordByStatus(c.GetStateDB(), c.GetLocalDB(), req.Status, req.CollateralizeId, req.RecordId)
......@@ -132,6 +139,7 @@ func (c *Collateralize) Query_CollateralizeRecordByStatus(req *pty.ReqCollateral
return ret, nil
}
//Query_CollateralizeConfig ...
func (c *Collateralize) Query_CollateralizeConfig(req *pty.ReqCollateralizeRecordByAddr) (types.Message, error) {
config, err := getCollateralizeConfig(c.GetStateDB())
if err != nil {
......@@ -158,6 +166,7 @@ func (c *Collateralize) Query_CollateralizeConfig(req *pty.ReqCollateralizeRecor
return ret, nil
}
//Query_CollateralizePrice ...
func (c *Collateralize) Query_CollateralizePrice(req *pty.ReqCollateralizeRecordByAddr) (types.Message, error) {
price, err := getLatestPrice(c.GetStateDB())
if err != nil {
......@@ -168,6 +177,7 @@ func (c *Collateralize) Query_CollateralizePrice(req *pty.ReqCollateralizeRecord
return &pty.RepCollateralizePrice{Price: price}, nil
}
//Query_CollateralizeUserBalance ...
func (c *Collateralize) Query_CollateralizeUserBalance(req *pty.ReqCollateralizeRecordByAddr) (types.Message, error) {
balance, err := queryCollateralizeUserBalance(c.GetStateDB(), c.GetLocalDB(), req.Addr)
if err != nil {
......
......@@ -24,11 +24,13 @@ func init() {
types.RegExec(CollateralizeX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(CollateralizeX, "Enable", 0)
cfg.RegisterDappFork(CollateralizeX, ForkCollateralizeTableUpdate, 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(CollateralizeX, NewType(cfg))
}
......
......@@ -16,7 +16,7 @@ var opt = &table.Option{
Index: []string{"status", "addr", "addr_status"},
}
//NewTable 新建表
//NewCollateralizeTable 新建表
func NewCollateralizeTable(kvdb db.KV) *table.Table {
rowmeta := NewCollatetalizeRow()
table, err := table.NewTable(rowmeta, kvdb, opt)
......@@ -31,7 +31,7 @@ type CollatetalizeRow struct {
*ReceiptCollateralize
}
//NewIssuanceRow 新建一个meta 结构
//NewCollatetalizeRow 新建一个meta 结构
func NewCollatetalizeRow() *CollatetalizeRow {
return &CollatetalizeRow{ReceiptCollateralize: &ReceiptCollateralize{}}
}
......@@ -81,12 +81,12 @@ func NewRecordTable(kvdb db.KV) *table.Table {
return table
}
//CollatetalizeRow table meta 结构
//CollateralizeRecordRow table meta 结构
type CollateralizeRecordRow struct {
*ReceiptCollateralize
}
//NewIssuanceRow 新建一个meta 结构
//NewRecordRow 新建一个meta 结构
func NewRecordRow() *CollateralizeRecordRow {
return &CollateralizeRecordRow{ReceiptCollateralize: &ReceiptCollateralize{}}
}
......
......@@ -24,7 +24,7 @@ type CollateralizeRepayTx struct {
Fee int64 `json:"fee"`
}
// CollateralizeAppednTx for construction
// CollateralizeAppendTx for construction
type CollateralizeAppendTx struct {
CollateralizeID string `json:"collateralizeId"`
RecordID string `json:"recordID"`
......
......@@ -43,6 +43,7 @@ const (
// CollateralizeAssetTypeEth
//)
//collater ...
const (
CollateralizeUserStatusCreate = 1 + iota
CollateralizeUserStatusWarning
......@@ -52,6 +53,7 @@ const (
CollateralizeUserStatusClose
)
//fork ...
var (
ForkCollateralizeTableUpdate = "ForkCollateralizeTableUpdate"
)
......@@ -70,6 +70,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&DPos{}))
......
......@@ -1277,6 +1277,10 @@ func (action *Action) RegistTopN(regist *dty.TopNCandidatorRegist) (*types.Recei
}
topNCands, err := action.readTopNCandicators(topNVersion)
if err != nil {
logger.Error("RegistTopN failed readTopNCandicators", "addr", action.fromaddr, "execaddr", action.execaddr, "version", topNVersion)
return nil, types.ErrInvalidParam
}
if topNCands == nil {
topNCands = &dty.TopNCandidators{
Version: topNVersion,
......
......@@ -15,7 +15,7 @@ data: voter
index: FromAddr,Pubkey,Votes,Index,Time
*/
var opt_dpos_voter = &table.Option{
var optDposVoter = &table.Option{
Prefix: "LODB-dpos",
Name: "voter",
Primary: "index",
......@@ -25,7 +25,7 @@ var opt_dpos_voter = &table.Option{
//NewDposVoteTable 新建表
func NewDposVoteTable(kvdb db.KV) *table.Table {
rowmeta := NewDposVoterRow()
table, err := table.NewTable(rowmeta, kvdb, opt_dpos_voter)
table, err := table.NewTable(rowmeta, kvdb, optDposVoter)
if err != nil {
panic(err)
}
......@@ -69,7 +69,7 @@ func (tx *DposVoterRow) Get(key string) ([]byte, error) {
return nil, types.ErrNotFound
}
var opt_dpos_candidator = &table.Option{
var optDposCandidator = &table.Option{
Prefix: "LODB-dpos",
Name: "candidator",
Primary: "pubkey",
......@@ -79,7 +79,7 @@ var opt_dpos_candidator = &table.Option{
//NewDposCandidatorTable 新建表
func NewDposCandidatorTable(kvdb db.KV) *table.Table {
rowmeta := NewDposCandidatorRow()
table, err := table.NewTable(rowmeta, kvdb, opt_dpos_candidator)
table, err := table.NewTable(rowmeta, kvdb, optDposCandidator)
if err != nil {
panic(err)
}
......@@ -121,7 +121,7 @@ func (tx *DposCandidatorRow) Get(key string) ([]byte, error) {
return nil, types.ErrNotFound
}
var opt_dpos_vrfm = &table.Option{
var optDposVrfm = &table.Option{
Prefix: "LODB-dpos",
Name: "vrfm",
Primary: "index",
......@@ -131,7 +131,7 @@ var opt_dpos_vrfm = &table.Option{
//NewDposVrfMTable 新建表
func NewDposVrfMTable(kvdb db.KV) *table.Table {
rowmeta := NewDposVrfMRow()
table, err := table.NewTable(rowmeta, kvdb, opt_dpos_vrfm)
table, err := table.NewTable(rowmeta, kvdb, optDposVrfm)
if err != nil {
panic(err)
}
......@@ -175,7 +175,7 @@ func (tx *DposVrfMRow) Get(key string) ([]byte, error) {
return nil, types.ErrNotFound
}
var opt_dpos_vrfrp = &table.Option{
var optDposVrfrp = &table.Option{
Prefix: "LODB-dpos",
Name: "vrfrp",
Primary: "index",
......@@ -185,7 +185,7 @@ var opt_dpos_vrfrp = &table.Option{
//NewDposVrfRPTable 新建表
func NewDposVrfRPTable(kvdb db.KV) *table.Table {
rowmeta := NewDposVrfRPRow()
table, err := table.NewTable(rowmeta, kvdb, opt_dpos_vrfrp)
table, err := table.NewTable(rowmeta, kvdb, optDposVrfrp)
if err != nil {
panic(err)
}
......@@ -229,7 +229,7 @@ func (tx *DposVrfRPRow) Get(key string) ([]byte, error) {
return nil, types.ErrNotFound
}
var opt_dpos_cb = &table.Option{
var optDposCb = &table.Option{
Prefix: "LODB-dpos",
Name: "cb",
Primary: "cycle",
......@@ -239,7 +239,7 @@ var opt_dpos_cb = &table.Option{
//NewDposCBTable 新建表
func NewDposCBTable(kvdb db.KV) *table.Table {
rowmeta := NewDposCBRow()
table, err := table.NewTable(rowmeta, kvdb, opt_dpos_cb)
table, err := table.NewTable(rowmeta, kvdb, optDposCb)
if err != nil {
panic(err)
}
......
......@@ -17,10 +17,12 @@ func init() {
types.RegExec(DPosX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(DPosX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(DPosX, NewType(cfg))
}
......
......@@ -42,10 +42,12 @@ func init() {
types.RegExec(EchoX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(EchoX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(EchoX, NewType(cfg))
}
......
......@@ -32,6 +32,7 @@ func init() {
types.RegExec(ExecutorName, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(ExecutorName, EVMEnable, 500000)
// EVM合约中的数据分散存储,支持大数据量
......@@ -44,6 +45,7 @@ func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(ExecutorName, ForkEVMFrozen, 1300000)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(ExecutorName, NewType(cfg))
}
......
......@@ -35,6 +35,7 @@ type exchange struct {
drivers.DriverBase
}
//NewExchange ...
func NewExchange() drivers.Driver {
t := &exchange{}
t.SetChild(t)
......@@ -47,6 +48,7 @@ func GetName() string {
return NewExchange().GetName()
}
//GetDriverName ...
func (e *exchange) GetDriverName() string {
return driverName
}
......
......@@ -186,12 +186,14 @@ func TestExchange(t *testing.T) {
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"}, RightAsset: &et.Asset{Execer: "paracross", Symbol: "coins.bty"}, Price: 50000000, Amount: 10 * types.Coin, Op: et.OpSell}, PrivKeyA, stateDB, kvdb, env)
//根据地址状态查看订单
orderList, err = Exec_QueryOrderList(et.Ordered, Nodes[0], "", stateDB, kvdb)
assert.Nil(t, err)
orderID3 := orderList.List[0].OrderID
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"},
RightAsset: &et.Asset{Execer: "paracross", Symbol: "coins.bty"}, Price: 50000000, Amount: 10 * types.Coin, Op: et.OpSell}, PrivKeyA, stateDB, kvdb, env)
//根据地址状态查看订单
orderList, err = Exec_QueryOrderList(et.Ordered, Nodes[0], "", stateDB, kvdb)
assert.Nil(t, err)
orderID4 := orderList.List[0].OrderID
//根据op查询市场深度
......@@ -244,11 +246,13 @@ func TestExchange(t *testing.T) {
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"},
RightAsset: &et.Asset{Execer: "token", Symbol: "CCNY"}, Price: 400000000, Amount: 5 * types.Coin, Op: et.OpBuy}, PrivKeyD, stateDB, kvdb, env)
orderList, err = Exec_QueryOrderList(et.Ordered, Nodes[3], "", stateDB, kvdb)
assert.Nil(t, err)
orderID6 := orderList.List[0].OrderID
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"},
RightAsset: &et.Asset{Execer: "token", Symbol: "CCNY"}, Price: 300000000, Amount: 10 * types.Coin, Op: et.OpSell}, PrivKeyC, stateDB, kvdb, env)
orderList, err = Exec_QueryOrderList(et.Ordered, Nodes[2], "", stateDB, kvdb)
assert.Nil(t, err)
orderID7 := orderList.List[0].OrderID
//此时订单6应该被吃掉
......@@ -266,10 +270,12 @@ func TestExchange(t *testing.T) {
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"},
RightAsset: &et.Asset{Execer: "token", Symbol: "CCNY"}, Price: 400000000, Amount: 5 * types.Coin, Op: et.OpSell}, PrivKeyC, stateDB, kvdb, env)
orderList, err = Exec_QueryOrderList(et.Ordered, Nodes[2], "", stateDB, kvdb)
assert.Nil(t, err)
orderID8 := orderList.List[0].OrderID
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"},
RightAsset: &et.Asset{Execer: "token", Symbol: "CCNY"}, Price: 500000000, Amount: 5 * types.Coin, Op: et.OpSell}, PrivKeyC, stateDB, kvdb, env)
orderList, err = Exec_QueryOrderList(et.Ordered, Nodes[2], "", stateDB, kvdb)
assert.Nil(t, err)
orderID9 := orderList.List[0].OrderID
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"},
......@@ -277,7 +283,7 @@ func TestExchange(t *testing.T) {
orderList, err = Exec_QueryOrderList(et.Ordered, Nodes[3], "", stateDB, kvdb)
//orderID10 := orderList.List[0].OrderID
assert.Equal(t, 5*types.Coin, orderList.List[0].Balance)
assert.Nil(t, err)
//order7和order8价格在吃单范围内
order, err = Exec_QueryOrder(orderID7, stateDB, kvdb)
assert.Equal(t, nil, err)
......@@ -300,9 +306,11 @@ func TestExchange(t *testing.T) {
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"},
RightAsset: &et.Asset{Execer: "token", Symbol: "CCNY"}, Price: 100000000, Amount: 2 * types.Coin, Op: et.OpSell}, PrivKeyC, stateDB, kvdb, env)
orderList, err = Exec_QueryOrderList(et.Completed, Nodes[2], "", stateDB, kvdb)
assert.Nil(t, err)
Exec_LimitOrder(t, &et.LimitOrder{LeftAsset: &et.Asset{Symbol: "bty", Execer: "coins"},
RightAsset: &et.Asset{Execer: "token", Symbol: "CCNY"}, Price: 100000000, Amount: 8 * types.Coin, Op: et.OpSell}, PrivKeyC, stateDB, kvdb, env)
orderList, err = Exec_QueryOrderList(et.Ordered, Nodes[2], "", stateDB, kvdb)
assert.Nil(t, err)
orderID10 := orderList.List[0].OrderID
assert.Equal(t, int32(et.Ordered), orderList.List[0].Status)
assert.Equal(t, 5*types.Coin, orderList.List[0].Balance)
......
......@@ -26,6 +26,7 @@ type Action struct {
api client.QueueProtocolAPI
}
//NewAction ...
func NewAction(e *exchange, tx *types.Transaction, index int) *Action {
hash := tx.Hash()
fromaddr := tx.From()
......@@ -45,7 +46,7 @@ func (a *Action) GetKVSet(order *et.Order) (kvset []*types.KeyValue) {
return kvset
}
//反转
//OpSwap 反转
func (a *Action) OpSwap(op int32) int32 {
if op == et.OpBuy {
return et.OpSell
......@@ -53,7 +54,7 @@ func (a *Action) OpSwap(op int32) int32 {
return et.OpBuy
}
//计算实际花费
//CalcActualCost 计算实际花费
func CalcActualCost(op int32, amount int64, price int64) int64 {
if op == et.OpBuy {
return SafeMul(amount, price)
......@@ -61,13 +62,15 @@ func CalcActualCost(op int32, amount int64, price int64) int64 {
return amount
}
//price 精度允许范围 1<=price<=1e16 整数
//CheckPrice price 精度允许范围 1<=price<=1e16 整数
func CheckPrice(price int64) bool {
if price > 1e16 || price < 1 {
return false
}
return true
}
//CheckOp ...
func CheckOp(op int32) bool {
if op == et.OpBuy || op == et.OpSell {
return true
......@@ -75,11 +78,12 @@ func CheckOp(op int32) bool {
return false
}
//CheckCount ...
func CheckCount(count int32) bool {
return count <= 20 && count >= 0
}
//最小交易1e8
//CheckAmount 最小交易1e8
func CheckAmount(amount int64) bool {
if amount < types.Coin || amount >= types.MaxCoin {
return false
......@@ -87,6 +91,7 @@ func CheckAmount(amount int64) bool {
return true
}
//CheckDirection ...
func CheckDirection(direction int32) bool {
if direction == et.ListASC || direction == et.ListDESC {
return true
......@@ -94,6 +99,7 @@ func CheckDirection(direction int32) bool {
return false
}
//CheckStatus ...
func CheckStatus(status int32) bool {
if status == et.Ordered || status == et.Completed || status == et.Revoked {
return true
......@@ -101,7 +107,7 @@ func CheckStatus(status int32) bool {
return false
}
//检查交易得资产是否合法
//CheckExchangeAsset 检查交易得资产是否合法
func CheckExchangeAsset(left, right *et.Asset) bool {
if left.Execer == "" || left.Symbol == "" || right.Execer == "" || right.Symbol == "" {
return false
......@@ -111,6 +117,8 @@ func CheckExchangeAsset(left, right *et.Asset) bool {
}
return true
}
//LimitOrder ...
func (a *Action) LimitOrder(payload *et.LimitOrder) (*types.Receipt, error) {
leftAsset := payload.GetLeftAsset()
rightAsset := payload.GetRightAsset()
......@@ -161,6 +169,7 @@ func (a *Action) LimitOrder(payload *et.LimitOrder) (*types.Receipt, error) {
return nil, fmt.Errorf("unknow op")
}
//RevokeOrder ...
func (a *Action) RevokeOrder(payload *et.RevokeOrder) (*types.Receipt, error) {
var logs []*types.ReceiptLog
var kvs []*types.KeyValue
......@@ -539,7 +548,7 @@ func findOrderIDListByPrice(localdb dbm.KV, left, right *et.Asset, price int64,
return &orderList, nil
}
//买单深度是按价格倒序,由高到低
//Direction 买单深度是按价格倒序,由高到低
func Direction(op int32) int32 {
if op == et.OpBuy {
return et.ListDESC
......@@ -547,7 +556,7 @@ func Direction(op int32) int32 {
return et.ListASC
}
//这里primaryKey当作主键索引来用,首次查询不需要填值,买单按价格由高往低,卖单按价格由低往高查询
//QueryMarketDepth 这里primaryKey当作主键索引来用,首次查询不需要填值,买单按价格由高往低,卖单按价格由低往高查询
func QueryMarketDepth(localdb dbm.KV, left, right *et.Asset, op int32, primaryKey string, count int32) (*et.MarketDepthList, error) {
table := NewMarketDepthTable(localdb)
prefix := []byte(fmt.Sprintf("%s:%s:%d", left.GetSymbol(), right.GetSymbol(), op))
......@@ -623,7 +632,7 @@ HERE:
return &orderList, nil
}
//QueryOrderList,默认展示最新的
//QueryOrderList 默认展示最新的
func QueryOrderList(localdb dbm.KV, addr string, status, count, direction int32, primaryKey string) (types.Message, error) {
var table *tab.Table
if status == et.Completed || status == et.Revoked {
......@@ -671,7 +680,7 @@ func queryMarketDepth(localdb dbm.KV, left, right *et.Asset, op int32, price int
return row.Data.(*et.MarketDepth), nil
}
//math库中的安全大数乘法,防溢出
//SafeMul math库中的安全大数乘法,防溢出
func SafeMul(x, y int64) int64 {
res := big.NewInt(0).Mul(big.NewInt(x), big.NewInt(y))
res = big.NewInt(0).Div(res, big.NewInt(types.Coin))
......
......@@ -277,6 +277,8 @@ func (e *exchange) updateMatchOrders(marketTable, orderTable, historyTable *tabl
}
return nil
}
//OpSwap ...
func OpSwap(op int32) int32 {
if op == ety.OpBuy {
return ety.OpSell
......
......@@ -50,7 +50,7 @@ var opt_exchange_history = &table.Option{
Index: []string{"name", "addr_status"},
}
//NewTable 新建表
//NewMarketDepthTable 新建表
func NewMarketDepthTable(kvdb db.KV) *table.Table {
rowmeta := NewMarketDepthRow()
table, err := table.NewTable(rowmeta, kvdb, opt_exchange_depth)
......@@ -60,6 +60,7 @@ func NewMarketDepthTable(kvdb db.KV) *table.Table {
return table
}
//NewMarketOrderTable ...
func NewMarketOrderTable(kvdb db.KV) *table.Table {
rowmeta := NewOrderRow()
table, err := table.NewTable(rowmeta, kvdb, opt_exchange_order)
......@@ -69,6 +70,7 @@ func NewMarketOrderTable(kvdb db.KV) *table.Table {
return table
}
//NewHistoryOrderTable ...
func NewHistoryOrderTable(kvdb db.KV) *table.Table {
rowmeta := NewHistoryOrderRow()
table, err := table.NewTable(rowmeta, kvdb, opt_exchange_history)
......@@ -88,7 +90,7 @@ func NewOrderRow() *OrderRow {
return &OrderRow{Order: &ety.Order{}}
}
//CreateRow
//CreateRow ...
func (r *OrderRow) CreateRow() *table.Row {
return &table.Row{Data: &ety.Order{}}
}
......@@ -119,10 +121,12 @@ type HistoryOrderRow struct {
*ety.Order
}
//NewHistoryOrderRow ...
func NewHistoryOrderRow() *HistoryOrderRow {
return &HistoryOrderRow{Order: &ety.Order{Value: &ety.Order_LimitOrder{LimitOrder: &ety.LimitOrder{}}}}
}
//CreateRow ...
func (m *HistoryOrderRow) CreateRow() *table.Row {
return &table.Row{Data: &ety.Order{Value: &ety.Order_LimitOrder{LimitOrder: &ety.LimitOrder{}}}}
}
......@@ -148,12 +152,12 @@ func (m *HistoryOrderRow) Get(key string) ([]byte, error) {
return nil, types.ErrNotFound
}
//marketDepthRow table meta 结构
//MarketDepthRow table meta 结构
type MarketDepthRow struct {
*ety.MarketDepth
}
//NewOracleRow 新建一个meta 结构
//NewMarketDepthRow 新建一个meta 结构
func NewMarketDepthRow() *MarketDepthRow {
return &MarketDepthRow{MarketDepth: &ety.MarketDepth{}}
}
......
......@@ -5,6 +5,7 @@ import (
"github.com/golang/protobuf/proto"
)
//Cli interface
type Cli interface {
Send(tx *types.Transaction, hexKey string) ([]*types.ReceiptLog, error)
Query(fn string, msg proto.Message) ([]byte, error)
......
......@@ -8,6 +8,7 @@ import (
et "github.com/33cn/plugin/plugin/dapp/exchange/types"
)
//setting ...
var (
cli *test.GRPCCli
PrivKeyA = "0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" // 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
......
......@@ -21,6 +21,7 @@ import (
et "github.com/33cn/plugin/plugin/dapp/exchange/types"
)
//ExecCli ...
type ExecCli struct {
ldb db.KVDB
sdb db.DB
......@@ -41,6 +42,7 @@ type ExecCli struct {
accD1 *account.DB
}
//Nodes ...
var (
Nodes = []string{
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4",
......@@ -50,6 +52,7 @@ var (
}
)
//NewExecCli ...
func NewExecCli() *ExecCli {
dir, sdb, ldb := util.CreateTestDB()
log.Println(dir)
......@@ -131,6 +134,7 @@ func NewExecCli() *ExecCli {
}
}
//Send ...
func (c *ExecCli) Send(tx *types.Transaction, hexKey string) ([]*types.ReceiptLog, error) {
var err error
tx, err = types.FormatTx(c.cfg, et.ExchangeX, tx)
......@@ -180,6 +184,7 @@ func (c *ExecCli) Send(tx *types.Transaction, hexKey string) ([]*types.ReceiptLo
return receipt.Logs, nil
}
//Query ...
func (c *ExecCli) Query(fn string, msg proto.Message) ([]byte, error) {
api, _ := client.New(c.q.Client(), nil)
exec := executor.NewExchange()
......@@ -215,6 +220,7 @@ func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error
return tx, nil
}
//GetExecAccount ...
func (c *ExecCli) GetExecAccount(addr string, exec string, symbol string) (*types.Account, error) {
//mavl-{coins}-{bty}-exec-{26htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp}:{1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP}
//mavl-{token}-{ccny}-exec-{26htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp}:{1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP}
......
......@@ -16,10 +16,12 @@ import (
"google.golang.org/grpc"
)
//GRPCCli ...
type GRPCCli struct {
client types.Chain33Client
}
//NewGRPCCli ...
func NewGRPCCli(grpcAddr string) *GRPCCli {
conn, err := grpc.Dial(grpcAddr, grpc.WithInsecure())
if err != nil {
......@@ -34,6 +36,7 @@ func NewGRPCCli(grpcAddr string) *GRPCCli {
}
}
//Send ...
func (c *GRPCCli) Send(tx *types.Transaction, hexKey string) ([]*types.ReceiptLog, error) {
txHash, logs, err := c.sendAndWaitReceipt(tx, hexKey)
if txHash != nil {
......@@ -50,6 +53,7 @@ func (c *GRPCCli) Send(tx *types.Transaction, hexKey string) ([]*types.ReceiptLo
return logs, nil
}
//Query ...
func (c *GRPCCli) Query(fn string, msg proto.Message) ([]byte, error) {
ss := strings.Split(fn, ".")
var in types.ChainExecutor
......@@ -72,6 +76,7 @@ func (c *GRPCCli) Query(fn string, msg proto.Message) ([]byte, error) {
return r.Msg, nil
}
//GetExecAccount ...
func (c *GRPCCli) GetExecAccount(addr string, exec string, symbol string) (*types.Account, error) {
if exec == "coins" {
// bty
......@@ -131,6 +136,7 @@ func (c *GRPCCli) sendAndWaitReceipt(tx *types.Transaction, hexKey string) (txHa
return r.Msg, d.Receipt.Logs, nil
}
//SendTx ...
func (c *GRPCCli) SendTx(tx *types.Transaction, hexKey string) (reply *types.Reply, err error) {
cfg := types.NewChain33Config(types.GetDefaultCfgstring())
cfg.SetTitleOnlyForTest("chain33")
......
......@@ -58,9 +58,9 @@ const (
)
const (
//单次list还回条数
//Count 单次list还回条数
Count = int32(10)
//系统最大撮合深度
//MaxMatchCount 系统最大撮合深度
MaxMatchCount = 100
)
......@@ -100,10 +100,12 @@ func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(ExchangeX, NewType(cfg))
}
//ExchangeType ...
type ExchangeType struct {
types.ExecTypeBase
}
//NewType ...
func NewType(cfg *types.Chain33Config) *ExchangeType {
c := &ExchangeType{}
c.SetChild(c)
......@@ -116,7 +118,7 @@ func (e *ExchangeType) GetPayload() types.Message {
return &ExchangeAction{}
}
// GeTypeMap 获取合约action的id和name信息
// GetTypeMap 获取合约action的id和name信息
func (e *ExchangeType) GetTypeMap() map[string]int32 {
return actionMap
}
......
......@@ -23,6 +23,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Game{}))
......
......@@ -145,6 +145,7 @@ func TestGame(t *testing.T) {
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(matchTx, receiptDate, int(1))
assert.Nil(t, err)
for _, kv := range set.KV {
kvdb.Set(kv.Key, kv.Value)
}
......@@ -163,7 +164,7 @@ func TestGame(t *testing.T) {
}
t.Log(msg)
msg, err = exec.Query(pty.FuncNameQueryGameListByStatusAndAddr, types.Encode(&pty.QueryGameListByStatusAndAddr{
_, err = exec.Query(pty.FuncNameQueryGameListByStatusAndAddr, types.Encode(&pty.QueryGameListByStatusAndAddr{
Status: pty.GameActionMatch}))
if err != nil {
t.Error(err)
......@@ -192,6 +193,7 @@ func TestGame(t *testing.T) {
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(closeTx, receiptDate, int(1))
assert.Nil(t, err)
for _, kv := range set.KV {
kvdb.Set(kv.Key, kv.Value)
}
......@@ -336,6 +338,7 @@ func TestGame(t *testing.T) {
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(matchTx, receiptDate, int(1))
assert.Nil(t, err)
for _, kv := range set.KV {
kvdb.Set(kv.Key, kv.Value)
}
......@@ -363,6 +366,7 @@ func TestGame(t *testing.T) {
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(closeTx, receiptDate, int(1))
assert.Nil(t, err)
for _, kv := range set.KV {
kvdb.Set(kv.Key, kv.Value)
}
......@@ -432,6 +436,7 @@ func TestGame(t *testing.T) {
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(matchTx, receiptDate, int(1))
assert.Nil(t, err)
for _, kv := range set.KV {
kvdb.Set(kv.Key, kv.Value)
}
......@@ -458,6 +463,7 @@ func TestGame(t *testing.T) {
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(closeTx, receiptDate, int(1))
assert.Nil(t, err)
for _, kv := range set.KV {
kvdb.Set(kv.Key, kv.Value)
}
......
......@@ -22,10 +22,12 @@ func init() {
types.RegExec(GameX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(GameX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(GameX, NewType(cfg))
}
......
......@@ -26,6 +26,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Guess{}))
......
......@@ -17,10 +17,12 @@ func init() {
types.RegExec(GuessX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(GuessX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(GuessX, NewType(cfg))
}
......
......@@ -22,6 +22,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Hashlock{}))
......
......@@ -23,11 +23,13 @@ func init() {
types.RegExec(HashlockX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(HashlockX, "Enable", 0)
cfg.RegisterDappFork(HashlockX, ForkBadRepeatSecretX, 2715575)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(HashlockX, NewType(cfg))
}
......
......@@ -51,6 +51,7 @@ func addIssuanceCreateFlags(cmd *cobra.Command) {
cmd.Flags().Uint64P("period", "p", 0, "period")
}
//IssuanceCreate ....
func IssuanceCreate(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -94,6 +95,7 @@ func addIssuanceDebtFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("value")
}
//IssuanceDebt ...
func IssuanceDebt(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -134,6 +136,7 @@ func addIssuanceRepayFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("debtID")
}
//IssuanceRepay ...
func IssuanceRepay(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -174,6 +177,7 @@ func addIssuancePriceFeedFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("volume")
}
//IssuancePriceFeed ...
func IssuancePriceFeed(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -212,6 +216,7 @@ func addIssuanceCloseFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("issuanceID")
}
//IssuanceClose ...
func IssuanceClose(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -249,6 +254,7 @@ func addIssuanceManageFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("addr")
}
//IssuanceManage ...
func IssuanceManage(cmd *cobra.Command, args []string) {
title, _ := cmd.Flags().GetString("title")
cfg := types.GetCliSysParam(title)
......@@ -270,6 +276,7 @@ func IssuanceManage(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal()
}
//IssuacneQueryPriceCmd ...
func IssuacneQueryPriceCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "price",
......@@ -279,6 +286,7 @@ func IssuacneQueryPriceCmd() *cobra.Command {
return cmd
}
//IssuanceQueryPrice ...
func IssuanceQueryPrice(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
......@@ -291,6 +299,7 @@ func IssuanceQueryPrice(cmd *cobra.Command, args []string) {
ctx.Run()
}
//IssuanceQueryUserBalanceCmd ...
func IssuanceQueryUserBalanceCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "balance",
......@@ -306,6 +315,7 @@ func addIssuanceQueryBalanceFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("address")
}
//IssuanceQueryUserBalance ...
func IssuanceQueryUserBalance(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
addr, _ := cmd.Flags().GetString("address")
......@@ -347,6 +357,7 @@ func addIssuanceQueryFlags(cmd *cobra.Command) {
cmd.Flags().StringP("debtID", "d", "", "debt ID")
}
//IssuanceQuery ...
func IssuanceQuery(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
issuanceID, _ := cmd.Flags().GetString("issuanceID")
......
......@@ -15,7 +15,7 @@ func (c *Issuance) Exec_Create(payload *pty.IssuanceCreate, tx *types.Transactio
return actiondb.IssuanceCreate(payload)
}
// Exec_Borrow Action
// Exec_Debt Action
func (c *Issuance) Exec_Debt(payload *pty.IssuanceDebt, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewIssuanceAction(c, tx, index)
return actiondb.IssuanceDebt(payload)
......
......@@ -14,6 +14,7 @@ import (
var clog = log.New("module", "execs.issuance")
var driverName = pty.IssuanceX
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Issuance{}))
......
......@@ -427,6 +427,7 @@ func TestIssuance(t *testing.T) {
res, err = exec.Query("IssuanceRecordsByStatus",
types.Encode(&pkt.ReqIssuanceRecords{Status: 4}))
assert.Nil(t, res)
assert.NotNil(t, err)
p8 := &pkt.IssuanceFeedTx{}
p8.Price = append(p8.Price, 0.5)
......@@ -488,9 +489,11 @@ func TestIssuance(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = exec.Query("IssuanceRecordsByStatus", types.Encode(&pkt.ReqIssuanceRecords{Status: 4}))
assert.NotNil(t, err)
assert.Nil(t, res)
res, err = exec.Query("IssuanceRecordsByStatus", types.Encode(&pkt.ReqIssuanceRecords{Status: 1}))
assert.Nil(t, res)
assert.NotNil(t, err)
// expire liquidate
p9 := &pkt.IssuanceDebtTx{
......
......@@ -23,6 +23,7 @@ const (
MaxCount = int32(100) // 最多取100条
)
//setting
const (
Coin = types.Coin // 1e8
DefaultDebtCeiling = 100000 * Coin // 默认借贷限额
......@@ -139,13 +140,13 @@ func Key(id string) (key []byte) {
return key
}
// Key for IssuanceAddrConfig
// AddrKey for IssuanceAddrConfig
func AddrKey() (key []byte) {
key = append(key, []byte("mavl-"+pty.IssuanceX+"-addr")...)
return key
}
// Key for IssuancePriceFeed
// PriceKey for IssuancePriceFeed
func PriceKey() (key []byte) {
key = append(key, []byte("mavl-"+pty.IssuanceX+"-price")...)
return key
......@@ -288,7 +289,7 @@ func getLatestExpireTime(issu *pty.Issuance) int64 {
return latest
}
// IssuanceConfig 设置全局借贷参数(管理员权限)
// IssuanceManage 设置全局借贷参数(管理员权限)
func (action *Action) IssuanceManage(manage *pty.IssuanceManage) (*types.Receipt, error) {
var kv []*types.KeyValue
var receipt *types.Receipt
......@@ -467,7 +468,7 @@ func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActiv
return false
}
// CheckExecAccount 检查账户token余额
// CheckExecTokenAccount 检查账户token余额
func (action *Action) CheckExecTokenAccount(addr string, amount int64, isFrozen bool) bool {
acc := action.tokenAccount.LoadExecAccount(addr, action.execaddr)
if isFrozen {
......
......@@ -9,6 +9,7 @@ import (
pty "github.com/33cn/plugin/plugin/dapp/issuance/types"
)
//Query_IssuanceInfoByID ...
func (c *Issuance) Query_IssuanceInfoByID(req *pty.ReqIssuanceInfo) (types.Message, error) {
issu, err := queryIssuanceByID(c.GetStateDB(), req.IssuanceId)
if err != nil {
......@@ -30,6 +31,7 @@ func (c *Issuance) Query_IssuanceInfoByID(req *pty.ReqIssuanceInfo) (types.Messa
}, nil
}
//Query_IssuanceInfoByIDs ...
func (c *Issuance) Query_IssuanceInfoByIDs(req *pty.ReqIssuanceInfos) (types.Message, error) {
infos := &pty.RepIssuanceCurrentInfos{}
for _, id := range req.IssuanceIds {
......@@ -56,6 +58,7 @@ func (c *Issuance) Query_IssuanceInfoByIDs(req *pty.ReqIssuanceInfos) (types.Mes
return infos, nil
}
//Query_IssuanceByStatus ...
func (c *Issuance) Query_IssuanceByStatus(req *pty.ReqIssuanceByStatus) (types.Message, error) {
ids := &pty.RepIssuanceIDs{}
issuIDs, err := queryIssuanceByStatus(c.GetLocalDB(), req.Status, req.IssuanceId)
......@@ -68,6 +71,7 @@ func (c *Issuance) Query_IssuanceByStatus(req *pty.ReqIssuanceByStatus) (types.M
return ids, nil
}
//Query_IssuanceRecordByID ...
func (c *Issuance) Query_IssuanceRecordByID(req *pty.ReqIssuanceRecords) (types.Message, error) {
ret := &pty.RepIssuanceDebtInfo{}
issuRecord, err := queryIssuanceRecordByID(c.GetStateDB(), req.IssuanceId, req.DebtId)
......@@ -80,6 +84,7 @@ func (c *Issuance) Query_IssuanceRecordByID(req *pty.ReqIssuanceRecords) (types.
return ret, nil
}
//Query_IssuanceRecordsByAddr ...
func (c *Issuance) Query_IssuanceRecordsByAddr(req *pty.ReqIssuanceRecords) (types.Message, error) {
ret := &pty.RepIssuanceRecords{}
records, err := queryIssuanceRecordByAddr(c.GetStateDB(), c.GetLocalDB(), req.Addr, req.Status, req.DebtId)
......@@ -101,6 +106,7 @@ func (c *Issuance) Query_IssuanceRecordsByAddr(req *pty.ReqIssuanceRecords) (typ
return ret, nil
}
//Query_IssuanceRecordsByStatus ...
func (c *Issuance) Query_IssuanceRecordsByStatus(req *pty.ReqIssuanceRecords) (types.Message, error) {
ret := &pty.RepIssuanceRecords{}
records, err := queryIssuanceRecordsByStatus(c.GetStateDB(), c.GetLocalDB(), req.Status, req.DebtId)
......@@ -113,6 +119,7 @@ func (c *Issuance) Query_IssuanceRecordsByStatus(req *pty.ReqIssuanceRecords) (t
return ret, nil
}
//Query_IssuancePrice ...
func (c *Issuance) Query_IssuancePrice(req *pty.ReqIssuanceRecords) (types.Message, error) {
price, err := getLatestPrice(c.GetStateDB())
if err != nil {
......@@ -123,6 +130,7 @@ func (c *Issuance) Query_IssuancePrice(req *pty.ReqIssuanceRecords) (types.Messa
return &pty.RepIssuancePrice{Price: price}, nil
}
//Query_IssuanceUserBalance ...
func (c *Issuance) Query_IssuanceUserBalance(req *pty.ReqIssuanceRecords) (types.Message, error) {
balance, err := queryIssuanceUserBalance(c.GetStateDB(), c.GetLocalDB(), req.Addr)
if err != nil {
......
......@@ -24,11 +24,13 @@ func init() {
types.RegExec(IssuanceX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(IssuanceX, "Enable", 0)
cfg.RegisterDappFork(IssuanceX, ForkIssuanceTableUpdate, 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(IssuanceX, NewType(cfg))
}
......
......@@ -16,7 +16,7 @@ var opt = &table.Option{
Index: []string{"status"},
}
//NewTable 新建表
//NewIssuanceTable 新建表
func NewIssuanceTable(kvdb db.KV) *table.Table {
rowmeta := NewIssuanceRow()
table, err := table.NewTable(rowmeta, kvdb, opt)
......@@ -77,12 +77,12 @@ func NewRecordTable(kvdb db.KV) *table.Table {
return table
}
//IssuanceRow table meta 结构
//IssuanceRecordRow table meta 结构
type IssuanceRecordRow struct {
*ReceiptIssuance
}
//NewIssuanceRow 新建一个meta 结构
//NewRecordRow 新建一个meta 结构
func NewRecordRow() *IssuanceRecordRow {
return &IssuanceRecordRow{ReceiptIssuance: &ReceiptIssuance{}}
}
......
......@@ -34,6 +34,7 @@ const (
IssuanceStatusClose
)
//status ...
const (
IssuanceUserStatusCreate = 1 + iota
IssuanceUserStatusWarning
......@@ -43,6 +44,7 @@ const (
IssuanceUserStatusClose
)
//type ...
const (
PriceFeedKey = "issuance-price-feed"
GuarantorKey = "issuance-guarantor"
......@@ -50,6 +52,7 @@ const (
FundKey = "issuance-fund"
)
//fork ...
var (
ForkIssuanceTableUpdate = "ForkIssuanceTableUpdate"
)
......@@ -37,6 +37,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&js{}))
......
......@@ -60,10 +60,12 @@ func init() {
types.RegExec(JsX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(JsX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(JsX, NewType(cfg))
}
......
......@@ -36,6 +36,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Lottery{}))
......
......@@ -23,10 +23,12 @@ func init() {
types.RegExec(LotteryX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(LotteryX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(LotteryX, NewType(cfg))
}
......
......@@ -38,6 +38,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&MultiSig{}))
......
......@@ -16,10 +16,12 @@ func init() {
types.RegExec(MultiSigX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(MultiSigX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(MultiSigX, NewType(cfg))
}
......
......@@ -20,6 +20,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&Norm{}))
......
......@@ -17,10 +17,12 @@ func init() {
types.RegExec(NormX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(NormX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(NormX, NewType(cfg))
}
......
......@@ -22,6 +22,7 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
InitExecType()
}
//InitExecType ...
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&oracle{}))
......
......@@ -19,10 +19,12 @@ func init() {
types.RegExec(OracleX, InitExecutor)
}
//InitFork ...
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(OracleX, "Enable", 0)
}
//InitExecutor ...
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(OracleX, NewType(cfg))
}
......
......@@ -252,7 +252,7 @@ function para_configkey() {
function query_tx() {
block_wait "${1}" 1
local times=100
local times=200
while true; do
ret=$(${1} tx query -s "${2}" | jq -r ".tx.hash")
echo "query hash is ${2}, return ${ret} "
......
......@@ -128,7 +128,7 @@ function paracross_Transfer_Withdraw_Inner() {
chain33_SignAndSendTx "$tx_hash" "$privkey" ${UNIT_HTTP}
#4 查询转移后余额状态
local times=100
local times=200
while true; do
para_balance_after=$(paracross_QueryParaBalance "$from_addr" "paracross")
echo "para after transferring:$para_balance_after"
......@@ -156,7 +156,7 @@ function paracross_Transfer_Withdraw_Inner() {
chain33_SignAndSendTx "$tx_hash" "$privkey" ${UNIT_HTTP}
#6 查询取钱后余额状态
local times=100
local times=200
while true; do
para_balance_withdraw_after=$(paracross_QueryParaBalance "$from_addr" "paracross")
echo "para after withdrawing :$para_balance_withdraw_after"
......@@ -165,7 +165,7 @@ function paracross_Transfer_Withdraw_Inner() {
#实际取钱金额
para_withdraw_real=$((para_balance_after - para_balance_withdraw_after))
main_withdraw_real=$((main_balance_withdraw_after - main_balance_after))
if [ "$withdraw_should" != "$para_withdraw_real" ] || [ "$withdraw_should" != "$main_withdraw_real" ]; then
if [ "$withdraw_should" != "$para_withdraw_real" ] && [ "$withdraw_should" != "$main_withdraw_real" ]; then
chain33_BlockWait 2 ${UNIT_HTTP}
times=$((times - 1))
if [ $times -le 0 ]; then
......@@ -320,7 +320,7 @@ function paracross_testTxGroupFail() {
#跨链失败后仍应该有5个,之前transfer到trade的2个应该保持不变
local count=0
local times=100
local times=300
local paracross_execer_name="user.p.para.paracross"
local trade_exec_name="user.p.para.trade"
local transfer_expect="200000000"
......@@ -377,7 +377,7 @@ function paracross_testParaAssetWithdrawFail() {
#跨链失败后仍应该有5个,之前transfer到trade的2个应该保持不变
local count=0
local times=100
local times=300
while true; do
left_exec_val=$(paracross_QueryMainAssetBalance "${game_token_test_addr}" "paracross" "user.p.game.coins.para")
if [ "${left_exec_val}" != $amount_left ]; then
......
......@@ -1305,7 +1305,7 @@ func stagesInfo(cmd *cobra.Command, args []string) {
ctx.Run()
}
// GetParaInfoCmd get para chain status by height
// GetSelfConsStagesCmd get para chain status by height
func GetSelfConsStagesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "all",
......@@ -1331,7 +1331,7 @@ func stageOneInfo(cmd *cobra.Command, args []string) {
ctx.Run()
}
// GetParaInfoCmd get para chain status by height
// GetSelfConsOneStageCmd get para chain status by height
func GetSelfConsOneStageCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "one",
......
......@@ -227,6 +227,7 @@ func makeDoneReceipt(cfg *types.Chain33Config, execMainHeight, execHeight int64,
}
}
//GetMostCommit ...
func GetMostCommit(commits [][]byte) (int, string) {
stats := make(map[string]int)
n := len(commits)
......
......@@ -18,6 +18,7 @@ import (
"github.com/pkg/errors"
)
//SymbolBty ...
const SymbolBty = "bty"
/*
......
......@@ -55,7 +55,7 @@ func (e *Paracross) Exec_AssetWithdraw(payload *types.AssetsWithdraw, tx *types.
return receipt, nil
}
//Exec_ParaAssetTransfer parallel chain asset transfer exec process
//Exec_CrossAssetTransfer parallel chain asset transfer exec process
func (e *Paracross) Exec_CrossAssetTransfer(payload *pt.CrossAssetTransfer, tx *types.Transaction, index int) (*types.Receipt, error) {
_, err := e.checkTxGroup(tx, index)
if err != nil {
......@@ -114,7 +114,7 @@ func (e *Paracross) Exec_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, tx *ty
return a.NodeGroupConfig(payload)
}
//Exec_NodeGroupConfig node group config process
//Exec_SelfStageConfig node group config process
func (e *Paracross) Exec_SelfStageConfig(payload *pt.ParaStageConfig, tx *types.Transaction, index int) (*types.Receipt, error) {
a := newAction(e, tx)
return a.SelfStageConfig(payload)
......
......@@ -159,7 +159,7 @@ func (e *Paracross) ExecDelLocal_AssetWithdraw(payload *types.AssetsWithdraw, tx
return nil, nil
}
//ExecDelLocal_AssetTransfer asset transfer del local db process
//ExecDelLocal_CrossAssetTransfer asset transfer del local db process
func (e *Paracross) ExecDelLocal_CrossAssetTransfer(payload *pt.CrossAssetTransfer, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
var set types.LocalDBSet
r, err := e.initLocalAssetTransfer(tx, true, nil)
......@@ -198,7 +198,7 @@ func (e *Paracross) ExecDelLocal_TransferToExec(payload *types.AssetsTransferToE
return nil, nil
}
//ExecLocal_SelfConsensStageConfig transfer asset to exec local db process
//ExecDelLocal_SelfStageConfig transfer asset to exec local db process
func (e *Paracross) ExecDelLocal_SelfStageConfig(payload *pt.ParaStageConfig, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return e.execAutoDelLocal(tx, receiptData)
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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