2018-03-17 11:53:21 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
2020-03-23 14:31:28 +00:00
|
|
|
"encoding/json"
|
2020-04-10 10:41:49 +00:00
|
|
|
"math/rand"
|
2020-03-23 14:31:28 +00:00
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"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-03-17 11:53:21 +00:00
|
|
|
)
|
|
|
|
|
2018-03-21 16:11:04 +00:00
|
|
|
// RegisterTX represents a register transaction.
|
2018-03-25 10:45:54 +00:00
|
|
|
// NOTE: This is deprecated.
|
2018-03-17 11:53:21 +00:00
|
|
|
type RegisterTX struct {
|
|
|
|
// The type of the asset being registered.
|
|
|
|
AssetType AssetType
|
|
|
|
|
|
|
|
// Name of the asset being registered.
|
2018-03-25 10:45:54 +00:00
|
|
|
Name string
|
2018-03-17 11:53:21 +00:00
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// Amount registered.
|
|
|
|
// Unlimited mode -0.00000001.
|
2018-03-17 11:53:21 +00:00
|
|
|
Amount util.Fixed8
|
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// Decimals.
|
2018-03-17 11:53:21 +00:00
|
|
|
Precision uint8
|
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// Public key of the owner.
|
2019-12-09 15:33:04 +00:00
|
|
|
Owner keys.PublicKey
|
2018-03-21 16:11:04 +00:00
|
|
|
|
2018-03-17 11:53:21 +00:00
|
|
|
Admin util.Uint160
|
|
|
|
}
|
|
|
|
|
2020-04-10 10:41:49 +00:00
|
|
|
// NewRegisterTX creates Transaction of RegisterType type.
|
|
|
|
func NewRegisterTX(register *RegisterTX) *Transaction {
|
|
|
|
return &Transaction{
|
|
|
|
Type: RegisterType,
|
|
|
|
Version: 0,
|
|
|
|
Nonce: rand.Uint32(),
|
|
|
|
Data: register,
|
|
|
|
Attributes: []Attribute{},
|
2020-04-30 13:00:33 +00:00
|
|
|
Cosigners: []Cosigner{},
|
2020-04-10 10:41:49 +00:00
|
|
|
Inputs: []Input{},
|
|
|
|
Outputs: []Output{},
|
|
|
|
Scripts: []Witness{},
|
|
|
|
Trimmed: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// DecodeBinary implements Serializable interface.
|
|
|
|
func (tx *RegisterTX) DecodeBinary(br *io.BinReader) {
|
2019-12-12 17:17:50 +00:00
|
|
|
tx.AssetType = AssetType(br.ReadB())
|
2018-03-25 10:45:54 +00:00
|
|
|
|
2019-08-28 16:27:06 +00:00
|
|
|
tx.Name = br.ReadString()
|
2018-03-25 10:45:54 +00:00
|
|
|
|
2019-12-12 15:52:23 +00:00
|
|
|
tx.Amount.DecodeBinary(br)
|
2019-12-12 17:17:50 +00:00
|
|
|
tx.Precision = uint8(br.ReadB())
|
2018-03-17 11:53:21 +00:00
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
tx.Owner.DecodeBinary(br)
|
2018-03-17 11:53:21 +00:00
|
|
|
|
2020-05-04 07:35:56 +00:00
|
|
|
tx.Admin.DecodeBinary(br)
|
2018-03-17 11:53:21 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// EncodeBinary implements Serializable interface.
|
|
|
|
func (tx *RegisterTX) EncodeBinary(bw *io.BinWriter) {
|
2019-12-12 17:17:50 +00:00
|
|
|
bw.WriteB(byte(tx.AssetType))
|
2019-08-28 16:27:06 +00:00
|
|
|
bw.WriteString(tx.Name)
|
2019-12-12 15:52:23 +00:00
|
|
|
tx.Amount.EncodeBinary(bw)
|
2019-12-12 17:17:50 +00:00
|
|
|
bw.WriteB(byte(tx.Precision))
|
2019-11-22 10:34:06 +00:00
|
|
|
bw.WriteBytes(tx.Owner.Bytes())
|
2020-05-04 07:35:56 +00:00
|
|
|
tx.Admin.EncodeBinary(bw)
|
2018-03-17 11:53:21 +00:00
|
|
|
}
|
2020-03-23 14:31:28 +00:00
|
|
|
|
|
|
|
// registeredAsset is a wrapper for RegisterTransaction
|
|
|
|
type registeredAsset struct {
|
|
|
|
AssetType AssetType `json:"type,omitempty"`
|
|
|
|
Name json.RawMessage `json:"name,omitempty"`
|
|
|
|
Amount util.Fixed8 `json:"amount,omitempty"`
|
|
|
|
Precision uint8 `json:"precision,omitempty"`
|
|
|
|
Owner keys.PublicKey `json:"owner,omitempty"`
|
|
|
|
Admin string `json:"admin,omitempty"`
|
|
|
|
}
|