You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

  1. package blockchain
  2. // thhis file implements code which controls output indexes
  3. // rewrites them during chain reorganisation
  4. import "fmt"
  5. import "encoding/binary"
  6. import "github.com/deroproject/derosuite/crypto"
  7. //import "github.com/deroproject/derosuite/crypto/ringct"
  8. type Output_index struct {
  9. Key crypto.Hash // stealth address key
  10. Commitment crypto.Hash // commitment public key
  11. Height uint64 // height to which this belongs
  12. }
  13. func (o *Output_index) Serialize() (result []byte) {
  14. result = append(o.Key[:], o.Commitment[:]...)
  15. result = append(result, itob(o.Height)...)
  16. return
  17. }
  18. func (o *Output_index) Deserialize(buf []byte) (err error) {
  19. if len(buf) != ( 32 + 32 + 8){
  20. return fmt.Errorf("Output index needs to be 72 bytes in size but found to be %d bytes", len(buf))
  21. }
  22. copy(o.Key[:],buf[:32])
  23. copy(o.Commitment[:],buf[32:64])
  24. o.Height = binary.BigEndian.Uint64(buf[64:])
  25. return
  26. }
  27. // this function writes or overwrites the data related to outputs
  28. // the following data is collected from each output
  29. // the secret key,
  30. // the commitment ( for miner tx the commitment is created from scratch
  31. // 8 bytes blockheight to which this output belongs
  32. // this function should always succeed or panic showing something is not correct
  33. // NOTE: this function should only be called after all the tx and the block has been stored to DB
  34. func (chain *Blockchain)write_output_index(block_id crypto.Hash){
  35. // load the block
  36. bl, err := chain.Load_BL_FROM_ID(block_id)
  37. if err != nil {
  38. panic(fmt.Sprintf("No such block %x\n", block_id))
  39. }
  40. _ = bl
  41. }