Commit 8de1b924 authored by 任硕's avatar 任硕 Committed by linj

query unfreeze

parent f9d4465d
......@@ -81,40 +81,10 @@ func (a *action) UnfreezeWithdraw(withdraw *uf.UnfreezeWithdraw) (*types.Receipt
}
var logs []*types.ReceiptLog
var kv []*types.KeyValue
currentTime := time.Now().Unix()
expectTimes := (currentTime + unfreeze.Period - unfreeze.StartTime) / unfreeze.Period
reaTimes := expectTimes - int64(unfreeze.WithdrawTimes)
if reaTimes <= 0 {
uflog.Error("unfreeze withdraw ", "execaddr", a.execaddr, "err", types.ErrUnfreezeBeforeDue)
return nil, types.ErrUnfreezeBeforeDue
}
if unfreeze.Remaining <= 0 {
uflog.Error("unfreeze withdraw ", "execaddr", a.execaddr, "err", types.ErrUnfreezeEmptied)
return nil, types.ErrUnfreezeEmptied
}
var available int64
switch unfreeze.Means {
case 1: // 百分比
for i := int64(0); i < reaTimes; i++ {
if tmp := unfreeze.Remaining * unfreeze.Amount / 10000; tmp == 0 {
available = unfreeze.Remaining
break
} else {
available += tmp
}
}
case 2: // 固额
for i := int64(0); i < reaTimes; i++ {
if unfreeze.Remaining <= unfreeze.Amount {
available = unfreeze.Remaining
break
}
available += unfreeze.Amount
}
default:
uflog.Error("unfreeze withdraw ", "execaddr", a.execaddr, "err", types.ErrUnfreezeMeans)
return nil, types.ErrUnfreezeMeans
reaTimes, available, err := getWithdrawAvailable(unfreeze)
if err != nil {
uflog.Error("unfreeze withdraw ", "execaddr", a.execaddr, "err", err)
return nil, err
}
tokenAccDB, err := account.NewAccountDB("token", unfreeze.TokenName, a.db)
......@@ -225,8 +195,63 @@ func (a *action) getTerminateLog(unfreeze *uf.Unfreeze) *types.ReceiptLog {
}
//查询可提币状态
func QueryWithdraw(stateDB dbm.KV, param *uf.QueryWithdrawStatus) (types.Message, error) {
func QueryWithdraw(stateDB dbm.KV, param *uf.QueryUnfreezeWithdraw) (types.Message, error) {
//查询提币次数
//计算当前可否提币
return &types.Reply{}, nil
unfreezeID := param.UnfreezeID
value, err := stateDB.Get(key(unfreezeID))
if err != nil {
uflog.Error("QueryWithdraw ", "unfreezeID", unfreezeID, "err", err)
return nil, err
}
var unfreeze uf.Unfreeze
err = types.Decode(value, &unfreeze)
if err != nil {
uflog.Error("QueryWithdraw ", "unfreezeID", unfreezeID, "err", err)
return nil, err
}
reply := &uf.ReplyQueryUnfreezeWithdraw{UnfreezeID: unfreezeID}
_, available, err := getWithdrawAvailable(unfreeze)
if err != nil {
reply.AvailableAmount = 0
} else {
reply.AvailableAmount = available
}
return reply, nil
}
func getWithdrawAvailable(unfreeze uf.Unfreeze) (int64, int64, error) {
currentTime := time.Now().Unix()
expectTimes := (currentTime + unfreeze.Period - unfreeze.StartTime) / unfreeze.Period
reaTimes := expectTimes - int64(unfreeze.WithdrawTimes)
if reaTimes <= 0 {
return 0, 0, types.ErrUnfreezeBeforeDue
}
if unfreeze.Remaining <= 0 {
return 0, 0, types.ErrUnfreezeEmptied
}
var available int64
switch unfreeze.Means {
case 1: // 百分比
for i := int64(0); i < reaTimes; i++ {
if tmp := unfreeze.Remaining * unfreeze.Amount / 10000; tmp == 0 {
available = unfreeze.Remaining
break
} else {
available += tmp
}
}
case 2: // 固额
for i := int64(0); i < reaTimes; i++ {
if unfreeze.Remaining <= unfreeze.Amount {
available = unfreeze.Remaining
break
}
available += unfreeze.Amount
}
default:
return 0, 0, types.ErrUnfreezeMeans
}
return reaTimes, available, nil
}
......@@ -5,6 +5,6 @@ import (
"gitlab.33.cn/chain33/chain33/types"
)
func (u *Unfreeze) Query_QueryWithdraw(in *uf.QueryWithdrawStatus) (types.Message, error) {
func (u *Unfreeze) Query_QueryWithdraw(in *uf.QueryUnfreezeWithdraw) (types.Message, error) {
return QueryWithdraw(u.GetStateDB(), in)
}
......@@ -72,6 +72,11 @@ message ReceiptTerminate {
}
// query
message QueryWithdrawStatus {
message QueryUnfreezeWithdraw {
string unfreezeID = 1;
}
message ReplyQueryUnfreezeWithdraw {
string unfreezeID = 1;
int64 availableAmount = 2;
}
\ No newline at end of file
......@@ -16,7 +16,8 @@ It has these top-level messages:
ReceiptCreate
ReceiptWithdraw
ReceiptTerminate
QueryWithdrawStatus
QueryUnfreezeWithdraw
ReplyQueryUnfreezeWithdraw
*/
package types
......@@ -466,22 +467,46 @@ func (m *ReceiptTerminate) GetUnfreezeID() string {
}
// query
type QueryWithdrawStatus struct {
type QueryUnfreezeWithdraw struct {
UnfreezeID string `protobuf:"bytes,1,opt,name=unfreezeID" json:"unfreezeID,omitempty"`
}
func (m *QueryWithdrawStatus) Reset() { *m = QueryWithdrawStatus{} }
func (m *QueryWithdrawStatus) String() string { return proto.CompactTextString(m) }
func (*QueryWithdrawStatus) ProtoMessage() {}
func (*QueryWithdrawStatus) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
func (m *QueryUnfreezeWithdraw) Reset() { *m = QueryUnfreezeWithdraw{} }
func (m *QueryUnfreezeWithdraw) String() string { return proto.CompactTextString(m) }
func (*QueryUnfreezeWithdraw) ProtoMessage() {}
func (*QueryUnfreezeWithdraw) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
func (m *QueryWithdrawStatus) GetUnfreezeID() string {
func (m *QueryUnfreezeWithdraw) GetUnfreezeID() string {
if m != nil {
return m.UnfreezeID
}
return ""
}
type ReplyQueryUnfreezeWithdraw struct {
UnfreezeID string `protobuf:"bytes,1,opt,name=unfreezeID" json:"unfreezeID,omitempty"`
AvailableAmount int64 `protobuf:"varint,2,opt,name=availableAmount" json:"availableAmount,omitempty"`
}
func (m *ReplyQueryUnfreezeWithdraw) Reset() { *m = ReplyQueryUnfreezeWithdraw{} }
func (m *ReplyQueryUnfreezeWithdraw) String() string { return proto.CompactTextString(m) }
func (*ReplyQueryUnfreezeWithdraw) ProtoMessage() {}
func (*ReplyQueryUnfreezeWithdraw) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} }
func (m *ReplyQueryUnfreezeWithdraw) GetUnfreezeID() string {
if m != nil {
return m.UnfreezeID
}
return ""
}
func (m *ReplyQueryUnfreezeWithdraw) GetAvailableAmount() int64 {
if m != nil {
return m.AvailableAmount
}
return 0
}
func init() {
proto.RegisterType((*Unfreeze)(nil), "types.Unfreeze")
proto.RegisterType((*UnfreezeAction)(nil), "types.UnfreezeAction")
......@@ -491,40 +516,42 @@ func init() {
proto.RegisterType((*ReceiptCreate)(nil), "types.ReceiptCreate")
proto.RegisterType((*ReceiptWithdraw)(nil), "types.ReceiptWithdraw")
proto.RegisterType((*ReceiptTerminate)(nil), "types.ReceiptTerminate")
proto.RegisterType((*QueryWithdrawStatus)(nil), "types.QueryWithdrawStatus")
proto.RegisterType((*QueryUnfreezeWithdraw)(nil), "types.QueryUnfreezeWithdraw")
proto.RegisterType((*ReplyQueryUnfreezeWithdraw)(nil), "types.ReplyQueryUnfreezeWithdraw")
}
func init() { proto.RegisterFile("unfreeze.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 459 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0x4d, 0x6f, 0xd3, 0x40,
0x10, 0x8d, 0xed, 0xda, 0x49, 0x26, 0x6a, 0x80, 0xe5, 0x6b, 0x0f, 0x08, 0x45, 0x16, 0x87, 0x9c,
0x82, 0x94, 0xaa, 0x12, 0x57, 0x28, 0x87, 0x70, 0x00, 0x89, 0xa5, 0x08, 0x71, 0xdc, 0xa6, 0x53,
0x58, 0x51, 0xef, 0x46, 0xeb, 0x31, 0x95, 0xf9, 0x8b, 0x5c, 0x38, 0xf0, 0x83, 0xaa, 0x5d, 0xdb,
0x89, 0xeb, 0x44, 0x49, 0x8f, 0xfb, 0xe6, 0xbd, 0xf1, 0xec, 0x9b, 0xb7, 0x86, 0x71, 0xa1, 0xaf,
0x2c, 0xe2, 0x1f, 0x9c, 0xad, 0xac, 0x21, 0xc3, 0x62, 0x2a, 0x57, 0x98, 0xa7, 0xff, 0x42, 0x18,
0x7c, 0xad, 0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85, 0x07, 0x6d, 0x25, 0xef, 0x8a, 0x7f, 0x7c, 0x06, 0x0f, 0x77, 0x54, 0xbc, 0x93,
0xf4, 0x01, 0x8e, 0x05, 0x2e, 0x50, 0xe5, 0x54, 0xa9, 0x77, 0x8f, 0x47, 0xb6, 0x7d, 0x08, 0x7e,
0xeb, 0x21, 0xc4, 0x5f, 0xe1, 0xa4, 0x1a, 0xb7, 0x59, 0x7b, 0x27, 0xb3, 0xde, 0xbe, 0xcc, 0xb6,
0x84, 0x0d, 0x76, 0x84, 0x2d, 0x25, 0xa9, 0x46, 0xdf, 0xff, 0x76, 0xaf, 0xe1, 0xf4, 0xd3, 0x1a,
0x4d, 0xf1, 0xcf, 0x5a, 0x2e, 0xe1, 0xa9, 0xc0, 0x3c, 0x29, 0xfe, 0x8b, 0xcd, 0xc6, 0x70, 0x22,
0xaf, 0xa5, 0x4a, 0xe4, 0x3c, 0xc1, 0x73, 0x67, 0xaf, 0xfb, 0x1d, 0xb5, 0xe1, 0x79, 0x64, 0xff,
0x76, 0x67, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xf9, 0x3c, 0xaa, 0xaf, 0xff, 0x04, 0x00, 0x00,
}
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