2019-11-25 17:39:11 +00:00
|
|
|
package entities
|
2018-04-16 20:15:30 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
2019-08-27 13:29:42 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
2019-09-16 09:18:13 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2018-04-16 20:15:30 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
const feeMode = 0x0
|
|
|
|
|
2019-02-09 15:53:58 +00:00
|
|
|
// AssetState represents the state of an NEO registered Asset.
|
2018-04-16 20:15:30 +00:00
|
|
|
type AssetState struct {
|
|
|
|
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.
|
|
|
|
func (a *AssetState) DecodeBinary(br *io.BinReader) {
|
2019-12-06 15:37:46 +00:00
|
|
|
br.ReadBytes(a.ID[:])
|
2019-08-28 16:27:06 +00:00
|
|
|
br.ReadLE(&a.AssetType)
|
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-08-28 16:27:06 +00:00
|
|
|
br.ReadLE(&a.Amount)
|
|
|
|
br.ReadLE(&a.Available)
|
|
|
|
br.ReadLE(&a.Precision)
|
|
|
|
br.ReadLE(&a.FeeMode)
|
2019-12-06 15:37:46 +00:00
|
|
|
br.ReadBytes(a.FeeAddress[:])
|
2018-04-16 20:15:30 +00:00
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
a.Owner.DecodeBinary(br)
|
2019-12-06 15:37:46 +00:00
|
|
|
br.ReadBytes(a.Admin[:])
|
|
|
|
br.ReadBytes(a.Issuer[:])
|
2019-08-28 16:27:06 +00:00
|
|
|
br.ReadLE(&a.Expiration)
|
|
|
|
br.ReadLE(&a.IsFrozen)
|
2018-04-16 20:15:30 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// EncodeBinary implements Serializable interface.
|
|
|
|
func (a *AssetState) EncodeBinary(bw *io.BinWriter) {
|
2019-12-06 15:22:21 +00:00
|
|
|
bw.WriteBytes(a.ID[:])
|
2019-08-28 16:27:06 +00:00
|
|
|
bw.WriteLE(a.AssetType)
|
|
|
|
bw.WriteString(a.Name)
|
|
|
|
bw.WriteLE(a.Amount)
|
|
|
|
bw.WriteLE(a.Available)
|
|
|
|
bw.WriteLE(a.Precision)
|
|
|
|
bw.WriteLE(a.FeeMode)
|
2019-12-06 15:22:21 +00:00
|
|
|
bw.WriteBytes(a.FeeAddress[:])
|
2019-08-28 16:27:06 +00:00
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
a.Owner.EncodeBinary(bw)
|
|
|
|
|
2019-12-06 15:22:21 +00:00
|
|
|
bw.WriteBytes(a.Admin[:])
|
|
|
|
bw.WriteBytes(a.Issuer[:])
|
2019-08-28 16:27:06 +00:00
|
|
|
bw.WriteLE(a.Expiration)
|
|
|
|
bw.WriteLE(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.
|
2018-11-26 21:12:33 +00:00
|
|
|
func (a *AssetState) GetName() string {
|
|
|
|
|
|
|
|
if a.AssetType == transaction.GoverningToken {
|
|
|
|
return "NEO"
|
|
|
|
} else if a.AssetType == transaction.UtilityToken {
|
|
|
|
return "NEOGas"
|
|
|
|
}
|
|
|
|
|
|
|
|
return a.Name
|
|
|
|
}
|