Unverified Commit 520d7cd3 authored by vipwzw's avatar vipwzw Committed by GitHub

Merge pull request #125 from icehawk-hyb/multisig

Multisig
parents 58852ebf ae26c4b9
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
_ "github.com/33cn/plugin/plugin/dapp/game" //auto gen _ "github.com/33cn/plugin/plugin/dapp/game" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/hashlock" //auto gen _ "github.com/33cn/plugin/plugin/dapp/hashlock" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/lottery" //auto gen _ "github.com/33cn/plugin/plugin/dapp/lottery" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/multisig" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/norm" //auto gen _ "github.com/33cn/plugin/plugin/dapp/norm" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/paracross" //auto gen _ "github.com/33cn/plugin/plugin/dapp/paracross" //auto gen
_ "github.com/33cn/plugin/plugin/dapp/pokerbull" //auto gen _ "github.com/33cn/plugin/plugin/dapp/pokerbull" //auto gen
......
This diff is collapsed.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package multisig
/*
多重签名合约实现功能:
创建一个多重签名的账户,并指定owner已经权重
账户属性交易:
owner的add/del/modify/replace
资产每日限额的修改
请求权重的修改
账户属性的修改都是一个交易,需要满足权重的要求才能被执行。
账户交易的确认和撤销:当交易提交者的权重不能满足权重要求时,需要其余的owner来一起确认。owner可以撤销自己对某笔交易的确认,但此交易必须是没有被执行。已执行的不应许撤销
多重签名账户的转入和转出:转入时,to地址必须是多重签名地址,from地址必须是非多重签名地址;
转出时,from地址必须是多重签名地址,to地址必须是非多重签名地址; 传出交易需要校验权重
cli 命令行主要分三块:account 账户相关的,owner 相关的以及tx交易相关的
cli multisig
Available Commands:
account multisig account
owner multisig owner
tx multisig tx
cli multisig account
Available Commands:
address get multisig account address
assets get assets of multisig account
count get multisig account count
create Create a multisig account transaction
creator get all multisig accounts created by the address
dailylimit Create a modify assets dailylimit transaction
info get multisig account info
unspent get assets unspent today amount
weight Create a modify required weight transaction
cli multisig owner
Available Commands:
add Create a add owner transaction
del Create a del owner transaction
modify Create a modify owner weight transaction
replace Create a replace owner transaction
cli multisig tx
Available Commands:
confirm Create a confirm transaction
confirmed_weight get the weight of the transaction confirmed.
count get multisig tx count
info get multisig account tx info
transfer_in Create a transfer to multisig account transaction
transfer_out Create a transfer from multisig account transaction
txids get multisig txids
测试步骤如下:
cli seed save -p heyubin -s "voice leisure mechanic tape cluster grunt receive joke nurse between monkey lunch save useful cruise"
cli wallet unlock -p heyubin
cli account import_key -l miner -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944
cli account create -l heyubin
cli account create -l heyubin1
cli account create -l heyubin2
cli account create -l heyubin3
cli account create -l heyubin4
cli account create -l heyubin5
cli account create -l heyubin6
cli account create -l heyubin7
cli account create -l heyubin8
cli send bty transfer -a 100 -n test -t 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
cli send bty transfer -a 100 -n test -t 1Kkgztjcni3xKw95y2VZHwPpsSHDEH5sXF -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
cli send bty transfer -a 100 -n test -t 1N8LP5gBufZXCEdf3hyViDhWFqeB7WPGdv -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
cli send bty transfer -a 100 -n test -t 1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
cli send bty transfer -a 100 -n test -t "1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj" -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
cli send bty transfer -a 100 -n test -t "17a5NQTf9M2Dz9qBS8KiQ8VUg8qhoYeQbA" -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
cli send bty transfer -a 100 -n test -t "1DeGvSFX8HAFsuHxhaVkLX56Ke3FzFbdct" -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
cli send bty transfer -a 100 -n test -t "166po3ghRbRu53hu8jBBQzddp7kUJ9Ynyf" -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
cli send bty transfer -a 100 -n test -t "1KHwX7ZadNeQDjBGpnweb4k2dqj2CWtAYo" -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
第一步:1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd地址创建多重签名的账户,owner:1Kkgztjcni3xKw95y2VZHwPpsSHDEH5sXF 1N8LP5gBufZXCEdf3hyViDhWFqeB7WPGdv
//构建交易
cli send multisig account create -d 10 -e coins -s BTY -a "1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK 1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj" -w "20 10" -r 15 -k 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd
//查看创建的账户个数
cli multisig account count
//通过账户index获取账户地址
cli multisig account address -e 0 -s 0
//通过账户addr获取账户详情
cli multisig account info -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47"
第二步,向multisig合约中转账 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd
cli exec addr -e "multisig"
14uBEP6LSHKdFvy97pTYRPVPAqij6bteee
// 转账
cli send bty transfer -a 50 -n test -t 14uBEP6LSHKdFvy97pTYRPVPAqij6bteee -k 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd
cli account balance -a 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd
第三步:从指定账户转账到多重签名地址 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd --》 "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47"
cli send multisig tx transfer_in -a 40 -e coins -s BTY -t "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -n test -k 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd
//查看1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd地上有40被转出了
cli account balance -a 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd
//多重签名地址转入40并冻结
cli account balance -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47"
cli multisig account assets -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47"
第四步:从多重签名账户传出 "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" --》1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj owner:1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK签名
cli send multisig tx transfer_out -a 11 -e coins -s BTY -f "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -t 1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj -n test -k "1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK"
查询账户信息
cli multisig account info -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47"
cli multisig account assets -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47"
查询接受地址是否收到币
cli multisig account assets -a 1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj
// 查询交易计数
cli multisig tx count -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47"
// 查询交易txid
cli multisig tx txids -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -s 0 -e 0
// 查询交易信息
cli multisig tx info -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -i 0
//owner "1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj," 转账5个币到1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj owner:1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj签名
cli send multisig tx transfer_out -a 5 -e coins -s BTY -f "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -t 1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj -n test -k "1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj"
第五步:测试add/del owner 使用高权重的owner添加交易 "1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK", add 1KHwX7ZadNeQDjBGpnweb4k2dqj2CWtAYo
cli send multisig owner add -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -o 1KHwX7ZadNeQDjBGpnweb4k2dqj2CWtAYo -w 5 -k "1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK"
查看owner的添加
cli multisig account info -a 13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47
cli multisig tx info -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -i 0
//del owner
cli send multisig owner del -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -o "1KHwX7ZadNeQDjBGpnweb4k2dqj2CWtAYo" -k 1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK
// modify dailylimit
cli send multisig account dailylimit -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -e coins -s BTY -d 12 -k 1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK
// modify weight
cli send multisig account weight -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -w 16 -k 1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK
//replace owner
cli send multisig owner replace -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -n 166po3ghRbRu53hu8jBBQzddp7kUJ9Ynyf -o 1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj -k 1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK
// modify owner
cli send multisig owner modify -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -o "166po3ghRbRu53hu8jBBQzddp7kUJ9Ynyf" -w 11 -k 1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK
//获取指定地址创建的所有多重签名账户
cli multisig account creator -a 1DkrXbz2bK6XMpY4v9z2YUnhwWTXT6V5jd
// 获取指定账户上指定资产的每日余额
cli multisig account unspent -a 13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47 -e coins -s BTY
第五步:测试交易的确认和撤销
//权重低的转账,owner:166po3ghRbRu53hu8jBBQzddp7kUJ9Ynyf
cli send multisig tx transfer_out -a 10 -e coins -s BTY -f "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -t 1LDGrokrZjo1HtSmSnw8ef3oy5Vm1nctbj -n test -k "166po3ghRbRu53hu8jBBQzddp7kUJ9Ynyf"
//撤销对某笔交易的确认
cli send multisig tx confirm -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -i 8 -c f -k 166po3ghRbRu53hu8jBBQzddp7kUJ9Ynyf
//确认某笔交易
cli send multisig tx confirm -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -i 8 -k "166po3ghRbRu53hu8jBBQzddp7kUJ9Ynyf"
cli send multisig tx confirm -a "13q53Ga1kquDCqx7EWF8FU94tLUK18Zd47" -i 8 -k "1C5xK2ytuoFqxmVGMcyz9XFKFWcDA8T3rK"
*/
This diff is collapsed.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executor
import (
"github.com/33cn/chain33/types"
mty "github.com/33cn/plugin/plugin/dapp/multisig/types"
)
//Exec_MultiSigAccCreate 创建多重签名账户
func (m *MultiSig) Exec_MultiSigAccCreate(payload *mty.MultiSigAccCreate, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newAction(m, tx, int32(index))
return action.MultiSigAccCreate(payload)
}
//Exec_MultiSigOwnerOperate 多重签名账户owner属性的修改:owner的add/del/replace等
func (m *MultiSig) Exec_MultiSigOwnerOperate(payload *mty.MultiSigOwnerOperate, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newAction(m, tx, int32(index))
return action.MultiSigOwnerOperate(payload)
}
//Exec_MultiSigAccOperate 多重签名账户属性的修改:weight权重以及每日限额的修改
func (m *MultiSig) Exec_MultiSigAccOperate(payload *mty.MultiSigAccOperate, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newAction(m, tx, int32(index))
return action.MultiSigAccOperate(payload)
}
//Exec_MultiSigConfirmTx 多重签名账户上交易的确认和撤销
func (m *MultiSig) Exec_MultiSigConfirmTx(payload *mty.MultiSigConfirmTx, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newAction(m, tx, int32(index))
return action.MultiSigConfirmTx(payload)
}
//Exec_MultiSigExecTransferTo 合约中外部账户转账到多重签名账户,Addr --->multiSigAddr
func (m *MultiSig) Exec_MultiSigExecTransferTo(payload *mty.MultiSigExecTransferTo, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newAction(m, tx, int32(index))
return action.MultiSigExecTransferTo(payload)
}
//Exec_MultiSigExecTransferFrom 合约中多重签名账户转账到外部账户,multiSigAddr--->Addr
func (m *MultiSig) Exec_MultiSigExecTransferFrom(payload *mty.MultiSigExecTransferFrom, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newAction(m, tx, int32(index))
return action.MultiSigExecTransferFrom(payload)
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executor
import (
"github.com/33cn/chain33/types"
mty "github.com/33cn/plugin/plugin/dapp/multisig/types"
)
//ExecDelLocal_MultiSigAccCreate 创建多重签名账户,根据payload和receiptData信息获取相关信息并保存到db中
func (m *MultiSig) ExecDelLocal_MultiSigAccCreate(payload *mty.MultiSigAccCreate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, false)
if err != nil {
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecDelLocal_MultiSigOwnerOperate 多重签名账户owner属性的修改:owner的add/del/replace/modify等
func (m *MultiSig) ExecDelLocal_MultiSigOwnerOperate(payload *mty.MultiSigOwnerOperate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, false)
if err != nil {
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecDelLocal_MultiSigAccOperate 多重签名账户属性的修改:weight权重以及每日限额的修改
func (m *MultiSig) ExecDelLocal_MultiSigAccOperate(payload *mty.MultiSigAccOperate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, false)
if err != nil {
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecDelLocal_MultiSigConfirmTx 多重签名账户上交易的确认和撤销
func (m *MultiSig) ExecDelLocal_MultiSigConfirmTx(payload *mty.MultiSigConfirmTx, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, false)
if err != nil {
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecDelLocal_MultiSigExecTransferTo 合约中外部账户转账到多重签名账户,Addr --->multiSigAddr
func (m *MultiSig) ExecDelLocal_MultiSigExecTransferTo(payload *mty.MultiSigExecTransferTo, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.saveMultiSigTransfer(tx, mty.IsSubmit, false)
if err != nil {
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecDelLocal_MultiSigExecTransferFrom 合约中多重签名账户转账到外部账户,multiSigAddr--->Addr
func (m *MultiSig) ExecDelLocal_MultiSigExecTransferFrom(payload *mty.MultiSigExecTransferFrom, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, false)
if err != nil {
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executor
import (
"github.com/33cn/chain33/types"
mty "github.com/33cn/plugin/plugin/dapp/multisig/types"
)
//ExecLocal_MultiSigAccCreate 创建多重签名账户,根据payload和receiptData信息获取相关信息并保存到db中
func (m *MultiSig) ExecLocal_MultiSigAccCreate(payload *mty.MultiSigAccCreate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, true)
if err != nil {
multisiglog.Error("ExecLocal_MultiSigAccCreate", "err", err)
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecLocal_MultiSigOwnerOperate 多重签名账户owner属性的修改:owner的add/del/replace/modify等
func (m *MultiSig) ExecLocal_MultiSigOwnerOperate(payload *mty.MultiSigOwnerOperate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, true)
if err != nil {
multisiglog.Error("ExecLocal_MultiSigOwnerOperate", "err", err)
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecLocal_MultiSigAccOperate 多重签名账户属性的修改:weight权重以及每日限额的修改
func (m *MultiSig) ExecLocal_MultiSigAccOperate(payload *mty.MultiSigAccOperate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, true)
if err != nil {
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecLocal_MultiSigConfirmTx 多重签名账户上交易的确认和撤销
func (m *MultiSig) ExecLocal_MultiSigConfirmTx(payload *mty.MultiSigConfirmTx, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, true)
if err != nil {
multisiglog.Error("ExecLocal_MultiSigConfirmTx", "err", err)
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecLocal_MultiSigExecTransferTo 合约中外部账户转账到多重签名账户,Addr --->multiSigAddr
func (m *MultiSig) ExecLocal_MultiSigExecTransferTo(payload *mty.MultiSigExecTransferTo, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.saveMultiSigTransfer(tx, mty.IsSubmit, true)
if err != nil {
multisiglog.Error("ExecLocal_MultiSigExecTransferTo", "err", err)
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
//ExecLocal_MultiSigExecTransferFrom 合约中多重签名账户转账到外部账户,multiSigAddr--->Addr
func (m *MultiSig) ExecLocal_MultiSigExecTransferFrom(payload *mty.MultiSigExecTransferFrom, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
if receiptData.GetTy() != types.ExecOk {
return &types.LocalDBSet{}, nil
}
kv, err := m.execLocalMultiSigReceipt(receiptData, tx, true)
if err != nil {
multisiglog.Error("ExecLocal_MultiSigExecTransferFrom", "err", err)
return nil, err
}
return &types.LocalDBSet{KV: kv}, nil
}
This diff is collapsed.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executor
import (
"fmt"
)
//数据库存储格式key
const (
//MultiSigPrefix statedb中账户和交易的存储格式
MultiSigPrefix = "mavl-multisig-"
MultiSigTxPrefix = "mavl-multisig-tx-"
//MultiSigLocalPrefix localdb中账户和交易的存储格式multisig account count记录账户个数
MultiSigLocalPrefix = "LODB-multisig-"
MultiSigAccCount = "acccount"
MultiSigAcc = "account"
MultiSigAllAcc = "allacc"
MultiSigTx = "tx"
MultiSigRecvAssets = "assets"
MultiSigAccCreate = "create"
)
//statedb中账户和交易的存储格式
func calcMultiSigAccountKey(multiSigAccAddr string) (key []byte) {
return []byte(fmt.Sprintf(MultiSigPrefix+"%s", multiSigAccAddr))
}
//存储格式:"mavl-multisig-tx-accaddr-000000000000"
func calcMultiSigAccTxKey(multiSigAccAddr string, txid uint64) (key []byte) {
txstr := fmt.Sprintf("%018d", txid)
return []byte(fmt.Sprintf(MultiSigTxPrefix+"%s-%s", multiSigAccAddr, txstr))
}
//localdb中账户相关的存储格式
//记录创建的账户数量,key:Msac value:count。
func calcMultiSigAccCountKey() []byte {
return []byte(fmt.Sprintf(MultiSigLocalPrefix+"%s", MultiSigAccCount))
}
//存储所有的MultiSig账户地址:按顺序存储方便以后分页查找: key:Ms:allacc:index,value:accaddr
func calcMultiSigAllAcc(accindex int64) (key []byte) {
accstr := fmt.Sprintf("%018d", accindex)
return []byte(fmt.Sprintf(MultiSigLocalPrefix+"%s-%s", MultiSigAllAcc, accstr))
}
//记录指定账号地址的信息value:MultiSig。key:Ms:acc
func calcMultiSigAcc(addr string) (key []byte) {
return []byte(fmt.Sprintf(MultiSigLocalPrefix+"%s-%s", MultiSigAcc, addr))
}
//记录某个地址创建的所有多重签名账户。key:Ms:create:createAddr,value:[]string。
func calcMultiSigAccCreateAddr(createAddr string) (key []byte) {
return []byte(fmt.Sprintf(MultiSigLocalPrefix+"%s:-%s", MultiSigAccCreate, createAddr))
}
//localdb中账户相关的存储格式
//记录指定账号地址的信息key:Ms:tx:addr:txid value:MultiSigTx。
func calcMultiSigAccTx(addr string, txid uint64) (key []byte) {
accstr := fmt.Sprintf("%018d", txid)
return []byte(fmt.Sprintf(MultiSigLocalPrefix+"%s-%s-%s", MultiSigTx, addr, accstr))
}
//可以通过前缀查找获取指定账户上收到的所有资产数量
//MultiSig合约中账户收到指定资产的计数key:Ms:assets:addr:execname:symbol value:AccountAssets。
//message AccountAssets {
// string multiSigAddr = 1;
// string execer = 2;
// string symbol = 3;
// int64 amount = 4;
func calcAddrRecvAmountKey(addr, execname, symbol string) []byte {
return []byte(fmt.Sprintf(MultiSigLocalPrefix+"%s-%s-%s-%s", MultiSigRecvAssets, addr, execname, symbol))
}
// 前缀查找某个账户下的所有资产信息
func calcAddrRecvAmountPrefix(addr string) []byte {
return []byte(fmt.Sprintf(MultiSigLocalPrefix+"%s-%s-", MultiSigRecvAssets, addr))
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package multisig
import (
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/multisig/commands"
"github.com/33cn/plugin/plugin/dapp/multisig/executor"
"github.com/33cn/plugin/plugin/dapp/multisig/rpc"
mty "github.com/33cn/plugin/plugin/dapp/multisig/types"
)
func init() {
pluginmgr.Register(&pluginmgr.PluginBase{
Name: mty.MultiSigX,
ExecName: executor.GetName(),
Exec: executor.Init,
Cmd: commands.MultiSigCmd,
RPC: rpc.Init,
})
}
all:
./create_protobuf.sh
#!/bin/sh
protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=. --proto_path="../../../../vendor/github.com/33cn/chain33/types/proto/"
This diff is collapsed.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc_test
import (
"strings"
"testing"
commonlog "github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/rpc/jsonclient"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
mty "github.com/33cn/plugin/plugin/dapp/multisig/types"
"github.com/stretchr/testify/assert"
// 注册system和plugin 包
rpctypes "github.com/33cn/chain33/rpc/types"
_ "github.com/33cn/chain33/system"
_ "github.com/33cn/plugin/plugin"
)
func init() {
commonlog.SetLogLevel("error")
}
func TestJRPCChannel(t *testing.T) {
// 启动RPCmocker
mocker := testnode.New("--notset--", nil)
defer func() {
mocker.Close()
}()
mocker.Listen()
jrpcClient := mocker.GetJSONC()
testCases := []struct {
fn func(*testing.T, *jsonclient.JSONClient) error
}{
{fn: testCreateMultiSigAccCreateCmd},
{fn: testCreateMultiSigAccOwnerAddCmd},
{fn: testCreateMultiSigAccOwnerDelCmd},
{fn: testCreateMultiSigAccOwnerModifyCmd},
{fn: testCreateMultiSigAccOwnerReplaceCmd},
{fn: testCreateMultiSigAccWeightModifyCmd},
{fn: testCreateMultiSigAccDailyLimitModifyCmd},
{fn: testCreateMultiSigConfirmTxCmd},
{fn: testCreateMultiSigAccTransferInCmd},
{fn: testCreateMultiSigAccTransferOutCmd},
{fn: testGetMultiSigAccCountCmd},
{fn: testGetMultiSigAccountsCmd},
{fn: testGetMultiSigAccountInfoCmd},
{fn: testGetMultiSigAccTxCountCmd},
{fn: testGetMultiSigTxidsCmd},
{fn: testGetMultiSigTxInfoCmd},
{fn: testGetGetMultiSigTxConfirmedWeightCmd},
{fn: testGetGetMultiSigAccUnSpentTodayCmd},
{fn: testGetMultiSigAccAssetsCmd},
{fn: testGetMultiSigAccAllAddressCmd},
}
for index, testCase := range testCases {
err := testCase.fn(t, jrpcClient)
if err == nil {
continue
}
assert.NotEqualf(t, err, types.ErrActionNotSupport, "test index %d", index)
if strings.Contains(err.Error(), "rpc: can't find") {
assert.FailNowf(t, err.Error(), "test index %d", index)
}
}
}
//创建交易
func testCreateMultiSigAccCreateCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigAccCreate{}
return jrpc.Call("multisig.MultiSigAccCreateTx", params, nil)
}
func testCreateMultiSigAccOwnerAddCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigOwnerOperate{}
return jrpc.Call("multisig.MultiSigOwnerOperateTx", params, nil)
}
func testCreateMultiSigAccOwnerDelCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigOwnerOperate{}
return jrpc.Call("multisig.MultiSigOwnerOperateTx", params, nil)
}
func testCreateMultiSigAccOwnerModifyCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigOwnerOperate{}
return jrpc.Call("multisig.MultiSigOwnerOperateTx", params, nil)
}
func testCreateMultiSigAccOwnerReplaceCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigOwnerOperate{}
return jrpc.Call("multisig.MultiSigOwnerOperateTx", params, nil)
}
func testCreateMultiSigAccWeightModifyCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigAccOperate{}
return jrpc.Call("multisig.MultiSigAccOperateTx", params, nil)
}
func testCreateMultiSigAccDailyLimitModifyCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigAccOperate{}
return jrpc.Call("multisig.MultiSigAccOperateTx", params, nil)
}
func testCreateMultiSigConfirmTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigConfirmTx{}
return jrpc.Call("multisig.MultiSigConfirmTx", params, nil)
}
func testCreateMultiSigAccTransferInCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigExecTransferTo{}
return jrpc.Call("multisig.MultiSigAccTransferInTx", params, nil)
}
func testCreateMultiSigAccTransferOutCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &mty.MultiSigExecTransferFrom{}
return jrpc.Call("multisig.MultiSigAccTransferOutTx", params, nil)
}
//get 多重签名账户信息
func testGetMultiSigAccCountCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &rpctypes.Query4Jrpc{
Execer: mty.MultiSigX,
FuncName: "MultiSigAccCount",
Payload: types.MustPBToJSON(&types.ReqNil{}),
}
var res types.Int64
return jrpc.Call("Chain33.Query", params, &res)
}
func testGetMultiSigAccountsCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &rpctypes.Query4Jrpc{
Execer: mty.MultiSigX,
FuncName: "MultiSigAccounts",
Payload: types.MustPBToJSON(&mty.ReqMultiSigAccs{}),
}
var res mty.ReplyMultiSigAccs
return jrpc.Call("Chain33.Query", params, &res)
}
func testGetMultiSigAccountInfoCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &rpctypes.Query4Jrpc{
Execer: mty.MultiSigX,
FuncName: "MultiSigAccountInfo",
Payload: types.MustPBToJSON(&mty.ReqMultiSigAccInfo{}),
}
var res mty.MultiSig
return jrpc.Call("Chain33.Query", params, &res)
}
func testGetMultiSigAccTxCountCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &rpctypes.Query4Jrpc{
Execer: mty.MultiSigX,
FuncName: "MultiSigAccTxCount",
Payload: types.MustPBToJSON(&mty.ReqMultiSigAccInfo{}),
}
var res mty.Uint64
return jrpc.Call("Chain33.Query", params, &res)
}
func testGetMultiSigTxidsCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
params := &rpctypes.Query4Jrpc{
Execer: mty.MultiSigX,
FuncName: "MultiSigTxids",
Payload: types.MustPBToJSON(&mty.ReqMultiSigTxids{}),
}
var res mty.ReplyMultiSigTxids
return jrpc.Call("Chain33.Query", params, &res)
}
func testGetMultiSigTxInfoCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &mty.ReqMultiSigTxInfo{}
params.Execer = mty.MultiSigX
params.FuncName = "MultiSigTxInfo"
params.Payload = types.MustPBToJSON(req)
rep = &mty.MultiSigTx{}
return jrpc.Call("Chain33.Query", &params, rep)
}
func testGetGetMultiSigTxConfirmedWeightCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &mty.ReqMultiSigTxInfo{}
params.Execer = mty.MultiSigX
params.FuncName = "MultiSigTxConfirmedWeight"
params.Payload = types.MustPBToJSON(req)
rep = &mty.Uint64{}
return jrpc.Call("Chain33.Query", &params, rep)
}
func testGetGetMultiSigAccUnSpentTodayCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &mty.ReqAccAssets{}
req.IsAll = true
params.Execer = mty.MultiSigX
params.FuncName = "MultiSigAccUnSpentToday"
params.Payload = types.MustPBToJSON(req)
rep = &mty.ReplyUnSpentAssets{}
return jrpc.Call("Chain33.Query", &params, rep)
}
func testGetMultiSigAccAssetsCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &mty.ReqAccAssets{}
req.IsAll = true
params.Execer = mty.MultiSigX
params.FuncName = "MultiSigAccAssets"
params.Payload = types.MustPBToJSON(req)
rep = &mty.ReplyAccAssets{}
return jrpc.Call("Chain33.Query", &params, rep)
}
func testGetMultiSigAccAllAddressCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := mty.ReqMultiSigAccInfo{
MultiSigAccAddr: "14jv8WB7CwNQSnh4qo9WDBgRPRBjM5LQo6",
}
params.Execer = mty.MultiSigX
params.FuncName = "MultiSigAccAllAddress"
params.Payload = types.MustPBToJSON(&req)
rep = &mty.AccAddress{}
return jrpc.Call("Chain33.Query", &params, rep)
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc
import (
"encoding/hex"
"github.com/33cn/chain33/types"
mty "github.com/33cn/plugin/plugin/dapp/multisig/types"
)
// MultiSigAccCreateTx :构造创建多重签名账户的交易
func (c *Jrpc) MultiSigAccCreateTx(param *mty.MultiSigAccCreate, result *interface{}) error {
if param == nil {
return types.ErrInvalidParam
}
data, err := types.CallCreateTx(types.ExecName(mty.MultiSigX), "MultiSigAccCreate", param)
if err != nil {
return err
}
*result = hex.EncodeToString(data)
return nil
}
// MultiSigOwnerOperateTx :构造修改多重签名账户owner属性的交易
func (c *Jrpc) MultiSigOwnerOperateTx(param *mty.MultiSigOwnerOperate, result *interface{}) error {
if param == nil {
return types.ErrInvalidParam
}
data, err := types.CallCreateTx(types.ExecName(mty.MultiSigX), "MultiSigOwnerOperate", param)
if err != nil {
return err
}
*result = hex.EncodeToString(data)
return nil
}
// MultiSigAccOperateTx :构造修改多重签名账户属性的交易
func (c *Jrpc) MultiSigAccOperateTx(param *mty.MultiSigAccOperate, result *interface{}) error {
if param == nil {
return types.ErrInvalidParam
}
data, err := types.CallCreateTx(types.ExecName(mty.MultiSigX), "MultiSigAccOperate", param)
if err != nil {
return err
}
*result = hex.EncodeToString(data)
return nil
}
// MultiSigConfirmTx :构造确认多重签名账户的交易
func (c *Jrpc) MultiSigConfirmTx(param *mty.MultiSigConfirmTx, result *interface{}) error {
if param == nil {
return types.ErrInvalidParam
}
data, err := types.CallCreateTx(types.ExecName(mty.MultiSigX), "MultiSigConfirmTx", param)
if err != nil {
return err
}
*result = hex.EncodeToString(data)
return nil
}
// MultiSigAccTransferInTx :构造在多重签名合约中转账到多重签名账户的交易
func (c *Jrpc) MultiSigAccTransferInTx(param *mty.MultiSigExecTransferTo, result *interface{}) error {
if param == nil {
return types.ErrInvalidParam
}
v := *param
data, err := types.CallCreateTx(types.ExecName(mty.MultiSigX), "MultiSigExecTransferTo", &v)
if err != nil {
return err
}
*result = hex.EncodeToString(data)
return nil
}
// MultiSigAccTransferOutTx :构造在多重签名合约中从多重签名账户转账的交易
func (c *Jrpc) MultiSigAccTransferOutTx(param *mty.MultiSigExecTransferFrom, result *interface{}) error {
if param == nil {
return types.ErrInvalidParam
}
v := *param
data, err := types.CallCreateTx(types.ExecName(mty.MultiSigX), "MultiSigExecTransferFrom", &v)
if err != nil {
return err
}
*result = hex.EncodeToString(data)
return nil
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc
import (
"github.com/33cn/chain33/rpc/types"
)
// Jrpc 申明Jrpc结构体
type Jrpc struct {
cli *channelClient
}
// Grpc 申明Grpc结构体
type Grpc struct {
*channelClient
}
type channelClient struct {
types.ChannelClient
}
// Init 初始化rpc实例
func Init(name string, s types.RPCServer) {
cli := &channelClient{}
grpc := &Grpc{channelClient: cli}
cli.Init(name, s, &Jrpc{cli: cli}, grpc)
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package types
import (
"strings"
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
var multisiglog = log15.New("module", "execs.multisig")
// OwnerAdd : 交易操作类型
var (
OwnerAdd uint64 = 1
OwnerDel uint64 = 2
OwnerModify uint64 = 3
OwnerReplace uint64 = 4
//AccWeightOp 账户属性的操作
AccWeightOp = true
AccDailyLimitOp = false
//OwnerOperate 多重签名交易类型:转账,owner操作,account操作
OwnerOperate uint64 = 1
AccountOperate uint64 = 2
TransferOperate uint64 = 3
//IsSubmit :
IsSubmit = true
IsConfirm = false
MultiSigX = "multisig"
OneDaySecond int64 = 24 * 3600
MinOwnersInit = 2
MinOwnersCount = 1 //一个多重签名的账户最少要保留一个owner
MaxOwnersCount = 20 //一个多重签名的账户最多拥有20个owner
Multisiglog = log15.New("module", MultiSigX)
)
// MultiSig 交易的actionid
const (
ActionMultiSigAccCreate = 10000
ActionMultiSigOwnerOperate = 10001
ActionMultiSigAccOperate = 10002
ActionMultiSigConfirmTx = 10003
ActionMultiSigExecTransferTo = 10004
ActionMultiSigExecTransferFrom = 10005
)
//多重签名账户执行输出的logid
const (
TyLogMultiSigAccCreate = 10000 //只输出多重签名的账户地址
TyLogMultiSigOwnerAdd = 10001 //输出add的owner:addr和weight
TyLogMultiSigOwnerDel = 10002 //输出del的owner:addr和weight
TyLogMultiSigOwnerModify = 10003 //输出modify的owner:preweight以及currentweight
TyLogMultiSigOwnerReplace = 10004 //输出old的owner的信息:以及当前的owner信息:addr+weight
TyLogMultiSigAccWeightModify = 10005 //输出修改前后确认权重的值:preReqWeight和curReqWeight
TyLogMultiSigAccDailyLimitAdd = 10006 //输出add的DailyLimit:Symbol和DailyLimit
TyLogMultiSigAccDailyLimitModify = 10007 //输出modify的DailyLimit:preDailyLimit以及currentDailyLimit
TyLogMultiSigConfirmTx = 10008 //对某笔未执行交易的确认
TyLogMultiSigConfirmTxRevoke = 10009 //已经确认交易的撤销只针对还未执行的交易
TyLogDailyLimitUpdate = 10010 //DailyLimit更新,DailyLimit在Submit和Confirm阶段都可能有变化
TyLogMultiSigTx = 10011 //在Submit提交交易阶段才会有更新
TyLogTxCountUpdate = 10012 //txcount只在在Submit阶段提交新的交易是才会增加计数
)
//AccAssetsResult 账户资产cli的显示,主要是amount需要转换成浮点型字符串
type AccAssetsResult struct {
Execer string `json:"execer,omitempty"`
Symbol string `json:"symbol,omitempty"`
Currency int32 `json:"currency,omitempty"`
Balance string `json:"balance,omitempty"`
Frozen string `json:"frozen,omitempty"`
Receiver string `json:"receiver,omitempty"`
Addr string `json:"addr,omitempty"`
}
//DailyLimitResult 每日限额信息的显示cli
type DailyLimitResult struct {
Symbol string `json:"symbol,omitempty"`
Execer string `json:"execer,omitempty"`
DailyLimit string `json:"dailyLimit,omitempty"`
SpentToday string `json:"spent,omitempty"`
LastDay string `json:"lastday,omitempty"`
}
//MultiSigResult 多重签名账户信息的显示cli
type MultiSigResult struct {
CreateAddr string `json:"createAddr,omitempty"`
MultiSigAddr string `json:"multiSigAddr,omitempty"`
Owners []*Owner `json:"owners,omitempty"`
DailyLimits []*DailyLimitResult `json:"dailyLimits,omitempty"`
TxCount uint64 `json:"txCount,omitempty"`
RequiredWeight uint64 `json:"requiredWeight,omitempty"`
}
//UnSpentAssetsResult 每日限额之内未花费额度的显示cli
type UnSpentAssetsResult struct {
Symbol string `json:"symbol,omitempty"`
Execer string `json:"execer,omitempty"`
UnSpent string `json:"unspent,omitempty"`
}
//IsAssetsInvalid 资产的合法性检测,Symbol:必须全部大写,例如:BTY,coins.BTY。exec:必须在types.AllowUserExec中存在
func IsAssetsInvalid(exec, symbol string) error {
//exec检测
allowExeName := types.AllowUserExec
nameLen := len(allowExeName)
execValid := false
for i := 0; i < nameLen; i++ {
if exec == string(allowExeName[i]) {
execValid = true
break
}
}
if !execValid {
multisiglog.Error("IsAssetsInvalid", "exec", exec)
return ErrInvalidExec
}
//Symbol检测
symbolstr := strings.Split(symbol, ".")[len(strings.Split(symbol, "."))-1]
valid := validSymbol([]byte(symbolstr))
if !valid {
multisiglog.Error("IsAssetsInvalid", "symbol", symbol)
return ErrInvalidSymbol
}
return nil
}
func isUpperChar(a byte) bool {
res := (a <= 'Z' && a >= 'A')
return res
}
func validSymbol(cs []byte) bool {
for _, c := range cs {
if !isUpperChar(c) {
return false
}
}
return true
}
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package types
import "errors"
//multisig 合约的错误码
var (
ErrRequiredweight = errors.New("ErrRequiredweight")
ErrCreatAccountAddr = errors.New("ErrCreatAccountAddr")
ErrOwnerExist = errors.New("ErrOwnerExist")
ErrOwnerNotExist = errors.New("ErrOwnerNotExist")
ErrTotalWeightNotEnough = errors.New("ErrTotalWeightNotEnough")
ErrIsNotOwner = errors.New("ErrIsNotOwner")
ErrDailyLimitIsZero = errors.New("ErrDailyLimitIsZero")
ErrInvalidTxid = errors.New("ErrInvalidTxid")
ErrTxidNotExist = errors.New("ErrTxidNotExist")
ErrTxHasExecuted = errors.New("ErrTxHasExecuted")
ErrDupConfirmed = errors.New("ErrDupConfirmed")
ErrConfirmNotExist = errors.New("ErrConfirmNotExist")
ErrExecerHashNoMatch = errors.New("ErrExecerHashNoMatch")
ErrPayLoadTypeNoMatch = errors.New("ErrPayLoadTypeNoMatch")
ErrTxHashNoMatch = errors.New("ErrTxHashNoMatch")
ErrAccCountNoMatch = errors.New("ErrAccCountNoMatch")
ErrAccountHasExist = errors.New("ErrAccountHasExist")
ErrOwnerNoMatch = errors.New("ErrOwnerNoMatch")
ErrDailyLimitNoMatch = errors.New("ErrDailyLimitNoMatch")
ErrExecutedNoMatch = errors.New("ErrExecutedNoMatch")
ErrActionTyNoMatch = errors.New("ErrActionTyNoMatch")
ErrTxTypeNoMatch = errors.New("ErrTxTypeNoMatch")
ErrTxidHasExist = errors.New("ErrTxidHasExist")
ErrOnlyOneOwner = errors.New("ErrOnlyOneOwner")
ErrOperateType = errors.New("ErrOperateType")
ErrNewOwnerExist = errors.New("ErrNewOwnerExist")
ErrOwnerLessThanTwo = errors.New("ErrOwnerLessThanTwo")
ErrAddrNotSupport = errors.New("ErrAddrNotSupport")
ErrMaxOwnerCount = errors.New("ErrMaxOwnerCount")
ErrInvalidSymbol = errors.New("ErrInvalidSymbol")
ErrInvalidExec = errors.New("ErrInvalidExec")
ErrInvalidWeight = errors.New("ErrInvalidWeight")
ErrInvalidDailyLimit = errors.New("ErrInvalidDailyLimit")
)
This diff is collapsed.
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package types
import (
"reflect"
"github.com/33cn/chain33/types"
)
func init() {
types.AllowUserExec = append(types.AllowUserExec, []byte(MultiSigX))
types.RegistorExecutor(MultiSigX, NewType())
types.RegisterDappFork(MultiSigX, "Enable", 0)
}
// MultiSigType multisig合约结构体
type MultiSigType struct {
types.ExecTypeBase
}
// NewType new一个新的multisig合约实例
func NewType() *MultiSigType {
c := &MultiSigType{}
c.SetChild(c)
return c
}
//GetPayload 获取交易payload的结构体信息:也就是multisig.pb.go中定义的具体交易类型结构体
func (m *MultiSigType) GetPayload() types.Message {
return &MultiSigAction{}
}
//GetName 获取合约name
func (m *MultiSigType) GetName() string {
return MultiSigX
}
//GetTypeMap 获取处理具体交易的接口函数,也就是exec.go中的函数实现,去掉EXEC_
func (m *MultiSigType) GetTypeMap() map[string]int32 {
return map[string]int32{
"MultiSigAccCreate": ActionMultiSigAccCreate,
"MultiSigOwnerOperate": ActionMultiSigOwnerOperate,
"MultiSigAccOperate": ActionMultiSigAccOperate,
"MultiSigConfirmTx": ActionMultiSigConfirmTx,
"MultiSigExecTransferTo": ActionMultiSigExecTransferTo,
"MultiSigExecTransferFrom": ActionMultiSigExecTransferFrom,
}
}
//GetLogMap 获取具体执行Receiptlog对应的结构体:
func (m *MultiSigType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{
TyLogMultiSigAccCreate: {Ty: reflect.TypeOf(MultiSig{}), Name: "LogMultiSigAccCreate"},
TyLogMultiSigOwnerAdd: {Ty: reflect.TypeOf(ReceiptOwnerAddOrDel{}), Name: "LogMultiSigOwnerAdd"},
TyLogMultiSigOwnerDel: {Ty: reflect.TypeOf(ReceiptOwnerAddOrDel{}), Name: "LogMultiSigOwnerDel"},
TyLogMultiSigOwnerModify: {Ty: reflect.TypeOf(ReceiptOwnerModOrRep{}), Name: "LogMultiSigOwnerModify"},
TyLogMultiSigOwnerReplace: {Ty: reflect.TypeOf(ReceiptOwnerModOrRep{}), Name: "LogMultiSigOwnerReplace"},
TyLogMultiSigAccWeightModify: {Ty: reflect.TypeOf(ReceiptWeightModify{}), Name: "LogMultiSigAccWeightModify"},
TyLogMultiSigAccDailyLimitAdd: {Ty: reflect.TypeOf(ReceiptDailyLimitOperate{}), Name: "LogMultiSigAccDailyLimitAdd"},
TyLogMultiSigAccDailyLimitModify: {Ty: reflect.TypeOf(ReceiptDailyLimitOperate{}), Name: "LogMultiSigAccDailyLimitModify"},
TyLogMultiSigConfirmTx: {Ty: reflect.TypeOf(ReceiptConfirmTx{}), Name: "LogMultiSigConfirmTx"},
TyLogMultiSigConfirmTxRevoke: {Ty: reflect.TypeOf(ReceiptConfirmTx{}), Name: "LogMultiSigConfirmTxRevoke"},
TyLogDailyLimitUpdate: {Ty: reflect.TypeOf(ReceiptAccDailyLimitUpdate{}), Name: "LogAccDailyLimitUpdate"},
TyLogMultiSigTx: {Ty: reflect.TypeOf(ReceiptMultiSigTx{}), Name: "LogMultiSigAccTx"},
TyLogTxCountUpdate: {Ty: reflect.TypeOf(ReceiptTxCountUpdate{}), Name: "LogTxCountUpdate"},
}
}
//DecodePayload 解码交易的Payload信息
func (m MultiSigType) DecodePayload(tx *types.Transaction) (types.Message, error) {
var action MultiSigAction
err := types.Decode(tx.Payload, &action)
if err != nil {
return nil, err
}
return &action, nil
}
//ActionName 获取actionid对应的name
func (m MultiSigType) ActionName(tx *types.Transaction) string {
var g MultiSigAction
err := types.Decode(tx.Payload, &g)
if err != nil {
return "unknown-MultiSig-action-err"
}
if g.Ty == ActionMultiSigAccCreate && g.GetMultiSigAccCreate() != nil {
return "MultiSigAccCreate"
} else if g.Ty == ActionMultiSigOwnerOperate && g.GetMultiSigOwnerOperate() != nil {
return "MultiSigOwnerOperate"
} else if g.Ty == ActionMultiSigAccOperate && g.GetMultiSigAccOperate() != nil {
return "MultiSigAccOperate"
} else if g.Ty == ActionMultiSigConfirmTx && g.GetMultiSigConfirmTx() != nil {
return "MultiSigTxConfirm"
} else if g.Ty == ActionMultiSigExecTransferTo && g.GetMultiSigExecTransferTo() != nil {
return "MultiSigExecTransfer"
} else if g.Ty == ActionMultiSigExecTransferFrom && g.GetMultiSigExecTransferFrom() != nil {
return "MultiSigAccExecTransfer"
}
return "unknown"
}
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