Commit 1c348a8b authored by linj's avatar linj Committed by 33cn

update chain33 20180308

parent 85f54748
...@@ -434,3 +434,41 @@ func genPrefixEdge(prefix []byte) (r []byte) { ...@@ -434,3 +434,41 @@ func genPrefixEdge(prefix []byte) (r []byte) {
return r return r
} }
// Mint 铸币
func (acc *DB) Mint(addr string, amount int64) (*types.Receipt, error) {
if !types.CheckAmount(amount) {
return nil, types.ErrAmount
}
accTo := acc.LoadAccount(addr)
balance, err := safeAdd(accTo.Balance, amount)
if err != nil {
return nil, err
}
copyAcc := *accTo
accTo.Balance = balance
receipt := &types.ReceiptAccountMint{
Prev: &copyAcc,
Current: accTo,
}
kv := acc.GetKVSet(accTo)
acc.SaveKVSet(kv)
return acc.mintReceipt(kv, receipt), nil
}
func (acc *DB) mintReceipt(kv []*types.KeyValue, receipt proto.Message) *types.Receipt {
ty := int32(types.TyLogMint)
log1 := &types.ReceiptLog{
Ty: ty,
Log: types.Encode(receipt),
}
return &types.Receipt{
Ty: types.ExecOk,
KV: kv,
Logs: []*types.ReceiptLog{log1},
}
}
...@@ -554,3 +554,13 @@ func TestGetExecBalance2(t *testing.T) { ...@@ -554,3 +554,13 @@ func TestGetExecBalance2(t *testing.T) {
assert.Equal(t, 1, len(reply.Items)) assert.Equal(t, 1, len(reply.Items))
*/ */
} }
func TestDB_Mint(t *testing.T) {
_, tokenCoin := GenerAccDb()
tokenCoin.GenerAccData()
_, err := tokenCoin.Mint(addr1, 10*1e8)
require.NoError(t, err)
t.Logf("Token mint addr balance [%d]", tokenCoin.LoadAccount(addr1).Balance)
require.Equal(t, int64(1000*1e8+10*1e8), tokenCoin.LoadAccount(addr1).Balance)
}
...@@ -198,6 +198,56 @@ func (m *ReceiptAccountTransfer) GetCurrent() *Account { ...@@ -198,6 +198,56 @@ func (m *ReceiptAccountTransfer) GetCurrent() *Account {
return nil return nil
} }
//铸币账户余额增加
type ReceiptAccountMint struct {
//铸币前
Prev *Account `protobuf:"bytes,1,opt,name=prev,proto3" json:"prev,omitempty"`
//铸币后
Current *Account `protobuf:"bytes,2,opt,name=current,proto3" json:"current,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReceiptAccountMint) Reset() { *m = ReceiptAccountMint{} }
func (m *ReceiptAccountMint) String() string { return proto.CompactTextString(m) }
func (*ReceiptAccountMint) ProtoMessage() {}
func (*ReceiptAccountMint) Descriptor() ([]byte, []int) {
return fileDescriptor_8e28828dcb8d24f0, []int{3}
}
func (m *ReceiptAccountMint) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReceiptAccountMint.Unmarshal(m, b)
}
func (m *ReceiptAccountMint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReceiptAccountMint.Marshal(b, m, deterministic)
}
func (m *ReceiptAccountMint) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReceiptAccountMint.Merge(m, src)
}
func (m *ReceiptAccountMint) XXX_Size() int {
return xxx_messageInfo_ReceiptAccountMint.Size(m)
}
func (m *ReceiptAccountMint) XXX_DiscardUnknown() {
xxx_messageInfo_ReceiptAccountMint.DiscardUnknown(m)
}
var xxx_messageInfo_ReceiptAccountMint proto.InternalMessageInfo
func (m *ReceiptAccountMint) GetPrev() *Account {
if m != nil {
return m.Prev
}
return nil
}
func (m *ReceiptAccountMint) GetCurrent() *Account {
if m != nil {
return m.Current
}
return nil
}
//查询一个地址列表在某个执行器中余额 //查询一个地址列表在某个执行器中余额
type ReqBalance struct { type ReqBalance struct {
//地址列表 //地址列表
...@@ -216,7 +266,7 @@ func (m *ReqBalance) Reset() { *m = ReqBalance{} } ...@@ -216,7 +266,7 @@ func (m *ReqBalance) Reset() { *m = ReqBalance{} }
func (m *ReqBalance) String() string { return proto.CompactTextString(m) } func (m *ReqBalance) String() string { return proto.CompactTextString(m) }
func (*ReqBalance) ProtoMessage() {} func (*ReqBalance) ProtoMessage() {}
func (*ReqBalance) Descriptor() ([]byte, []int) { func (*ReqBalance) Descriptor() ([]byte, []int) {
return fileDescriptor_8e28828dcb8d24f0, []int{3} return fileDescriptor_8e28828dcb8d24f0, []int{4}
} }
func (m *ReqBalance) XXX_Unmarshal(b []byte) error { func (m *ReqBalance) XXX_Unmarshal(b []byte) error {
...@@ -284,7 +334,7 @@ func (m *Accounts) Reset() { *m = Accounts{} } ...@@ -284,7 +334,7 @@ func (m *Accounts) Reset() { *m = Accounts{} }
func (m *Accounts) String() string { return proto.CompactTextString(m) } func (m *Accounts) String() string { return proto.CompactTextString(m) }
func (*Accounts) ProtoMessage() {} func (*Accounts) ProtoMessage() {}
func (*Accounts) Descriptor() ([]byte, []int) { func (*Accounts) Descriptor() ([]byte, []int) {
return fileDescriptor_8e28828dcb8d24f0, []int{4} return fileDescriptor_8e28828dcb8d24f0, []int{5}
} }
func (m *Accounts) XXX_Unmarshal(b []byte) error { func (m *Accounts) XXX_Unmarshal(b []byte) error {
...@@ -324,7 +374,7 @@ func (m *ExecAccount) Reset() { *m = ExecAccount{} } ...@@ -324,7 +374,7 @@ func (m *ExecAccount) Reset() { *m = ExecAccount{} }
func (m *ExecAccount) String() string { return proto.CompactTextString(m) } func (m *ExecAccount) String() string { return proto.CompactTextString(m) }
func (*ExecAccount) ProtoMessage() {} func (*ExecAccount) ProtoMessage() {}
func (*ExecAccount) Descriptor() ([]byte, []int) { func (*ExecAccount) Descriptor() ([]byte, []int) {
return fileDescriptor_8e28828dcb8d24f0, []int{5} return fileDescriptor_8e28828dcb8d24f0, []int{6}
} }
func (m *ExecAccount) XXX_Unmarshal(b []byte) error { func (m *ExecAccount) XXX_Unmarshal(b []byte) error {
...@@ -371,7 +421,7 @@ func (m *AllExecBalance) Reset() { *m = AllExecBalance{} } ...@@ -371,7 +421,7 @@ func (m *AllExecBalance) Reset() { *m = AllExecBalance{} }
func (m *AllExecBalance) String() string { return proto.CompactTextString(m) } func (m *AllExecBalance) String() string { return proto.CompactTextString(m) }
func (*AllExecBalance) ProtoMessage() {} func (*AllExecBalance) ProtoMessage() {}
func (*AllExecBalance) Descriptor() ([]byte, []int) { func (*AllExecBalance) Descriptor() ([]byte, []int) {
return fileDescriptor_8e28828dcb8d24f0, []int{6} return fileDescriptor_8e28828dcb8d24f0, []int{7}
} }
func (m *AllExecBalance) XXX_Unmarshal(b []byte) error { func (m *AllExecBalance) XXX_Unmarshal(b []byte) error {
...@@ -423,7 +473,7 @@ func (m *ReqAllExecBalance) Reset() { *m = ReqAllExecBalance{} } ...@@ -423,7 +473,7 @@ func (m *ReqAllExecBalance) Reset() { *m = ReqAllExecBalance{} }
func (m *ReqAllExecBalance) String() string { return proto.CompactTextString(m) } func (m *ReqAllExecBalance) String() string { return proto.CompactTextString(m) }
func (*ReqAllExecBalance) ProtoMessage() {} func (*ReqAllExecBalance) ProtoMessage() {}
func (*ReqAllExecBalance) Descriptor() ([]byte, []int) { func (*ReqAllExecBalance) Descriptor() ([]byte, []int) {
return fileDescriptor_8e28828dcb8d24f0, []int{7} return fileDescriptor_8e28828dcb8d24f0, []int{8}
} }
func (m *ReqAllExecBalance) XXX_Unmarshal(b []byte) error { func (m *ReqAllExecBalance) XXX_Unmarshal(b []byte) error {
...@@ -483,6 +533,7 @@ func init() { ...@@ -483,6 +533,7 @@ func init() {
proto.RegisterType((*Account)(nil), "types.Account") proto.RegisterType((*Account)(nil), "types.Account")
proto.RegisterType((*ReceiptExecAccountTransfer)(nil), "types.ReceiptExecAccountTransfer") proto.RegisterType((*ReceiptExecAccountTransfer)(nil), "types.ReceiptExecAccountTransfer")
proto.RegisterType((*ReceiptAccountTransfer)(nil), "types.ReceiptAccountTransfer") proto.RegisterType((*ReceiptAccountTransfer)(nil), "types.ReceiptAccountTransfer")
proto.RegisterType((*ReceiptAccountMint)(nil), "types.ReceiptAccountMint")
proto.RegisterType((*ReqBalance)(nil), "types.ReqBalance") proto.RegisterType((*ReqBalance)(nil), "types.ReqBalance")
proto.RegisterType((*Accounts)(nil), "types.Accounts") proto.RegisterType((*Accounts)(nil), "types.Accounts")
proto.RegisterType((*ExecAccount)(nil), "types.ExecAccount") proto.RegisterType((*ExecAccount)(nil), "types.ExecAccount")
...@@ -493,31 +544,32 @@ func init() { ...@@ -493,31 +544,32 @@ func init() {
func init() { proto.RegisterFile("account.proto", fileDescriptor_8e28828dcb8d24f0) } func init() { proto.RegisterFile("account.proto", fileDescriptor_8e28828dcb8d24f0) }
var fileDescriptor_8e28828dcb8d24f0 = []byte{ var fileDescriptor_8e28828dcb8d24f0 = []byte{
// 414 bytes of a gzipped FileDescriptorProto // 427 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x53, 0xc1, 0x6e, 0xd3, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x54, 0xcd, 0x6a, 0x14, 0x41,
0x10, 0xd5, 0xc6, 0x49, 0x5d, 0x4f, 0xa0, 0x12, 0x7b, 0xa8, 0x56, 0x15, 0x15, 0x66, 0x4f, 0x3e, 0x10, 0xa6, 0xf7, 0x27, 0x9b, 0xa9, 0xd5, 0x80, 0x7d, 0x08, 0x4d, 0x30, 0x38, 0xf6, 0x69, 0x0e,
0x20, 0x47, 0xc2, 0xfc, 0x40, 0x2b, 0x21, 0x71, 0x43, 0x5a, 0x38, 0xf5, 0x82, 0xd6, 0xdb, 0x09, 0xb2, 0x0b, 0x8e, 0x2f, 0x90, 0x80, 0xe0, 0x45, 0x84, 0xd6, 0x53, 0x2e, 0xd2, 0xd3, 0xa9, 0x75,
0x89, 0x70, 0x6d, 0x77, 0x77, 0x83, 0x08, 0x1f, 0xc0, 0x6f, 0x20, 0xf1, 0xa5, 0x68, 0x27, 0xeb, 0x07, 0x27, 0x3d, 0x93, 0xee, 0x5e, 0x71, 0x7d, 0x00, 0x5f, 0x43, 0xf0, 0x49, 0xa5, 0x6b, 0x7b,
0xc6, 0x25,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 0xdf, 0x3c, 0x92, 0x15, 0x13, 0x32, 0xc0, 0x2c, 0xdd, 0xf4, 0x9f, 0x66, 0x94, 0x68, 0x79, 0x05, 0x27, 0x17, 0x4d, 0x13, 0x7b, 0xf6,
0xc8, 0xe3, 0xcc, 0x11, 0xa3, 0xc6, 0x6d, 0xf2, 0x27, 0x83, 0x67, 0x0a, 0xef, 0x8f, 0x98, 0xff, 0x63, 0xea, 0xcf, 0x93, 0xed, 0xcf, 0x93, 0xbf, 0x3a, 0x90, 0x15, 0x23, 0x32, 0xc8, 0x53, 0xcf,
0x9f, 0xc2, 0xbf, 0x7e, 0x71, 0x73, 0xf9, 0x79, 0xed, 0x57, 0x9b, 0xba, 0x34, 0xdd, 0xdd, 0xa2, 0x01, 0xa3, 0x86, 0x69, 0xf2, 0x07, 0x83, 0x27, 0x0a, 0x6f, 0x1f, 0xd0, 0xff, 0x3f, 0x0d, 0xff,
0xaa, 0x4c, 0xbb, 0x30, 0x2b, 0xbd, 0x6e, 0xab, 0x6a, 0x41, 0xbb, 0xd5, 0x27, 0xf4, 0xb9, 0x56, 0xf2, 0xd9, 0xd5, 0xf9, 0xa7, 0x3a, 0xac, 0x37, 0xd5, 0xc2, 0xb4, 0x37, 0xcb, 0xb2, 0x34, 0x76,
0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xf3, 0x95, 0x98, 0xa9, 0xbf, 0x03, 0x00, 0x00, 0x69, 0xd6, 0xba, 0xb6, 0x65, 0xb9, 0xa4, 0xb7, 0x55, 0x47, 0xf4, 0x4b, 0x28, 0x7f, 0x05, 0x00,
0x00, 0xff, 0xff, 0x1b, 0xce, 0xc2, 0x14, 0x23, 0x04, 0x00, 0x00,
} }
...@@ -103,6 +103,7 @@ const ( ...@@ -103,6 +103,7 @@ const (
TyLogGenesisTransfer = 11 TyLogGenesisTransfer = 11
TyLogGenesisDeposit = 12 TyLogGenesisDeposit = 12
TyLogRollback = 13 TyLogRollback = 13
TyLogMint = 14
) )
//SystemLog 系统log日志 //SystemLog 系统log日志
......
...@@ -33,6 +33,14 @@ message ReceiptAccountTransfer { ...@@ -33,6 +33,14 @@ message ReceiptAccountTransfer {
Account current = 2; Account current = 2;
} }
//铸币账户余额增加
message ReceiptAccountMint {
//铸币前
Account prev = 1;
//铸币后
Account current = 2;
}
//查询一个地址列表在某个执行器中余额 //查询一个地址列表在某个执行器中余额
message ReqBalance { message ReqBalance {
//地址列表 //地址列表
......
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