This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
WSBlockChain.h
98 lines (78 loc) · 3.3 KB
/
WSBlockChain.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// WSBlockChain.h
// BitcoinSPV
//
// Created by Davide De Rosa on 02/07/14.
// Copyright (c) 2014 Davide De Rosa. All rights reserved.
//
// https://github.com/keeshux
//
// This file is part of BitcoinSPV.
//
// BitcoinSPV is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// BitcoinSPV is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with BitcoinSPV. If not, see <http://www.gnu.org/licenses/>.
//
#import <Foundation/Foundation.h>
#import "WSIndentableDescription.h"
@class WSHash256;
@protocol WSBlockStore;
@class WSStorableBlock;
@class WSBlockHeader;
@class WSFilteredBlock;
@class WSBlockLocator;
@class WSCoreDataManager;
#pragma mark -
@protocol WSBlockChainDelegate;
typedef enum {
WSBlockChainLocationNone,
WSBlockChainLocationMain,
WSBlockChainLocationFork,
WSBlockChainLocationOrphan
} WSBlockChainLocation;
typedef void (^WSBlockChainReorganizeBlock)(WSStorableBlock *, NSArray *, NSArray *);
//
// thread-safe: no (just a business wrapper around a block store)
//
@interface WSBlockChain : NSObject <WSIndentableDescription>
@property (nonatomic, weak) id<WSBlockChainDelegate> delegate;
- (instancetype)initWithStore:(id<WSBlockStore>)store;
- (instancetype)initWithStore:(id<WSBlockStore>)store maxSize:(NSUInteger)maxSize;
- (NSUInteger)maxSize;
- (void)truncate;
- (WSStorableBlock *)head;
- (WSStorableBlock *)blockForId:(WSHash256 *)blockId;
- (NSArray *)allBlockIds;
- (uint32_t)currentHeight;
- (uint32_t)currentTimestamp;
- (WSBlockLocator *)currentLocator;
- (WSStorableBlock *)addCheckpoint:(WSStorableBlock *)checkpoint error:(NSError **)error;
- (WSStorableBlock *)addBlockWithHeader:(WSBlockHeader *)header
transactions:(NSOrderedSet *)transactions
location:(WSBlockChainLocation *)location
connectedOrphans:(NSArray **)connectedOrphans
reorganizeBlock:(WSBlockChainReorganizeBlock)reorganizeBlock
error:(NSError **)error;
- (BOOL)isOrphanBlock:(WSStorableBlock *)block;
- (BOOL)isKnownOrphanBlockWithId:(WSHash256 *)blockId;
- (WSStorableBlock *)findForkBaseFromHead:(WSStorableBlock *)forkHead;
- (void)loadFromCoreDataManager:(WSCoreDataManager *)manager;
- (void)saveToCoreDataManager:(WSCoreDataManager *)manager;
- (NSString *)descriptionWithMaxBlocks:(NSUInteger)maxBlocks;
- (NSString *)descriptionWithIndent:(NSUInteger)indent maxBlocks:(NSUInteger)maxBlocks;
@end
#pragma mark -
@protocol WSBlockChainDelegate <NSObject>
- (void)blockChain:(WSBlockChain *)blockChain didAddNewBlock:(WSStorableBlock *)block location:(WSBlockChainLocation)location;
- (void)blockChain:(WSBlockChain *)blockChain didReplaceHead:(WSStorableBlock *)head;
- (void)blockChain:(WSBlockChain *)blockChain didReorganizeAtBase:(WSStorableBlock *)base oldBlocks:(NSArray *)oldBlocks newBlocks:(NSArray *)newBlocks;
@end