mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-27 23:04:18 +00:00
Merge pull request #1380 from nspcc-dev/examples/token_sale_fix
examples: fix AddToCirculation method of TokenSale
This commit is contained in:
commit
d40a730e5a
1 changed files with 27 additions and 2 deletions
|
@ -92,10 +92,16 @@ func InCirculation() int {
|
||||||
return getIntFromDB(ctx, token.CirculationKey)
|
return getIntFromDB(ctx, token.CirculationKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddToCirculation sets the given amount as "in circulation" in the storage.
|
// addToCirculation sets the given amount as "in circulation" in the storage.
|
||||||
func AddToCirculation(amount int) bool {
|
func addToCirculation(amount int) bool {
|
||||||
|
if amount < 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
supply := getIntFromDB(ctx, token.CirculationKey)
|
supply := getIntFromDB(ctx, token.CirculationKey)
|
||||||
supply += amount
|
supply += amount
|
||||||
|
if supply > token.TotalSupply {
|
||||||
|
return false
|
||||||
|
}
|
||||||
storage.Put(ctx, token.CirculationKey, supply)
|
storage.Put(ctx, token.CirculationKey, supply)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -257,3 +263,22 @@ func Allowance(from, to []byte) interface{} {
|
||||||
key := append(from, to...)
|
key := append(from, to...)
|
||||||
return getIntFromDB(ctx, key)
|
return getIntFromDB(ctx, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mint initial supply of tokens
|
||||||
|
func Mint(to []byte) bool {
|
||||||
|
if trigger != runtime.Application {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !checkOwnerWitness() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
minted := storage.Get(ctx, []byte("minted"))
|
||||||
|
if minted != nil && minted.(bool) == true {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
storage.Put(ctx, to, token.TotalSupply)
|
||||||
|
storage.Put(ctx, []byte("minted"), true)
|
||||||
|
addToCirculation(token.TotalSupply)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue