forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLedgerHashUtils.h
73 lines (70 loc) · 2.36 KB
/
LedgerHashUtils.h
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
69
70
71
72
73
#pragma once
// Copyright 2018 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "crypto/ByteSliceHasher.h"
#include "xdr/Stellar-ledger.h"
#include <functional>
// implements a default hasher for "LedgerKey"
namespace std
{
template <> class hash<stellar::LedgerKey>
{
public:
size_t
operator()(stellar::LedgerKey const& lk) const
{
size_t res;
switch (lk.type())
{
case stellar::ACCOUNT:
res = stellar::shortHash::computeHash(
stellar::ByteSlice(lk.account().accountID.ed25519().data(), 8));
break;
case stellar::TRUSTLINE:
{
auto& tl = lk.trustLine();
res = stellar::shortHash::computeHash(
stellar::ByteSlice(tl.accountID.ed25519().data(), 8));
switch (lk.trustLine().asset.type())
{
case stellar::ASSET_TYPE_NATIVE:
break;
case stellar::ASSET_TYPE_CREDIT_ALPHANUM4:
{
auto& tl4 = tl.asset.alphaNum4();
res ^= stellar::shortHash::computeHash(
stellar::ByteSlice(tl4.issuer.ed25519().data(), 8));
res ^= tl4.assetCode[0];
break;
}
case stellar::ASSET_TYPE_CREDIT_ALPHANUM12:
{
auto& tl12 = tl.asset.alphaNum12();
res ^= stellar::shortHash::computeHash(
stellar::ByteSlice(tl12.issuer.ed25519().data(), 8));
res ^= tl12.assetCode[0];
break;
}
default:
abort();
}
break;
}
case stellar::DATA:
res = stellar::shortHash::computeHash(
stellar::ByteSlice(lk.data().accountID.ed25519().data(), 8));
res ^= stellar::shortHash::computeHash(stellar::ByteSlice(
lk.data().dataName.data(), lk.data().dataName.size()));
break;
case stellar::OFFER:
res = stellar::shortHash::computeHash(stellar::ByteSlice(
&lk.offer().offerID, sizeof(lk.offer().offerID)));
break;
default:
abort();
}
return res;
}
};
}