Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs of build framework #100

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 71 additions & 58 deletions CoreBitcoin.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions CoreBitcoin/BTCAddress+Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ + (void) runAllTests {
[self testPrivateKeyAddress];
[self testPrivateKeyAddressWithCompressedPoint];
[self testScriptHashKeyAddress];
[self testQTUMPublicKeyAddress];
}

+ (void) testPublicKeyAddress {
Expand Down Expand Up @@ -64,4 +65,20 @@ + (void) testScriptHashKeyAddress {
NSAssert([@"3NukJ6fYZJ5Kk8bPjycAnruZkE5Q7UW7i8" isEqualToString:addr2.string], @"Must encode hash160 correctly.");
}

+ (void) testLTCPublicKeyAddress {
LTCPublicKeyAddress* addr = [LTCPublicKeyAddress addressWithString:@"Lae8PAGSuFHuVKSGaMkT8xqjB4dtFPvm5M"];
NSAssert(addr, @"Address should be decoded");
NSAssert([addr isKindOfClass:[LTCPublicKeyAddress class]], @"Address should be an instance of BTCPublicKeyAddress");
NSAssert([@"a91c5141dd1a2ab7aead02929c1cc6514ab591f2" isEqualToString:[addr.data hex]], @"Must decode hash160 correctly.");
NSAssert([addr isEqual:addr.publicAddress], @"Address should be equal to its publicAddress");
}

+ (void) testQTUMPublicKeyAddress {
QTUMPublicKeyAddress* addr = [QTUMPublicKeyAddress addressWithString:@"QXmeNJ1mHmJVjmZCCrZ7DWWUMiWtKXPGBu"];
NSAssert(addr, @"Address should be decoded");
NSAssert([addr isKindOfClass:[QTUMPublicKeyAddress class]], @"Address should be an instance of BTCPublicKeyAddress");
NSAssert([@"7a7d105b98ea62a40ef0cc421a19401ddaa5a22d" isEqualToString:[addr.data hex]], @"Must decode hash160 correctly.");
NSAssert([addr isEqual:addr.publicAddress], @"Address should be equal to its publicAddress");
}

@end
7 changes: 7 additions & 0 deletions CoreBitcoin/BTCAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@
@end
@interface BTCScriptHashAddressTestnet : BTCScriptHashAddress
@end

@interface LTCPublicKeyAddress : BTCPublicKeyAddress
@end

@interface QTUMPublicKeyAddress : BTCPublicKeyAddress

@end
27 changes: 26 additions & 1 deletion CoreBitcoin/BTCAddress.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
BTCPublicKeyAddressVersionTestnet = 111,
BTCPrivateKeyAddressVersionTestnet = 239,
BTCScriptHashAddressVersionTestnet = 196,
LTCPublicKeyAddressVersion = 48,
QTUMPublicKeyAddressVersion = 58,
};

