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 <TrustWalletCore/TWBitcoinSigHashType.h>
10
#include <TrustWalletCore/TWCoinType.h>
11

12
namespace TW::Bitcoin {
13

14
// Defines the number of bits of the hash type which is used to identify which
15
// outputs are signed.
16
static const uint8_t SigHashMask = 0x1f;
17

18
// Return the default HashType for the given coin, such as TWBitcoinSigHashTypeAll.
19 1
inline uint32_t hashTypeForCoin(enum TWCoinType coinType) {
20
    // set fork hash type for BCH
21 1
    switch (coinType) {
22
        case TWCoinTypeBitcoinCash:
23 1
            return (uint32_t)TWBitcoinSigHashTypeAll | (uint32_t)TWBitcoinSigHashTypeFork;
24
        case TWCoinTypeBitcoinGold:
25 1
            return (uint32_t)TWBitcoinSigHashTypeAll | (uint32_t)TWBitcoinSigHashTypeForkBTG;
26
        default:
27 1
            return TWBitcoinSigHashTypeAll;
28
    }
29
}
30

31 1
inline bool hashTypeIsSingle(enum TWBitcoinSigHashType type) { return (type & SigHashMask) == TWBitcoinSigHashTypeSingle; }
32

33 1
inline bool hashTypeIsNone(enum TWBitcoinSigHashType type) { return (type & SigHashMask) == TWBitcoinSigHashTypeNone; }
34

35
} // namespace TW::Bitcoin

Read our documentation on viewing source code .

Loading