Skip to content

Commit

Permalink
move AngorScripts.CreateStage to ITaprootScriptBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
dangershony committed Nov 14, 2023
1 parent fc4f258 commit 0049090
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/Angor.Test/ProtocolNew/InvestmentIntegrationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public InvestmentIntegrationsTests()
new ProjectScriptsBuilder(_derivationOperations),
new InvestmentScriptBuilder(new SeederScriptTreeBuilder())),
new InvestmentTransactionBuilder(_networkConfiguration.Object,
new ProjectScriptsBuilder(_derivationOperations), new InvestmentScriptBuilder(new SeederScriptTreeBuilder())),
new ProjectScriptsBuilder(_derivationOperations), new InvestmentScriptBuilder(new SeederScriptTreeBuilder()), new TaprootScriptBuilder()),
new TaprootScriptBuilder(), _networkConfiguration.Object);

_investorTransactionActions = new InvestorTransactionActions(new NullLogger<InvestorTransactionActions>(),
Expand All @@ -90,7 +90,7 @@ public InvestmentIntegrationsTests()
new InvestmentScriptBuilder(new SeederScriptTreeBuilder())),
new InvestmentTransactionBuilder(_networkConfiguration.Object,
new ProjectScriptsBuilder(_derivationOperations),
new InvestmentScriptBuilder(new SeederScriptTreeBuilder())),
new InvestmentScriptBuilder(new SeederScriptTreeBuilder()), new TaprootScriptBuilder()),
new TaprootScriptBuilder(), _networkConfiguration.Object);

_founderTransactionActions = new FounderTransactionActions(new NullLogger<FounderTransactionActions>(), _networkConfiguration.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public InvestmentTransactionBuilderTest()

_sut = new InvestmentTransactionBuilder(_networkConfiguration.Object,
_projectScriptsBuilder.Object,
_investmentScriptBuilder.Object);
_investmentScriptBuilder.Object,
new TaprootScriptBuilder());
}

private Script GivenTheAngorFeeScript(ProjectInfo projectInvestmentInfo)
Expand Down
2 changes: 1 addition & 1 deletion src/Angor.Test/WalletOperationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public WalletOperationsTest()
new InvestmentScriptBuilder(new SeederScriptTreeBuilder()),
new ProjectScriptsBuilder(_derivationOperations),
new SpendingTransactionBuilder(_networkConfiguration.Object, new ProjectScriptsBuilder(_derivationOperations), new InvestmentScriptBuilder(new SeederScriptTreeBuilder())),
new InvestmentTransactionBuilder(_networkConfiguration.Object, new ProjectScriptsBuilder(_derivationOperations), new InvestmentScriptBuilder(new SeederScriptTreeBuilder())),
new InvestmentTransactionBuilder(_networkConfiguration.Object, new ProjectScriptsBuilder(_derivationOperations), new InvestmentScriptBuilder(new SeederScriptTreeBuilder()), new TaprootScriptBuilder()),
new TaprootScriptBuilder(),
_networkConfiguration.Object);

Expand Down
1 change: 0 additions & 1 deletion src/Angor/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
builder.Services.AddScoped<IClipboardService, ClipboardService>();
builder.Services.AddScoped<IDerivationOperations, DerivationOperations>();
builder.Services.AddScoped<NavMenuState>();
builder.Services.AddScoped<InvestmentOperations>();

builder.Services.AddScoped<IIndexerService, IndexerService>();
builder.Services.AddScoped<IRelayService, RelayService>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Angor.Shared.Models;
namespace Angor.Shared.Models;

/// <summary>
/// Contains all the requisite information for a founder.
Expand All @@ -11,4 +9,4 @@ public class FounderContext
public ProjectSeeders ProjectSeeders { get; set; }
public string ChangeAddress { get; set; }
public List<string> InvestmentTrasnactionsHex { get; set; } = new ();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Angor.Shared.Models;
namespace Angor.Shared.Models;

/// <summary>
/// Contains all the requisite information for an investor to formulate an investment transaction.
Expand All @@ -21,4 +19,4 @@ public class InvestorContext
// ==============================================

public string ChangeAddress { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Angor/Shared/ProtocolNew/Scripts/ITaprootScriptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Angor.Shared.ProtocolNew.Scripts;

public interface ITaprootScriptBuilder
{
Script CreateStage(Blockcore.Networks.Network network, ProjectScripts scripts);

public Script CreateControlBlock(ProjectScripts scripts, Expression<Func<ProjectScripts, Script>> func);

(Script controlBlock, Script execute, Script[] secrets) CreateControlSeederSecrets(ProjectScripts scripts, int threshold,
Expand Down
9 changes: 9 additions & 0 deletions src/Angor/Shared/ProtocolNew/Scripts/TaprootScriptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ namespace Angor.Shared.ProtocolNew.Scripts;

public class TaprootScriptBuilder : ITaprootScriptBuilder
{
public Script CreateStage(Blockcore.Networks.Network network, ProjectScripts scripts)
{
var treeInfo = BuildTaprootSpendInfo(scripts);

var address = treeInfo.OutputPubKey.GetAddress(NetworkMapper.Map(network));

return new Script(address.ScriptPubKey.ToBytes());
}

public Script CreateControlBlock(ProjectScripts scripts, Expression<Func<ProjectScripts,Script>> scriptSelector)
{
var treeInfo = BuildTaprootSpendInfo(scripts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public class InvestmentTransactionBuilder : IInvestmentTransactionBuilder
private readonly INetworkConfiguration _networkConfiguration;
private readonly IProjectScriptsBuilder _projectScriptsBuilder;
private readonly IInvestmentScriptBuilder _investmentScriptBuilder;
private readonly ITaprootScriptBuilder _taprootScriptBuilder;

public InvestmentTransactionBuilder(INetworkConfiguration networkConfiguration, IProjectScriptsBuilder projectScriptsBuilder,
IInvestmentScriptBuilder investmentScriptBuilder)
IInvestmentScriptBuilder investmentScriptBuilder, ITaprootScriptBuilder taprootScriptBuilder)
{
_networkConfiguration = networkConfiguration;
_projectScriptsBuilder = projectScriptsBuilder;
_investmentScriptBuilder = investmentScriptBuilder;
_taprootScriptBuilder = taprootScriptBuilder;
}

public Transaction BuildInvestmentTransaction(ProjectInfo projectInfo, Script opReturnScript,
Expand All @@ -37,7 +39,7 @@ public Transaction BuildInvestmentTransaction(ProjectInfo projectInfo, Script op
var investorInfoOutput = new TxOut(new Money(0), opReturnScript);
investmentTransaction.AddOutput(investorInfoOutput);

var stagesScripts = projectScripts.Select(_ => AngorScripts.CreateStage(network, _)); //TODO replace angor scripts
var stagesScripts = projectScripts.Select(_ => _taprootScriptBuilder.CreateStage(network, _));

var stagesOutputs = stagesScripts.Select((_, i) =>
new TxOut(new Money(Convert.ToInt64(totalInvestmentAmount * (projectInfo.Stages[i].AmountToRelease / 100))),
Expand Down

0 comments on commit 0049090

Please sign in to comment.