packetcc

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2020 License: GPL-3.0, GPL-3.0 Imports: 16 Imported by: 0

README

红包合约

红包的情形

1.随机红包

MinAmount<MaxAmount

2.固定金额红包

MinAmount==MaxAmount

3.领取时指定金额红包

红包定时中isConstant=true 只有这种红包允许多Token,每种Token的余额是记录在Packet.Tokens对象中

Documentation

Index

Constants

View Source
const PACKET_ADDRESS = "PCGTta3M4t3yXu8uRgkKvaWd2d8DSDC6K99"
View Source
const PacketAllocationRecordPrefix = "R-"
View Source
const PacketBalancePrefix = "B-"
View Source
const PacketPrefix = "P-"

Variables

This section is empty.

Functions

func NormalRandom

func NormalRandom(seed int64, expect uint64, min, max uint64) uint64

随机返回数额

Types

type OldPacket added in v1.0.8

type OldPacket struct {
	PubKey          []byte         //红包对应的公钥,也是红包的唯一标识
	Creator         common.Address //红包发放人员地址
	Token           *modules.Asset //红包中的TokenID
	Amount          uint64         //红包总金额
	Count           uint32         //红包数,为0表示可以无限领取
	MinPacketAmount uint64         //单个红包最小额
	MaxPacketAmount uint64         //单个红包最大额,最大额最小额相同,则说明不是随机红包,0则表示完全随机
	ExpiredTime     uint64         //红包过期时间,0表示永不过期
	Remark          string         //红包的备注
	Constant        bool           //是否固定数额
}

old packet

type OldPacketAllocationRecord added in v1.0.8

type OldPacketAllocationRecord struct {
	PubKey      []byte //红包公钥
	Message     string //领取红包用的消息,防止重复领取
	Amount      uint64 //领取的Token数量
	Token       *modules.Asset
	ToAddress   common.Address //领取人的地址
	RequestHash common.Hash    //领取请求的Hash
	Timestamp   uint64         //领取的时间戳,主要用于排序
}

旧的红包领取记录

type Packet

type Packet struct {
	PubKey          []byte         //红包对应的公钥,也是红包的唯一标识
	Creator         common.Address //红包发放人员地址
	Tokens          []*Tokens      //红包中的TokenID
	Amount          uint64         //红包总金额
	Count           uint32         //红包数,为0表示可以无限领取
	MinPacketAmount uint64         //单个红包最小额
	MaxPacketAmount uint64         //单个红包最大额,最大额最小额相同,则说明不是随机红包,0则表示完全随机
	ExpiredTime     uint64         //红包过期时间,0表示永不过期
	Remark          string         //红包的备注
	Constant        bool           //是否固定数额
}

new Packet

func OldPacket2New added in v1.0.8

func OldPacket2New(old *OldPacket, BalanceAmount uint64, BalanceCount uint32) *Packet

func (*Packet) GetPullAmount

func (p *Packet) GetPullAmount(seed int64, amount uint64, count uint32) uint64

func (*Packet) IsFixAmount

func (p *Packet) IsFixAmount() bool

func (*Packet) PubKeyAddress added in v1.0.8

func (p *Packet) PubKeyAddress() common.Address

type PacketAllocationRecord

type PacketAllocationRecord struct {
	PubKey      []byte //红包公钥
	Message     string //领取红包用的消息,防止重复领取
	Tokens      []*RecordTokens
	ToAddress   common.Address //领取人的地址
	RequestHash common.Hash    //领取请求的Hash
	Timestamp   uint64         //领取的时间戳,主要用于排序
}

红包领取记录

func OldRecord2New added in v1.0.8

兼容

type PacketAllocationRecordJson

type PacketAllocationRecordJson struct {
	PubKey      string //红包公钥
	Message     string //领取红包用的消息,防止重复领取
	Tokens      []RecordTokensJson
	ToAddress   common.Address //领取人的地址
	RequestHash string         //领取请求的Hash
	Timestamp   uint64         //领取的时间戳,主要用于排序
}

