|
@@ -22,10 +22,25 @@ namespace HyperCube.Models
|
|
|
{
|
|
|
public struct TransactionObject
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// transaction sender
|
|
|
+ /// </summary>
|
|
|
public string from;
|
|
|
+ /// <summary>
|
|
|
+ /// transaction receiver
|
|
|
+ /// </summary>
|
|
|
public string to;
|
|
|
+ /// <summary>
|
|
|
+ /// payload - function pointer and all other custom parameters
|
|
|
+ /// </summary>
|
|
|
public string data;
|
|
|
+ /// <summary>
|
|
|
+ /// gas amount
|
|
|
+ /// </summary>
|
|
|
public string gas;
|
|
|
+ /// <summary>
|
|
|
+ /// value in Wei
|
|
|
+ /// </summary>
|
|
|
public string value;
|
|
|
}
|
|
|
|
|
@@ -40,6 +55,8 @@ namespace HyperCube.Models
|
|
|
}
|
|
|
set { }
|
|
|
}
|
|
|
+ public const string MultiOwnerContractRinkeby = "0x862A2Ac8D1dB37085c786981A8F5bd54594f7162";
|
|
|
+ public const string HCBAddress = "0xe5D682717955d6C35d465A3485625C64655a04f4";
|
|
|
public static string tokenName;
|
|
|
public static string decimals;
|
|
|
public static string symbol;
|
|
@@ -150,50 +167,58 @@ namespace HyperCube.Models
|
|
|
transObj.from = address;
|
|
|
transObj.to = ERC20Address;// "0xe5D682717955d6C35d465A3485625C64655a04f4";
|
|
|
transObj.gas = "9000";
|
|
|
- transObj.value = contractAddress;
|
|
|
transObj.data = await compileFunction($"function transferOwnership(address newOwner)");
|
|
|
var answer = await RunFunction2("eth_sendTransaction", transObj);
|
|
|
}
|
|
|
|
|
|
- public async Task Approve(string spender, string amount, string tokenAddress)
|
|
|
+ public async Task Transactions(string multiOwnerContract)
|
|
|
+ {
|
|
|
+ TransactionObject transObj = new TransactionObject();
|
|
|
+ transObj.to = multiOwnerContract;// "0xe5D682717955d6C35d465A3485625C64655a04f4";
|
|
|
+ transObj.gas = "9000";
|
|
|
+ transObj.data = await compileFunction($"transactionCount");
|
|
|
+ var answer = await RunFunction2("eth_call", transObj, "latest");
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task Approve(string owner, string spender, string amount, string tokenAddress)
|
|
|
{
|
|
|
TransactionObject transObj = new TransactionObject();
|
|
|
- transObj.from = spender;
|
|
|
+ transObj.from = owner;
|
|
|
transObj.to = tokenAddress;// "0xe5D682717955d6C35d465A3485625C64655a04f4";
|
|
|
transObj.gas = "9000";
|
|
|
- transObj.value = "0";
|
|
|
transObj.data = await compileFunction($"function approve(address spender, uint256 amount)");
|
|
|
if (tokenAddress != null)
|
|
|
{
|
|
|
- transObj.data += zerofill(tokenAddress, 64, true);
|
|
|
transObj.data += zerofill(spender, 64, true);
|
|
|
transObj.data += zerofill(dec2hex(Convert.ToInt32(amount)), 64, true);
|
|
|
}
|
|
|
var answer = await RunFunction2("eth_sendTransaction", transObj);
|
|
|
}
|
|
|
|
|
|
- public async Task SubmitTransaction(string owner, string tokenvalue, string receiver, string tokenAddress = "0xe5D682717955d6C35d465A3485625C64655a04f4")
|
|
|
+ public async Task<string> SubmitTransaction(string owner, int tokenvalue, string receiver, string tokenAddress = HCBAddress)
|
|
|
{
|
|
|
//"submitTransaction(address destination, uint value, address tokenAddress)"
|
|
|
- var tokenAmount = float.Parse(tokenvalue, System.Globalization.CultureInfo.InvariantCulture);// * 1000000000000000000;
|
|
|
+ //var tokenAmount = float.Parse(tokenvalue, System.Globalization.CultureInfo.InvariantCulture);// * 1000000000000000000;
|
|
|
|
|
|
//ETHtoERC20(address tokenAddress)
|
|
|
//ERC20toETH(address tokenAddress, address sender, uint256 tokenAmount, uint256 ethAmount) public payable returns(bool)
|
|
|
TransactionObject transObj = new TransactionObject();
|
|
|
transObj.from = owner;
|
|
|
- transObj.to = "0x862A2Ac8D1dB37085c786981A8F5bd54594f7162";// "0xe5D682717955d6C35d465A3485625C64655a04f4";
|
|
|
+ transObj.to = MultiOwnerContractRinkeby;
|
|
|
transObj.gas = "9000";
|
|
|
- transObj.value = "0";
|
|
|
- transObj.data = await compileFunction($"submitTransaction(address destination, uint value, address tokenAddress)");
|
|
|
- if (tokenvalue != null)
|
|
|
+ transObj.data = await compileFunction($"function submitTransaction(address destination, uint256 value, address tokenAddress)");
|
|
|
+ if (tokenvalue > 0)
|
|
|
{
|
|
|
transObj.data += zerofill(receiver, 64, true);
|
|
|
- transObj.data += zerofill(dec2hex(Convert.ToInt32(tokenAmount)), 64, true);
|
|
|
+ transObj.data += zerofill(dec2hex(tokenvalue), 64, true);
|
|
|
transObj.data += zerofill(tokenAddress, 64, true);
|
|
|
}
|
|
|
var answer = await RunFunction2("eth_sendTransaction", transObj);
|
|
|
+ return ParseStringAnswer(answer)[0];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //нужна проверка балансов системы и юзера перед обменом
|
|
|
public async Task ChangeCurrency(string from_token_selected, string to_token_selected, string tokenAddress, string sender, string from, string to, string fi, string ti)
|
|
|
{
|
|
|
var val = float.Parse(fi, System.Globalization.CultureInfo.InvariantCulture);
|
|
@@ -204,9 +229,8 @@ namespace HyperCube.Models
|
|
|
//ERC20toETH(address tokenAddress, address sender, uint256 tokenAmount, uint256 ethAmount) public payable returns(bool)
|
|
|
TransactionObject transObj = new TransactionObject();
|
|
|
transObj.from = sender;
|
|
|
- transObj.to = "0x862A2Ac8D1dB37085c786981A8F5bd54594f7162";// "0xe5D682717955d6C35d465A3485625C64655a04f4";
|
|
|
+ transObj.to = MultiOwnerContractRinkeby;
|
|
|
transObj.gas = "9000";
|
|
|
- transObj.value = "0";
|
|
|
transObj.data = await compileFunction($"function ERC20toETH(address tokenAddress, address sender, uint256 tokenAmount, uint256 ethAmount)");
|
|
|
if (tokenAddress != null && tokenAmount != null)
|
|
|
{
|
|
@@ -539,7 +563,7 @@ namespace HyperCube.Models
|
|
|
public async Task<string> compileFunction(string input, bool getsha = true)
|
|
|
{
|
|
|
//\s = пробел
|
|
|
- //\S = любой символ, кроме промельного
|
|
|
+ //\S = любой символ, кроме пробельного
|
|
|
//+ одно или более вхождений
|
|
|
//. любой сивол, кроме перевода строки
|
|
|
//* ноль или более вхождений «а»
|