@implementation BTCAddress {
Expand Down Expand Up @@ -431,4 +433,27 @@ - (BOOL) isTestnet {
return YES;
}

@end
@end


@implementation LTCPublicKeyAddress

+ (void) load {
[BTCAddress registerAddressClass:self version:[self BTCVersionPrefix]];
}

+ (uint8_t) BTCVersionPrefix {
return LTCPublicKeyAddressVersion;
}
@end

@implementation QTUMPublicKeyAddress

+ (void) load {
[BTCAddress registerAddressClass:self version:[self BTCVersionPrefix]];
}

+ (uint8_t) BTCVersionPrefix {
return QTUMPublicKeyAddressVersion;
}
@end
2 changes: 2 additions & 0 deletions CoreBitcoin/BTCScriptTestData.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// CoreBitcoin by Oleg Andreev <[email protected]>, WTFPL.

//
// BTCScriptTestData.m
// CoreBitcoin
Expand Down
3 changes: 3 additions & 0 deletions CoreBitcoin/BTCSignatureHashType.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ typedef NS_ENUM(unsigned char, BTCSignatureHashType)
SIGHASH_SINGLE = 3,
BTCSignatureHashTypeSingle = SIGHASH_SINGLE,

SIGHASH_FORKID = 0x40,
BCHSignatureHashTypeForkIDAll = SIGHASH_ALL | SIGHASH_FORKID,

// This mask is used to determine one of the first types independently from ANYONECANPAY option:
// E.g. if (type & SIGHASH_OUTPUT_MASK == SIGHASH_NONE) { blank all outputs }
SIGHASH_OUTPUT_MASK = 0x1F,
Expand Down
2 changes: 2 additions & 0 deletions CoreBitcoin/BTCTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ NSString* BTCTransactionIDFromHash(NSData* txhash) DEPRECATED_ATTRIBUTE;
// You should supply the output script of the previous transaction, desired hash type and input index in this transaction.
- (NSData*) signatureHashForScript:(BTCScript*)subscript inputIndex:(uint32_t)inputIndex hashType:(BTCSignatureHashType)hashType error:(NSError**)errorOut;

- (NSData *)signatureWitnessHashForScript:(BTCScript *)redeemScript amount:(BTCAmount)amount inputIndex:(uint32_t)inputIndex hashType:(BTCSignatureHashType)hashType error:(NSError**)errorOut;

// Adds input script
- (void) addInput:(BTCTransactionInput*)input;

Expand Down
59 changes: 59 additions & 0 deletions CoreBitcoin/BTCTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,68 @@ - (NSData*) signatureHashForScript:(BTCScript*)subscript inputIndex:(uint32_t)in
// NSLog(@"TX HASH: %@", BTCHexFromData(hash));
// NSLog(@"TX PLIST: %@", tx.dictionary);


return hash;
}

- (NSData *)signatureWitnessHashForScript:(BTCScript *)redeemScript amount:(BTCAmount)amount inputIndex:(uint32_t)inputIndex hashType:(BTCSignatureHashType)hashType error:(NSError**)errorOut {

NSMutableData *fullData = [[NSMutableData alloc] initWithCapacity:256];

NSMutableData *prevoutsData = [[NSMutableData alloc] init];
for (int i = 0; i < self.inputs.count; i++) {
BTCTransactionInput *input = self.inputs[i];
[prevoutsData appendData:input.previousHash];
uint32_t vindex = OSSwapHostToLittleInt32(input.previousIndex);
[prevoutsData appendBytes:&vindex length:sizeof(vindex)];
}
NSData *hashPrevouts = BTCHash256(prevoutsData);

NSMutableData *sequenceData = [[NSMutableData alloc] init];
for (int i = 0; i < self.inputs.count; i++) {
BTCTransactionInput *input = self.inputs[i];
uint32_t sequence = OSSwapHostToLittleInt32(input.sequence);
[sequenceData appendBytes:&sequence length:sizeof(sequence)];
}
NSData *hashSequence = BTCHash256(sequenceData);

NSMutableData *outputData = [[NSMutableData alloc] init];
for(int i = 0; i < self.outputs.count; i++) {
BTCTransactionOutput *output = self.outputs[i];
uint64_t value = OSSwapHostToLittleInt64(output.value);
[outputData appendBytes:&value length:sizeof(value)];
NSData *scriptData = output.script.data;

[outputData appendData:[BTCProtocolSerialization dataForVarInt:scriptData.length]];
[outputData appendData:scriptData];
}
NSData *hashOutputs = BTCHash256(outputData);

BTCTransactionInput *currentInput = self.inputs[inputIndex];

uint32_t version = OSSwapHostToLittleInt32(self.version);
[fullData appendBytes:&version length:sizeof(version)];
[fullData appendData:hashPrevouts];
[fullData appendData:hashSequence];
[fullData appendData:currentInput.previousHash];
uint32_t currentInputVInext = OSSwapHostToLittleInt32(currentInput.previousIndex);
[fullData appendBytes:&currentInputVInext length:sizeof(currentInputVInext)];
[fullData appendData:[BTCProtocolSerialization dataForVarInt:redeemScript.data.length]];
[fullData appendData:redeemScript.data];
uint64_t amountValue = OSSwapHostToLittleInt64(amount);
[fullData appendBytes:&amountValue length:sizeof(amountValue)];
uint32_t currentInputSequence = OSSwapHostToLittleInt32(currentInput.sequence);
[fullData appendBytes:&currentInputSequence length:sizeof(currentInputSequence)];
[fullData appendData:hashOutputs];
uint32_t lockTime = OSSwapHostToLittleInt32(self.lockTime);
[fullData appendBytes:&lockTime length:sizeof(lockTime)];
uint32_t hashType32 = OSSwapHostToLittleInt32((uint32_t)hashType);
[fullData appendBytes:&hashType32 length:sizeof(hashType32)];

NSData* hash = BTCHash256(fullData);
return hash;

}



