Commit 814d6a11 authored by harrylee's avatar harrylee Committed by vipwzw

add accountmanager

parent cde06358
all:
chmod +x ./build.sh
./build.sh $(OUT) $(FLAG)
#!/bin/sh
# 官方ci集成脚本
strpwd=$(pwd)
strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
#FLAG=$2
mkdir -p "${OUT_DIR}"
cp ./build/* "${OUT_DIR}"
/*Package commands implement dapp client commands*/
package commands
import (
"github.com/spf13/cobra"
)
/*
* 实现合约对应客户端
*/
// Cmd accountmanager client command
func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "accountmanager",
Short: "accountmanager command",
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(
//add sub command
)
return cmd
}
package executor
import (
"fmt"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
et "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
// Action action struct
type Action struct {
statedb dbm.KV
txhash []byte
fromaddr string
blocktime int64
height int64
execaddr string
localDB dbm.KVDB
index int
api client.QueueProtocolAPI
}
func NewAction(e accountmanager, tx *types.Transaction, index int) *Action {
hash := tx.Hash()
fromaddr := tx.From()
return &Action{e.GetStateDB(), hash, fromaddr,
e.GetBlockTime(), e.GetHeight(), dapp.ExecAddress(string(tx.Execer)), e.GetLocalDB(), index, e.GetAPI()}
}
//GetIndex get index
func (a *Action) GetIndex() int64 {
return (a.height*types.MaxTxsPerBlock + int64(a.index)) * 1e4
}
//GetKVSet get kv set
func (a *Action) GetKVSet(account *et.Account) (kvset []*types.KeyValue) {
kvset = append(kvset, &types.KeyValue{Key: calcAccountKey(account.AccountID), Value: types.Encode(account)})
return kvset
}
func (a *Action) Register(payload *et.Register) (*types.Receipt, error) {
var logs []*types.ReceiptLog
account, err := queryMarketDepth(a.localDB, payload.AccountID)
if err == nil && account != nil {
return nil, et.ErrAccountNameExist
}
//TODO 有效期后面统一配置目前暂定五年时间
re := &et.Receipt{
AccountID: payload.AccountID,
Addr: a.fromaddr,
Index: a.GetIndex(),
Status: et.Normal,
CreateTime: a.blocktime,
ExpireTime: a.blocktime + 5*360*24*3600,
}
receiptlog := &types.ReceiptLog{Ty: et.TyRegisterLog, Log: types.Encode(re)}
logs = append(logs, receiptlog)
receipts := &types.Receipt{Ty: types.ExecOk, KV: nil, Logs: logs}
return receipts, nil
}
//为了避免别人恶意重置别人的帐号,这个操作仅有系统管理员有权限去操作
func (a *Action) ReSet(payload *et.Reset) (*types.Receipt, error) {
var logs []*types.ReceiptLog
account, err := queryMarketDepth(a.localDB, payload.AccountID)
if err != nil {
return nil, et.ErrAccountNameNotExist
}
//TODO 重置公钥锁定期暂定15天,后面可以由管理员去配置
re := &et.Receipt{
AccountID: account.AccountID,
PrevAddr: account.Addr,
Addr: payload.Addr,
Index: account.Index,
Status: et.Locked,
CreateTime: account.CreateTime,
ExpireTime: account.ExpireTime,
LockTime: a.blocktime + 15*24*3600,
}
receiptlog := &types.ReceiptLog{Ty: et.TyRegisterLog, Log: types.Encode(re)}
logs = append(logs, receiptlog)
receipts := &types.Receipt{Ty: types.ExecOk, KV: nil, Logs: logs}
return receipts, nil
}
func(a *Action) Transfer(payload *et.Transfer)(*types.Receipt, error){
cfg := a.api.GetConfig()
acc, err := account.NewAccountDB(cfg, payload.Asset.GetExecer(), payload.Asset.GetSymbol(), a.statedb)
if err != nil {
return nil, err
}
}
func queryMarketDepth(localdb dbm.KV, accountName string) (*et.Account, error) {
table := NewAccountTable(localdb)
primaryKey := []byte(fmt.Sprintf("%s", accountName))
row, err := table.GetData(primaryKey)
if err != nil {
return nil, err
}
return row.Data.(*et.Account), nil
}
package executor
import (
log "github.com/33cn/chain33/common/log/log15"
drivers "github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
accountmanagertypes "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
/*
* 执行器相关定义
* 重载基类相关接口
*/
var (
//日志
elog = log.New("module", "accountmanager.executor")
)
var driverName = accountmanagertypes.AccountmanagerX
// Init register dapp
func Init(name string, cfg *types.Chain33Config, sub []byte) {
drivers.Register(cfg, GetName(), newAccountmanager, cfg.GetDappFork(driverName, "Enable"))
InitExecType()
}
// InitExecType Init Exec Type
func InitExecType() {
ety := types.LoadExecutorType(driverName)
ety.InitFuncList(types.ListMethod(&accountmanager{}))
}
type accountmanager struct {
drivers.DriverBase
}
func newAccountmanager() drivers.Driver {
t := &accountmanager{}
t.SetChild(t)
t.SetExecutorType(types.LoadExecutorType(driverName))
return t
}
// GetName get driver name
func GetName() string {
return newAccountmanager().GetName()
}
func (a *accountmanager) GetDriverName() string {
return driverName
}
// CheckTx 实现自定义检验交易接口,供框架调用
func (a *accountmanager) CheckTx(tx *types.Transaction, index int) error {
// implement code
return nil
}
package executor
import (
"github.com/33cn/chain33/types"
aty "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
/*
* 实现交易的链上执行接口
* 关键数据上链(statedb)并生成交易回执(log)
*/
func (a *accountmanager) Exec_Register(payload *aty.Register, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt
//implement code
return receipt, nil
}
func (a *accountmanager) Exec_Reset(payload *aty.Reset, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt
//implement code
return receipt, nil
}
func (a *accountmanager) Exec_Transfer(payload *aty.Transfer, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt
//implement code
return receipt, nil
}
func (a *accountmanager) Exec_Supervise(payload *aty.Supervise, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt
//implement code
return receipt, nil
}
func (a *accountmanager) ExecApply(payload *aty.Apply, tx *types.Transaction, index int) (*types.Receipt, error) {
var receipt *types.Receipt
//implement code
return receipt, nil
}
\ No newline at end of file
package executor
import (
"github.com/33cn/chain33/types"
)
/*
* 实现区块回退时本地执行的数据清除
*/
// ExecDelLocal 回退自动删除,重写基类
func (a *accountmanager) ExecDelLocal(tx *types.Transaction, receipt *types.ReceiptData, index int) (*types.LocalDBSet, error) {
kvs, err := a.DelRollbackKV(tx, tx.Execer)
if err != nil {
return nil, err
}
dbSet := &types.LocalDBSet{}
dbSet.KV = append(dbSet.KV, kvs...)
return dbSet, nil
}
package executor
import (
"github.com/33cn/chain33/types"
accountmanagertypes "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
/*
* 实现交易相关数据本地执行,数据不上链
* 非关键数据,本地存储(localDB), 用于辅助查询,效率高
*/
func (a *accountmanager) ExecLocal_Register(payload *accountmanagertypes.Register, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
//implement code
return a.addAutoRollBack(tx, dbSet.KV), nil
}
func (a *accountmanager) ExecLocal_Reset(payload *accountmanagertypes.Reset, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
//implement code
return a.addAutoRollBack(tx, dbSet.KV), nil
}
func (a *accountmanager) ExecLocal_Apply(payload *accountmanagertypes.Apply, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
//implement code
return a.addAutoRollBack(tx, dbSet.KV), nil
}
func (a *accountmanager) ExecLocal_Transfer(payload *accountmanagertypes.Transfer, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
//implement code
return a.addAutoRollBack(tx, dbSet.KV), nil
}
func (a *accountmanager) ExecLocal_Supervise(payload *accountmanagertypes.Supervise, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{}
//implement code
return a.addAutoRollBack(tx, dbSet.KV), nil
}
//设置自动回滚
func (a *accountmanager) addAutoRollBack(tx *types.Transaction, kv []*types.KeyValue) *types.LocalDBSet {
dbSet := &types.LocalDBSet{}
dbSet.KV = a.AddRollbackKV(tx, tx.Execer, kv)
return dbSet
}
package executor
import (
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
aty "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
/*
* 用户合约存取kv数据时,key值前缀需要满足一定规范
* 即key = keyPrefix + userKey
* 需要字段前缀查询时,使用’-‘作为分割符号
*/
const (
//KeyPrefixStateDB state db key必须前缀
KeyPrefixStateDB = "mavl-accountmanager-"
//KeyPrefixLocalDB local db的key必须前缀
KeyPrefixLocalDB = "LODB-accountmanager"
)
var opt_account = &table.Option{
Prefix: KeyPrefixLocalDB,
Name: "account",
Primary: "accountName",
Index: []string{"status"},
}
//状态数据库中存储具体账户信息
func calcAccountKey(accountName string) []byte {
key := fmt.Sprintf("%s"+"accountName:%s", KeyPrefixStateDB, accountName)
return []byte(key)
}
func NewAccountTable(kvdb db.KV) *table.Table {
rowmeta := NewAccountRow()
table, err := table.NewTable(rowmeta, kvdb, opt_account)
if err != nil {
panic(err)
}
return table
}
//account table meta 结构
type AccountRow struct {
*aty.Account
}
//NewAccountRow 新建一个meta 结构
func NewAccountRow() *AccountRow {
return &AccountRow{Account: &aty.Account{}}
}
//CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存eventid)
func (m *AccountRow) CreateRow() *table.Row {
return &table.Row{Data: &aty.Account{}}
}
//SetPayload 设置数据
func (m *AccountRow) SetPayload(data types.Message) error {
if txdata, ok := data.(*aty.Account); ok {
m.Account = txdata
return nil
}
return types.ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func (m *AccountRow) Get(key string) ([]byte, error) {
if key == "accountID" {
return []byte(fmt.Sprintf("%s", m.AccountID)), nil
} else if key == "status" {
return []byte(fmt.Sprintf("%d", m.Status)), nil
}
return nil, types.ErrNotFound
}
package executor
import (
"fmt"
"testing"
)
func Test(t *testing.T){
t.Log(fmt.Sprintf("%-s","aaaa100000b"))
}
\ No newline at end of file
package types
import (
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/accountmanager/commands"
"github.com/33cn/plugin/plugin/dapp/accountmanager/executor"
"github.com/33cn/plugin/plugin/dapp/accountmanager/rpc"
accountmanagertypes "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
/*
* 初始化dapp相关的组件
*/
func init() {
pluginmgr.Register(&pluginmgr.PluginBase{
Name: accountmanagertypes.AccountmanagerX,
ExecName: executor.GetName(),
Exec: executor.Init,
Cmd: commands.Cmd,
RPC: rpc.Init,
})
}
syntax = "proto3";
package types;
message Accountmanager {
}
message AccountmanagerAction {
oneof value {
//注册
Register register = 1;
//重置公钥
Reset reset = 2;
//转账
Transfer transfer = 3;
//监管操作
Supervise supervise = 4;
//申请操作,预留接口
Apply apply = 5;
}
int32 ty = 6;
}
//注册
message Register {
string accountID = 1;
// string addr = 2;
}
//重置公钥
message Reset {
string accountID = 1;
string addr = 2;
}
//用户申请服务
message Apply {
string accountID = 1;
//操作, 0,账户注册,1,账户公钥重置 2,账户延期申请 3,账户注销
int32 op = 2;
}
//资产类型
message asset {
string execer = 1;
string symbol = 2;
}
//合约内部账户之间转账
message Transfer {
//资产类型
asset Asset = 1;
// from账户
string fromAccountID = 2;
// to账户
string toAccountID = 3;
//转账金额
int64 amount = 4;
}
//管理员监管操作
message Supervise {
//账户名单
repeated string accountIDs = 1;
//操作, 1为冻结,2为解冻
int32 op = 2;
}
message Account{
//账户名称
string accountID = 1;
//地址
string addr = 2;
//上一次公钥地址
string prevAddr = 3;
//账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
int32 status = 4;
//注册时间
int64 createTime = 5;
//失效时间
int64 expireTime = 6;
//锁定时间
int64 lockTime = 7;
//索引
int64 index = 8;
}
message Receipt{
//账户名称
string accountID = 1;
//地址
string addr = 2;
//上一次公钥地址
string prevAddr = 3;
//账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
int32 status = 4;
//注册时间
int64 createTime = 5;
//失效时间
int64 expireTime = 6;
//锁定时间
int64 lockTime = 7;
//索引
int64 index = 8;
}
service accountmanager {
}
#!/bin/sh
# proto生成命令,将pb.go文件生成到types/目录下, chain33_path支持引用chain33框架的proto文件
chain33_path=$(go list -f '{{.Dir}}' "github.com/33cn/chain33")
protoc --go_out=plugins=grpc:../types ./*.proto --proto_path=. --proto_path="${chain33_path}/types/proto/"
package rpc
/*
* 实现json rpc和grpc service接口
* json rpc用Jrpc结构作为接收实例
* grpc使用channelClient结构作为接收实例
*/
package rpc
import (
rpctypes "github.com/33cn/chain33/rpc/types"
accountmanagertypes "github.com/33cn/plugin/plugin/dapp/accountmanager/types"
)
/*
* rpc相关结构定义和初始化
*/
// 实现grpc的service接口
type channelClient struct {
rpctypes.ChannelClient
}
// Jrpc 实现json rpc调用实例
type Jrpc struct {
cli *channelClient
}
// Grpc grpc
type Grpc struct {
*channelClient
}
// Init init rpc
func Init(name string, s rpctypes.RPCServer) {
cli := &channelClient{}
grpc := &Grpc{channelClient: cli}
cli.Init(name, s, &Jrpc{cli: cli}, grpc)
//存在grpc service时注册grpc server,需要生成对应的pb.go文件
accountmanagertypes.RegisterAccountmanagerServer(s.GRPC(), grpc)
}
package types
import (
log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
/*
* 交易相关类型定义
* 交易action通常有对应的log结构,用于交易回执日志记录
* 每一种action和log需要用id数值和name名称加以区分
*/
// action类型id和name,这些常量可以自定义修改
const (
TyUnknowAction = iota + 100
TyRegisterAction
TyResetAction
TyTransferAction
TySuperviseAction
TyApplyAction
NameRegisterAction = "Register"
NameResetAction = "Reset"
NameTransferAction = "Transfer"
NameSuperviseAction = "Supervise"
NameApplyAction = "Apply"
)
// log类型id值
const (
TyUnknownLog = iota + 100
TyRegisterLog
TyApplyLog
TyTransferLog
TySuperviseLog
)
//状态
const (
UnknownStatus = iota
Normal
Frozen
Locked
Expired
)
var (
//AccountmanagerX 执行器名称定义
AccountmanagerX = "accountmanager"
//定义actionMap
actionMap = map[string]int32{
NameRegisterAction: TyRegisterAction,
NameResetAction: TyResetAction,
NameApplyAction: TyApplyAction,
NameTransferAction: TyTransferAction,
NameSuperviseAction: TySuperviseAction,
}
//定义log的id和具体log类型及名称,填入具体自定义log类型
logMap = map[int64]*types.LogInfo{
//LogID: {Ty: reflect.TypeOf(LogStruct), Name: LogName},
}
tlog = log.New("module", "accountmanager.types")
)
// init defines a register function
func init() {
types.AllowUserExec = append(types.AllowUserExec, []byte(AccountmanagerX))
//注册合约启用高度
types.RegFork(AccountmanagerX, InitFork)
types.RegExec(AccountmanagerX, InitExecutor)
}
// InitFork defines register fork
func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(AccountmanagerX, "Enable", 0)
}
// InitExecutor defines register executor
func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(AccountmanagerX, NewType(cfg))
}
type accountmanagerType struct {
types.ExecTypeBase
}
func NewType(cfg *types.Chain33Config) *accountmanagerType {
c := &accountmanagerType{}
c.SetChild(c)
c.SetConfig(cfg)
return c
}
// GetPayload 获取合约action结构
func (a *accountmanagerType) GetPayload() types.Message {
return &AccountmanagerAction{}
}
// GeTypeMap 获取合约action的id和name信息
func (a *accountmanagerType) GetTypeMap() map[string]int32 {
return actionMap
}
// GetLogMap 获取合约log相关信息
func (a *accountmanagerType) GetLogMap() map[int64]*types.LogInfo {
return logMap
}
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: accountmanager.proto
/*
Package types is a generated protocol buffer package.
It is generated from these files:
accountmanager.proto
It has these top-level messages:
Accountmanager
AccountmanagerAction
Register
Reset
Apply
Asset
Transfer
Supervise
Account
Receipt
*/
package types
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Accountmanager struct {
}
func (m *Accountmanager) Reset() { *m = Accountmanager{} }
func (m *Accountmanager) String() string { return proto.CompactTextString(m) }
func (*Accountmanager) ProtoMessage() {}
func (*Accountmanager) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type AccountmanagerAction struct {
// Types that are valid to be assigned to Value:
// *AccountmanagerAction_Register
// *AccountmanagerAction_Reset_
// *AccountmanagerAction_Transfer
// *AccountmanagerAction_Supervise
// *AccountmanagerAction_Apply
Value isAccountmanagerAction_Value `protobuf_oneof:"value"`
Ty int32 `protobuf:"varint,6,opt,name=ty" json:"ty,omitempty"`
}
func (m *AccountmanagerAction) Reset() { *m = AccountmanagerAction{} }
func (m *AccountmanagerAction) String() string { return proto.CompactTextString(m) }
func (*AccountmanagerAction) ProtoMessage() {}
func (*AccountmanagerAction) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
type isAccountmanagerAction_Value interface {
isAccountmanagerAction_Value()
}
type AccountmanagerAction_Register struct {
Register *Register `protobuf:"bytes,1,opt,name=register,oneof"`
}
type AccountmanagerAction_Reset_ struct {
Reset_ *Reset `protobuf:"bytes,2,opt,name=reset,oneof"`
}
type AccountmanagerAction_Transfer struct {
Transfer *Transfer `protobuf:"bytes,3,opt,name=transfer,oneof"`
}
type AccountmanagerAction_Supervise struct {
Supervise *Supervise `protobuf:"bytes,4,opt,name=supervise,oneof"`
}
type AccountmanagerAction_Apply struct {
Apply *Apply `protobuf:"bytes,5,opt,name=apply,oneof"`
}
func (*AccountmanagerAction_Register) isAccountmanagerAction_Value() {}
func (*AccountmanagerAction_Reset_) isAccountmanagerAction_Value() {}
func (*AccountmanagerAction_Transfer) isAccountmanagerAction_Value() {}
func (*AccountmanagerAction_Supervise) isAccountmanagerAction_Value() {}
func (*AccountmanagerAction_Apply) isAccountmanagerAction_Value() {}
func (m *AccountmanagerAction) GetValue() isAccountmanagerAction_Value {
if m != nil {
return m.Value
}
return nil
}
func (m *AccountmanagerAction) GetRegister() *Register {
if x, ok := m.GetValue().(*AccountmanagerAction_Register); ok {
return x.Register
}
return nil
}
func (m *AccountmanagerAction) GetReset_() *Reset {
if x, ok := m.GetValue().(*AccountmanagerAction_Reset_); ok {
return x.Reset_
}
return nil
}
func (m *AccountmanagerAction) GetTransfer() *Transfer {
if x, ok := m.GetValue().(*AccountmanagerAction_Transfer); ok {
return x.Transfer
}
return nil
}
func (m *AccountmanagerAction) GetSupervise() *Supervise {
if x, ok := m.GetValue().(*AccountmanagerAction_Supervise); ok {
return x.Supervise
}
return nil
}
func (m *AccountmanagerAction) GetApply() *Apply {
if x, ok := m.GetValue().(*AccountmanagerAction_Apply); ok {
return x.Apply
}
return nil
}
func (m *AccountmanagerAction) GetTy() int32 {
if m != nil {
return m.Ty
}
return 0
}
// XXX_OneofFuncs is for the internal use of the proto package.
func (*AccountmanagerAction) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
return _AccountmanagerAction_OneofMarshaler, _AccountmanagerAction_OneofUnmarshaler, _AccountmanagerAction_OneofSizer, []interface{}{
(*AccountmanagerAction_Register)(nil),
(*AccountmanagerAction_Reset_)(nil),
(*AccountmanagerAction_Transfer)(nil),
(*AccountmanagerAction_Supervise)(nil),
(*AccountmanagerAction_Apply)(nil),
}
}
func _AccountmanagerAction_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*AccountmanagerAction)
// value
switch x := m.Value.(type) {
case *AccountmanagerAction_Register:
b.EncodeVarint(1<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.Register); err != nil {
return err
}
case *AccountmanagerAction_Reset_:
b.EncodeVarint(2<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.Reset_); err != nil {
return err
}
case *AccountmanagerAction_Transfer:
b.EncodeVarint(3<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.Transfer); err != nil {
return err
}
case *AccountmanagerAction_Supervise:
b.EncodeVarint(4<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.Supervise); err != nil {
return err
}
case *AccountmanagerAction_Apply:
b.EncodeVarint(5<<3 | proto.WireBytes)
if err := b.EncodeMessage(x.Apply); err != nil {
return err
}
case nil:
default:
return fmt.Errorf("AccountmanagerAction.Value has unexpected type %T", x)
}
return nil
}
func _AccountmanagerAction_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*AccountmanagerAction)
switch tag {
case 1: // value.register
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(Register)
err := b.DecodeMessage(msg)
m.Value = &AccountmanagerAction_Register{msg}
return true, err
case 2: // value.reset
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(Reset)
err := b.DecodeMessage(msg)
m.Value = &AccountmanagerAction_Reset_{msg}
return true, err
case 3: // value.transfer
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(Transfer)
err := b.DecodeMessage(msg)
m.Value = &AccountmanagerAction_Transfer{msg}
return true, err
case 4: // value.supervise
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(Supervise)
err := b.DecodeMessage(msg)
m.Value = &AccountmanagerAction_Supervise{msg}
return true, err
case 5: // value.apply
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
msg := new(Apply)
err := b.DecodeMessage(msg)
m.Value = &AccountmanagerAction_Apply{msg}
return true, err
default:
return false, nil
}
}
func _AccountmanagerAction_OneofSizer(msg proto.Message) (n int) {
m := msg.(*AccountmanagerAction)
// value
switch x := m.Value.(type) {
case *AccountmanagerAction_Register:
s := proto.Size(x.Register)
n += proto.SizeVarint(1<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *AccountmanagerAction_Reset_:
s := proto.Size(x.Reset_)
n += proto.SizeVarint(2<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *AccountmanagerAction_Transfer:
s := proto.Size(x.Transfer)
n += proto.SizeVarint(3<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *AccountmanagerAction_Supervise:
s := proto.Size(x.Supervise)
n += proto.SizeVarint(4<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case *AccountmanagerAction_Apply:
s := proto.Size(x.Apply)
n += proto.SizeVarint(5<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(s))
n += s
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
// 注册
type Register struct {
AccountID string `protobuf:"bytes,1,opt,name=accountID" json:"accountID,omitempty"`
}
func (m *Register) Reset() { *m = Register{} }
func (m *Register) String() string { return proto.CompactTextString(m) }
func (*Register) ProtoMessage() {}
func (*Register) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *Register) GetAccountID() string {
if m != nil {
return m.AccountID
}
return ""
}
// 重置公钥
type Reset struct {
AccountID string `protobuf:"bytes,1,opt,name=accountID" json:"accountID,omitempty"`
Addr string `protobuf:"bytes,2,opt,name=addr" json:"addr,omitempty"`
}
func (m *Reset) Reset() { *m = Reset{} }
func (m *Reset) String() string { return proto.CompactTextString(m) }
func (*Reset) ProtoMessage() {}
func (*Reset) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (m *Reset) GetAccountID() string {
if m != nil {
return m.AccountID
}
return ""
}
func (m *Reset) GetAddr() string {
if m != nil {
return m.Addr
}
return ""
}
// 用户申请服务
type Apply struct {
AccountID string `protobuf:"bytes,1,opt,name=accountID" json:"accountID,omitempty"`
// 操作, 0,账户注册,1,账户公钥重置 2,账户延期申请 3,账户注销
Op int32 `protobuf:"varint,2,opt,name=op" json:"op,omitempty"`
}
func (m *Apply) Reset() { *m = Apply{} }
func (m *Apply) String() string { return proto.CompactTextString(m) }
func (*Apply) ProtoMessage() {}
func (*Apply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
func (m *Apply) GetAccountID() string {
if m != nil {
return m.AccountID
}
return ""
}
func (m *Apply) GetOp() int32 {
if m != nil {
return m.Op
}
return 0
}
// 资产类型
type Asset struct {
Execer string `protobuf:"bytes,1,opt,name=execer" json:"execer,omitempty"`
Symbol string `protobuf:"bytes,2,opt,name=symbol" json:"symbol,omitempty"`
}
func (m *Asset) Reset() { *m = Asset{} }
func (m *Asset) String() string { return proto.CompactTextString(m) }
func (*Asset) ProtoMessage() {}
func (*Asset) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
func (m *Asset) GetExecer() string {
if m != nil {
return m.Execer
}
return ""
}
func (m *Asset) GetSymbol() string {
if m != nil {
return m.Symbol
}
return ""
}
// 合约内部账户之间转账
type Transfer struct {
// 资产类型
Asset *Asset `protobuf:"bytes,1,opt,name=Asset" json:"Asset,omitempty"`
// from账户
FromAccountID string `protobuf:"bytes,2,opt,name=fromAccountID" json:"fromAccountID,omitempty"`
// to账户
ToAccountID string `protobuf:"bytes,3,opt,name=toAccountID" json:"toAccountID,omitempty"`
// 转账金额
Amount int64 `protobuf:"varint,4,opt,name=amount" json:"amount,omitempty"`
}
func (m *Transfer) Reset() { *m = Transfer{} }
func (m *Transfer) String() string { return proto.CompactTextString(m) }
func (*Transfer) ProtoMessage() {}
func (*Transfer) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
func (m *Transfer) GetAsset() *Asset {
if m != nil {
return m.Asset
}
return nil
}
func (m *Transfer) GetFromAccountID() string {
if m != nil {
return m.FromAccountID
}
return ""
}
func (m *Transfer) GetToAccountID() string {
if m != nil {
return m.ToAccountID
}
return ""
}
func (m *Transfer) GetAmount() int64 {
if m != nil {
return m.Amount
}
return 0
}
// 管理员监管操作
type Supervise struct {
// 账户名单
AccountIDs []string `protobuf:"bytes,1,rep,name=accountIDs" json:"accountIDs,omitempty"`
// 操作, 1为冻结,2为解冻
Op int32 `protobuf:"varint,2,opt,name=op" json:"op,omitempty"`
}
func (m *Supervise) Reset() { *m = Supervise{} }
func (m *Supervise) String() string { return proto.CompactTextString(m) }
func (*Supervise) ProtoMessage() {}
func (*Supervise) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
func (m *Supervise) GetAccountIDs() []string {
if m != nil {
return m.AccountIDs
}
return nil
}
func (m *Supervise) GetOp() int32 {
if m != nil {
return m.Op
}
return 0
}
type Account struct {
// 账户名称
AccountID string `protobuf:"bytes,1,opt,name=accountID" json:"accountID,omitempty"`
// 地址
Addr string `protobuf:"bytes,2,opt,name=addr" json:"addr,omitempty"`
// 上一次公钥地址
PrevAddr string `protobuf:"bytes,3,opt,name=prevAddr" json:"prevAddr,omitempty"`
// 账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
Status int32 `protobuf:"varint,4,opt,name=status" json:"status,omitempty"`
// 注册时间
CreateTime int64 `protobuf:"varint,5,opt,name=createTime" json:"createTime,omitempty"`
// 失效时间
ExpireTime int64 `protobuf:"varint,6,opt,name=expireTime" json:"expireTime,omitempty"`
// 锁定时间
LockTime int64 `protobuf:"varint,7,opt,name=lockTime" json:"lockTime,omitempty"`
// 索引
Index int64 `protobuf:"varint,8,opt,name=index" json:"index,omitempty"`
}
func (m *Account) Reset() { *m = Account{} }
func (m *Account) String() string { return proto.CompactTextString(m) }
func (*Account) ProtoMessage() {}
func (*Account) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
func (m *Account) GetAccountID() string {
if m != nil {
return m.AccountID
}
return ""
}
func (m *Account) GetAddr() string {
if m != nil {
return m.Addr
}
return ""
}
func (m *Account) GetPrevAddr() string {
if m != nil {
return m.PrevAddr
}
return ""
}
func (m *Account) GetStatus() int32 {
if m != nil {
return m.Status
}
return 0
}
func (m *Account) GetCreateTime() int64 {
if m != nil {
return m.CreateTime
}
return 0
}
func (m *Account) GetExpireTime() int64 {
if m != nil {
return m.ExpireTime
}
return 0
}
func (m *Account) GetLockTime() int64 {
if m != nil {
return m.LockTime
}
return 0
}
func (m *Account) GetIndex() int64 {
if m != nil {
return m.Index
}
return 0
}
type Receipt struct {
// 账户名称
AccountID string `protobuf:"bytes,1,opt,name=accountID" json:"accountID,omitempty"`
// 地址
Addr string `protobuf:"bytes,2,opt,name=addr" json:"addr,omitempty"`
// 上一次公钥地址
PrevAddr string `protobuf:"bytes,3,opt,name=prevAddr" json:"prevAddr,omitempty"`
// 账户状态 1 正常, 2表示冻结, 3表示锁定 4,过期注销
Status int32 `protobuf:"varint,4,opt,name=status" json:"status,omitempty"`
// 注册时间
CreateTime int64 `protobuf:"varint,5,opt,name=createTime" json:"createTime,omitempty"`
// 失效时间
ExpireTime int64 `protobuf:"varint,6,opt,name=expireTime" json:"expireTime,omitempty"`
// 锁定时间
LockTime int64 `protobuf:"varint,7,opt,name=lockTime" json:"lockTime,omitempty"`
// 索引
Index int64 `protobuf:"varint,8,opt,name=index" json:"index,omitempty"`
}
func (m *Receipt) Reset() { *m = Receipt{} }
func (m *Receipt) String() string { return proto.CompactTextString(m) }
func (*Receipt) ProtoMessage() {}
func (*Receipt) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} }
func (m *Receipt) GetAccountID() string {
if m != nil {
return m.AccountID
}
return ""
}
func (m *Receipt) GetAddr() string {
if m != nil {
return m.Addr
}
return ""
}
func (m *Receipt) GetPrevAddr() string {
if m != nil {
return m.PrevAddr
}
return ""
}
func (m *Receipt) GetStatus() int32 {
if m != nil {
return m.Status
}
return 0
}
func (m *Receipt) GetCreateTime() int64 {
if m != nil {
return m.CreateTime
}
return 0
}
func (m *Receipt) GetExpireTime() int64 {
if m != nil {
return m.ExpireTime
}
return 0
}
func (m *Receipt) GetLockTime() int64 {
if m != nil {
return m.LockTime
}
return 0
}
func (m *Receipt) GetIndex() int64 {
if m != nil {
return m.Index
}
return 0
}
func init() {
proto.RegisterType((*Accountmanager)(nil), "types.Accountmanager")
proto.RegisterType((*AccountmanagerAction)(nil), "types.AccountmanagerAction")
proto.RegisterType((*Register)(nil), "types.Register")
proto.RegisterType((*Reset)(nil), "types.Reset")
proto.RegisterType((*Apply)(nil), "types.Apply")
proto.RegisterType((*Asset)(nil), "types.asset")
proto.RegisterType((*Transfer)(nil), "types.Transfer")
proto.RegisterType((*Supervise)(nil), "types.Supervise")
proto.RegisterType((*Account)(nil), "types.Account")
proto.RegisterType((*Receipt)(nil), "types.Receipt")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// Client API for Accountmanager service
type AccountmanagerClient interface {
}
type accountmanagerClient struct {
cc *grpc.ClientConn
}
func NewAccountmanagerClient(cc *grpc.ClientConn) AccountmanagerClient {
return &accountmanagerClient{cc}
}
// Server API for Accountmanager service
type AccountmanagerServer interface {
}
func RegisterAccountmanagerServer(s *grpc.Server, srv AccountmanagerServer) {
s.RegisterService(&_Accountmanager_serviceDesc, srv)
}
var _Accountmanager_serviceDesc = grpc.ServiceDesc{
ServiceName: "types.accountmanager",
HandlerType: (*AccountmanagerServer)(nil),
Methods: []grpc.MethodDesc{},
Streams: []grpc.StreamDesc{},
Metadata: "accountmanager.proto",
}
func init() { proto.RegisterFile("accountmanager.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 476 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x54, 0xd1, 0x8a, 0xd3, 0x40,
0x14, 0x6d, 0xd2, 0x9d, 0xb6, 0xb9, 0xab, 0xb5, 0x0c, 0x45, 0x82, 0x88, 0x94, 0xb0, 0x0f, 0x7d,
0xb1, 0xc8, 0x8a, 0x88, 0xf8, 0x14, 0xf1, 0xa1, 0xbe, 0x8e, 0xfb, 0x03, 0xb3, 0xe9, 0xdd, 0x25,
0xd8, 0x64, 0x86, 0x99, 0x69, 0x69, 0xbe, 0x41, 0xf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0x8d, 0xd8, 0x29, 0xb1, 0x7d, 0xcd,
0x97, 0xc0, 0xca, 0x7a, 0x87, 0xa7, 0x74, 0x46, 0x44, 0x5b, 0xd0, 0x8e, 0x02, 0x0b, 0x2c, 0xf5,
0x7f, 0xbb, 0xe3, 0xed, 0x02, 0xe6, 0xc3, 0x3f, 0xd5, 0xfd, 0x84, 0x7e, 0x55, 0x6f, 0x7f, 0x05,
0x00, 0x00, 0xff, 0xff, 0x6e, 0x2a, 0x31, 0x91, 0xc2, 0x04, 0x00, 0x00,
}
package types
import "fmt"
// some errors definition
var (
ErrAccountNameExist = fmt.Errorf("%s", "The account name has been registered!")
ErrAccountNameNotExist = fmt.Errorf("%s", "The account name is not exist")
)
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