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 "../BinaryCoding.h"
12
#include "ReadData.h"
13
#include "ISerializable.h"
14
#include "Serializable.h"
15

16
namespace TW::NEO {
17

18 1
class TransactionOutput : public Serializable {
19
  public:
20
    static const size_t assetIdSize = 32;
21
    static const size_t valueSize = 8;
22
    static const size_t scriptHashSize = 20;
23

24
    uint256_t assetId;
25 1
    int64_t value = 0;
26
    uint256_t scriptHash;
27

28 1
    virtual ~TransactionOutput() {}
29

30 1
    int64_t size() const override {
31 1
        return store(assetId).size() + valueSize + store(scriptHash).size();
32
    }
33

34 1
    void deserialize(const Data& data, int initial_pos = 0) override {
35 1
        assetId = load(readBytes(data, assetIdSize, initial_pos));
36 1
        value = decode64LE(data.data() + initial_pos + assetIdSize);
37 1
        scriptHash = load(readBytes(data, scriptHashSize, initial_pos + assetIdSize + valueSize));
38
    }
39

40 1
    Data serialize() const override {
41 1
        auto resp = store(assetId);
42 1
        encode64LE(value, resp);
43 1
        return concat(resp, store(scriptHash));
44
    }
45

46 1
    bool operator==(const TransactionOutput &other) const {
47 1
        return this->assetId == other.assetId
48 1
            && this->value == other.value
49 1
            && this->scriptHash == other.scriptHash;
50
    }
51
};
52

53
}

Read our documentation on viewing source code .

Loading