-
Notifications
You must be signed in to change notification settings - Fork 9
/
WonkaAutogenExtensions.cs
148 lines (122 loc) · 6.93 KB
/
WonkaAutogenExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Nethereum.Contracts;
using Nethereum.Web3;
namespace Wonka.Eth.Extensions
{
/// <summary>
///
/// This extensions class provides the functionality to perform actions on behalf of the Autogen
/// classes, like deploy Wonka contracts to the chain.
///
/// </summary>
public static class WonkaAutogenExtensions
{
/// <summary>
///
/// This method will use Nethereum to deploy a Wonka contract to the chain.
///
/// <param name="poDeployMsg">The deployment message with the bytecodes that can create the target contract</param>
/// <param name="psWonkaAbi">The ABI of the target contract</param>
/// <param name="psSenderAddress">The ABI of the target contract</param>
/// <param name="psWeb3HttpUrl">The client node to which we will deploy the contract</param>
/// <returns>The address of the new instance of the target contract</returns>
/// </summary>
public static string DeployContract(this ContractDeploymentMessage poDeployMsg, Web3 poWeb3, string psWonkaAbi, string psSenderAddress, string psWeb3HttpUrl = "")
{
var transactionHash =
poWeb3.Eth.DeployContract.SendRequestAsync(psWonkaAbi, poDeployMsg.ByteCode, psSenderAddress).Result;
// NOTE: Should we start/stop mining by default?
// var mineResult = poWeb3.Miner.Start.SendRequestAsync(6).Result;
var receipt = poWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).Result;
while (receipt == null)
{
Thread.Sleep(5000);
receipt = poWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).Result;
}
// NOTE: Should we start/stop mining by default?
// mineResult = poWeb3.Miner.Stop.SendRequestAsync().Result;
var contractAddress = receipt.ContractAddress;
return contractAddress;
}
/// <summary>
///
/// This method will use Nethereum to deploy a Wonka contract to the chain.
///
/// <param name="poDeployMsg">The deployment message with the bytecodes that can create the target contract</param>
/// <param name="psWonkaAbi">The ABI of the target contract</param>
/// <param name="psSenderAddress">The ABI of the target contract</param>
/// <param name="psWeb3HttpUrl">The client node to which we will deploy the contract</param>
/// <returns>The address of the new instance of the target contract</returns>
/// </summary>
public static async Task<string> DeployContractAsync(this ContractDeploymentMessage poDeployMsg, Web3 poWeb3, string psWonkaAbi, string psSenderAddress, string psWeb3HttpUrl = "")
{
var transactionHash =
await poWeb3.Eth.DeployContract.SendRequestAsync(psWonkaAbi, poDeployMsg.ByteCode, psSenderAddress).ConfigureAwait(false);
var receipt = await poWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).ConfigureAwait(false);
while (receipt == null)
{
Thread.Sleep(5000);
receipt = await poWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).ConfigureAwait(false);
}
var contractAddress = receipt.ContractAddress;
return contractAddress;
}
/// <summary>
///
/// This method will use Nethereum to deploy a Wonka contract to the chain.
///
/// <param name="poDeployMsg">The deployment message with the bytecodes that can create the target contract</param>
/// <param name="psWonkaAbi">The ABI of the target contract</param>
/// <param name="psSenderAddress">The ABI of the target contract</param>
/// <param name="pnGas">The amount of gas supplied for the deployment of the contract</param>
/// <param name="psWeb3HttpUrl">The client node to which we will deploy the contract</param>
/// <returns>The address of the new instance of the target contract</returns>
/// </summary>
public static string DeployContract(this ContractDeploymentMessage poDeployMsg, Web3 poWeb3, string psWonkaAbi, string psSenderAddress, Nethereum.Hex.HexTypes.HexBigInteger pnGas, string psWeb3HttpUrl = "")
{
var transactionHash =
poWeb3.Eth.DeployContract.SendRequestAsync(psWonkaAbi, poDeployMsg.ByteCode, psSenderAddress, pnGas).Result;
// NOTE: Should we start/stop mining by default?
// var mineResult = poWeb3.Miner.Start.SendRequestAsync(6).Result;
var receipt = poWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).Result;
while (receipt == null)
{
Thread.Sleep(5000);
receipt = poWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).Result;
}
// NOTE: Should we start/stop mining by default?
// mineResult = poWeb3.Miner.Stop.SendRequestAsync().Result;
var contractAddress = receipt.ContractAddress;
return contractAddress;
}
/// <summary>
///
/// This method will use Nethereum to deploy a Wonka contract to the chain.
///
/// <param name="poDeployMsg">The deployment message with the bytecodes that can create the target contract</param>
/// <param name="psWonkaAbi">The ABI of the target contract</param>
/// <param name="psSenderAddress">The ABI of the target contract</param>
/// <param name="pnGas">The amount of gas supplied for the deployment of the contract</param>
/// <param name="psWeb3HttpUrl">The client node to which we will deploy the contract</param>
/// <returns>The address of the new instance of the target contract</returns>
/// </summary>
public static async Task<string> DeployContractAsync(this ContractDeploymentMessage poDeployMsg, Web3 poWeb3, string psWonkaAbi, string psSenderAddress, Nethereum.Hex.HexTypes.HexBigInteger pnGas, string psWeb3HttpUrl = "")
{
var transactionHash =
await poWeb3.Eth.DeployContract.SendRequestAsync(psWonkaAbi, poDeployMsg.ByteCode, psSenderAddress, pnGas).ConfigureAwait(false);
var receipt = await poWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).ConfigureAwait(false);
while (receipt == null)
{
Thread.Sleep(5000);
receipt = await poWeb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash).ConfigureAwait(false);
}
var contractAddress = receipt.ContractAddress;
return contractAddress;
}
}
}