Documentation ¶
Index ¶
- Constants
- Variables
- func FromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)
- type CachedPayload
- type ID
- type Payload
- func (p *Payload) Bytes() []byte
- func (p *Payload) ID() ID
- func (p *Payload) ObjectStorageKey() []byte
- func (p *Payload) ObjectStorageValue() (bytes []byte)
- func (p *Payload) Parent1ID() ID
- func (p *Payload) Parent2ID() ID
- func (p *Payload) String() string
- func (p *Payload) Transaction() *transaction.Transaction
- func (p *Payload) Type() payload.Type
- func (p *Payload) Update(other objectstorage.StorableObject)
Examples ¶
Constants ¶
const IDLength = 32
IDLength defined the amount of bytes in a payload id (32 bytes hash value).
const (
// ObjectName defines the name of the value object.
ObjectName = "value"
)
Variables ¶
var Type = payload.NewType(1, ObjectName, func(data []byte) (payload payload.Payload, err error) { payload, _, err = FromBytes(data) return })
Type represents the identifier which addresses the value Payload type.
Functions ¶
func FromObjectStorage ¶
func FromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)
FromObjectStorage is a factory method that creates a new Payload from the ObjectStorage.
Types ¶
type CachedPayload ¶
type CachedPayload struct {
objectstorage.CachedObject
}
CachedPayload is a wrapper for the object storage, that takes care of type casting the managed objects. Since go does not have generics (yet), the object storage works based on the generic "interface{}" type, which means that we have to regularly type cast the returned objects, to match the expected type. To reduce the burden of manually managing these type, we create a wrapper that does this for us. This way, we can consistently handle the specialized types of CachedObjects, without having to manually type cast over and over again.
func (*CachedPayload) Consume ¶
func (c *CachedPayload) Consume(consumer func(payload *Payload)) bool
Consume wraps the underlying method to return the correctly typed objects in the callback.
func (*CachedPayload) Retain ¶
func (c *CachedPayload) Retain() *CachedPayload
Retain wraps the underlying method to return a new "wrapped object".
func (*CachedPayload) Unwrap ¶
func (c *CachedPayload) Unwrap() *Payload
Unwrap provides a way to "Get" a type casted version of the underlying object.
type ID ¶
ID represents the hash of a payload that is used to identify the given payload.
var GenesisID ID
GenesisID contains the zero value of this ID which represents the genesis.
func IDFromBytes ¶
func IDFromBytes(bytes []byte, optionalTargetObject ...*ID) (result ID, consumedBytes int, err error)
IDFromBytes unmarshals a payload id from a sequence of bytes. It either creates a new payload id or fills the optionally provided object with the parsed information.
func ParseID ¶
func ParseID(marshalUtil *marshalutil.MarshalUtil) (ID, error)
ParseID is a wrapper for simplified unmarshaling in a byte stream using the marshalUtil package.
type Payload ¶
type Payload struct { objectstorage.StorableObjectFlags // contains filtered or unexported fields }
Payload represents the entity that forms the Tangle by referencing other Payloads using their parent1 and parent2. A Payload contains a transaction and defines, where in the Tangle a transaction is attached.
Example ¶
// 1. create value transfer (user provides this) valueTransfer := transaction.New( // inputs transaction.NewInputs( transaction.NewOutputID(address.Random(), transaction.RandomID()), transaction.NewOutputID(address.Random(), transaction.RandomID()), ), // outputs transaction.NewOutputs(map[address.Address][]*balance.Balance{ address.Random(): { balance.New(balance.ColorIOTA, 1337), }, }), ) // 2. create value payload (the ontology creates this and wraps the user provided transfer accordingly) valuePayload := New( // parent1 in "value transfer ontology" (filled by ontology tipSelector) GenesisID, // parent2 in "value transfer ontology" (filled by ontology tipSelector) GenesisID, // value transfer valueTransfer, ) // 3. build actual transaction (the base layer creates this and wraps the ontology provided payload) tx := tangle.NewMessage( []tangle.MessageID{tangle.EmptyMessageID}, []tangle.MessageID{}, // the time when the transaction was created time.Now(), // public key of the issuer ed25519.PublicKey{}, // the ever increasing sequence number of this transaction 0, // payload valuePayload, // nonce to check PoW 0, // signature ed25519.Signature{}, ) fmt.Println(tx)
Output:
func FromBytes ¶
FromBytes parses the marshaled version of a Payload into an object. It either returns a new Payload or fills an optionally provided Payload with the parsed information.
func New ¶
func New(parent1PayloadID, parent2PayloadID ID, valueTransfer *transaction.Transaction) *Payload
New is the constructor of a Payload and creates a new Payload object from the given details.
func Parse ¶
func Parse(marshalUtil *marshalutil.MarshalUtil) (result *Payload, err error)
Parse unmarshals a Payload using the given marshalUtil (for easier marshaling/unmarshaling).
func (*Payload) ObjectStorageKey ¶
ObjectStorageKey returns the bytes that are used a key when storing the Payload in an objectstorage.
func (*Payload) ObjectStorageValue ¶
ObjectStorageValue returns the bytes that represent all remaining information (not stored in the key) of a marshaled Parent2.
func (*Payload) Parent2ID ¶
Parent2ID returns the second Payload that is referenced by this Payload.
func (*Payload) Transaction ¶
func (p *Payload) Transaction() *transaction.Transaction
Transaction returns the Transaction that is being attached in this Payload.
func (*Payload) Update ¶
func (p *Payload) Update(other objectstorage.StorableObject)
Update is disabled but needs to be implemented to be compatible with the objectstorage.