Expand Down
2 changes: 1 addition & 1 deletion CoreBitcoin/CoreBitcoin+Categories.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// CoreBitcoin by Oleg Andreev <[email protected]>, WTFPL.

#import <CoreBitcoin/CoreBitcoin.h>
#import <CoreBitcoin/NS+BTCBase58.h>
#import <CoreBitcoin/NSData+BTCData.h>
#import <CoreBitcoin/NS+BTCBase58.h>
75 changes: 38 additions & 37 deletions CoreBitcoin/CoreBitcoin.h
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
// CoreBitcoin by Oleg Andreev <[email protected]>, WTFPL.

#import <CoreBitcoin/BTCPaymentMethodDetails.h>
#import <CoreBitcoin/BTCProcessor.h>
#import <CoreBitcoin/BTCCurvePoint.h>
#import <CoreBitcoin/BTCData.h>
#import <CoreBitcoin/BTCMerkleTree.h>
#import <CoreBitcoin/BTCOutpoint.h>
#import <CoreBitcoin/BTCProtocolBuffers.h>
#import <CoreBitcoin/BTC256.h>
#import <CoreBitcoin/SwiftBridgingHeader.h>
#import <CoreBitcoin/BTCAddress.h>
#import <CoreBitcoin/BTCPaymentMethod.h>
#import <CoreBitcoin/BTCHashID.h>
#import <CoreBitcoin/BTCCurrencyConverter.h>
#import <CoreBitcoin/BTCScript.h>
#import <CoreBitcoin/BTCPaymentRequest.h>
#import <CoreBitcoin/BTCScriptTestData.h>
#import <CoreBitcoin/BTCTransactionOutput.h>
#import <CoreBitcoin/BTCAddressSubclass.h>
#import <CoreBitcoin/BTCAssetAddress.h>
#import <CoreBitcoin/BTCAssetID.h>
#import <CoreBitcoin/BTCAssetType.h>
#import <CoreBitcoin/BTCKey.h>
#import <CoreBitcoin/BTCEncryptedMessage.h>
#import <CoreBitcoin/BTCBase58.h>
#import <CoreBitcoin/BTCBigNumber.h>
#import <CoreBitcoin/BTCBitcoinURL.h>
#import <CoreBitcoin/BTCPaymentMethodRequest.h>
#import <CoreBitcoin/BTCPaymentProtocol.h>
#import <CoreBitcoin/BTCErrors.h>
#import <CoreBitcoin/BTCBlindSignature.h>
#import <CoreBitcoin/BTCQRCode.h>
#import <CoreBitcoin/BTCAssetID.h>
#import <CoreBitcoin/BTCTransactionBuilder.h>
#import <CoreBitcoin/BTCAssetType.h>
#import <CoreBitcoin/BTCKeychain.h>
#import <CoreBitcoin/BTCEncryptedBackup.h>
#import <CoreBitcoin/BTCBlock.h>
#import <CoreBitcoin/BTCBlockchainInfo.h>
#import <CoreBitcoin/BTCBlockHeader.h>
#import <CoreBitcoin/BTCChainCom.h>
#import <CoreBitcoin/BTCCurrencyConverter.h>
#import <CoreBitcoin/BTCCurvePoint.h>
#import <CoreBitcoin/BTCData.h>
#import <CoreBitcoin/BTCEncryptedBackup.h>
#import <CoreBitcoin/BTCEncryptedMessage.h>
#import <CoreBitcoin/BTCErrors.h>
#import <CoreBitcoin/BTCFancyEncryptedMessage.h>
#import <CoreBitcoin/BTCHashID.h>
#import <CoreBitcoin/BTCKey.h>
#import <CoreBitcoin/BTCKeychain.h>
#import <CoreBitcoin/BTCMerkleTree.h>
#import <CoreBitcoin/BTCMnemonic.h>
#import <CoreBitcoin/BTCNetwork.h>
#import <CoreBitcoin/BTCNumberFormatter.h>
#import <CoreBitcoin/BTCBlockchainInfo.h>
#import <CoreBitcoin/BTCBigNumber.h>
#import <CoreBitcoin/BTCTransaction.h>
#import <CoreBitcoin/BTCUnitsAndLimits.h>
#import <CoreBitcoin/BTCFancyEncryptedMessage.h>
#import <CoreBitcoin/BTCOpcode.h>
#import <CoreBitcoin/BTCOutpoint.h>
#import <CoreBitcoin/BTCPaymentMethod.h>
#import <CoreBitcoin/BTCPaymentMethodDetails.h>
#import <CoreBitcoin/BTCPaymentMethodRequest.h>
#import <CoreBitcoin/BTCPaymentProtocol.h>
#import <CoreBitcoin/BTCPaymentRequest.h>
#import <CoreBitcoin/BTCPriceSource.h>
#import <CoreBitcoin/BTCProcessor.h>
#import <CoreBitcoin/BTCProtocolBuffers.h>
#import <CoreBitcoin/BTCProtocolSerialization.h>
#import <CoreBitcoin/BTCQRCode.h>
#import <CoreBitcoin/BTCScript.h>
#import <CoreBitcoin/BTCScriptMachine.h>
#import <CoreBitcoin/BTCSecretSharing.h>
#import <CoreBitcoin/BTCSignatureHashType.h>
#import <CoreBitcoin/BTCTransaction.h>
#import <CoreBitcoin/BTCTransactionBuilder.h>
#import <CoreBitcoin/BTCMnemonic.h>
#import <CoreBitcoin/BTCProtocolSerialization.h>
#import <CoreBitcoin/BTCNetwork.h>
#import <CoreBitcoin/BTCScriptMachine.h>
#import <CoreBitcoin/BTCTransactionInput.h>
#import <CoreBitcoin/BTCTransactionOutput.h>
#import <CoreBitcoin/BTCUnitsAndLimits.h>
#import <CoreBitcoin/SwiftBridgingHeader.h>
#import <CoreBitcoin/BTCAssetAddress.h>
#import <CoreBitcoin/BTCBitcoinURL.h>
#import <CoreBitcoin/BTCChainCom.h>
3 changes: 2 additions & 1 deletion postprocess_openssl_includes_in_framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

#include <openssl/bn.h> => #include <CoreBitcoin/openssl/bn.h>
data.gsub!(%r{#(include|import) <openssl/}, "#\\1 <CoreBitcoin/openssl/")

data.gsub!(%r{# (include|import) <openssl/}, "#\\1 <CoreBitcoin/openssl/")

#import "BTCSignatureHashType.h" => #import <CoreBitcoin/BTCSignatureHashType.h>
data.gsub!(%r{#(include|import) "(BTC.*?\.h)"}, "#\\1 <CoreBitcoin/\\2>")

Expand Down