Skip to content
Snippets Groups Projects
Commit 3997501e authored by Hans Moog's avatar Hans Moog
Browse files

Feat: started rewriting output model

parent feb06868
No related branches found
No related tags found
No related merge requests found
...@@ -104,6 +104,15 @@ func (output *Output) Balances() []*balance.Balance { ...@@ -104,6 +104,15 @@ func (output *Output) Balances() []*balance.Balance {
return output.balances return output.balances
} }
// ObjectStorageKey returns the key that is used to store the object in the database.
// It is required to match StorableObject interface.
func (output *Output) ObjectStorageKey() []byte {
return marshalutil.New(OutputIdLength).
WriteBytes(output.address.Bytes()).
WriteBytes(output.transactionId.Bytes()).
Bytes()
}
// ObjectStorageValue marshals the balances into a sequence of bytes - the address and transaction id are stored inside the key // ObjectStorageValue marshals the balances into a sequence of bytes - the address and transaction id are stored inside the key
// and are ignored here. // and are ignored here.
func (output *Output) ObjectStorageValue() (data []byte) { func (output *Output) ObjectStorageValue() (data []byte) {
...@@ -112,13 +121,11 @@ func (output *Output) ObjectStorageValue() (data []byte) { ...@@ -112,13 +121,11 @@ func (output *Output) ObjectStorageValue() (data []byte) {
// initialize helper // initialize helper
marshalUtil := marshalutil.New(4 + balanceCount*balance.Length) marshalUtil := marshalutil.New(4 + balanceCount*balance.Length)
marshalUtil.WriteBool(output.solid)
// marshal the amount of balances marshalUtil.WriteTime(output.solidSince)
marshalUtil.WriteUint32(uint32(balanceCount)) marshalUtil.WriteUint32(uint32(balanceCount))
for _, balanceToMarshal := range output.balances {
// marshal balances marshalUtil.WriteBytes(balanceToMarshal.Bytes())
for _, balance := range output.balances {
marshalUtil.WriteBytes(balance.Bytes())
} }
return return
...@@ -137,11 +144,5 @@ func (output *Output) Update(other objectstorage.StorableObject) { ...@@ -137,11 +144,5 @@ func (output *Output) Update(other objectstorage.StorableObject) {
panic("this object should never be updated") panic("this object should never be updated")
} }
// ObjectStorageKey returns the key that is used to store the object in the database.
// It is required to match StorableObject interface.
func (output *Output) ObjectStorageKey() []byte {
return output.storageKey
}
// define contract (ensure that the struct fulfills the given interface) // define contract (ensure that the struct fulfills the given interface)
var _ objectstorage.StorableObject = &Output{} var _ objectstorage.StorableObject = &Output{}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment