-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3613 from AElfProject/feature/multi-tx
Add MultiTransaction type and one new web api to handle this
- Loading branch information
Showing
8 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Linq; | ||
using Google.Protobuf; | ||
|
||
namespace AElf.Types | ||
{ | ||
public partial class MultiTransaction | ||
{ | ||
private Hash _transactionId; | ||
|
||
public Hash GetHash() | ||
{ | ||
if (_transactionId == null) | ||
_transactionId = HashHelper.ComputeFrom(GetSignatureData()); | ||
|
||
return _transactionId; | ||
} | ||
|
||
public ValidationStatus VerifyFields() | ||
{ | ||
if (Transactions.Count < 2) | ||
return ValidationStatus.OnlyOneTransaction; | ||
|
||
if (!AllTransactionsHaveSameFrom()) | ||
return ValidationStatus.MoreThanOneFrom; | ||
|
||
if (Transactions.Any(transaction => string.IsNullOrEmpty(transaction.Transaction.MethodName))) | ||
return ValidationStatus.MethodNameIsEmpty; | ||
|
||
if (Transactions.Any(transaction => transaction.Transaction.Signature.IsEmpty)) | ||
{ | ||
return ValidationStatus.UserSignatureIsEmpty; | ||
} | ||
|
||
return ValidationStatus.Success; | ||
} | ||
|
||
public enum ValidationStatus | ||
{ | ||
Success, | ||
OnlyOneTransaction, | ||
MoreThanOneFrom, | ||
MethodNameIsEmpty, | ||
UserSignatureIsEmpty | ||
} | ||
|
||
private bool AllTransactionsHaveSameFrom() | ||
{ | ||
var firstFrom = Transactions[0].Transaction.From; | ||
return Transactions.All(transaction => transaction.Transaction.From == firstFrom); | ||
} | ||
|
||
private byte[] GetSignatureData() | ||
{ | ||
var verifyResult = VerifyFields(); | ||
if (verifyResult != ValidationStatus.Success) | ||
throw new InvalidOperationException($"Invalid multi transaction, {verifyResult.ToString()}: {this}"); | ||
|
||
if (Signature.IsEmpty) | ||
return this.ToByteArray(); | ||
|
||
var multiTransaction = Clone(); | ||
multiTransaction.Signature = ByteString.Empty; | ||
return multiTransaction.ToByteArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/AElf.WebApp.Application.Chain/Dto/SendMultiTransactionInput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace AElf.WebApp.Application.Chain.Dto; | ||
|
||
public class SendMultiTransactionInput : SendTransactionsInput | ||
{ | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/AElf.WebApp.Application.Chain/Dto/SendMultiTransactionOutput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace AElf.WebApp.Application.Chain.Dto; | ||
|
||
public class SendMultiTransactionOutput | ||
{ | ||
public string[] TransactionIds { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace AElf.WebApp.Application.Chain; | ||
|
||
public class MultiTransactionOptions | ||
{ | ||
public string GatewayAddress { get; set; } | ||
public string GatewayContractAddress { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters