2019-11-28 16:06:09 +00:00
|
|
|
package state
|
2018-04-16 20:15:30 +00:00
|
|
|
|
|
|
|
import (
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2018-04-16 20:15:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const feeMode = 0x0
|
|
|
|
|
2019-11-28 16:06:09 +00:00
|
|
|
// Asset represents the state of an NEO registered Asset.
|
|
|
|
type Asset struct {
|
2018-04-16 20:15:30 +00:00
|
|
|
ID util.Uint256
|
|
|
|
AssetType transaction.AssetType
|
|
|
|
Name string
|
|
|
|
Amount util.Fixed8
|
|
|
|
Available util.Fixed8
|
|
|
|
Precision uint8
|
|
|
|
FeeMode uint8
|
2018-11-26 21:12:33 +00:00
|
|
|
FeeAddress util.Uint160
|
2019-12-09 15:33:04 +00:00
|
|
|
Owner keys.PublicKey
|
2018-04-16 20:15:30 +00:00
|
|
|
Admin util.Uint160
|
|
|
|
Issuer util.Uint160
|
|
|
|
Expiration uint32
|
|
|
|
IsFrozen bool
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// DecodeBinary implements Serializable interface.
|
2019-11-28 16:06:09 +00:00
|
|
|
func (a *Asset) DecodeBinary(br *io.BinReader) {
|
2019-12-06 15:37:46 +00:00
|
|
|
br.ReadBytes(a.ID[:])
|
2019-12-12 17:17:50 +00:00
|
|
|
a.AssetType = transaction.AssetType(br.ReadB())
|
2018-04-16 20:15:30 +00:00
|
|
|
|
2019-08-28 16:27:06 +00:00
|
|
|
a.Name = br.ReadString()
|
2018-04-16 20:15:30 +00:00
|
|
|
|
2019-12-12 15:52:23 +00:00
|
|
|
a.Amount.DecodeBinary(br)
|
|
|
|
a.Available.DecodeBinary(br)
|
2019-12-12 17:17:50 +00:00
|
|
|
a.Precision = uint8(br.ReadB())
|
|
|
|
a.FeeMode = uint8(br.ReadB())
|
2020-05-04 07:35:56 +00:00
|
|
|
a.FeeAddress.DecodeBinary(br)
|
2018-04-16 20:15:30 +00:00
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
a.Owner.DecodeBinary(br)
|
2020-05-04 07:35:56 +00:00
|
|
|
a.Admin.DecodeBinary(br)
|
|
|
|
a.Issuer.DecodeBinary(br)
|
2019-12-12 15:52:23 +00:00
|
|
|
a.Expiration = br.ReadU32LE()
|
|
|
|
a.IsFrozen = br.ReadBool()
|
2018-04-16 20:15:30 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// EncodeBinary implements Serializable interface.
|
2019-11-28 16:06:09 +00:00
|
|
|
func (a *Asset) EncodeBinary(bw *io.BinWriter) {
|
2019-12-06 15:22:21 +00:00
|
|
|
bw.WriteBytes(a.ID[:])
|
2019-12-12 17:17:50 +00:00
|
|
|
bw.WriteB(byte(a.AssetType))
|
2019-08-28 16:27:06 +00:00
|
|
|
bw.WriteString(a.Name)
|
2019-12-12 15:52:23 +00:00
|
|
|
a.Amount.EncodeBinary(bw)
|
|
|
|
a.Available.EncodeBinary(bw)
|
2019-12-12 17:17:50 +00:00
|
|
|
bw.WriteB(byte(a.Precision))
|
|
|
|
bw.WriteB(byte(a.FeeMode))
|
2020-05-04 07:35:56 +00:00
|
|
|
a.FeeAddress.EncodeBinary(bw)
|
2019-08-28 16:27:06 +00:00
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
a.Owner.EncodeBinary(bw)
|
|
|
|
|
2020-05-04 07:35:56 +00:00
|
|
|
a.Admin.EncodeBinary(bw)
|
|
|
|
a.Issuer.EncodeBinary(bw)
|
2019-12-12 15:52:23 +00:00
|
|
|
bw.WriteU32LE(a.Expiration)
|
|
|
|
bw.WriteBool(a.IsFrozen)
|
2018-04-16 20:15:30 +00:00
|
|
|
}
|
2018-11-26 21:12:33 +00:00
|
|
|
|
2019-01-22 12:14:52 +00:00
|
|
|
// GetName returns the asset name based on its type.
|
2019-11-28 16:06:09 +00:00
|
|
|
func (a *Asset) GetName() string {
|
2018-11-26 21:12:33 +00:00
|
|
|
|
|
|
|
if a.AssetType == transaction.GoverningToken {
|
|
|
|
return "NEO"
|
|
|
|
} else if a.AssetType == transaction.UtilityToken {
|
|
|
|
return "NEOGas"
|
|
|
|
}
|
|
|
|
|
|
|
|
return a.Name
|
|
|
|
}
|