aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/asset_wire.h
blob: e5f63a01be2cb19924aecc63290734c2c50d089c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include <string>
#include <vector>

#include <boost/optional.hpp>

#include "asset_confidential.h"

namespace cryptonote
{
namespace assets
{
  constexpr uint8_t ASSET_TRANSACTION_WIRE_VERSION = 1;
  constexpr size_t MAX_ASSET_BALANCE_GROUPS = 8;
  constexpr size_t MAX_ASSET_TOTAL_INPUTS = 64;
  constexpr size_t MAX_ASSET_TOTAL_DESTINATIONS = 64;
  constexpr size_t MAX_ASSET_OWNERSHIP_PROOFS = 64;
  constexpr size_t MAX_ASSET_RANGE_PROOFS = 16;
  constexpr size_t MAX_ASSET_WIRE_BYTES = 256 * 1024;

  struct confidential_asset_output
  {
    rct::key destination{};
    rct::key commitment{};
  };

  // Inactive canonical payload prototype. The carrier hash is computed from
  // the native transaction prefix with this envelope omitted; activation code
  // must enforce that procedure to avoid a self-referential hash.
  struct asset_transaction_payload
  {
    uint8_t version = ASSET_TRANSACTION_WIRE_VERSION;
    network_type network = UNDEFINED;
    crypto::hash carrier_prefix_hash{};
    boost::optional<issuance_payload> issuance;
    std::vector<confidential_asset_balance> balances;
    std::vector<std::vector<rct::key>> output_destinations;
    std::vector<asset_ownership_proof> ownership_proofs;
  };

  bool validate_asset_transaction_payload_shape(
    const asset_transaction_payload& payload,
    std::string* error = nullptr);
  bool encode_asset_transaction_payload(
    const asset_transaction_payload& payload,
    std::vector<uint8_t>& encoded,
    std::string* error = nullptr);
  bool decode_asset_transaction_payload(
    const std::vector<uint8_t>& encoded,
    asset_transaction_payload& payload,
    std::string* error = nullptr);
  bool verify_asset_transaction_payload(
    const asset_transaction_payload& payload,
    const std::set<crypto::hash>& known_assets,
    network_type expected_network,
    const crypto::hash& expected_carrier_prefix_hash,
    std::string* error = nullptr);
  bool derive_asset_output_id(
    network_type network,
    const crypto::hash& carrier_prefix_hash,
    const crypto::hash& asset_id,
    uint32_t output_index,
    const confidential_asset_output& output,
    crypto::hash& output_id,
    std::string* error = nullptr);
}
}