Skip to content

Commit a9cc53a

Browse files
authored
Put a limit to founder if target amount was not reached (#227)
* Put a limit to founder if amount was not reached * Prepare the methods that will be used to release funds (WIP) * mrege master fixes * move the box inside the spinner section * create a release page * lookup release sigs * Add the code so sign and validate the release trx and also add a test method to check it all works * Filter events by subject * Write the code to sign the release sigs * Sending a json type as encrypted data for the recovery request to founder instead of just the trx hex * show investor they have a pending release * Create the release page and implement investor release funds * All code is done ready to be test * Add handling of nostr events in an async event * check if a message was already decrypted * flow now works end to end * add missing braces * Act on review * Delete the extra `SignatureReleaseItem` class * Act on review * Fix some tests that incorrectly used TargetAmount as coins instead of sats * Some more fixes to the amount param in various places * Removing the TargetInvestmentReached param * act on review * Rename to UnfundedReleaseAddress * Write test to call a relay subscription
1 parent bff0434 commit a9cc53a

40 files changed

+1973
-373
lines changed

src/Angor.Test/InvestmentOperationsTest.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void SpendFounderStage_Test()
7575
var funderReceiveCoinsKey = new Key();
7676

7777
var projectInvestmentInfo = new ProjectInfo();
78-
projectInvestmentInfo.TargetAmount = 3;
78+
projectInvestmentInfo.TargetAmount = Money.Coins(3).Satoshi;
7979
projectInvestmentInfo.StartDate = DateTime.UtcNow;
8080
projectInvestmentInfo.ExpiryDate = DateTime.UtcNow.AddDays(5);
8181
projectInvestmentInfo.Stages = new List<Stage>
@@ -157,7 +157,7 @@ public void SpendFounderStage_Test()
157157
// create seeder1 investment transaction
158158

159159
var seeder1InvTrx = operations.CreateInvestmentTransaction(network, seeder1Context,
160-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
160+
projectInvestmentInfo.TargetAmount);
161161

162162
seeder1Context.TransactionHex = operations.SignInvestmentTransaction(network, seeder1Context.ChangeAddress,
163163
seeder1InvTrx, null, new List<UtxoDataWithPath>(), _expectedFeeEstimation)
@@ -168,7 +168,7 @@ public void SpendFounderStage_Test()
168168
// create seeder2 investment transaction
169169

170170
var seeder2InvTrx = operations.CreateInvestmentTransaction(network, seeder2Context,
171-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
171+
projectInvestmentInfo.TargetAmount);
172172

173173
seeder2Context.TransactionHex = operations.SignInvestmentTransaction(network, seeder2Context.ChangeAddress,
174174
seeder2InvTrx, null, new List<UtxoDataWithPath>(), _expectedFeeEstimation)
@@ -179,7 +179,7 @@ public void SpendFounderStage_Test()
179179
// create seeder3 investment transaction
180180

181181
var seeder3InvTrx = operations.CreateInvestmentTransaction(network, seeder3Context,
182-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
182+
projectInvestmentInfo.TargetAmount);
183183

184184
seeder3Context.TransactionHex = operations.SignInvestmentTransaction(network, seeder3Context.ChangeAddress,
185185
seeder3InvTrx, null, new List<UtxoDataWithPath>(), _expectedFeeEstimation)
@@ -190,7 +190,7 @@ public void SpendFounderStage_Test()
190190
// create investor 1 investment transaction
191191

192192
var investor1InvTrx = operations.CreateInvestmentTransaction(network, investor1Context,
193-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
193+
projectInvestmentInfo.TargetAmount);
194194

195195
investor1Context.TransactionHex = operations.SignInvestmentTransaction(network,
196196
investor1Context.ChangeAddress, investor1InvTrx, null, new List<UtxoDataWithPath>(),
@@ -202,7 +202,7 @@ public void SpendFounderStage_Test()
202202
// create investor 2 investment transaction
203203

204204
var investor2InvTrx = operations.CreateInvestmentTransaction(network, investor2Context,
205-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
205+
projectInvestmentInfo.TargetAmount);
206206

207207
investor2Context.TransactionHex = operations.SignInvestmentTransaction(network,
208208
investor2Context.ChangeAddress, investor2InvTrx, null, new List<UtxoDataWithPath>(),
@@ -231,7 +231,7 @@ public void SeederTransaction_EndOfProject_Test()
231231
var words = new WalletWords { Words = new Mnemonic(Wordlist.English, WordCount.Twelve).ToString() };
232232

233233
var projectInvestmentInfo = new ProjectInfo();
234-
projectInvestmentInfo.TargetAmount = 3;
234+
projectInvestmentInfo.TargetAmount = Money.Coins(3).Satoshi;
235235
projectInvestmentInfo.StartDate = DateTime.UtcNow;
236236
projectInvestmentInfo.ExpiryDate = DateTime.UtcNow.AddDays(5);
237237
projectInvestmentInfo.Stages = new List<Stage>
@@ -260,7 +260,7 @@ public void SeederTransaction_EndOfProject_Test()
260260
// create the investment transaction
261261

262262
var seeder1InvTrx = operations.CreateInvestmentTransaction(network, seeder1Context,
263-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
263+
projectInvestmentInfo.TargetAmount);
264264

265265
seeder1Context.TransactionHex = operations.SignInvestmentTransaction(network, seeder1Context.ChangeAddress,
266266
seeder1InvTrx, null, new List<UtxoDataWithPath>(), _expectedFeeEstimation)
@@ -284,7 +284,7 @@ public void InvestorTransaction_EndOfProject_Test()
284284
var words = new WalletWords { Words = new Mnemonic(Wordlist.English, WordCount.Twelve).ToString() };
285285

286286
var projectInvestmentInfo = new ProjectInfo();
287-
projectInvestmentInfo.TargetAmount = 3;
287+
projectInvestmentInfo.TargetAmount = Money.Coins(3).Satoshi;
288288
projectInvestmentInfo.StartDate = DateTime.UtcNow;
289289
projectInvestmentInfo.ExpiryDate = DateTime.UtcNow.AddDays(5);
290290
projectInvestmentInfo.Stages = new List<Stage>
@@ -312,7 +312,7 @@ public void InvestorTransaction_EndOfProject_Test()
312312
// create the investment transaction
313313

314314
var seeder1InvTrx = operations.CreateInvestmentTransaction(network, seeder1Context,
315-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
315+
projectInvestmentInfo.TargetAmount);
316316

317317
seeder1Context.TransactionHex = operations.SignInvestmentTransaction(network, seeder1Context.ChangeAddress,
318318
seeder1InvTrx, null, new List<UtxoDataWithPath>(),
@@ -337,7 +337,7 @@ public void InvestorTransaction_WithSeederHashes_EndOfProject_Test()
337337
var words = new WalletWords { Words = new Mnemonic(Wordlist.English, WordCount.Twelve).ToString() };
338338

339339
var projectInvestmentInfo = new ProjectInfo();
340-
projectInvestmentInfo.TargetAmount = 3;
340+
projectInvestmentInfo.TargetAmount = Money.Coins(3).Satoshi;
341341
projectInvestmentInfo.StartDate = DateTime.UtcNow;
342342
projectInvestmentInfo.ExpiryDate = DateTime.UtcNow.AddDays(5);
343343
projectInvestmentInfo.Stages = new List<Stage>
@@ -371,7 +371,7 @@ public void InvestorTransaction_WithSeederHashes_EndOfProject_Test()
371371
// create the investment transaction
372372

373373
var seeder1InvTrx = operations.CreateInvestmentTransaction(network, seeder1Context,
374-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
374+
projectInvestmentInfo.TargetAmount);
375375

376376
seeder1Context.TransactionHex = operations.SignInvestmentTransaction(network, seeder1Context.ChangeAddress,
377377
seeder1InvTrx, null, new List<UtxoDataWithPath>(), _expectedFeeEstimation)
@@ -408,7 +408,7 @@ public void SpendInvestorRecoveryTest()
408408
{
409409
ProjectInfo = new ProjectInfo
410410
{
411-
TargetAmount = 3,
411+
TargetAmount = Money.Coins(3).Satoshi,
412412
StartDate = DateTime.UtcNow,
413413
ExpiryDate = DateTime.UtcNow.AddDays(5),
414414
Stages = new List<Stage>
@@ -430,7 +430,7 @@ public void SpendInvestorRecoveryTest()
430430
// create the investment transaction
431431

432432
var investmentTransaction = operations.CreateInvestmentTransaction(network, investorContext,
433-
Money.Coins(investorContext.ProjectInfo.TargetAmount).Satoshi);
433+
investorContext.ProjectInfo.TargetAmount);
434434

435435
investorContext.TransactionHex = investmentTransaction.ToHex();
436436

@@ -508,7 +508,7 @@ public void SpendInvestorConsolidatedRecoveryTest()
508508
{
509509
ProjectInfo = new ProjectInfo
510510
{
511-
TargetAmount = 3,
511+
TargetAmount = Money.Coins(3).Satoshi,
512512
StartDate = DateTime.UtcNow,
513513
ExpiryDate = DateTime.UtcNow.AddDays(5),
514514
Stages = new List<Stage>
@@ -539,7 +539,7 @@ public void SpendInvestorConsolidatedRecoveryTest()
539539
// create the investment transaction
540540

541541
var investmentTransaction = operations.CreateInvestmentTransaction(network, investorContext,
542-
Money.Coins(investorContext.ProjectInfo.TargetAmount).Satoshi);
542+
investorContext.ProjectInfo.TargetAmount);
543543

544544
investorContext.TransactionHex = investmentTransaction.ToHex();
545545

@@ -621,7 +621,7 @@ public void SpendSeederConsolidatedRecoveryTest()
621621
{
622622
ProjectInfo = new ProjectInfo
623623
{
624-
TargetAmount = 3,
624+
TargetAmount = Money.Coins(3).Satoshi,
625625
StartDate = DateTime.UtcNow,
626626
ExpiryDate = DateTime.UtcNow.AddDays(5),
627627
Stages = new List<Stage>
@@ -644,7 +644,7 @@ public void SpendSeederConsolidatedRecoveryTest()
644644
// create the investment transaction
645645

646646
var investmentTransaction = operations.CreateInvestmentTransaction(network, seederContext,
647-
Money.Coins(seederContext.ProjectInfo.TargetAmount).Satoshi);
647+
seederContext.ProjectInfo.TargetAmount);
648648

649649
seederContext.TransactionHex = investmentTransaction.ToHex();
650650

@@ -711,7 +711,7 @@ public void InvestorTransaction_NoPenalty_Test()
711711
var words = new WalletWords { Words = new Mnemonic(Wordlist.English, WordCount.Twelve).ToString() };
712712

713713
var projectInvestmentInfo = new ProjectInfo();
714-
projectInvestmentInfo.TargetAmount = 3;
714+
projectInvestmentInfo.TargetAmount = Money.Coins(3).Satoshi;
715715
projectInvestmentInfo.StartDate = DateTime.UtcNow;
716716
projectInvestmentInfo.ExpiryDate = DateTime.UtcNow.AddDays(5);
717717
projectInvestmentInfo.Stages = new List<Stage>
@@ -750,7 +750,7 @@ public void InvestorTransaction_NoPenalty_Test()
750750
// create the investment transaction
751751

752752
var seeder1InvTrx = operations.CreateInvestmentTransaction(network, seeder1Context,
753-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
753+
projectInvestmentInfo.TargetAmount);
754754

755755
seeder1Context.TransactionHex = operations.SignInvestmentTransaction(network, seeder1Context.ChangeAddress,
756756
seeder1InvTrx, null, new List<UtxoDataWithPath>(), _expectedFeeEstimation)

src/Angor.Test/ProtocolNew/AngorTestData.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Angor.Shared;
22
using Angor.Shared.Models;
33
using Angor.Shared.Networks;
4+
using Blockcore.NBitcoin;
45
using Blockcore.NBitcoin.BIP39;
56
using Microsoft.Extensions.Logging.Abstractions;
67
using Moq;
@@ -35,7 +36,7 @@ protected ProjectInfo GivenValidProjectInvestmentInfo( WalletWords? words = null
3536
startDate ??= DateTime.UtcNow;
3637

3738
var projectInvestmentInfo = new ProjectInfo();
38-
projectInvestmentInfo.TargetAmount = 3;
39+
projectInvestmentInfo.TargetAmount = Money.Coins(3).Satoshi;
3940
projectInvestmentInfo.StartDate = startDate.Value;
4041
projectInvestmentInfo.ExpiryDate = startDate.Value.AddDays(5);
4142
projectInvestmentInfo.PenaltyDays = 10;

src/Angor.Test/ProtocolNew/FounderTransactionActionTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private Transaction GivenASeederTransaction(ProjectInfo projectInvestmentInfo)
7272
projectInvestmentInfo.ProjectSeeders.SecretHashes.Add(seederContext.InvestorSecretHash);
7373

7474
return operations.CreateInvestmentTransaction(network, seederContext,
75-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
75+
projectInvestmentInfo.TargetAmount);
7676
}
7777

7878
private Transaction GivenAnInvestorTransaction(ProjectInfo projectInvestmentInfo)
@@ -88,8 +88,7 @@ private Transaction GivenAnInvestorTransaction(ProjectInfo projectInvestmentInfo
8888
context.InvestorKey = Encoders.Hex.EncodeData(seederKey.PubKey.ToBytes());
8989
context.ChangeAddress = seederChangeKey.PubKey.GetSegwitAddress(network).ToString();
9090

91-
return operations.CreateInvestmentTransaction(network, context,
92-
Money.Coins(projectInvestmentInfo.TargetAmount).Satoshi);
91+
return operations.CreateInvestmentTransaction(network, context, projectInvestmentInfo.TargetAmount);
9392
}
9493

9594
/// <summary>

0 commit comments

Comments
 (0)