type PacketBalance

type PacketBalance struct {
	Amount uint64
	Count  uint32
}

红包余额

type PacketJson

type PacketJson struct {
	PubKey          string          //红包对应的公钥,也是红包的唯一标识
	Creator         common.Address  //红包发放人员地址
	Token           []*TokensJson   //红包中的TokenID
	TotalAmount     decimal.Decimal //红包总金额
	PacketCount     uint32          //红包数,为0表示可以无限领取
	MinPacketAmount decimal.Decimal //单个红包最小额
	MaxPacketAmount decimal.Decimal //单个红包最大额,最大额最小额相同,则说明不是随机红包
	ExpiredTime     string          //红包过期时间,0表示永不过期
	Remark          string          //红包的备注
	IsConstant      string          //是否固定数额
	BalanceAmount   decimal.Decimal //红包剩余额度
	BalanceCount    uint32          //红包剩余次数
}

type PacketMgr

type PacketMgr struct {
}

func (*PacketMgr) CreatePacket

func (p *PacketMgr) CreatePacket(stub shim.ChaincodeStubInterface, pubKey []byte, count uint32,
	minAmount, maxAmount decimal.Decimal, expiredTime *time.Time, remark string, isConstant bool) error

func (*PacketMgr) GetAllPacketInfo

func (p *PacketMgr) GetAllPacketInfo(stub shim.ChaincodeStubInterface) ([]*PacketJson, error)

func (*PacketMgr) GetPacketAllocationHistory

func (p *PacketMgr) GetPacketAllocationHistory(stub shim.ChaincodeStubInterface,
	pubKey []byte) ([]*PacketAllocationRecordJson, error)

func (*PacketMgr) GetPacketInfo

func (p *PacketMgr) GetPacketInfo(stub shim.ChaincodeStubInterface, pubKey []byte) (*PacketJson, error)

func (*PacketMgr) Init

func (*PacketMgr) Invoke

func (*PacketMgr) IsPulledPacket

func (p *PacketMgr) IsPulledPacket(stub shim.ChaincodeStubInterface, pubKey []byte, msg string) bool

func (*PacketMgr) PullPacket

func (p *PacketMgr) PullPacket(stub shim.ChaincodeStubInterface,
	pubKey []byte, msg string, signature []byte,
	pullAddr common.Address, amounts string) error

领取红包,如果该红包有多种Token,那么amounts参数就可以是一个以逗号分割金额的字符串,并根据对应的index领取对应金额的Token

func (*PacketMgr) RecyclePacket

func (p *PacketMgr) RecyclePacket(stub shim.ChaincodeStubInterface, pubKey []byte) error

func (*PacketMgr) UpdatePacket

func (p *PacketMgr) UpdatePacket(stub shim.ChaincodeStubInterface, pubKey []byte, count uint32,
	minAmount, maxAmount decimal.Decimal, expiredTime *time.Time, remark string, isConstant bool) error

增加额度,调整红包产生等

type RecordTokens added in v1.0.8

type RecordTokens struct {
	Amount uint64         `json:"amount"` //数量
	Asset  *modules.Asset `json:"asset"`  //资产
}

type RecordTokensJson added in v1.0.8

type RecordTokensJson struct {
	Amount decimal.Decimal `json:"amount"` //数量
	Asset  string          `json:"asset"`  //资产
}

type Tokens added in v1.0.8

type Tokens struct {
	Amount        uint64         `json:"amount"` //数量
	Asset         *modules.Asset `json:"asset"`  //资产
	BalanceAmount uint64         //红包剩余额度
	BalanceCount  uint32         //红包剩余次数
}

type TokensJson added in v1.0.8

type TokensJson struct {
	Amount        decimal.Decimal `json:"amount"` //数量
	Asset         string          `json:"asset"`  //资产
	BalanceAmount decimal.Decimal //红包剩余额度
	BalanceCount  uint32          //红包剩余次数
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL