Commit 6c0df23b authored by wjx@disanbo.com's avatar wjx@disanbo.com Committed by vipwzw

fix hashlock retrieve lint warning

parent 7e93b4c3
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// HashlockCmd cmds
func HashlockCmd() *cobra.Command { func HashlockCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "hashlock", Use: "hashlock",
...@@ -31,7 +32,7 @@ func HashlockCmd() *cobra.Command { ...@@ -31,7 +32,7 @@ func HashlockCmd() *cobra.Command {
return cmd return cmd
} }
// 锁定 // HashlockLockCmd construct lock tx
func HashlockLockCmd() *cobra.Command { func HashlockLockCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "lock", Use: "lock",
...@@ -96,7 +97,7 @@ func hashlockLockCmd(cmd *cobra.Command, args []string) { ...@@ -96,7 +97,7 @@ func hashlockLockCmd(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// 解锁 // HashlockUnlockCmd construct unlock tx
func HashlockUnlockCmd() *cobra.Command { func HashlockUnlockCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "unlock", Use: "unlock",
...@@ -139,7 +140,7 @@ func hashlockUnlockCmd(cmd *cobra.Command, args []string) { ...@@ -139,7 +140,7 @@ func hashlockUnlockCmd(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// 发送 // HashlockSendCmd construct send tx
func HashlockSendCmd() *cobra.Command { func HashlockSendCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "send", Use: "send",
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
pty "github.com/33cn/plugin/plugin/dapp/hashlock/types" pty "github.com/33cn/plugin/plugin/dapp/hashlock/types"
) )
// Exec_Hlock Action
func (h *Hashlock) Exec_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, index int) (*types.Receipt, error) { func (h *Hashlock) Exec_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, index int) (*types.Receipt, error) {
clog.Debug("hashlocklock action") clog.Debug("hashlocklock action")
if hlock.Amount <= 0 { if hlock.Amount <= 0 {
...@@ -38,6 +39,7 @@ func (h *Hashlock) Exec_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, in ...@@ -38,6 +39,7 @@ func (h *Hashlock) Exec_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, in
return actiondb.Hashlocklock(hlock) return actiondb.Hashlocklock(hlock)
} }
// Exec_Hsend Action
func (h *Hashlock) Exec_Hsend(transfer *pty.HashlockSend, tx *types.Transaction, index int) (*types.Receipt, error) { func (h *Hashlock) Exec_Hsend(transfer *pty.HashlockSend, tx *types.Transaction, index int) (*types.Receipt, error) {
//unlock 有两个条件: 1. 时间已经过期 2. 密码是对的,返回原来的账户 //unlock 有两个条件: 1. 时间已经过期 2. 密码是对的,返回原来的账户
clog.Debug("hashlockunlock action") clog.Debug("hashlockunlock action")
...@@ -45,6 +47,7 @@ func (h *Hashlock) Exec_Hsend(transfer *pty.HashlockSend, tx *types.Transaction, ...@@ -45,6 +47,7 @@ func (h *Hashlock) Exec_Hsend(transfer *pty.HashlockSend, tx *types.Transaction,
return actiondb.Hashlocksend(transfer) return actiondb.Hashlocksend(transfer)
} }
// Exec_Hunlock Action
func (h *Hashlock) Exec_Hunlock(transfer *pty.HashlockUnlock, tx *types.Transaction, index int) (*types.Receipt, error) { func (h *Hashlock) Exec_Hunlock(transfer *pty.HashlockUnlock, tx *types.Transaction, index int) (*types.Receipt, error) {
//send 有两个条件:1. 时间没有过期 2. 密码是对的,币转移到 ToAddress //send 有两个条件:1. 时间没有过期 2. 密码是对的,币转移到 ToAddress
clog.Debug("hashlocksend action") clog.Debug("hashlocksend action")
......
...@@ -10,8 +10,9 @@ import ( ...@@ -10,8 +10,9 @@ import (
pty "github.com/33cn/plugin/plugin/dapp/hashlock/types" pty "github.com/33cn/plugin/plugin/dapp/hashlock/types"
) )
// ExecDelLocal_Hlock Action
func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
info := pty.Hashlockquery{hlock.Time, hashlockLocked, hlock.Amount, h.GetBlockTime(), 0} info := pty.Hashlockquery{Time: hlock.Time, Status: hashlockLocked, Amount: hlock.Amount, CreateTime: h.GetBlockTime(), CurrentTime: 0}
kv, err := UpdateHashReciver(h.GetLocalDB(), hlock.Hash, info) kv, err := UpdateHashReciver(h.GetLocalDB(), hlock.Hash, info)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -19,8 +20,9 @@ func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transac ...@@ -19,8 +20,9 @@ func (h *Hashlock) ExecDelLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transac
return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil
} }
// ExecDelLocal_Hsend Action
func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
info := pty.Hashlockquery{0, hashlockSent, 0, 0, 0} info := pty.Hashlockquery{Time: 0, Status: hashlockSent, Amount: 0, CreateTime: 0, CurrentTime: 0}
kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hsend.Secret), info) kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hsend.Secret), info)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -28,8 +30,9 @@ func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transac ...@@ -28,8 +30,9 @@ func (h *Hashlock) ExecDelLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transac
return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil
} }
// ExecDelLocal_Hunlock Action
func (h *Hashlock) ExecDelLocal_Hunlock(hunlock *pty.HashlockUnlock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (h *Hashlock) ExecDelLocal_Hunlock(hunlock *pty.HashlockUnlock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
info := pty.Hashlockquery{0, hashlockUnlocked, 0, 0, 0} info := pty.Hashlockquery{Time: 0, Status: hashlockUnlocked, Amount: 0, CreateTime: 0, CurrentTime: 0}
kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hunlock.Secret), info) kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hunlock.Secret), info)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -10,8 +10,9 @@ import ( ...@@ -10,8 +10,9 @@ import (
pty "github.com/33cn/plugin/plugin/dapp/hashlock/types" pty "github.com/33cn/plugin/plugin/dapp/hashlock/types"
) )
// ExecLocal_Hlock Action
func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
info := pty.Hashlockquery{hlock.Time, hashlockLocked, hlock.Amount, h.GetBlockTime(), 0} info := pty.Hashlockquery{Time: hlock.Time, Status: hashlockLocked, Amount: hlock.Amount, CreateTime: h.GetBlockTime(), CurrentTime: 0}
clog.Error("ExecLocal", "info", info) clog.Error("ExecLocal", "info", info)
kv, err := UpdateHashReciver(h.GetLocalDB(), hlock.Hash, info) kv, err := UpdateHashReciver(h.GetLocalDB(), hlock.Hash, info)
if err != nil { if err != nil {
...@@ -20,8 +21,9 @@ func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transactio ...@@ -20,8 +21,9 @@ func (h *Hashlock) ExecLocal_Hlock(hlock *pty.HashlockLock, tx *types.Transactio
return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil
} }
// ExecLocal_Hsend Action
func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
info := pty.Hashlockquery{0, hashlockSent, 0, 0, 0} info := pty.Hashlockquery{Time: 0, Status: hashlockSent, Amount: 0, CreateTime: 0, CurrentTime: 0}
clog.Error("ExecLocal", "info", info) clog.Error("ExecLocal", "info", info)
kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hsend.Secret), info) kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hsend.Secret), info)
if err != nil { if err != nil {
...@@ -30,8 +32,9 @@ func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transactio ...@@ -30,8 +32,9 @@ func (h *Hashlock) ExecLocal_Hsend(hsend *pty.HashlockSend, tx *types.Transactio
return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil return &types.LocalDBSet{KV: []*types.KeyValue{kv}}, nil
} }
// ExecLocal_Hunlock Action
func (h *Hashlock) ExecLocal_Hunlock(hunlock *pty.HashlockUnlock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (h *Hashlock) ExecLocal_Hunlock(hunlock *pty.HashlockUnlock, tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
info := pty.Hashlockquery{0, hashlockUnlocked, 0, 0, 0} info := pty.Hashlockquery{Time: 0, Status: hashlockUnlocked, Amount: 0, CreateTime: 0, CurrentTime: 0}
clog.Error("ExecLocal", "info", info) clog.Error("ExecLocal", "info", info)
kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hunlock.Secret), info) kv, err := UpdateHashReciver(h.GetLocalDB(), common.Sha256(hunlock.Secret), info)
if err != nil { if err != nil {
......
...@@ -21,14 +21,17 @@ func init() { ...@@ -21,14 +21,17 @@ func init() {
ety.InitFuncList(types.ListMethod(&Hashlock{})) ety.InitFuncList(types.ListMethod(&Hashlock{}))
} }
// Init hashlock
func Init(name string, sub []byte) { func Init(name string, sub []byte) {
drivers.Register(GetName(), newHashlock, types.GetDappFork(driverName, "Enable")) drivers.Register(GetName(), newHashlock, types.GetDappFork(driverName, "Enable"))
} }
// GetName for hashlock
func GetName() string { func GetName() string {
return newHashlock().GetName() return newHashlock().GetName()
} }
// Hashlock driver
type Hashlock struct { type Hashlock struct {
drivers.DriverBase drivers.DriverBase
} }
...@@ -40,10 +43,12 @@ func newHashlock() drivers.Driver { ...@@ -40,10 +43,12 @@ func newHashlock() drivers.Driver {
return h return h
} }
// GetDriverName driverName
func (h *Hashlock) GetDriverName() string { func (h *Hashlock) GetDriverName() string {
return driverName return driverName
} }
// CheckTx nil
func (h *Hashlock) CheckTx(tx *types.Transaction, index int) error { func (h *Hashlock) CheckTx(tx *types.Transaction, index int) error {
return nil return nil
} }
...@@ -387,7 +387,7 @@ func estHashsend(t *testing.T) { ...@@ -387,7 +387,7 @@ func estHashsend(t *testing.T) {
} }
func lock(secret []byte) error { func lock(secret []byte) error {
vlock := &hlt.HashlockAction_Hlock{&hlt.HashlockLock{Amount: lockAmount, Time: int64(locktime), Hash: common.Sha256(secret), ToAddress: addr[accountindexB], ReturnAddress: addr[accountindexA]}} vlock := &hlt.HashlockAction_Hlock{Hlock: &hlt.HashlockLock{Amount: lockAmount, Time: int64(locktime), Hash: common.Sha256(secret), ToAddress: addr[accountindexB], ReturnAddress: addr[accountindexA]}}
//fmt.Println(vlock) //fmt.Println(vlock)
transfer := &hlt.HashlockAction{Value: vlock, Ty: hlt.HashlockActionLock} transfer := &hlt.HashlockAction{Value: vlock, Ty: hlt.HashlockActionLock}
tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: addr[accountindexB]} tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: addr[accountindexB]}
...@@ -406,7 +406,7 @@ func lock(secret []byte) error { ...@@ -406,7 +406,7 @@ func lock(secret []byte) error {
} }
func unlock(secret []byte) error { func unlock(secret []byte) error {
vunlock := &hlt.HashlockAction_Hunlock{&hlt.HashlockUnlock{Secret: secret}} vunlock := &hlt.HashlockAction_Hunlock{Hunlock: &hlt.HashlockUnlock{Secret: secret}}
transfer := &hlt.HashlockAction{Value: vunlock, Ty: hlt.HashlockActionUnlock} transfer := &hlt.HashlockAction{Value: vunlock, Ty: hlt.HashlockActionUnlock}
tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: addr[accountindexB]} tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: addr[accountindexB]}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -424,7 +424,7 @@ func unlock(secret []byte) error { ...@@ -424,7 +424,7 @@ func unlock(secret []byte) error {
func send(secret []byte) error { func send(secret []byte) error {
vsend := &hlt.HashlockAction_Hsend{&hlt.HashlockSend{Secret: secret}} vsend := &hlt.HashlockAction_Hsend{Hsend: &hlt.HashlockSend{Secret: secret}}
transfer := &hlt.HashlockAction{Value: vsend, Ty: hlt.HashlockActionSend} transfer := &hlt.HashlockAction{Value: vsend, Ty: hlt.HashlockActionSend}
tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: addr[accountindexB]} tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: addr[accountindexB]}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -463,9 +463,10 @@ func showOrCheckAcc(c types.Chain33Client, addr string, sorc int, balance int64) ...@@ -463,9 +463,10 @@ func showOrCheckAcc(c types.Chain33Client, addr string, sorc int, balance int64)
} }
if sorc != onlyshow { if sorc != onlyshow {
return false return false
} else {
return true
} }
return true
} }
func showAccount(c types.Chain33Client, addr string) { func showAccount(c types.Chain33Client, addr string) {
...@@ -520,7 +521,7 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount ...@@ -520,7 +521,7 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount
//defer conn.Close() //defer conn.Close()
//fmt.Println("sign key privkey: ", common.ToHex(priv.Bytes())) //fmt.Println("sign key privkey: ", common.ToHex(priv.Bytes()))
if amount > 0 { if amount > 0 {
v := &cty.CoinsAction_Transfer{&types.AssetsTransfer{Amount: amount}} v := &cty.CoinsAction_Transfer{Transfer: &types.AssetsTransfer{Amount: amount}}
transfer := &cty.CoinsAction{Value: v, Ty: cty.CoinsActionTransfer} transfer := &cty.CoinsAction{Value: v, Ty: cty.CoinsActionTransfer}
tx := &types.Transaction{Execer: []byte("coins"), Payload: types.Encode(transfer), Fee: fee, To: to} tx := &types.Transaction{Execer: []byte("coins"), Payload: types.Encode(transfer), Fee: fee, To: to}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -536,8 +537,9 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount ...@@ -536,8 +537,9 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount
return errors.New(string(reply.GetMsg())) return errors.New(string(reply.GetMsg()))
} }
return nil return nil
} else { }
v := &cty.CoinsAction_Withdraw{&types.AssetsWithdraw{Amount: -amount}}
v := &cty.CoinsAction_Withdraw{Withdraw: &types.AssetsWithdraw{Amount: -amount}}
withdraw := &cty.CoinsAction{Value: v, Ty: cty.CoinsActionWithdraw} withdraw := &cty.CoinsAction{Value: v, Ty: cty.CoinsActionWithdraw}
tx := &types.Transaction{Execer: []byte("coins"), Payload: types.Encode(withdraw), Fee: fee, To: to} tx := &types.Transaction{Execer: []byte("coins"), Payload: types.Encode(withdraw), Fee: fee, To: to}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -553,7 +555,7 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount ...@@ -553,7 +555,7 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount
return errors.New(string(reply.GetMsg())) return errors.New(string(reply.GetMsg()))
} }
return nil return nil
}
} }
func getAccounts() (*types.WalletAccounts, error) { func getAccounts() (*types.WalletAccounts, error) {
......
...@@ -103,7 +103,7 @@ func ConstructLockTx() *types.Transaction { ...@@ -103,7 +103,7 @@ func ConstructLockTx() *types.Transaction {
var locktime int64 = 70 var locktime int64 = 70
var fee int64 = 1e6 var fee int64 = 1e6
vlock := &pty.HashlockAction_Hlock{&pty.HashlockLock{Amount: lockAmount, Time: locktime, Hash: common.Sha256(secret), ToAddress: toAddr, ReturnAddress: returnAddr}} vlock := &pty.HashlockAction_Hlock{Hlock: &pty.HashlockLock{Amount: lockAmount, Time: locktime, Hash: common.Sha256(secret), ToAddress: toAddr, ReturnAddress: returnAddr}}
transfer := &pty.HashlockAction{Value: vlock, Ty: pty.HashlockActionLock} transfer := &pty.HashlockAction{Value: vlock, Ty: pty.HashlockActionLock}
tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: toAddr} tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: toAddr}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -116,7 +116,7 @@ func ConstructUnlockTx() *types.Transaction { ...@@ -116,7 +116,7 @@ func ConstructUnlockTx() *types.Transaction {
var fee int64 = 1e6 var fee int64 = 1e6
vunlock := &pty.HashlockAction_Hunlock{&pty.HashlockUnlock{Secret: secret}} vunlock := &pty.HashlockAction_Hunlock{Hunlock: &pty.HashlockUnlock{Secret: secret}}
transfer := &pty.HashlockAction{Value: vunlock, Ty: pty.HashlockActionUnlock} transfer := &pty.HashlockAction{Value: vunlock, Ty: pty.HashlockActionUnlock}
tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: toAddr} tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: toAddr}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -128,7 +128,7 @@ func ConstructSendTx() *types.Transaction { ...@@ -128,7 +128,7 @@ func ConstructSendTx() *types.Transaction {
var fee int64 = 1e6 var fee int64 = 1e6
vsend := &pty.HashlockAction_Hsend{&pty.HashlockSend{Secret: secret}} vsend := &pty.HashlockAction_Hsend{Hsend: &pty.HashlockSend{Secret: secret}}
transfer := &pty.HashlockAction{Value: vsend, Ty: pty.HashlockActionSend} transfer := &pty.HashlockAction{Value: vsend, Ty: pty.HashlockActionSend}
tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: toAddr} tx := &types.Transaction{Execer: []byte("hashlock"), Payload: types.Encode(transfer), Fee: fee, To: toAddr}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -174,11 +174,11 @@ func (e *TestDB) Set(key []byte, value []byte) error { ...@@ -174,11 +174,11 @@ func (e *TestDB) Set(key []byte, value []byte) error {
return nil return nil
} }
func (db *TestDB) BatchGet(keys [][]byte) (values [][]byte, err error) { func (e *TestDB) BatchGet(keys [][]byte) (values [][]byte, err error) {
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
//从数据库中查询数据列表,set 中的cache 更新不会影响这个list //从数据库中查询数据列表,set 中的cache 更新不会影响这个list
func (l *TestDB) List(prefix, key []byte, count, direction int32) ([][]byte, error) { func (e *TestDB) List(prefix, key []byte, count, direction int32) ([][]byte, error) {
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
...@@ -25,10 +25,12 @@ const ( ...@@ -25,10 +25,12 @@ const (
hashlockSent = 3 hashlockSent = 3
) )
// DB struct
type DB struct { type DB struct {
pty.Hashlock pty.Hashlock
} }
// NewDB instance
func NewDB(id []byte, returnWallet string, toAddress string, blocktime int64, amount int64, time int64) *DB { func NewDB(id []byte, returnWallet string, toAddress string, blocktime int64, amount int64, time int64) *DB {
h := &DB{} h := &DB{}
h.HashlockId = id h.HashlockId = id
...@@ -41,13 +43,15 @@ func NewDB(id []byte, returnWallet string, toAddress string, blocktime int64, am ...@@ -41,13 +43,15 @@ func NewDB(id []byte, returnWallet string, toAddress string, blocktime int64, am
return h return h
} }
// GetKVSet for hashlock
func (h *DB) GetKVSet() (kvset []*types.KeyValue) { func (h *DB) GetKVSet() (kvset []*types.KeyValue) {
value := types.Encode(&h.Hashlock) value := types.Encode(&h.Hashlock)
kvset = append(kvset, &types.KeyValue{Key(h.HashlockId), value}) kvset = append(kvset, &types.KeyValue{Key: Key(h.HashlockId), Value: value})
return kvset return kvset
} }
// Save KV
func (h *DB) Save(db dbm.KV) { func (h *DB) Save(db dbm.KV) {
set := h.GetKVSet() set := h.GetKVSet()
for i := 0; i < len(set); i++ { for i := 0; i < len(set); i++ {
...@@ -55,12 +59,14 @@ func (h *DB) Save(db dbm.KV) { ...@@ -55,12 +59,14 @@ func (h *DB) Save(db dbm.KV) {
} }
} }
// Key for hashlock
func Key(id []byte) (key []byte) { func Key(id []byte) (key []byte) {
key = append(key, []byte("mavl-hashlock-")...) key = append(key, []byte("mavl-hashlock-")...)
key = append(key, id...) key = append(key, id...)
return key return key
} }
// Action def
type Action struct { type Action struct {
coinsAccount *account.DB coinsAccount *account.DB
db dbm.KV db dbm.KV
...@@ -71,12 +77,14 @@ type Action struct { ...@@ -71,12 +77,14 @@ type Action struct {
execaddr string execaddr string
} }
// NewAction gen action instance
func NewAction(h *Hashlock, tx *types.Transaction, execaddr string) *Action { func NewAction(h *Hashlock, tx *types.Transaction, execaddr string) *Action {
hash := tx.Hash() hash := tx.Hash()
fromaddr := tx.From() fromaddr := tx.From()
return &Action{h.GetCoinsAccount(), h.GetStateDB(), hash, fromaddr, h.GetBlockTime(), h.GetHeight(), execaddr} return &Action{h.GetCoinsAccount(), h.GetStateDB(), hash, fromaddr, h.GetBlockTime(), h.GetHeight(), execaddr}
} }
// Hashlocklock Action
func (action *Action) Hashlocklock(hlock *pty.HashlockLock) (*types.Receipt, error) { func (action *Action) Hashlocklock(hlock *pty.HashlockLock) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
...@@ -105,10 +113,11 @@ func (action *Action) Hashlocklock(hlock *pty.HashlockLock) (*types.Receipt, err ...@@ -105,10 +113,11 @@ func (action *Action) Hashlocklock(hlock *pty.HashlockLock) (*types.Receipt, err
//logs = append(logs, h.GetReceiptLog()) //logs = append(logs, h.GetReceiptLog())
kv = append(kv, h.GetKVSet()...) kv = append(kv, h.GetKVSet()...)
receipt = &types.Receipt{types.ExecOk, kv, logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil return receipt, nil
} }
// Hashlockunlock Action
func (action *Action) Hashlockunlock(unlock *pty.HashlockUnlock) (*types.Receipt, error) { func (action *Action) Hashlockunlock(unlock *pty.HashlockUnlock) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
...@@ -150,10 +159,11 @@ func (action *Action) Hashlockunlock(unlock *pty.HashlockUnlock) (*types.Receipt ...@@ -150,10 +159,11 @@ func (action *Action) Hashlockunlock(unlock *pty.HashlockUnlock) (*types.Receipt
//logs = append(logs, t.GetReceiptLog()) //logs = append(logs, t.GetReceiptLog())
kv = append(kv, h.GetKVSet()...) kv = append(kv, h.GetKVSet()...)
receipt = &types.Receipt{types.ExecOk, kv, logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil return receipt, nil
} }
// Hashlocksend Action
func (action *Action) Hashlocksend(send *pty.HashlockSend) (*types.Receipt, error) { func (action *Action) Hashlocksend(send *pty.HashlockSend) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
...@@ -194,7 +204,7 @@ func (action *Action) Hashlocksend(send *pty.HashlockSend) (*types.Receipt, erro ...@@ -194,7 +204,7 @@ func (action *Action) Hashlocksend(send *pty.HashlockSend) (*types.Receipt, erro
//logs = append(logs, t.GetReceiptLog()) //logs = append(logs, t.GetReceiptLog())
kv = append(kv, h.GetKVSet()...) kv = append(kv, h.GetKVSet()...)
receipt = &types.Receipt{types.ExecOk, kv, logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil return receipt, nil
} }
...@@ -212,19 +222,20 @@ func readHashlock(db dbm.KV, id []byte) (*pty.Hashlock, error) { ...@@ -212,19 +222,20 @@ func readHashlock(db dbm.KV, id []byte) (*pty.Hashlock, error) {
return &hashlock, nil return &hashlock, nil
} }
// NewHashlockquery gen query instance
func NewHashlockquery() *pty.Hashlockquery { func NewHashlockquery() *pty.Hashlockquery {
q := pty.Hashlockquery{} q := pty.Hashlockquery{}
return &q return &q
} }
func calcHashlockIdKey(id []byte) []byte { func calcHashlockIDKey(id []byte) []byte {
return append([]byte("LODB-hashlock-"), id...) return append([]byte("LODB-hashlock-"), id...)
} }
//将Information转换成byte类型,使输出为kv模式 // GeHashReciverKV gen KV
func GeHashReciverKV(hashlockID []byte, information *pty.Hashlockquery) *types.KeyValue { func GeHashReciverKV(hashlockID []byte, information *pty.Hashlockquery) *types.KeyValue {
clog.Error("GeHashReciverKV action") clog.Error("GeHashReciverKV action")
infor := pty.Hashlockquery{information.Time, information.Status, information.Amount, information.CreateTime, information.CurrentTime} infor := pty.Hashlockquery{Time: information.Time, Status: information.Status, Amount: information.Amount, CreateTime: information.CreateTime, CurrentTime: information.CurrentTime}
clog.Error("GeHashReciverKV action", "Status", information.Status) clog.Error("GeHashReciverKV action", "Status", information.Status)
reciver, err := json.Marshal(infor) reciver, err := json.Marshal(infor)
if err == nil { if err == nil {
...@@ -233,12 +244,12 @@ func GeHashReciverKV(hashlockID []byte, information *pty.Hashlockquery) *types.K ...@@ -233,12 +244,12 @@ func GeHashReciverKV(hashlockID []byte, information *pty.Hashlockquery) *types.K
fmt.Println(err) fmt.Println(err)
} }
clog.Error("GeHashReciverKV action", "reciver", reciver) clog.Error("GeHashReciverKV action", "reciver", reciver)
kv := &types.KeyValue{calcHashlockIdKey(hashlockID), reciver} kv := &types.KeyValue{Key: calcHashlockIDKey(hashlockID), Value: reciver}
clog.Error("GeHashReciverKV action", "kv", kv) clog.Error("GeHashReciverKV action", "kv", kv)
return kv return kv
} }
//从db里面根据key获取value,期间需要进行解码 // GetHashReciver get hashlock
func GetHashReciver(db dbm.KVDB, hashlockID []byte) (*pty.Hashlockquery, error) { func GetHashReciver(db dbm.KVDB, hashlockID []byte) (*pty.Hashlockquery, error) {
//reciver := types.Int64{} //reciver := types.Int64{}
clog.Error("GetHashReciver action", "hashlockID", hashlockID) clog.Error("GetHashReciver action", "hashlockID", hashlockID)
...@@ -264,14 +275,14 @@ func GetHashReciver(db dbm.KVDB, hashlockID []byte) (*pty.Hashlockquery, error) ...@@ -264,14 +275,14 @@ func GetHashReciver(db dbm.KVDB, hashlockID []byte) (*pty.Hashlockquery, error)
return reciver, nil return reciver, nil
} }
//将hashlockId和information都以key和value形式存入db // SetHashReciver save hashlock
func SetHashReciver(db dbm.KVDB, hashlockID []byte, information *pty.Hashlockquery) error { func SetHashReciver(db dbm.KVDB, hashlockID []byte, information *pty.Hashlockquery) error {
clog.Error("SetHashReciver action") clog.Error("SetHashReciver action")
kv := GeHashReciverKV(hashlockID, information) kv := GeHashReciverKV(hashlockID, information)
return db.Set(kv.Key, kv.Value) return db.Set(kv.Key, kv.Value)
} }
//根据状态值对db中存入的数据进行更改 // UpdateHashReciver update status for hashlock
func UpdateHashReciver(cachedb dbm.KVDB, hashlockID []byte, information pty.Hashlockquery) (*types.KeyValue, error) { func UpdateHashReciver(cachedb dbm.KVDB, hashlockID []byte, information pty.Hashlockquery) (*types.KeyValue, error) {
clog.Error("UpdateHashReciver", "hashlockId", hashlockID) clog.Error("UpdateHashReciver", "hashlockId", hashlockID)
recv, err := GetHashReciver(cachedb, hashlockID) recv, err := GetHashReciver(cachedb, hashlockID)
...@@ -315,7 +326,7 @@ func UpdateHashReciver(cachedb dbm.KVDB, hashlockID []byte, information pty.Hash ...@@ -315,7 +326,7 @@ func UpdateHashReciver(cachedb dbm.KVDB, hashlockID []byte, information pty.Hash
return GeHashReciverKV(hashlockID, recv), nil return GeHashReciverKV(hashlockID, recv), nil
} }
//根据hashlockid获取相关信息 // GetTxsByHashlockID get hashlock record
func (n *Hashlock) GetTxsByHashlockID(hashlockID []byte, differTime int64) (types.Message, error) { func (n *Hashlock) GetTxsByHashlockID(hashlockID []byte, differTime int64) (types.Message, error) {
clog.Error("GetTxsByHashlockId action") clog.Error("GetTxsByHashlockId action")
db := n.GetLocalDB() db := n.GetLocalDB()
......
...@@ -6,6 +6,7 @@ package executor ...@@ -6,6 +6,7 @@ package executor
import "github.com/33cn/chain33/types" import "github.com/33cn/chain33/types"
// Query_GetHashlocKById get hashlock instance
func (h *Hashlock) Query_GetHashlocKById(in []byte) (types.Message, error) { func (h *Hashlock) Query_GetHashlocKById(in []byte) (types.Message, error) {
differTime := types.Now().UnixNano()/1e9 - h.GetBlockTime() differTime := types.Now().UnixNano()/1e9 - h.GetBlockTime()
clog.Error("Query action") clog.Error("Query action")
......
...@@ -6,6 +6,7 @@ package types ...@@ -6,6 +6,7 @@ package types
import "errors" import "errors"
// hashlock errors
var ( var (
ErrHashlockAmount = errors.New("ErrHashlockAmount") ErrHashlockAmount = errors.New("ErrHashlockAmount")
ErrHashlockHash = errors.New("ErrHashlockHash") ErrHashlockHash = errors.New("ErrHashlockHash")
......
...@@ -23,24 +23,27 @@ func init() { ...@@ -23,24 +23,27 @@ func init() {
types.RegisterDappFork(HashlockX, "Enable", 0) types.RegisterDappFork(HashlockX, "Enable", 0)
} }
// HashlockType def
type HashlockType struct { type HashlockType struct {
types.ExecTypeBase types.ExecTypeBase
} }
// NewType method
func NewType() *HashlockType { func NewType() *HashlockType {
c := &HashlockType{} c := &HashlockType{}
c.SetChild(c) c.SetChild(c)
return c return c
} }
// GetPayload method
func (hashlock *HashlockType) GetPayload() types.Message { func (hashlock *HashlockType) GetPayload() types.Message {
return &HashlockAction{} return &HashlockAction{}
} }
// TODO 暂时不修改实现, 先完成结构的重构 // CreateTx method
func (hashlock *HashlockType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) { func (hashlock *HashlockType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
hlog.Debug("hashlock.CreateTx", "action", action) hlog.Debug("hashlock.CreateTx", "action", action)
var tx *types.Transaction
if action == "HashlockLock" { if action == "HashlockLock" {
var param HashlockLockTx var param HashlockLockTx
err := json.Unmarshal(message, &param) err := json.Unmarshal(message, &param)
...@@ -68,9 +71,9 @@ func (hashlock *HashlockType) CreateTx(action string, message json.RawMessage) ( ...@@ -68,9 +71,9 @@ func (hashlock *HashlockType) CreateTx(action string, message json.RawMessage) (
} else { } else {
return nil, types.ErrNotSupport return nil, types.ErrNotSupport
} }
return tx, nil
} }
// GetTypeMap method
func (hashlock *HashlockType) GetTypeMap() map[string]int32 { func (hashlock *HashlockType) GetTypeMap() map[string]int32 {
return map[string]int32{ return map[string]int32{
"Hlock": HashlockActionLock, "Hlock": HashlockActionLock,
...@@ -79,42 +82,12 @@ func (hashlock *HashlockType) GetTypeMap() map[string]int32 { ...@@ -79,42 +82,12 @@ func (hashlock *HashlockType) GetTypeMap() map[string]int32 {
} }
} }
func (at *HashlockType) GetLogMap() map[int64]*types.LogInfo { // GetLogMap method
func (hashlock *HashlockType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{} return map[int64]*types.LogInfo{}
} }
type CoinsDepositLog struct { // CreateRawHashlockLockTx method
}
func (l CoinsDepositLog) Name() string {
return "LogDeposit"
}
func (l CoinsDepositLog) Decode(msg []byte) (interface{}, error) {
var logTmp types.ReceiptAccountTransfer
err := types.Decode(msg, &logTmp)
if err != nil {
return nil, err
}
return logTmp, err
}
type CoinsGetTxsByAddr struct {
}
func (t *CoinsGetTxsByAddr) JsonToProto(message json.RawMessage) ([]byte, error) {
var req types.ReqAddr
err := json.Unmarshal(message, &req)
if err != nil {
return nil, err
}
return types.Encode(&req), nil
}
func (t *CoinsGetTxsByAddr) ProtoToJson(reply *types.Message) (interface{}, error) {
return reply, nil
}
func CreateRawHashlockLockTx(parm *HashlockLockTx) (*types.Transaction, error) { func CreateRawHashlockLockTx(parm *HashlockLockTx) (*types.Transaction, error) {
if parm == nil { if parm == nil {
hlog.Error("CreateRawHashlockLockTx", "parm", parm) hlog.Error("CreateRawHashlockLockTx", "parm", parm)
...@@ -145,6 +118,7 @@ func CreateRawHashlockLockTx(parm *HashlockLockTx) (*types.Transaction, error) { ...@@ -145,6 +118,7 @@ func CreateRawHashlockLockTx(parm *HashlockLockTx) (*types.Transaction, error) {
return tx, nil return tx, nil
} }
// CreateRawHashlockUnlockTx method
func CreateRawHashlockUnlockTx(parm *HashlockUnlockTx) (*types.Transaction, error) { func CreateRawHashlockUnlockTx(parm *HashlockUnlockTx) (*types.Transaction, error) {
if parm == nil { if parm == nil {
hlog.Error("CreateRawHashlockUnlockTx", "parm", parm) hlog.Error("CreateRawHashlockUnlockTx", "parm", parm)
...@@ -173,6 +147,7 @@ func CreateRawHashlockUnlockTx(parm *HashlockUnlockTx) (*types.Transaction, erro ...@@ -173,6 +147,7 @@ func CreateRawHashlockUnlockTx(parm *HashlockUnlockTx) (*types.Transaction, erro
return tx, nil return tx, nil
} }
// CreateRawHashlockSendTx method
func CreateRawHashlockSendTx(parm *HashlockSendTx) (*types.Transaction, error) { func CreateRawHashlockSendTx(parm *HashlockSendTx) (*types.Transaction, error) {
if parm == nil { if parm == nil {
hlog.Error("CreateRawHashlockSendTx", "parm", parm) hlog.Error("CreateRawHashlockSendTx", "parm", parm)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package types package types
// HashlockLockTx for construction
type HashlockLockTx struct { type HashlockLockTx struct {
Secret string `json:"secret"` Secret string `json:"secret"`
Amount int64 `json:"amount"` Amount int64 `json:"amount"`
...@@ -13,11 +14,13 @@ type HashlockLockTx struct { ...@@ -13,11 +14,13 @@ type HashlockLockTx struct {
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// HashlockUnlockTx for construction
type HashlockUnlockTx struct { type HashlockUnlockTx struct {
Secret string `json:"secret"` Secret string `json:"secret"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// HashlockSendTx for construction
type HashlockSendTx struct { type HashlockSendTx struct {
Secret string `json:"secret"` Secret string `json:"secret"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
......
...@@ -11,4 +11,5 @@ const ( ...@@ -11,4 +11,5 @@ const (
HashlockActionUnlock = 3 HashlockActionUnlock = 3
) )
// HashlockX name
var HashlockX = "hashlock" var HashlockX = "hashlock"
...@@ -14,12 +14,14 @@ import ( ...@@ -14,12 +14,14 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// RetrieveResult response
type RetrieveResult struct { type RetrieveResult struct {
DelayPeriod int64 `json:"delayPeriod"` DelayPeriod int64 `json:"delayPeriod"`
//RemainTime int64 `json:"remainTime"` //RemainTime int64 `json:"remainTime"`
Status string `json:"status"` Status string `json:"status"`
} }
// RetrieveCmd cmds
func RetrieveCmd() *cobra.Command { func RetrieveCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "retrieve", Use: "retrieve",
...@@ -38,7 +40,7 @@ func RetrieveCmd() *cobra.Command { ...@@ -38,7 +40,7 @@ func RetrieveCmd() *cobra.Command {
return cmd return cmd
} }
// 备份 // BackupCmd construct backup tx
func BackupCmd() *cobra.Command { func BackupCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "backup", Use: "backup",
...@@ -83,7 +85,7 @@ func backupCmd(cmd *cobra.Command, args []string) { ...@@ -83,7 +85,7 @@ func backupCmd(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// 准备 // PrepareCmd construct prepare tx
func PrepareCmd() *cobra.Command { func PrepareCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "prepare", Use: "prepare",
...@@ -120,7 +122,7 @@ func prepareCmd(cmd *cobra.Command, args []string) { ...@@ -120,7 +122,7 @@ func prepareCmd(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// 执行 // PerformCmd construct perform tx
func PerformCmd() *cobra.Command { func PerformCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "perform", Use: "perform",
...@@ -147,7 +149,7 @@ func performCmd(cmd *cobra.Command, args []string) { ...@@ -147,7 +149,7 @@ func performCmd(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// 取消 // CancelCmd construct cancel tx
func CancelCmd() *cobra.Command { func CancelCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "cancel", Use: "cancel",
...@@ -174,7 +176,7 @@ func cancelCmd(cmd *cobra.Command, args []string) { ...@@ -174,7 +176,7 @@ func cancelCmd(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// 查询 // RetrieveQueryCmd cmds
func RetrieveQueryCmd() *cobra.Command { func RetrieveQueryCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "query", Use: "query",
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
rt "github.com/33cn/plugin/plugin/dapp/retrieve/types" rt "github.com/33cn/plugin/plugin/dapp/retrieve/types"
) )
// Exec_Backup Action
func (c *Retrieve) Exec_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Retrieve) Exec_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewRetrieveAcction(c, tx) actiondb := NewRetrieveAcction(c, tx)
if backup.DelayPeriod < minPeriod { if backup.DelayPeriod < minPeriod {
...@@ -18,18 +19,21 @@ func (c *Retrieve) Exec_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, ...@@ -18,18 +19,21 @@ func (c *Retrieve) Exec_Backup(backup *rt.BackupRetrieve, tx *types.Transaction,
return actiondb.RetrieveBackup(backup) return actiondb.RetrieveBackup(backup)
} }
// Exec_Perform Action
func (c *Retrieve) Exec_Perform(perf *rt.PerformRetrieve, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Retrieve) Exec_Perform(perf *rt.PerformRetrieve, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewRetrieveAcction(c, tx) actiondb := NewRetrieveAcction(c, tx)
rlog.Debug("PerformRetrieve action") rlog.Debug("PerformRetrieve action")
return actiondb.RetrievePerform(perf) return actiondb.RetrievePerform(perf)
} }
// Exec_Prepare Action
func (c *Retrieve) Exec_Prepare(pre *rt.PrepareRetrieve, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Retrieve) Exec_Prepare(pre *rt.PrepareRetrieve, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewRetrieveAcction(c, tx) actiondb := NewRetrieveAcction(c, tx)
rlog.Debug("PreRetrieve action") rlog.Debug("PreRetrieve action")
return actiondb.RetrievePrepare(pre) return actiondb.RetrievePrepare(pre)
} }
// Exec_Cancel Action
func (c *Retrieve) Exec_Cancel(cancel *rt.CancelRetrieve, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Retrieve) Exec_Cancel(cancel *rt.CancelRetrieve, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewRetrieveAcction(c, tx) actiondb := NewRetrieveAcction(c, tx)
rlog.Debug("PreRetrieve action") rlog.Debug("PreRetrieve action")
......
...@@ -10,10 +10,11 @@ import ( ...@@ -10,10 +10,11 @@ import (
rt "github.com/33cn/plugin/plugin/dapp/retrieve/types" rt "github.com/33cn/plugin/plugin/dapp/retrieve/types"
) )
// DelRetrieveInfo local
func DelRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types.KeyValue, error) { func DelRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types.KeyValue, error) {
switch Status { switch Status {
case retrieveBackup: case retrieveBackup:
kv := &types.KeyValue{calcRetrieveKey(info.BackupAddress, info.DefaultAddress), nil} kv := &types.KeyValue{Key: calcRetrieveKey(info.BackupAddress, info.DefaultAddress), Value: nil}
db.Set(kv.Key, kv.Value) db.Set(kv.Key, kv.Value)
return kv, nil return kv, nil
case retrievePrepare: case retrievePrepare:
...@@ -25,7 +26,7 @@ func DelRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types. ...@@ -25,7 +26,7 @@ func DelRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types.
info.Status = retrieveBackup info.Status = retrieveBackup
info.PrepareTime = 0 info.PrepareTime = 0
value := types.Encode(info) value := types.Encode(info)
kv := &types.KeyValue{calcRetrieveKey(info.BackupAddress, info.DefaultAddress), value} kv := &types.KeyValue{Key: calcRetrieveKey(info.BackupAddress, info.DefaultAddress), Value: value}
db.Set(kv.Key, kv.Value) db.Set(kv.Key, kv.Value)
return kv, nil return kv, nil
case retrievePerform: case retrievePerform:
...@@ -39,7 +40,7 @@ func DelRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types. ...@@ -39,7 +40,7 @@ func DelRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types.
info.Status = retrievePrepare info.Status = retrievePrepare
info.PrepareTime = oldInfo.PrepareTime info.PrepareTime = oldInfo.PrepareTime
value := types.Encode(info) value := types.Encode(info)
kv := &types.KeyValue{calcRetrieveKey(info.BackupAddress, info.DefaultAddress), value} kv := &types.KeyValue{Key: calcRetrieveKey(info.BackupAddress, info.DefaultAddress), Value: value}
db.Set(kv.Key, kv.Value) db.Set(kv.Key, kv.Value)
return kv, nil return kv, nil
default: default:
...@@ -58,10 +59,11 @@ func (c *Retrieve) execDelLocal(tx *types.Transaction, receipt *types.ReceiptDat ...@@ -58,10 +59,11 @@ func (c *Retrieve) execDelLocal(tx *types.Transaction, receipt *types.ReceiptDat
return set, nil return set, nil
} }
// ExecDelLocal_Backup Action
func (c *Retrieve) ExecDelLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (c *Retrieve) ExecDelLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set, err := c.execDelLocal(tx, receiptData, index) set, _ := c.execDelLocal(tx, receiptData, index)
info := rt.RetrieveQuery{backup.BackupAddress, backup.DefaultAddress, backup.DelayPeriod, zeroPrepareTime, zeroRemainTime, retrieveBackup} info := rt.RetrieveQuery{BackupAddress: backup.BackupAddress, DefaultAddress: backup.DefaultAddress, DelayPeriod: backup.DelayPeriod, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrieveBackup}
kv, err := DelRetrieveInfo(&info, retrieveBackup, c.GetLocalDB()) kv, err := DelRetrieveInfo(&info, retrieveBackup, c.GetLocalDB())
if err != nil { if err != nil {
return set, nil return set, nil
...@@ -74,10 +76,11 @@ func (c *Retrieve) ExecDelLocal_Backup(backup *rt.BackupRetrieve, tx *types.Tran ...@@ -74,10 +76,11 @@ func (c *Retrieve) ExecDelLocal_Backup(backup *rt.BackupRetrieve, tx *types.Tran
return set, nil return set, nil
} }
// ExecDelLocal_Prepare Action
func (c *Retrieve) ExecDelLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (c *Retrieve) ExecDelLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set, err := c.execDelLocal(tx, receiptData, index) set, _ := c.execDelLocal(tx, receiptData, index)
info := rt.RetrieveQuery{pre.BackupAddress, pre.DefaultAddress, zeroDelay, c.GetBlockTime(), zeroRemainTime, retrievePrepare} info := rt.RetrieveQuery{BackupAddress: pre.BackupAddress, DefaultAddress: pre.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: c.GetBlockTime(), RemainTime: zeroRemainTime, Status: retrievePrepare}
kv, err := DelRetrieveInfo(&info, retrievePrepare, c.GetLocalDB()) kv, err := DelRetrieveInfo(&info, retrievePrepare, c.GetLocalDB())
if err != nil { if err != nil {
return set, nil return set, nil
...@@ -90,10 +93,11 @@ func (c *Retrieve) ExecDelLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Trans ...@@ -90,10 +93,11 @@ func (c *Retrieve) ExecDelLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Trans
return set, nil return set, nil
} }
// ExecDelLocal_Perform Action
func (c *Retrieve) ExecDelLocal_Perform(perf *rt.PerformRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (c *Retrieve) ExecDelLocal_Perform(perf *rt.PerformRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set, err := c.execDelLocal(tx, receiptData, index) set, _ := c.execDelLocal(tx, receiptData, index)
info := rt.RetrieveQuery{perf.BackupAddress, perf.DefaultAddress, zeroDelay, zeroPrepareTime, zeroRemainTime, retrievePerform} info := rt.RetrieveQuery{BackupAddress: perf.BackupAddress, DefaultAddress: perf.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrievePerform}
kv, err := DelRetrieveInfo(&info, retrievePerform, c.GetLocalDB()) kv, err := DelRetrieveInfo(&info, retrievePerform, c.GetLocalDB())
if err != nil { if err != nil {
return set, nil return set, nil
...@@ -106,10 +110,11 @@ func (c *Retrieve) ExecDelLocal_Perform(perf *rt.PerformRetrieve, tx *types.Tran ...@@ -106,10 +110,11 @@ func (c *Retrieve) ExecDelLocal_Perform(perf *rt.PerformRetrieve, tx *types.Tran
return set, nil return set, nil
} }
// ExecDelLocal_Cancel Action
func (c *Retrieve) ExecDelLocal_Cancel(cancel *rt.CancelRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (c *Retrieve) ExecDelLocal_Cancel(cancel *rt.CancelRetrieve, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set, err := c.execDelLocal(tx, receiptData, index) set, _ := c.execDelLocal(tx, receiptData, index)
info := rt.RetrieveQuery{cancel.BackupAddress, cancel.DefaultAddress, zeroDelay, zeroPrepareTime, zeroRemainTime, retrieveCancel} info := rt.RetrieveQuery{BackupAddress: cancel.BackupAddress, DefaultAddress: cancel.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrieveCancel}
kv, err := DelRetrieveInfo(&info, retrieveCancel, c.GetLocalDB()) kv, err := DelRetrieveInfo(&info, retrieveCancel, c.GetLocalDB())
if err != nil { if err != nil {
return set, nil return set, nil
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
rt "github.com/33cn/plugin/plugin/dapp/retrieve/types" rt "github.com/33cn/plugin/plugin/dapp/retrieve/types"
) )
// SaveRetrieveInfo local
func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types.KeyValue, error) { func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types.KeyValue, error) {
rlog.Debug("Retrieve SaveRetrieveInfo", "backupaddr", info.BackupAddress, "defaddr", info.DefaultAddress) rlog.Debug("Retrieve SaveRetrieveInfo", "backupaddr", info.BackupAddress, "defaddr", info.DefaultAddress)
switch Status { switch Status {
...@@ -19,7 +20,7 @@ func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types ...@@ -19,7 +20,7 @@ func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types
return nil, err return nil, err
} }
value := types.Encode(info) value := types.Encode(info)
kv := &types.KeyValue{calcRetrieveKey(info.BackupAddress, info.DefaultAddress), value} kv := &types.KeyValue{Key: calcRetrieveKey(info.BackupAddress, info.DefaultAddress), Value: value}
db.Set(kv.Key, kv.Value) db.Set(kv.Key, kv.Value)
return kv, nil return kv, nil
case retrievePrepare: case retrievePrepare:
...@@ -29,7 +30,7 @@ func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types ...@@ -29,7 +30,7 @@ func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types
} }
info.DelayPeriod = oldInfo.DelayPeriod info.DelayPeriod = oldInfo.DelayPeriod
value := types.Encode(info) value := types.Encode(info)
kv := &types.KeyValue{calcRetrieveKey(info.BackupAddress, info.DefaultAddress), value} kv := &types.KeyValue{Key: calcRetrieveKey(info.BackupAddress, info.DefaultAddress), Value: value}
db.Set(kv.Key, kv.Value) db.Set(kv.Key, kv.Value)
return kv, nil return kv, nil
case retrievePerform: case retrievePerform:
...@@ -42,7 +43,7 @@ func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types ...@@ -42,7 +43,7 @@ func SaveRetrieveInfo(info *rt.RetrieveQuery, Status int64, db dbm.KVDB) (*types
info.DelayPeriod = oldInfo.DelayPeriod info.DelayPeriod = oldInfo.DelayPeriod
info.PrepareTime = oldInfo.PrepareTime info.PrepareTime = oldInfo.PrepareTime
value := types.Encode(info) value := types.Encode(info)
kv := &types.KeyValue{calcRetrieveKey(info.BackupAddress, info.DefaultAddress), value} kv := &types.KeyValue{Key: calcRetrieveKey(info.BackupAddress, info.DefaultAddress), Value: value}
db.Set(kv.Key, kv.Value) db.Set(kv.Key, kv.Value)
return kv, nil return kv, nil
default: default:
...@@ -59,10 +60,11 @@ func (c *Retrieve) execLocal(receipt types.ExecTypeGet) (*types.LocalDBSet, erro ...@@ -59,10 +60,11 @@ func (c *Retrieve) execLocal(receipt types.ExecTypeGet) (*types.LocalDBSet, erro
return dbSet, nil return dbSet, nil
} }
// ExecLocal_Backup Action
func (c *Retrieve) ExecLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, receiptData types.ExecTypeGet, index int) (*types.LocalDBSet, error) { func (c *Retrieve) ExecLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transaction, receiptData types.ExecTypeGet, index int) (*types.LocalDBSet, error) {
set, err := c.execLocal(receiptData) set, _ := c.execLocal(receiptData)
info := rt.RetrieveQuery{backup.BackupAddress, backup.DefaultAddress, backup.DelayPeriod, zeroPrepareTime, zeroRemainTime, retrieveBackup} info := rt.RetrieveQuery{BackupAddress: backup.BackupAddress, DefaultAddress: backup.DefaultAddress, DelayPeriod: backup.DelayPeriod, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrieveBackup}
kv, err := SaveRetrieveInfo(&info, retrieveBackup, c.GetLocalDB()) kv, err := SaveRetrieveInfo(&info, retrieveBackup, c.GetLocalDB())
if err != nil { if err != nil {
return set, nil return set, nil
...@@ -75,10 +77,11 @@ func (c *Retrieve) ExecLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transac ...@@ -75,10 +77,11 @@ func (c *Retrieve) ExecLocal_Backup(backup *rt.BackupRetrieve, tx *types.Transac
return set, nil return set, nil
} }
// ExecLocal_Prepare Action
func (c *Retrieve) ExecLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transaction, receiptData types.ExecTypeGet, index int) (*types.LocalDBSet, error) { func (c *Retrieve) ExecLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transaction, receiptData types.ExecTypeGet, index int) (*types.LocalDBSet, error) {
set, err := c.execLocal(receiptData) set, _ := c.execLocal(receiptData)
info := rt.RetrieveQuery{pre.BackupAddress, pre.DefaultAddress, zeroDelay, zeroPrepareTime, zeroRemainTime, retrievePrepare} info := rt.RetrieveQuery{BackupAddress: pre.BackupAddress, DefaultAddress: pre.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrievePrepare}
kv, err := SaveRetrieveInfo(&info, retrievePrepare, c.GetLocalDB()) kv, err := SaveRetrieveInfo(&info, retrievePrepare, c.GetLocalDB())
if err != nil { if err != nil {
return set, nil return set, nil
...@@ -91,10 +94,11 @@ func (c *Retrieve) ExecLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transact ...@@ -91,10 +94,11 @@ func (c *Retrieve) ExecLocal_Prepare(pre *rt.PrepareRetrieve, tx *types.Transact
return set, nil return set, nil
} }
// ExecLocal_Perf Action
func (c *Retrieve) ExecLocal_Perf(perf *rt.PerformRetrieve, tx *types.Transaction, receiptData types.ExecTypeGet, index int) (*types.LocalDBSet, error) { func (c *Retrieve) ExecLocal_Perf(perf *rt.PerformRetrieve, tx *types.Transaction, receiptData types.ExecTypeGet, index int) (*types.LocalDBSet, error) {
set, err := c.execLocal(receiptData) set, _ := c.execLocal(receiptData)
info := rt.RetrieveQuery{perf.BackupAddress, perf.DefaultAddress, zeroDelay, zeroPrepareTime, zeroRemainTime, retrievePerform} info := rt.RetrieveQuery{BackupAddress: perf.BackupAddress, DefaultAddress: perf.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrievePerform}
kv, err := SaveRetrieveInfo(&info, retrievePerform, c.GetLocalDB()) kv, err := SaveRetrieveInfo(&info, retrievePerform, c.GetLocalDB())
if err != nil { if err != nil {
return set, nil return set, nil
...@@ -107,10 +111,11 @@ func (c *Retrieve) ExecLocal_Perf(perf *rt.PerformRetrieve, tx *types.Transactio ...@@ -107,10 +111,11 @@ func (c *Retrieve) ExecLocal_Perf(perf *rt.PerformRetrieve, tx *types.Transactio
return set, nil return set, nil
} }
// ExecLocal_Cancel Action
func (c *Retrieve) ExecLocal_Cancel(cancel *rt.CancelRetrieve, tx *types.Transaction, receiptData types.ExecTypeGet, index int) (*types.LocalDBSet, error) { func (c *Retrieve) ExecLocal_Cancel(cancel *rt.CancelRetrieve, tx *types.Transaction, receiptData types.ExecTypeGet, index int) (*types.LocalDBSet, error) {
set, err := c.execLocal(receiptData) set, _ := c.execLocal(receiptData)
info := rt.RetrieveQuery{cancel.BackupAddress, cancel.DefaultAddress, zeroDelay, zeroPrepareTime, zeroRemainTime, retrieveCancel} info := rt.RetrieveQuery{BackupAddress: cancel.BackupAddress, DefaultAddress: cancel.DefaultAddress, DelayPeriod: zeroDelay, PrepareTime: zeroPrepareTime, RemainTime: zeroRemainTime, Status: retrieveCancel}
kv, err := SaveRetrieveInfo(&info, retrieveCancel, c.GetLocalDB()) kv, err := SaveRetrieveInfo(&info, retrieveCancel, c.GetLocalDB())
if err != nil { if err != nil {
return set, nil return set, nil
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
rt "github.com/33cn/plugin/plugin/dapp/retrieve/types" rt "github.com/33cn/plugin/plugin/dapp/retrieve/types"
) )
// Query_GetRetrieveInfo get retrieve state
func (r *Retrieve) Query_GetRetrieveInfo(in *rt.ReqRetrieveInfo) (types.Message, error) { func (r *Retrieve) Query_GetRetrieveInfo(in *rt.ReqRetrieveInfo) (types.Message, error) {
rlog.Debug("Retrieve Query", "backupaddr", in.BackupAddress, "defaddr", in.DefaultAddress) rlog.Debug("Retrieve Query", "backupaddr", in.BackupAddress, "defaddr", in.DefaultAddress)
info, err := getRetrieveInfo(r.GetLocalDB(), in.BackupAddress, in.DefaultAddress) info, err := getRetrieveInfo(r.GetLocalDB(), in.BackupAddress, in.DefaultAddress)
......
...@@ -32,15 +32,17 @@ func init() { ...@@ -32,15 +32,17 @@ func init() {
ety.InitFuncList(types.ListMethod(&Retrieve{})) ety.InitFuncList(types.ListMethod(&Retrieve{}))
} }
//const maxTimeWeight = 2 //Init retrieve
func Init(name string, sub []byte) { func Init(name string, sub []byte) {
drivers.Register(GetName(), newRetrieve, types.GetDappFork(driverName, "Enable")) drivers.Register(GetName(), newRetrieve, types.GetDappFork(driverName, "Enable"))
} }
// GetName method
func GetName() string { func GetName() string {
return newRetrieve().GetName() return newRetrieve().GetName()
} }
// Retrieve def
type Retrieve struct { type Retrieve struct {
drivers.DriverBase drivers.DriverBase
} }
...@@ -52,10 +54,12 @@ func newRetrieve() drivers.Driver { ...@@ -52,10 +54,12 @@ func newRetrieve() drivers.Driver {
return r return r
} }
// GetDriverName method
func (r *Retrieve) GetDriverName() string { func (r *Retrieve) GetDriverName() string {
return driverName return driverName
} }
// CheckTx nil
func (r *Retrieve) CheckTx(tx *types.Transaction, index int) error { func (r *Retrieve) CheckTx(tx *types.Transaction, index int) error {
return nil return nil
} }
......
...@@ -447,7 +447,7 @@ func estRetrievePerformB(t *testing.T) { ...@@ -447,7 +447,7 @@ func estRetrievePerformB(t *testing.T) {
} }
func backup(backupaddrindex int, defaultaddrindex int, privkeyindex int, delayperiod int64) ([]byte, error) { func backup(backupaddrindex int, defaultaddrindex int, privkeyindex int, delayperiod int64) ([]byte, error) {
vbackup := &rt.RetrieveAction_Backup{&rt.BackupRetrieve{BackupAddress: addr[backupaddrindex], DefaultAddress: addr[defaultaddrindex], DelayPeriod: delayperiod}} vbackup := &rt.RetrieveAction_Backup{Backup: &rt.BackupRetrieve{BackupAddress: addr[backupaddrindex], DefaultAddress: addr[defaultaddrindex], DelayPeriod: delayperiod}}
//fmt.Println(vlock) //fmt.Println(vlock)
transfer := &rt.RetrieveAction{Value: vbackup, Ty: rt.RetrieveBackup} transfer := &rt.RetrieveAction{Value: vbackup, Ty: rt.RetrieveBackup}
tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: addr[backupaddrindex]} tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: addr[backupaddrindex]}
...@@ -466,7 +466,7 @@ func backup(backupaddrindex int, defaultaddrindex int, privkeyindex int, delaype ...@@ -466,7 +466,7 @@ func backup(backupaddrindex int, defaultaddrindex int, privkeyindex int, delaype
} }
func prepare(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byte, error) { func prepare(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byte, error) {
vprepare := &rt.RetrieveAction_Prepare{&rt.PrepareRetrieve{BackupAddress: addr[backupaddrindex], DefaultAddress: addr[defaultaddrindex]}} vprepare := &rt.RetrieveAction_Prepare{Prepare: &rt.PrepareRetrieve{BackupAddress: addr[backupaddrindex], DefaultAddress: addr[defaultaddrindex]}}
transfer := &rt.RetrieveAction{Value: vprepare, Ty: rt.RetrievePreapre} transfer := &rt.RetrieveAction{Value: vprepare, Ty: rt.RetrievePreapre}
tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: addr[backupaddrindex]} tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: addr[backupaddrindex]}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -483,7 +483,7 @@ func prepare(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byt ...@@ -483,7 +483,7 @@ func prepare(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byt
} }
func perform(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byte, error) { func perform(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byte, error) {
vperform := &rt.RetrieveAction_Perform{&rt.PerformRetrieve{BackupAddress: addr[backupaddrindex], DefaultAddress: addr[defaultaddrindex]}} vperform := &rt.RetrieveAction_Perform{Perform: &rt.PerformRetrieve{BackupAddress: addr[backupaddrindex], DefaultAddress: addr[defaultaddrindex]}}
transfer := &rt.RetrieveAction{Value: vperform, Ty: rt.RetrievePerform} transfer := &rt.RetrieveAction{Value: vperform, Ty: rt.RetrievePerform}
tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: addr[backupaddrindex]} tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: addr[backupaddrindex]}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -500,7 +500,7 @@ func perform(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byt ...@@ -500,7 +500,7 @@ func perform(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byt
} }
func cancel(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byte, error) { func cancel(backupaddrindex int, defaultaddrindex int, privkeyindex int) ([]byte, error) {
vcancel := &rt.RetrieveAction_Cancel{&rt.CancelRetrieve{BackupAddress: addr[backupaddrindex], DefaultAddress: addr[defaultaddrindex]}} vcancel := &rt.RetrieveAction_Cancel{Cancel: &rt.CancelRetrieve{BackupAddress: addr[backupaddrindex], DefaultAddress: addr[defaultaddrindex]}}
transfer := &rt.RetrieveAction{Value: vcancel, Ty: rt.RetrieveCancel} transfer := &rt.RetrieveAction{Value: vcancel, Ty: rt.RetrieveCancel}
tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: addr[backupaddrindex]} tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: addr[backupaddrindex]}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -576,9 +576,8 @@ func showOrCheckAcc(c types.Chain33Client, addr string, sorc int, balance int64) ...@@ -576,9 +576,8 @@ func showOrCheckAcc(c types.Chain33Client, addr string, sorc int, balance int64)
} }
if sorc != onlyshow { if sorc != onlyshow {
return false return false
} else {
return true
} }
return true
} }
func genaddress() (string, crypto.PrivKey) { func genaddress() (string, crypto.PrivKey) {
...@@ -614,7 +613,7 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount ...@@ -614,7 +613,7 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount
//defer conn.Close() //defer conn.Close()
//fmt.Println("sign key privkey: ", common.ToHex(priv.Bytes())) //fmt.Println("sign key privkey: ", common.ToHex(priv.Bytes()))
if amount > 0 { if amount > 0 {
v := &cty.CoinsAction_Transfer{&types.AssetsTransfer{Amount: amount}} v := &cty.CoinsAction_Transfer{Transfer: &types.AssetsTransfer{Amount: amount}}
transfer := &cty.CoinsAction{Value: v, Ty: cty.CoinsActionTransfer} transfer := &cty.CoinsAction{Value: v, Ty: cty.CoinsActionTransfer}
tx := &types.Transaction{Execer: []byte("coins"), Payload: types.Encode(transfer), Fee: fee, To: to} tx := &types.Transaction{Execer: []byte("coins"), Payload: types.Encode(transfer), Fee: fee, To: to}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -630,8 +629,8 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount ...@@ -630,8 +629,8 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount
return nil, errors.New(string(reply.GetMsg())) return nil, errors.New(string(reply.GetMsg()))
} }
return tx.Hash(), nil return tx.Hash(), nil
} else { }
v := &cty.CoinsAction_Withdraw{&types.AssetsWithdraw{Amount: -amount}} v := &cty.CoinsAction_Withdraw{Withdraw: &types.AssetsWithdraw{Amount: -amount}}
withdraw := &cty.CoinsAction{Value: v, Ty: cty.CoinsActionWithdraw} withdraw := &cty.CoinsAction{Value: v, Ty: cty.CoinsActionWithdraw}
tx := &types.Transaction{Execer: []byte("coins"), Payload: types.Encode(withdraw), Fee: fee, To: to} tx := &types.Transaction{Execer: []byte("coins"), Payload: types.Encode(withdraw), Fee: fee, To: to}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -647,7 +646,7 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount ...@@ -647,7 +646,7 @@ func sendtoaddress(c types.Chain33Client, priv crypto.PrivKey, to string, amount
return nil, errors.New(string(reply.GetMsg())) return nil, errors.New(string(reply.GetMsg()))
} }
return tx.Hash(), nil return tx.Hash(), nil
}
} }
func getAccounts() (*types.WalletAccounts, error) { func getAccounts() (*types.WalletAccounts, error) {
......
...@@ -86,7 +86,7 @@ func ConstructBackupTx() *types.Transaction { ...@@ -86,7 +86,7 @@ func ConstructBackupTx() *types.Transaction {
var delayPeriod int64 = 70 var delayPeriod int64 = 70
var fee int64 = 1e6 var fee int64 = 1e6
vbackup := &rt.RetrieveAction_Backup{&rt.BackupRetrieve{BackupAddress: backupAddr, DefaultAddress: defaultAddr, DelayPeriod: delayPeriod}} vbackup := &rt.RetrieveAction_Backup{Backup: &rt.BackupRetrieve{BackupAddress: backupAddr, DefaultAddress: defaultAddr, DelayPeriod: delayPeriod}}
//fmt.Println(vlock) //fmt.Println(vlock)
transfer := &rt.RetrieveAction{Value: vbackup, Ty: rt.RetrieveBackup} transfer := &rt.RetrieveAction{Value: vbackup, Ty: rt.RetrieveBackup}
tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: backupAddr} tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: backupAddr}
...@@ -97,7 +97,7 @@ func ConstructBackupTx() *types.Transaction { ...@@ -97,7 +97,7 @@ func ConstructBackupTx() *types.Transaction {
func ConstructPrepareTx() *types.Transaction { func ConstructPrepareTx() *types.Transaction {
var fee int64 = 1e6 var fee int64 = 1e6
vprepare := &rt.RetrieveAction_Prepare{&rt.PrepareRetrieve{BackupAddress: backupAddr, DefaultAddress: defaultAddr}} vprepare := &rt.RetrieveAction_Prepare{Prepare: &rt.PrepareRetrieve{BackupAddress: backupAddr, DefaultAddress: defaultAddr}}
transfer := &rt.RetrieveAction{Value: vprepare, Ty: rt.RetrievePreapre} transfer := &rt.RetrieveAction{Value: vprepare, Ty: rt.RetrievePreapre}
tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: backupAddr} tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: backupAddr}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -109,7 +109,7 @@ func ConstructPrepareTx() *types.Transaction { ...@@ -109,7 +109,7 @@ func ConstructPrepareTx() *types.Transaction {
func ConstructPerformTx() *types.Transaction { func ConstructPerformTx() *types.Transaction {
var fee int64 = 1e6 var fee int64 = 1e6
vperform := &rt.RetrieveAction_Perform{&rt.PerformRetrieve{BackupAddress: backupAddr, DefaultAddress: defaultAddr}} vperform := &rt.RetrieveAction_Perform{Perform: &rt.PerformRetrieve{BackupAddress: backupAddr, DefaultAddress: defaultAddr}}
transfer := &rt.RetrieveAction{Value: vperform, Ty: rt.RetrievePerform} transfer := &rt.RetrieveAction{Value: vperform, Ty: rt.RetrievePerform}
tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: backupAddr} tx := &types.Transaction{Execer: []byte("retrieve"), Payload: types.Encode(transfer), Fee: fee, To: backupAddr}
tx.Nonce = r.Int63() tx.Nonce = r.Int63()
...@@ -156,11 +156,11 @@ func (e *TestDB) Set(key []byte, value []byte) error { ...@@ -156,11 +156,11 @@ func (e *TestDB) Set(key []byte, value []byte) error {
return nil return nil
} }
func (db *TestDB) BatchGet(keys [][]byte) (values [][]byte, err error) { func (e *TestDB) BatchGet(keys [][]byte) (values [][]byte, err error) {
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
//从数据库中查询数据列表,set 中的cache 更新不会影响这个list //从数据库中查询数据列表,set 中的cache 更新不会影响这个list
func (l *TestDB) List(prefix, key []byte, count, direction int32) ([][]byte, error) { func (e *TestDB) List(prefix, key []byte, count, direction int32) ([][]byte, error) {
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
...@@ -24,12 +24,15 @@ const ( ...@@ -24,12 +24,15 @@ const (
retrieveCancel = 4 retrieveCancel = 4
) )
// MaxRelation when backup
const MaxRelation = 10 const MaxRelation = 10
// DB def
type DB struct { type DB struct {
rt.Retrieve rt.Retrieve
} }
// NewDB instance
func NewDB(backupaddress string) *DB { func NewDB(backupaddress string) *DB {
r := &DB{} r := &DB{}
r.BackupAddress = backupaddress r.BackupAddress = backupaddress
...@@ -37,22 +40,25 @@ func NewDB(backupaddress string) *DB { ...@@ -37,22 +40,25 @@ func NewDB(backupaddress string) *DB {
return r return r
} }
// RelateDB on retrieve action
func (r *DB) RelateDB(defaultAddress string, createTime int64, delayPeriod int64) bool { func (r *DB) RelateDB(defaultAddress string, createTime int64, delayPeriod int64) bool {
if len(r.RetPara) >= MaxRelation { if len(r.RetPara) >= MaxRelation {
return false return false
} }
rlog.Debug("RetrieveBackup", "RelateDB", defaultAddress) rlog.Debug("RetrieveBackup", "RelateDB", defaultAddress)
para := &rt.RetrievePara{defaultAddress, retrieveBackup, createTime, 0, delayPeriod} para := &rt.RetrievePara{DefaultAddress: defaultAddress, Status: retrieveBackup, CreateTime: createTime, PrepareTime: 0, DelayPeriod: delayPeriod}
r.RetPara = append(r.RetPara, para) r.RetPara = append(r.RetPara, para)
return true return true
} }
// UnRelateDB on retrieve action
func (r *DB) UnRelateDB(index int) bool { func (r *DB) UnRelateDB(index int) bool {
r.RetPara = append(r.RetPara[:index], r.RetPara[index+1:]...) r.RetPara = append(r.RetPara[:index], r.RetPara[index+1:]...)
return true return true
} }
// CheckRelation on retrieve action
func (r *DB) CheckRelation(defaultAddress string) (int, bool) { func (r *DB) CheckRelation(defaultAddress string) (int, bool) {
for i := 0; i < len(r.RetPara); i++ { for i := 0; i < len(r.RetPara); i++ {
if r.RetPara[i].DefaultAddress == defaultAddress { if r.RetPara[i].DefaultAddress == defaultAddress {
...@@ -62,12 +68,14 @@ func (r *DB) CheckRelation(defaultAddress string) (int, bool) { ...@@ -62,12 +68,14 @@ func (r *DB) CheckRelation(defaultAddress string) (int, bool) {
return MaxRelation, false return MaxRelation, false
} }
// GetKVSet for retrieve
func (r *DB) GetKVSet() (kvset []*types.KeyValue) { func (r *DB) GetKVSet() (kvset []*types.KeyValue) {
value := types.Encode(&r.Retrieve) value := types.Encode(&r.Retrieve)
kvset = append(kvset, &types.KeyValue{Key(r.BackupAddress), value}) kvset = append(kvset, &types.KeyValue{Key: Key(r.BackupAddress), Value: value})
return kvset return kvset
} }
// Save KV
func (r *DB) Save(db dbm.KV) { func (r *DB) Save(db dbm.KV) {
set := r.GetKVSet() set := r.GetKVSet()
for i := 0; i < len(set); i++ { for i := 0; i < len(set); i++ {
...@@ -75,12 +83,14 @@ func (r *DB) Save(db dbm.KV) { ...@@ -75,12 +83,14 @@ func (r *DB) Save(db dbm.KV) {
} }
} }
// Key for retrieve
func Key(address string) (key []byte) { func Key(address string) (key []byte) {
key = append(key, []byte("mavl-retrieve-")...) key = append(key, []byte("mavl-retrieve-")...)
key = append(key, address...) key = append(key, address...)
return key return key
} }
// Action def
type Action struct { type Action struct {
coinsAccount *account.DB coinsAccount *account.DB
db dbm.KV db dbm.KV
...@@ -91,6 +101,7 @@ type Action struct { ...@@ -91,6 +101,7 @@ type Action struct {
execaddr string execaddr string
} }
// NewRetrieveAcction gen instance
func NewRetrieveAcction(r *Retrieve, tx *types.Transaction) *Action { func NewRetrieveAcction(r *Retrieve, tx *types.Transaction) *Action {
hash := tx.Hash() hash := tx.Hash()
fromaddr := tx.From() fromaddr := tx.From()
...@@ -98,7 +109,7 @@ func NewRetrieveAcction(r *Retrieve, tx *types.Transaction) *Action { ...@@ -98,7 +109,7 @@ func NewRetrieveAcction(r *Retrieve, tx *types.Transaction) *Action {
r.GetBlockTime(), r.GetHeight(), dapp.ExecAddress(string(tx.Execer))} r.GetBlockTime(), r.GetHeight(), dapp.ExecAddress(string(tx.Execer))}
} }
//wait for valuable comment // RetrieveBackup Action
func (action *Action) RetrieveBackup(backupRet *rt.BackupRetrieve) (*types.Receipt, error) { func (action *Action) RetrieveBackup(backupRet *rt.BackupRetrieve) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -149,10 +160,11 @@ func (action *Action) RetrieveBackup(backupRet *rt.BackupRetrieve) (*types.Recei ...@@ -149,10 +160,11 @@ func (action *Action) RetrieveBackup(backupRet *rt.BackupRetrieve) (*types.Recei
r.Save(action.db) r.Save(action.db)
kv = append(kv, r.GetKVSet()...) kv = append(kv, r.GetKVSet()...)
receipt = &types.Receipt{types.ExecOk, kv, logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil return receipt, nil
} }
// RetrievePrepare Action
func (action *Action) RetrievePrepare(preRet *rt.PrepareRetrieve) (*types.Receipt, error) { func (action *Action) RetrievePrepare(preRet *rt.PrepareRetrieve) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -187,10 +199,11 @@ func (action *Action) RetrievePrepare(preRet *rt.PrepareRetrieve) (*types.Receip ...@@ -187,10 +199,11 @@ func (action *Action) RetrievePrepare(preRet *rt.PrepareRetrieve) (*types.Receip
r.Save(action.db) r.Save(action.db)
kv = append(kv, r.GetKVSet()...) kv = append(kv, r.GetKVSet()...)
receipt = &types.Receipt{types.ExecOk, kv, logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil return receipt, nil
} }
// RetrievePerform Action
func (action *Action) RetrievePerform(perfRet *rt.PerformRetrieve) (*types.Receipt, error) { func (action *Action) RetrievePerform(perfRet *rt.PerformRetrieve) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -246,10 +259,11 @@ func (action *Action) RetrievePerform(perfRet *rt.PerformRetrieve) (*types.Recei ...@@ -246,10 +259,11 @@ func (action *Action) RetrievePerform(perfRet *rt.PerformRetrieve) (*types.Recei
kv = append(kv, receipt.KV...) kv = append(kv, receipt.KV...)
kv = append(kv, r.GetKVSet()...) kv = append(kv, r.GetKVSet()...)
receipt = &types.Receipt{types.ExecOk, kv, logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil return receipt, nil
} }
// RetrieveCancel Action
func (action *Action) RetrieveCancel(cancel *rt.CancelRetrieve) (*types.Receipt, error) { func (action *Action) RetrieveCancel(cancel *rt.CancelRetrieve) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -285,7 +299,7 @@ func (action *Action) RetrieveCancel(cancel *rt.CancelRetrieve) (*types.Receipt, ...@@ -285,7 +299,7 @@ func (action *Action) RetrieveCancel(cancel *rt.CancelRetrieve) (*types.Receipt,
r.Save(action.db) r.Save(action.db)
kv = append(kv, r.GetKVSet()...) kv = append(kv, r.GetKVSet()...)
receipt = &types.Receipt{types.ExecOk, kv, logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
return receipt, nil return receipt, nil
} }
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/33cn/plugin/plugin/dapp/retrieve/types" "github.com/33cn/plugin/plugin/dapp/retrieve/types"
) )
// CreateRawRetrieveBackupTx construct backup tx
func (c *Jrpc) CreateRawRetrieveBackupTx(in *RetrieveBackupTx, result *interface{}) error { func (c *Jrpc) CreateRawRetrieveBackupTx(in *RetrieveBackupTx, result *interface{}) error {
head := &types.BackupRetrieve{ head := &types.BackupRetrieve{
BackupAddress: in.BackupAddr, BackupAddress: in.BackupAddr,
...@@ -27,6 +28,7 @@ func (c *Jrpc) CreateRawRetrieveBackupTx(in *RetrieveBackupTx, result *interface ...@@ -27,6 +28,7 @@ func (c *Jrpc) CreateRawRetrieveBackupTx(in *RetrieveBackupTx, result *interface
return nil return nil
} }
// CreateRawRetrievePrepareTx construct prepare tx
func (c *Jrpc) CreateRawRetrievePrepareTx(in *RetrievePrepareTx, result *interface{}) error { func (c *Jrpc) CreateRawRetrievePrepareTx(in *RetrievePrepareTx, result *interface{}) error {
head := &types.PrepareRetrieve{ head := &types.PrepareRetrieve{
BackupAddress: in.BackupAddr, BackupAddress: in.BackupAddr,
...@@ -42,6 +44,7 @@ func (c *Jrpc) CreateRawRetrievePrepareTx(in *RetrievePrepareTx, result *interfa ...@@ -42,6 +44,7 @@ func (c *Jrpc) CreateRawRetrievePrepareTx(in *RetrievePrepareTx, result *interfa
return nil return nil
} }
// CreateRawRetrievePerformTx construct perform tx
func (c *Jrpc) CreateRawRetrievePerformTx(in *RetrievePerformTx, result *interface{}) error { func (c *Jrpc) CreateRawRetrievePerformTx(in *RetrievePerformTx, result *interface{}) error {
head := &types.PerformRetrieve{ head := &types.PerformRetrieve{
BackupAddress: in.BackupAddr, BackupAddress: in.BackupAddr,
...@@ -56,6 +59,7 @@ func (c *Jrpc) CreateRawRetrievePerformTx(in *RetrievePerformTx, result *interfa ...@@ -56,6 +59,7 @@ func (c *Jrpc) CreateRawRetrievePerformTx(in *RetrievePerformTx, result *interfa
return nil return nil
} }
// CreateRawRetrieveCancelTx construct cancel tx
func (c *Jrpc) CreateRawRetrieveCancelTx(in *RetrieveCancelTx, result *interface{}) error { func (c *Jrpc) CreateRawRetrieveCancelTx(in *RetrieveCancelTx, result *interface{}) error {
head := &types.CancelRetrieve{ head := &types.CancelRetrieve{
BackupAddress: in.BackupAddr, BackupAddress: in.BackupAddr,
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
func (c *channelClient) Backup(ctx context.Context, v *rt.BackupRetrieve) (*types.UnsignTx, error) { func (c *channelClient) Backup(ctx context.Context, v *rt.BackupRetrieve) (*types.UnsignTx, error) {
backup := &rt.RetrieveAction{ backup := &rt.RetrieveAction{
Ty: rt.RetrieveActionBackup, Ty: rt.RetrieveActionBackup,
Value: &rt.RetrieveAction_Backup{v}, Value: &rt.RetrieveAction_Backup{Backup: v},
} }
tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(backup)) tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(backup))
if err != nil { if err != nil {
...@@ -27,7 +27,7 @@ func (c *channelClient) Backup(ctx context.Context, v *rt.BackupRetrieve) (*type ...@@ -27,7 +27,7 @@ func (c *channelClient) Backup(ctx context.Context, v *rt.BackupRetrieve) (*type
func (c *channelClient) Prepare(ctx context.Context, v *rt.PrepareRetrieve) (*types.UnsignTx, error) { func (c *channelClient) Prepare(ctx context.Context, v *rt.PrepareRetrieve) (*types.UnsignTx, error) {
prepare := &rt.RetrieveAction{ prepare := &rt.RetrieveAction{
Ty: rt.RetrieveActionPrepare, Ty: rt.RetrieveActionPrepare,
Value: &rt.RetrieveAction_Prepare{v}, Value: &rt.RetrieveAction_Prepare{Prepare: v},
} }
tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(prepare)) tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(prepare))
if err != nil { if err != nil {
...@@ -41,7 +41,7 @@ func (c *channelClient) Prepare(ctx context.Context, v *rt.PrepareRetrieve) (*ty ...@@ -41,7 +41,7 @@ func (c *channelClient) Prepare(ctx context.Context, v *rt.PrepareRetrieve) (*ty
func (c *channelClient) Perform(ctx context.Context, v *rt.PerformRetrieve) (*types.UnsignTx, error) { func (c *channelClient) Perform(ctx context.Context, v *rt.PerformRetrieve) (*types.UnsignTx, error) {
perform := &rt.RetrieveAction{ perform := &rt.RetrieveAction{
Ty: rt.RetrieveActionPerform, Ty: rt.RetrieveActionPerform,
Value: &rt.RetrieveAction_Perform{v}, Value: &rt.RetrieveAction_Perform{Perform: v},
} }
tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(perform)) tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(perform))
if err != nil { if err != nil {
...@@ -54,7 +54,7 @@ func (c *channelClient) Perform(ctx context.Context, v *rt.PerformRetrieve) (*ty ...@@ -54,7 +54,7 @@ func (c *channelClient) Perform(ctx context.Context, v *rt.PerformRetrieve) (*ty
func (c *channelClient) Cancel(ctx context.Context, v *rt.CancelRetrieve) (*types.UnsignTx, error) { func (c *channelClient) Cancel(ctx context.Context, v *rt.CancelRetrieve) (*types.UnsignTx, error) {
cancel := &rt.RetrieveAction{ cancel := &rt.RetrieveAction{
Ty: rt.RetrieveActionCancel, Ty: rt.RetrieveActionCancel,
Value: &rt.RetrieveAction_Cancel{v}, Value: &rt.RetrieveAction_Cancel{Cancel: v},
} }
tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(cancel)) tx, err := types.CreateFormatTx(string(rt.ExecerRetrieve), types.Encode(cancel))
if err != nil { if err != nil {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package rpc package rpc
// RetrieveBackupTx construction
type RetrieveBackupTx struct { type RetrieveBackupTx struct {
BackupAddr string `json:"backupAddr"` BackupAddr string `json:"backupAddr"`
DefaultAddr string `json:"defaultAddr"` DefaultAddr string `json:"defaultAddr"`
...@@ -11,18 +12,21 @@ type RetrieveBackupTx struct { ...@@ -11,18 +12,21 @@ type RetrieveBackupTx struct {
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// RetrievePrepareTx construction
type RetrievePrepareTx struct { type RetrievePrepareTx struct {
BackupAddr string `json:"backupAddr"` BackupAddr string `json:"backupAddr"`
DefaultAddr string `json:"defaultAddr"` DefaultAddr string `json:"defaultAddr"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// RetrievePerformTx construction
type RetrievePerformTx struct { type RetrievePerformTx struct {
BackupAddr string `json:"backupAddr"` BackupAddr string `json:"backupAddr"`
DefaultAddr string `json:"defaultAddr"` DefaultAddr string `json:"defaultAddr"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// RetrieveCancelTx construction
type RetrieveCancelTx struct { type RetrieveCancelTx struct {
BackupAddr string `json:"backupAddr"` BackupAddr string `json:"backupAddr"`
DefaultAddr string `json:"defaultAddr"` DefaultAddr string `json:"defaultAddr"`
......
...@@ -8,10 +8,12 @@ import ( ...@@ -8,10 +8,12 @@ import (
"github.com/33cn/chain33/rpc/types" "github.com/33cn/chain33/rpc/types"
) )
// Jrpc def
type Jrpc struct { type Jrpc struct {
cli *channelClient cli *channelClient
} }
// Grpc def
type Grpc struct { type Grpc struct {
*channelClient *channelClient
} }
...@@ -20,6 +22,7 @@ type channelClient struct { ...@@ -20,6 +22,7 @@ type channelClient struct {
types.ChannelClient types.ChannelClient
} }
// Init retrieve rpc
func Init(name string, s types.RPCServer) { func Init(name string, s types.RPCServer) {
cli := &channelClient{} cli := &channelClient{}
grpc := &Grpc{channelClient: cli} grpc := &Grpc{channelClient: cli}
......
...@@ -22,6 +22,7 @@ const ( ...@@ -22,6 +22,7 @@ const (
RetrieveActionCancel = 4 RetrieveActionCancel = 4
) )
// retrieve names
var ( var (
JRPCName = "Retrieve" JRPCName = "Retrieve"
RetrieveX = "retrieve" RetrieveX = "retrieve"
......
...@@ -6,6 +6,7 @@ package types ...@@ -6,6 +6,7 @@ package types
import "errors" import "errors"
// retrieve errors
var ( var (
ErrRetrieveRepeatAddress = errors.New("ErrRetrieveRepeatAddress") ErrRetrieveRepeatAddress = errors.New("ErrRetrieveRepeatAddress")
ErrRetrieveDefaultAddress = errors.New("ErrRetrieveDefaultAddress") ErrRetrieveDefaultAddress = errors.New("ErrRetrieveDefaultAddress")
......
...@@ -18,17 +18,19 @@ func init() { ...@@ -18,17 +18,19 @@ func init() {
types.RegisterDappFork(RetrieveX, "ForkRetrive", 180000) types.RegisterDappFork(RetrieveX, "ForkRetrive", 180000)
} }
// RetrieveType def
type RetrieveType struct { type RetrieveType struct {
types.ExecTypeBase types.ExecTypeBase
} }
// NewType for retrieve
func NewType() *RetrieveType { func NewType() *RetrieveType {
c := &RetrieveType{} c := &RetrieveType{}
c.SetChild(c) c.SetChild(c)
return c return c
} }
//GetRealToAddr,避免老的,没有To字段的交易分叉 // GetRealToAddr 避免老的,没有To字段的交易分叉
func (r RetrieveType) GetRealToAddr(tx *types.Transaction) string { func (r RetrieveType) GetRealToAddr(tx *types.Transaction) string {
if len(tx.To) == 0 { if len(tx.To) == 0 {
return address.ExecAddress(string(tx.Execer)) return address.ExecAddress(string(tx.Execer))
...@@ -36,22 +38,27 @@ func (r RetrieveType) GetRealToAddr(tx *types.Transaction) string { ...@@ -36,22 +38,27 @@ func (r RetrieveType) GetRealToAddr(tx *types.Transaction) string {
return tx.To return tx.To
} }
func (at *RetrieveType) GetPayload() types.Message { // GetPayload method
func (r *RetrieveType) GetPayload() types.Message {
return &RetrieveAction{} return &RetrieveAction{}
} }
func (at *RetrieveType) GetName() string { // GetName method
func (r *RetrieveType) GetName() string {
return RetrieveX return RetrieveX
} }
func (at *RetrieveType) GetLogMap() map[int64]*types.LogInfo { // GetLogMap method
func (r *RetrieveType) GetLogMap() map[int64]*types.LogInfo {
return nil return nil
} }
func (at *RetrieveType) GetTypeMap() map[string]int32 { // GetTypeMap method
func (r *RetrieveType) GetTypeMap() map[string]int32 {
return actionName return actionName
} }
// ActionName method
func (r RetrieveType) ActionName(tx *types.Transaction) string { func (r RetrieveType) ActionName(tx *types.Transaction) string {
var action RetrieveAction var action RetrieveAction
err := types.Decode(tx.Payload, &action) err := types.Decode(tx.Payload, &action)
...@@ -70,42 +77,12 @@ func (r RetrieveType) ActionName(tx *types.Transaction) string { ...@@ -70,42 +77,12 @@ func (r RetrieveType) ActionName(tx *types.Transaction) string {
return "unknown" return "unknown"
} }
// Amount method
func (r RetrieveType) Amount(tx *types.Transaction) (int64, error) { func (r RetrieveType) Amount(tx *types.Transaction) (int64, error) {
return 0, nil return 0, nil
} }
func (retrieve RetrieveType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) { // CreateTx method
func (r RetrieveType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
return nil, nil return nil, nil
} }
type CoinsDepositLog struct {
}
func (l CoinsDepositLog) Name() string {
return "LogDeposit"
}
func (l CoinsDepositLog) Decode(msg []byte) (interface{}, error) {
var logTmp types.ReceiptAccountTransfer
err := types.Decode(msg, &logTmp)
if err != nil {
return nil, err
}
return logTmp, err
}
type RetrieveGetInfo struct {
}
func (t *RetrieveGetInfo) JsonToProto(message json.RawMessage) ([]byte, error) {
var req ReqRetrieveInfo
err := json.Unmarshal(message, &req)
if err != nil {
return nil, err
}
return types.Encode(&req), nil
}
func (t *RetrieveGetInfo) ProtoToJson(reply *types.Message) (interface{}, error) {
return reply, nil
}
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