Skip to content

Commit f7e6646

Browse files
fassadlrnoescape00
andauthored
[Interflux] Merge InterFlux: groundwork to add interoperability with Binance chain (BNB) #521 (#607)
* InterFlux: groundwork to add interoperability with Binance chain (BNB) #521 * Update LaunchSidechainMasternode script with updated interflux settings (#606) Co-authored-by: noescape0 <NoEscape0@ya.ru>
1 parent a045dec commit f7e6646

29 files changed

+446
-2328
lines changed

Scripts/LaunchSidechainMasternode.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,11 @@ if ( $NodeType -eq "50K" )
490490
{
491491
if ( $ethGasPrice )
492492
{
493-
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -interop=1 -ethereumaccount=$ethAddress -ethereumpassphrase=$ethPassword -multisigwalletcontractaddress=$ethMultiSigContract -wrappedstraxcontractaddress=$ethWrappedStraxContract -ethereumgasprice=$ethGasPrice -ethereumgas=$ethGasLimit" -PassThru
493+
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -eth_interopenabled=1 -eth_account=$ethAddress -eth_passphrase=$ethPassword -eth_multisigwalletcontractaddress=$ethMultiSigContract -eth_wrappedstraxcontractaddress=$ethWrappedStraxContract -eth_gasprice=$ethGasPrice -eth_gas=$ethGasLimit" -PassThru
494494
}
495495
Else
496496
{
497-
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -interop=1 -ethereumaccount=$ethAddress -ethereumpassphrase=$ethPassword -multisigwalletcontractaddress=$ethMultiSigContract -wrappedstraxcontractaddress=$ethWrappedStraxContract" -PassThru
497+
$StartNode = Start-Process dotnet -ArgumentList "run -c Release -- -sidechain -apiport=$sideChainAPIPort -counterchainapiport=$mainChainAPIPort -redeemscript=""$redeemscript"" -publickey=$multiSigPublicKey -federationips=$federationIPs -eth_interopenabled=1 -eth_account=$ethAddress -eth_passphrase=$ethPassword -eth_multisigwalletcontractaddress=$ethMultiSigContract -eth_wrappedstraxcontractaddress=$ethWrappedStraxContract" -PassThru
498498
}
499499
}
500500
Else
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Stratis.Bitcoin.Features.Interop.ETHClient
2+
{
3+
public interface IBNBClient : IETHClient
4+
{
5+
}
6+
7+
public class BNBClient : ETHClient, IBNBClient
8+
{
9+
public BNBClient(InteropSettings interopSettings) : base(interopSettings)
10+
{
11+
}
12+
13+
protected override void SetupConfiguration(InteropSettings interopSettings)
14+
{
15+
this.settings = interopSettings.BNBSettings;
16+
}
17+
}
18+
}

src/Stratis.Bitcoin.Features.Interop/EthereumClient/ContractSource/GnosisSafeProxy.cs renamed to src/Stratis.Bitcoin.Features.Interop/ETHClient/ContractSource/GnosisSafeProxy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class ExecTransactionFunction : FunctionMessage
6363

6464
[Parameter("uint256", "value", 2)]
6565
public BigInteger Value { get; set; }
66-
66+
6767
[Parameter("bytes", "data", 3)]
6868
public byte[] Data { get; set; }
6969

@@ -152,13 +152,13 @@ public static async Task<string> ExecTransactionAsync(Web3 web3, string proxyCon
152152
SafeTxGas = safeTxGas,
153153
BaseGas = baseGas,
154154
GasPrice = Web3.Convert.ToWei(gasPrice, UnitConversion.EthUnit.Gwei),
155-
GasToken = EthereumClientBase.ZeroAddress,
156-
RefundReceiver = EthereumClientBase.ZeroAddress,
155+
GasToken = ETHClient.ETHClient.ZeroAddress,
156+
RefundReceiver = ETHClient.ETHClient.ZeroAddress,
157157
Signatures = signatures
158158
};
159159

160160
TransactionReceipt execTransactionReceipt = await execHandler.SendRequestAndWaitForReceiptAsync(proxyContract, execTransactionFunctionMessage).ConfigureAwait(false);
161-
161+
162162
return execTransactionReceipt.TransactionHash;
163163
}
164164

src/Stratis.Bitcoin.Features.Interop/EthereumClient/ContractSource/GnosisSafeProxyFactory.cs renamed to src/Stratis.Bitcoin.Features.Interop/ETHClient/ContractSource/GnosisSafeProxyFactory.cs

File renamed without changes.

src/Stratis.Bitcoin.Features.Interop/ETHClient/ETHClient.cs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,36 @@ public interface IETHClient
110110

111111
public class ETHClient : IETHClient
112112
{
113-
private readonly InteropSettings interopSettings;
114-
private readonly Web3 web3;
115-
private Event<TransferEventDTO> transferEventHandler;
116-
private NewFilterInput filterAllTransferEventsForContract;
117-
private HexBigInteger filterId;
113+
protected ETHInteropSettings settings;
114+
protected Web3 web3;
115+
protected Event<TransferEventDTO> transferEventHandler;
116+
protected NewFilterInput filterAllTransferEventsForContract;
117+
protected HexBigInteger filterId;
118118

119119
public const string ZeroAddress = "0x0000000000000000000000000000000000000000";
120120

121121
public ETHClient(InteropSettings interopSettings)
122122
{
123-
this.interopSettings = interopSettings;
124-
125-
if (!this.interopSettings.InteropEnabled)
123+
this.SetupConfiguration(interopSettings);
124+
125+
if (!this.settings.InteropEnabled)
126126
return;
127127

128-
var account = new ManagedAccount(interopSettings.ETHAccount, interopSettings.ETHPassphrase);
129-
128+
var account = new ManagedAccount(this.settings.Account, this.settings.Passphrase);
129+
130130
// TODO: Support loading offline accounts from keystore JSON directly?
131-
this.web3 = !string.IsNullOrWhiteSpace(interopSettings.ETHClientUrl) ? new Web3(account, interopSettings.ETHClientUrl) : new Web3(account);
131+
this.web3 = !string.IsNullOrWhiteSpace(this.settings.ClientUrl) ? new Web3(account, this.settings.ClientUrl) : new Web3(account);
132+
}
133+
134+
protected virtual void SetupConfiguration(InteropSettings interopSettings)
135+
{
136+
this.settings = interopSettings.ETHSettings;
132137
}
133138

134139
/// <inheritdoc />
135140
public async Task CreateTransferEventFilterAsync()
136141
{
137-
this.transferEventHandler = this.web3.Eth.GetEvent<TransferEventDTO>(this.interopSettings.ETHWrappedStraxContractAddress);
142+
this.transferEventHandler = this.web3.Eth.GetEvent<TransferEventDTO>(this.settings.WrappedStraxContractAddress);
138143
this.filterAllTransferEventsForContract = this.transferEventHandler.CreateFilterInput();
139144
this.filterId = await this.transferEventHandler.CreateFilterAsync(this.filterAllTransferEventsForContract).ConfigureAwait(false);
140145
}
@@ -159,7 +164,7 @@ public async Task<List<EventLog<TransferEventDTO>>> GetTransferEventsForWrappedS
159164
/// <inheritdoc />
160165
public async Task<string> GetDestinationAddressAsync(string address)
161166
{
162-
return await WrappedStrax.GetDestinationAddressAsync(this.web3, this.interopSettings.ETHWrappedStraxContractAddress, address).ConfigureAwait(false);
167+
return await WrappedStrax.GetDestinationAddressAsync(this.web3, this.settings.WrappedStraxContractAddress, address).ConfigureAwait(false);
163168
}
164169

165170
/// <inheritdoc />
@@ -183,19 +188,19 @@ public async Task<BigInteger> GetBalanceAsync(string address)
183188
/// <inheritdoc />
184189
public async Task<MultisigTransactionIdentifiers> SubmitTransactionAsync(string destination, BigInteger value, string data, int gasPrice)
185190
{
186-
return await MultisigWallet.SubmitTransactionAsync(this.web3, this.interopSettings.ETHMultisigWalletAddress, destination, value, data, this.interopSettings.ETHGasLimit, gasPrice).ConfigureAwait(false);
191+
return await MultisigWallet.SubmitTransactionAsync(this.web3, this.settings.MultisigWalletAddress, destination, value, data, this.settings.GasLimit, this.settings.GasPrice).ConfigureAwait(false);
187192
}
188193

189194
/// <inheritdoc />
190195
public async Task<string> ConfirmTransactionAsync(BigInteger transactionId, int gasPrice)
191196
{
192-
return await MultisigWallet.ConfirmTransactionAsync(this.web3, this.interopSettings.ETHMultisigWalletAddress, transactionId, this.interopSettings.ETHGasLimit, gasPrice).ConfigureAwait(false);
197+
return await MultisigWallet.ConfirmTransactionAsync(this.web3, this.settings.MultisigWalletAddress, transactionId, this.settings.GasLimit, this.settings.GasPrice).ConfigureAwait(false);
193198
}
194199

195200
/// <inheritdoc />
196201
public async Task<BigInteger> GetMultisigConfirmationCountAsync(BigInteger transactionId)
197202
{
198-
return await MultisigWallet.GetConfirmationCountAsync(this.web3, this.interopSettings.ETHMultisigWalletAddress, transactionId).ConfigureAwait(false);
203+
return await MultisigWallet.GetConfirmationCountAsync(this.web3, this.settings.MultisigWalletAddress, transactionId).ConfigureAwait(false);
199204
}
200205

201206
public async Task<BigInteger> GetConfirmationsAsync(string transactionHash)
@@ -214,7 +219,7 @@ public async Task<BigInteger> GetConfirmationsAsync(string transactionHash)
214219

215220
public async Task<BigInteger> GetErc20BalanceAsync(string addressToQuery)
216221
{
217-
return await WrappedStrax.GetErc20BalanceAsync(this.web3, this.interopSettings.ETHWrappedStraxContractAddress, addressToQuery).ConfigureAwait(false);
222+
return await WrappedStrax.GetErc20BalanceAsync(this.web3, this.settings.WrappedStraxContractAddress, addressToQuery).ConfigureAwait(false);
218223
}
219224

220225
/// <inheritdoc />
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Stratis.Bitcoin.Features.Wallet;
5+
6+
namespace Stratis.Bitcoin.Features.Interop.ETHClient
7+
{
8+
public interface IETHCompatibleClientProvider
9+
{
10+
/// <summary>Provides client for specified chain type.</summary>
11+
IETHClient GetClientForChain(DestinationChain chain);
12+
13+
/// <summary>Provides collection of clients for all supported chains.</summary>
14+
Dictionary<DestinationChain, IETHClient> GetAllSupportedChains(bool excludeDisabled = true);
15+
16+
/// <summary>Returns <c>true</c> if specified chain is supported, <c>false</c> otherwise.</summary>
17+
bool IsChainSupported(DestinationChain chain);
18+
19+
/// <summary>Returns <c>true</c> if specified chain is supported and interop is enabled, <c>false</c> otherwise.</summary>
20+
bool IsChainSupportedAndEnabled(DestinationChain chain);
21+
}
22+
23+
public class ETHCompatibleClientProvider : IETHCompatibleClientProvider
24+
{
25+
private readonly Dictionary<DestinationChain, IETHClient> supportedChains;
26+
27+
private readonly InteropSettings interopSettings;
28+
29+
public ETHCompatibleClientProvider(IETHClient ethClient, IBNBClient bnbClient, InteropSettings interopSettings)
30+
{
31+
this.supportedChains = new Dictionary<DestinationChain, IETHClient>()
32+
{
33+
{ DestinationChain.ETH, ethClient },
34+
{ DestinationChain.BNB, bnbClient },
35+
};
36+
37+
this.interopSettings = interopSettings;
38+
}
39+
40+
/// <inheritdoc />
41+
public IETHClient GetClientForChain(DestinationChain chain)
42+
{
43+
if (!this.supportedChains.ContainsKey(chain))
44+
throw new NotImplementedException("Provided chain type not supported: " + chain);
45+
46+
return this.supportedChains[chain];
47+
}
48+
49+
/// <inheritdoc />
50+
public Dictionary<DestinationChain, IETHClient> GetAllSupportedChains(bool excludeDisabled = true)
51+
{
52+
if (!excludeDisabled)
53+
return this.supportedChains;
54+
55+
return this.supportedChains.Where(x => this.interopSettings.GetSettingsByChain(x.Key).InteropEnabled).ToDictionary(x => x.Key, x => x.Value);
56+
}
57+
58+
/// <inheritdoc />
59+
public bool IsChainSupported(DestinationChain chain)
60+
{
61+
return this.supportedChains.ContainsKey(chain);
62+
}
63+
64+
/// <inheritdoc />
65+
public bool IsChainSupportedAndEnabled(DestinationChain chain)
66+
{
67+
bool supported = this.IsChainSupported(chain);
68+
69+
if (!supported)
70+
return false;
71+
72+
return this.interopSettings.GetSettingsByChain(chain).InteropEnabled;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)