-
Notifications
You must be signed in to change notification settings - Fork 16
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/asset lock payload #585
Conversation
WalkthroughThe changes focus on enhancing the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
DashSync/shared/Models/Transactions/Base/DSAssetLockTransaction.m (2)
80-87
: Add validation for payloadData resultConsider validating the result of
payloadData
before appending it to avoid potential issues with corrupted or invalid payload data.Here's a suggested improvement:
- (NSData *)toDataWithSubscriptIndex:(NSUInteger)subscriptIndex { @synchronized(self) { NSMutableData *data = [[super toDataWithSubscriptIndex:subscriptIndex] mutableCopy]; - [data appendCountedData:[self payloadData]]; + NSData *payload = [self payloadData]; + if (!payload) { + return nil; // or handle error appropriately + } + [data appendCountedData:payload]; if (subscriptIndex != NSNotFound) [data appendUInt32:SIGHASH_ALL]; return data; } }
88-90
: Add safety check for size calculationThe size calculation could be incorrect if
payloadData
returns nil. Consider adding a safety check.Here's a suggested improvement:
- (size_t)size { - return [super size] + [self payloadData].length; + NSData *payload = [self payloadData]; + return [super size] + (payload ? payload.length : 0); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Example/Podfile.lock
is excluded by!**/*.lock
📒 Files selected for processing (1)
DashSync/shared/Models/Transactions/Base/DSAssetLockTransaction.m
(2 hunks)
🔇 Additional comments (3)
DashSync/shared/Models/Transactions/Base/DSAssetLockTransaction.m (3)
22-22
: LGTM!
The added import for NSMutableData+Dash is necessary for the new payload data handling methods.
63-65
: LGTM!
Good separation of concerns. The wrapper method provides a clean public interface while allowing for potential specialization in subclasses.
63-90
: Verify implementation against protocol specification
Please ensure that the payload data format matches the Dash protocol specification for asset lock transactions, particularly:
- The order of fields in the payload
- The size and format of each field
- The handling of SIGHASH_ALL
✅ Verification successful
Based on the search results, I can now provide a final response. The code analysis reveals that the implementation follows the Dash protocol's transaction type system, where Asset Lock is type 8 (DSTransactionType_AssetLock), and the payload format consists of:
- Special transaction version (uint8)
- Credit outputs count (VarInt)
- For each credit output:
- Amount (uint64)
- Output script (counted data)
The implementation in DSAssetLockTransaction matches this format exactly:
- Correctly orders fields in payload
- Uses proper data types and serialization
- Properly handles SIGHASH_ALL in toDataWithSubscriptIndex
Implementation correctly follows protocol specification
- Transaction type is properly defined as DSTransactionType_AssetLock = 8
- Payload serialization follows the expected format
- SIGHASH_ALL is correctly appended when generating transaction data for signing
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for protocol specification or test files
rg -g "!*.{lock,log}" -i "asset.*lock.*protocol|asset.*lock.*specification"
# Search for related test files
fd -e m -e mm "test.*assetlock|assetlock.*test"
Length of output: 127
Script:
#!/bin/bash
# Let's search for test cases and usage of DSAssetLockTransaction
rg -A 5 "DSAssetLockTransaction"
# Search for any documentation or comments about asset lock transaction format
rg -i "asset.*lock.*transaction.*format|asset.*lock.*payload"
# Look for any constant definitions related to asset lock transactions
ast-grep --pattern 'extern NSString * const $_AssetLock$_'
# Search for any protocol version or special transaction version definitions
rg "specialTransactionVersion.*asset.*lock" -A 2
Length of output: 17373
Script:
#!/bin/bash
# Let's look for transaction type definitions and version information
rg "DSTransactionType_AssetLock" -A 5
# Search for any special transaction version constants or enums
rg "typedef.*SpecialTransactionVersion|enum.*SpecialTransactionVersion" -A 10
# Look for any protocol documentation in header files
fd -e h | xargs rg -l "Asset Lock" | xargs cat
# Search for any test initialization of asset lock transactions
ast-grep --pattern 'DSAssetLockTransaction *$_ = [[DSAssetLockTransaction alloc] $_'
Length of output: 15780
- (NSData *)basePayloadData { | ||
NSMutableData *data = [NSMutableData data]; | ||
[data appendUInt8:self.specialTransactionVersion]; | ||
NSUInteger creditOutputsCount = self.creditOutputs.count; | ||
[data appendVarInt:creditOutputsCount]; | ||
for (NSUInteger i = 0; i < creditOutputsCount; i++) { | ||
DSTransactionOutput *output = self.creditOutputs[i]; | ||
[data appendUInt64:output.amount]; | ||
[data appendCountedData:output.outScript]; | ||
} | ||
return data; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add nil check for creditOutputs array
The method could crash if self.creditOutputs
is nil. Consider adding a defensive check.
Here's a suggested fix:
- (NSData *)basePayloadData {
NSMutableData *data = [NSMutableData data];
[data appendUInt8:self.specialTransactionVersion];
- NSUInteger creditOutputsCount = self.creditOutputs.count;
+ NSArray *outputs = self.creditOutputs ?: @[];
+ NSUInteger creditOutputsCount = outputs.count;
[data appendVarInt:creditOutputsCount];
for (NSUInteger i = 0; i < creditOutputsCount; i++) {
- DSTransactionOutput *output = self.creditOutputs[i];
+ DSTransactionOutput *output = outputs[i];
[data appendUInt64:output.amount];
[data appendCountedData:output.outScript];
}
return data;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
- (NSData *)basePayloadData { | |
NSMutableData *data = [NSMutableData data]; | |
[data appendUInt8:self.specialTransactionVersion]; | |
NSUInteger creditOutputsCount = self.creditOutputs.count; | |
[data appendVarInt:creditOutputsCount]; | |
for (NSUInteger i = 0; i < creditOutputsCount; i++) { | |
DSTransactionOutput *output = self.creditOutputs[i]; | |
[data appendUInt64:output.amount]; | |
[data appendCountedData:output.outScript]; | |
} | |
return data; | |
} | |
- (NSData *)basePayloadData { | |
NSMutableData *data = [NSMutableData data]; | |
[data appendUInt8:self.specialTransactionVersion]; | |
NSArray *outputs = self.creditOutputs ?: @[]; | |
NSUInteger creditOutputsCount = outputs.count; | |
[data appendVarInt:creditOutputsCount]; | |
for (NSUInteger i = 0; i < creditOutputsCount; i++) { | |
DSTransactionOutput *output = outputs[i]; | |
[data appendUInt64:output.amount]; | |
[data appendCountedData:output.outScript]; | |
} | |
return data; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Fix with asset lock payload implementation
Issue being fixed or feature implemented
What was done?
How Has This Been Tested?
Breaking Changes
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit