1
// Copyright © 2017-2020 Trust Wallet.
2
//
3
// This file is part of Trust. The full Trust copyright notice, including
4
// terms governing use, modification, and redistribution, is contained in the
5
// file LICENSE at the root of the source code distribution tree.
6

7
#pragma once
8

9
#include "../uint256.h"
10
#include "../Data.h"
11
#include "../Hash.h"
12
#include "../BinaryCoding.h"
13
#include "ISerializable.h"
14
#include "Serializable.h"
15

16
namespace TW::NEO {
17

18 1
class CoinReference : public Serializable {
19
  public:
20
    /// Number of bytes for prevIndex.
21
    static const size_t prevIndexSize = 2;
22

23
    uint256_t prevHash;
24 1
    uint16_t prevIndex = 0;
25

26 1
    virtual ~CoinReference() {}
27

28 1
    int64_t size() const override {
29 1
        return Hash::sha256Size + prevIndexSize;
30
    }
31

32 1
    void deserialize(const Data& data, int initial_pos = 0) override {
33 1
        prevHash = load(readBytes(data, Hash::sha256Size, initial_pos));
34 1
        prevIndex = decode16LE(data.data() + initial_pos + Hash::sha256Size);
35
    }
36

37 1
    Data serialize() const override {
38 1
        auto resp = store(prevHash);
39 1
        encode16LE(prevIndex, resp);
40 1
        return resp;
41
    }
42

43 1
    bool operator==(const CoinReference &other) const {
44 1
        return this->prevHash == other.prevHash
45 1
            && this->prevIndex == other.prevIndex;
46
    }
47
};
48

49
}

Read our documentation on viewing source code .

Loading