private static Transaction[] GenerateTxsForRefunds(IGrouping <Address, DepositDetails> depositGroup, DevKeyStoreWallet wallet) { Console.WriteLine(); Console.Write($"Provide nonce for {depositGroup.Key}: "); int nonce = int.Parse(Console.ReadLine()); Console.Write($"Provide address to send the refund to: "); string hexAddress = Console.ReadLine(); Address refundTo = new Address(hexAddress); SecureString securedPassword = ConsoleUtils.ReadSecret("Provide password: "******"Password has been accepted."); Console.WriteLine(); Console.WriteLine($"Great, will generate refund transactions for deposits of {depositGroup.Key} starting with nonce {nonce}. ETH/DAI will be sent to {refundTo}."); List <Transaction> transactions = new List <Transaction>(depositGroup.Count()); foreach (DepositDetails depositDetails in depositGroup) { Deposit deposit = depositDetails.Deposit; RefundClaim refundClaim = new RefundClaim(deposit.Id, depositDetails.DataAsset.Id, deposit.Units, deposit.Value, deposit.ExpiryTime, depositDetails.Pepper, depositDetails.DataAsset.Provider.Address, refundTo); UInt256 gasPrice = 20.GWei(); AbiEncoder abiEncoder = new AbiEncoder(); byte[] txData = abiEncoder.Encode(AbiEncodingStyle.IncludeSignature, ContractData.ClaimRefundSig, depositDetails.DataAsset.Id, refundClaim.Units, refundClaim.Value, refundClaim.ExpiryTime, refundClaim.Pepper, refundClaim.Provider, depositDetails.Consumer); Transaction transaction = new Transaction(); transaction.Value = 0; transaction.Data = txData; transaction.To = new Address("0xb1AD03b75bD9E5AB89968D7a37d99F9dd220796D"); transaction.SenderAddress = depositDetails.Consumer; transaction.GasLimit = 100000; transaction.GasPrice = gasPrice; transaction.Nonce = (UInt256)nonce++; wallet.Sign(transaction, ChainId.Mainnet); EthereumEcdsa ecdsa = new EthereumEcdsa(ChainId.Mainnet, LimboLogs.Instance); Address recoveredAddress = ecdsa.RecoverAddress(transaction); if (recoveredAddress != transaction.SenderAddress) { Console.WriteLine("Signature failure"); return(new Transaction[0]); } transactions.Add(transaction); } return(transactions.ToArray()); } Console.WriteLine("Incorrect password."); return(new Transaction[0]); }
public void Test(AbiTest abiTest) { AbiEncoder encoder = new AbiEncoder(); AbiSignature signature = new AbiSignature(abiTest.Name, abiTest.Types); byte[] encoded = encoder.Encode(signature, abiTest.Args).Slice(4); Assert.True(Bytes.AreEqual(abiTest.Result, encoded)); }
public byte[] Pack(UserOperation op) { UserOperationAbi abi = op.Abi; abi.Signature = Bytes.Empty; byte[] encodedBytes = _abiEncoder.Encode(AbiEncodingStyle.None, _opSignature, abi); byte[] slicedBytes = encodedBytes.Slice(32, encodedBytes.Length - 64); return(slicedBytes); }
public void Test_abi_encoding() { string text = string.Empty; string[] potentialLocations = new string[] { Path.Combine(TestContext.CurrentContext.TestDirectory, "basic_abi_tests.json"), Path.Combine(TestContext.CurrentContext.WorkDirectory, "basic_abi_tests.json"), Path.Combine(AppDomain.CurrentDomain.BaseDirectory ?? string.Empty, "basic_abi_tests.json"), Path.Combine(AppDomain.CurrentDomain.DynamicDirectory ?? string.Empty, "basic_abi_tests.json"), }; foreach (string potentialLocation in potentialLocations) { try { text = File.ReadAllText(potentialLocation); break; } catch (IOException) { TestContext.WriteLine($"Could not find test in {potentialLocation}"); } } Dictionary <string, AbiTest> tests = JsonConvert.DeserializeObject <Dictionary <string, AbiTest> >(text); foreach ((string testName, AbiTest abiTest) in tests) { AbiSignature signature = new AbiSignature( testName, abiTest.Types.Select(t => _abiTypes[t]).ToArray()); AbiEncoder encoder = new AbiEncoder(); byte[] abi = encoder.Encode(AbiEncodingStyle.None, signature, abiTest.Args.Select(JsonToObject).ToArray()); abi.Should().BeEquivalentTo(Bytes.FromHexString(abiTest.Result)); } }
public void Dynamic_array_of_dynamic_array_of_uint(AbiEncodingStyle encodingStyle) { AbiType type = new AbiArray(new AbiArray(AbiType.UInt256)); AbiSignature signature = new AbiSignature("abc", type); BigInteger[] element = { 1, 2, 3 }; BigInteger[][] data = { element, element }; byte[] encoded = _abiEncoder.Encode(encodingStyle, signature, new object[] { data }); object[] arguments = _abiEncoder.Decode(encodingStyle, signature, encoded); Assert.AreEqual(arguments[0], data); }
/// <summary> /// Generates transaction. /// That transaction can be added to a produced block or broadcasted - if <see cref="GeneratedTransaction"/> is used as <see cref="T"/>. /// That transaction can be used in <see cref="CallableContract.Call(Nethermind.Core.BlockHeader,Nethermind.Core.Transaction)"/> if <see cref="SystemTransaction"/> is used as <see cref="T"/>. /// </summary> /// <param name="functionName">Function in contract that is called by the transaction.</param> /// <param name="sender">Sender of the transaction - caller of the function.</param> /// <param name="gasLimit">Gas limit for generated transaction.</param> /// <param name="contractAddress">address of the contract</param> /// <param name="arguments">Arguments to the function.</param> /// <typeparam name="T">Type of <see cref="Transaction"/>.</typeparam> /// <returns>Transaction.</returns> protected Transaction GenerateTransaction <T>(string functionName, Address sender, long gasLimit, Address contractAddress, params object[] arguments) where T : Transaction, new() => GenerateTransaction <T>(AbiEncoder.Encode(AbiDefinition.GetFunction(functionName).GetCallInfo(), arguments), sender, contractAddress, gasLimit);
/// <summary> /// Generates transaction. /// That transaction can be added to a produced block or broadcasted - if <see cref="GeneratedTransaction"/> is used as <see cref="T"/>. /// That transaction can be used in <see cref="Call(Nethermind.Core.BlockHeader,Nethermind.Core.Transaction)"/> if <see cref="SystemTransaction"/> is used as <see cref="T"/>. /// </summary> /// <param name="function">Function in contract that is called by the transaction.</param> /// <param name="sender">Sender of the transaction - caller of the function.</param> /// <param name="arguments">Arguments to the function.</param> /// <typeparam name="T">Type of <see cref="Transaction"/>.</typeparam> /// <returns>Transaction.</returns> protected Transaction GenerateTransaction <T>(AbiFunctionDescription function, Address sender, params object[] arguments) where T : Transaction, new() => GenerateTransaction <T>(AbiEncoder.Encode(function.GetCallInfo(), arguments), sender);