Skip to content

Commit

Permalink
Contract, handlers, extensions, etc changes / improvements and refact…
Browse files Browse the repository at this point in the history
…oring

* Fix Tests (Everywhere) to include Extensions, FunctionMessage, Event attribute (with event name)
* Fix Tests for namespace changes
* Added project to create class diagrams, with Web3 diagram and IClient, ITransactionManager, IAccount
* ABI registry, validate if type is valid for Function and Event. Added methos to get using type not just Generic
* ContractBuilder expose EventAbi and FunctionAbi
* Remove eventBuilder creator using generics (not needed as there is not need of the builder with the extensions)
* Removed the DefaultBlock from contract, still is accessed through Eth when used in Functions (it might be removed all together eventually)
* ContractDeployment moved to Nethereum.Contracts inherits now from ContractMessageBase
* ContractDeploymentHandler recreated using now all the individual handlers
* Individual handlers for deployment (Estimation, SendTransaction, Signing, Polling)
* Recreated ContractHandler  to use the handlers
* New individual handlers for queries (Raw, SimpleType and ObjectOutput)
* Two ContractQueryHandlers (top level wrappers) one uses Eth and another the Client and default address.
* New IFunctionOutputDTO required to mark FunctionOuput classes
*
* New Contract transaction handlers individuals
* Event generic and Event normal refactoring (now enforces valid types when using generic decoding) Introduction of base event handler to remove ambiguity when dealing with generics decoding. Mainly if Event<T> is created will only decode for T.
Enforce use of the extensions generic decoders, no need to use EventBuilder.
Constructors now use only the EventABI or a type for decoding the ABI
* Added further extensions for FilterLogs and JToken log, to allow for simple decoding of TransactionReceipts or FilterLogs.
* Added extra method to event to just use the NewFilterInput when creating a filter, these can be created with the new extensions, builders.
* EventDTO has new extension to return the EventABI which then has more extensions method to build filtes, etc.
* TransactionManager now gets the latest gas price, this needs to be moved to an interface
* Remove more async methods for .net35 stuff as not needed
* Moved / tidy Geth pending transactions from the pull
* Address util check Is valid hex format changed to not use regex
  • Loading branch information
juanfranblanco committed Jul 9, 2018
1 parent 1c03e0c commit 2f68f61
Show file tree
Hide file tree
Showing 144 changed files with 2,516 additions and 1,286 deletions.
24 changes: 23 additions & 1 deletion Nethereum.sln
Expand Up @@ -143,7 +143,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{AF1D64E0-8
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nethereum.XUnitEthereumClients", "src\Nethereum.XUnitEthereumClients\Nethereum.XUnitEthereumClients.csproj", "{A73012C6-D409-437D-8302-BE2D3BE150B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethereum.JsonRpc.WebSocketClient", "src\Nethereum.JsonRpc.WebSocketClient\Nethereum.JsonRpc.WebSocketClient.csproj", "{9097C44C-1CA0-4C89-8BAA-1054EAAA8FF1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nethereum.JsonRpc.WebSocketClient", "src\Nethereum.JsonRpc.WebSocketClient\Nethereum.JsonRpc.WebSocketClient.csproj", "{9097C44C-1CA0-4C89-8BAA-1054EAAA8FF1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ClassDiagrams", "ClassDiagrams", "{EFC55CCF-06EE-42B1-B2B3-04E94586F8DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethereum.ClassDiagrams", "src\Nethereum.ClassDiagrams\Nethereum.ClassDiagrams.csproj", "{5BBEAE99-333E-4B98-8453-C5667FB22184}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -941,6 +945,22 @@ Global
{9097C44C-1CA0-4C89-8BAA-1054EAAA8FF1}.Release|x64.Build.0 = Release|Any CPU
{9097C44C-1CA0-4C89-8BAA-1054EAAA8FF1}.Release|x86.ActiveCfg = Release|Any CPU
{9097C44C-1CA0-4C89-8BAA-1054EAAA8FF1}.Release|x86.Build.0 = Release|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Debug|ARM.ActiveCfg = Debug|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Debug|ARM.Build.0 = Debug|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Debug|x64.ActiveCfg = Debug|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Debug|x64.Build.0 = Debug|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Debug|x86.ActiveCfg = Debug|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Debug|x86.Build.0 = Debug|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Release|Any CPU.Build.0 = Release|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Release|ARM.ActiveCfg = Release|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Release|ARM.Build.0 = Release|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Release|x64.ActiveCfg = Release|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Release|x64.Build.0 = Release|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Release|x86.ActiveCfg = Release|Any CPU
{5BBEAE99-333E-4B98-8453-C5667FB22184}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1016,6 +1036,8 @@ Global
{AF1D64E0-8D83-4C70-AEE1-3DD57738BBBA} = {962EC435-6130-4B75-BAC1-12323B067443}
{A73012C6-D409-437D-8302-BE2D3BE150B1} = {AF1D64E0-8D83-4C70-AEE1-3DD57738BBBA}
{9097C44C-1CA0-4C89-8BAA-1054EAAA8FF1} = {F7E94706-FF67-4766-BBBD-27E7CED957A3}
{EFC55CCF-06EE-42B1-B2B3-04E94586F8DD} = {962EC435-6130-4B75-BAC1-12323B067443}
{5BBEAE99-333E-4B98-8453-C5667FB22184} = {EFC55CCF-06EE-42B1-B2B3-04E94586F8DD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {07A44726-8749-4A9A-8079-FA3C3213BDC1}
Expand Down
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Nethereum.ABI.Decoders;
using Nethereum.Contracts.CQS;
using Nethereum.Contracts.Extensions;
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.XUnitEthereumClients;
using SolidityCallAnotherContract.Contracts.Test.CQS;
Expand Down Expand Up @@ -131,7 +132,7 @@ public async void ShouldCallDifferentContractsUsingDataBytesArraysFixedAndVariab
Name = "Hi",
Greeting = "From the other contract"
};

var contracthandler = web3.Eth.GetContractHandler(deploymentReceiptCaller.ContractAddress);

var callManyOthersFunctionMessage = new CallManyContractsSameQueryFunction()
Expand Down
13 changes: 7 additions & 6 deletions src/Nethereum.Accounts.IntegrationTests/ABIIntegerTests.cs
Expand Up @@ -4,6 +4,7 @@
using Common.Logging.Simple;
using Nethereum.ABI;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.Contracts.CQS;
using Nethereum.JsonRpc.Client;
using Nethereum.XUnitEthereumClients;
Expand Down Expand Up @@ -85,25 +86,25 @@ public class TestDeployment : ContractDeploymentMessage
}

[Function("MaxUint", "uint256")]
public class MaxFunction : ContractMessage
public class MaxFunction : FunctionMessage
{

}

[Function("MaxInt256", "int256")]
public class MaxInt256Function : ContractMessage
public class MaxInt256Function : FunctionMessage
{

}

[Function("MinInt256", "int256")]
public class MinInt256Function : ContractMessage
public class MinInt256Function : FunctionMessage
{

}

[Function("UnderflowInt256ByQuantity", "int256")]
public class UnderflowInt256ByQuantityFunction : ContractMessage
public class UnderflowInt256ByQuantityFunction : FunctionMessage
{
[Parameter("int256", "value", 1)]
public BigInteger Value { get; set; }
Expand All @@ -112,7 +113,7 @@ public class UnderflowInt256ByQuantityFunction : ContractMessage
}

[Function("OverflowInt256ByQuantity", "int256")]
public class OverflowInt256ByQuantityFunction : ContractMessage
public class OverflowInt256ByQuantityFunction : FunctionMessage
{
[Parameter("int256", "value", 1)]
public BigInteger Value { get; set; }
Expand All @@ -121,7 +122,7 @@ public class OverflowInt256ByQuantityFunction : ContractMessage
}

[Function("OverflowUInt256ByQuantity", "uint256")]
public class OverflowUInt256ByQuantityFunction : ContractMessage
public class OverflowUInt256ByQuantityFunction : FunctionMessage
{
[Parameter("uint256", "value", 1)]
public BigInteger Value { get; set; }
Expand Down
23 changes: 12 additions & 11 deletions src/Nethereum.Accounts.IntegrationTests/ABIStructsTests.cs
Expand Up @@ -6,6 +6,7 @@
using System.Reflection;
using System.Threading.Tasks;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.Contracts.CQS;
using Nethereum.Hex.HexTypes;
using Nethereum.Web3.Accounts;
Expand Down Expand Up @@ -91,45 +92,45 @@ public async Task StringTest()


[Function("id1", "uint256")]
public class Id1Function : ContractMessage
public class Id1Function : FunctionMessage
{

}

[Function("id2", "uint256")]
public class Id2Function : ContractMessage
public class Id2Function : FunctionMessage
{

}

[Function("id3", "uint256")]
public class Id3Function : ContractMessage
public class Id3Function : FunctionMessage
{

}

[Function("id4", "string")]
public class Id4Function : ContractMessage
public class Id4Function : FunctionMessage
{

}

[Function("GetTest")]
public class GetTestFunction : ContractMessage
public class GetTestFunction : FunctionMessage
{

}

[Function("testStructStorage")]
public class GetTestStructStorageFunction : ContractMessage
public class GetTestStructStorageFunction : FunctionMessage
{

}



[FunctionOutput]
public class GetTestFunctionOuptputDTO
public class GetTestFunctionOuptputDTO:IFunctionOutputDTO
{
[Parameter("tuple")]
public TestStructStrings TestStruct { get; set; }
Expand All @@ -144,21 +145,21 @@ public class GetTestFunctionOuptputDTO
}

[Function("Test")]
public class TestFunction : ContractMessage
public class TestFunction : FunctionMessage
{
[Parameter("tuple", "testStruct")]
public TestStructStrings TestStruct { get; set; }
}

[Function("SetStorageStruct")]
public class SetStorageStructFunction : ContractMessage
public class SetStorageStructFunction : FunctionMessage
{
[Parameter("tuple", "testStruct")]
public TestStructStrings TestStruct { get; set; }
}

[Event("TestStructStorageChanged")]
public class TestStructStorageChangedEvent
public class TestStructStorageChangedEvent: IEventDTO
{
[Parameter("address", "sender", 1)]
public string Address { get; set; }
Expand All @@ -169,7 +170,7 @@ public class TestStructStorageChangedEvent


[FunctionOutput]
public class TestStructStrings
public class TestStructStrings: IFunctionOutputDTO
{
[Parameter("uint256", "id", 1)]
public BigInteger Id { get; set; }
Expand Down
Expand Up @@ -4,11 +4,12 @@
using Nethereum.Hex.HexTypes;
using Nethereum.Contracts.CQS;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using SolidityCallAnotherContract.Contracts.Test.DTOs;
namespace SolidityCallAnotherContract.Contracts.Test.CQS
{
[Function("CallAnotherContract", "bytes")]
public class CallAnotherContractFunction:ContractMessage
public class CallAnotherContractFunction:FunctionMessage
{
[Parameter("address", "theOther", 1)]
public string TheOther {get; set;}
Expand Down
Expand Up @@ -5,11 +5,13 @@
using Nethereum.Hex.HexTypes;
using Nethereum.Contracts.CQS;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using SolidityCallAnotherContract.Contracts.Test.DTOs;

namespace SolidityCallAnotherContract.Contracts.Test.CQS
{
[Function("callManyContractsSameQuery", "bytes[]")]
public class CallManyContractsSameQueryFunctionBase:ContractMessage
public class CallManyContractsSameQueryFunctionBase:FunctionMessage
{
[Parameter("address[]", "destination", 1)]
public virtual List<BigInteger> Destination {get; set;}
Expand Down
Expand Up @@ -5,11 +5,12 @@
using Nethereum.Hex.HexTypes;
using Nethereum.Contracts.CQS;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using SolidityCallAnotherContract.Contracts.Test.DTOs;
namespace SolidityCallAnotherContract.Contracts.Test.CQS
{
[Function("callManyContractsVariableReturn", "bytes[]")]
public class CallManyContractsVariableReturnFunction:ContractMessage
public class CallManyContractsVariableReturnFunction:FunctionMessage
{
[Parameter("address[]", "destination", 1)]
public List<string> Destination {get; set;}
Expand Down
Expand Up @@ -4,11 +4,12 @@
using Nethereum.Hex.HexTypes;
using Nethereum.Contracts.CQS;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using SolidityCallAnotherContract.Contracts.Test.DTOs;
namespace SolidityCallAnotherContract.Contracts.Test.CQS
{
[Function("callManyOtherContractsFixedArrayReturn", "bytes[10]")]
public class CallManyOtherContractsFixedArrayReturnFunction:ContractMessage
public class CallManyOtherContractsFixedArrayReturnFunction:FunctionMessage
{
[Parameter("address", "theOther", 1)]
public string TheOther {get; set;}
Expand Down
Expand Up @@ -4,11 +4,12 @@
using Nethereum.Hex.HexTypes;
using Nethereum.Contracts.CQS;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using SolidityCallAnotherContract.Contracts.Test.DTOs;
namespace SolidityCallAnotherContract.Contracts.Test.CQS
{
[Function("callManyOtherContractsVariableArrayReturn", "bytes[]")]
public class CallManyOtherContractsVariableArrayReturnFunction:ContractMessage
public class CallManyOtherContractsVariableArrayReturnFunction:FunctionMessage
{
[Parameter("address", "theOther", 1)]
public string TheOther {get; set;}
Expand Down
Expand Up @@ -4,6 +4,8 @@
using Nethereum.Hex.HexTypes;
using Nethereum.Contracts.CQS;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;

namespace SolidityCallAnotherContract.Contracts.Test.CQS
{
public class TestDeployment:ContractDeploymentMessage
Expand Down
Expand Up @@ -8,6 +8,7 @@
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Contracts.CQS;
using System.Threading;
using Nethereum.Contracts.ContractHandlers;
using SolidityCallAnotherContract.Contracts.Test.CQS;
using SolidityCallAnotherContract.Contracts.Test.DTOs;
namespace SolidityCallAnotherContract.Contracts.Test.Service
Expand Down
Expand Up @@ -4,6 +4,7 @@
using Nethereum.Hex.HexTypes;
using Nethereum.Contracts.CQS;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using SolidityCallAnotherContract.Contracts.TheOther.DTOs;
namespace SolidityCallAnotherContract.Contracts.TheOther.CQS
{
Expand Down
Expand Up @@ -4,6 +4,8 @@
using Nethereum.Hex.HexTypes;
using Nethereum.Contracts.CQS;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;

namespace SolidityCallAnotherContract.Contracts.TheOther.CQS
{
public class TheOtherDeployment:ContractDeploymentMessage
Expand Down
Expand Up @@ -7,6 +7,7 @@
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Contracts.CQS;
using System.Threading;
using Nethereum.Contracts.ContractHandlers;
using SolidityCallAnotherContract.Contracts.TheOther.CQS;
using SolidityCallAnotherContract.Contracts.TheOther.DTOs;
namespace SolidityCallAnotherContract.Contracts.TheOther.Service
Expand Down
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.Contracts.CQS;
using Nethereum.Web3.Accounts;
using Xunit;
Expand All @@ -10,7 +11,7 @@ public class SignOfflineTransactionTest
{

[Function("transfer", "bool")]
public class TransferFunction : ContractMessage
public class TransferFunction : FunctionMessage
{
[Parameter("address", "_to", 1)]
public string To { get; set; }
Expand All @@ -19,7 +20,6 @@ public class TransferFunction : ContractMessage
public int TokenAmount { get; set; }
}


[Fact]
public async Task ShouldSignOfflineTransaction()
{
Expand All @@ -29,13 +29,15 @@ public async Task ShouldSignOfflineTransaction()
{
To = "0x12890d2cce102216644c59daE5baed380d84830c",
TokenAmount = 10,
Nonce = 1,
Nonce = 1, //we set the nonce so it does not get the latest
Gas = 100, //we set the gas so it does not try to estimate it
GasPrice=100 // we set the gas price so it does not retrieve the latest averate
};

var signedMessage = await web3.Eth.GetContractHandler("0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe")
.SignTransactionAsync(transfer, false);
.SignTransactionAsync(transfer);

Assert.Equal("f8a9018504a817c80082520894de0b295669a9fd93d5f28d9ec85e40f4cb697bae80b844a9059cbb00000000000000000000000012890d2cce102216644c59dae5baed380d84830c000000000000000000000000000000000000000000000000000000000000000a1ba052955ae4c9e47442c607fb627511ed9a98438aaa69cd86763c10e12353fd3d27a04967781092a6a9041277ae906d6125b89a04b20b109de73c7781a727fe76d926", signedMessage);
Assert.Equal("f8a201646494de0b295669a9fd93d5f28d9ec85e40f4cb697bae80b844a9059cbb00000000000000000000000012890d2cce102216644c59dae5baed380d84830c000000000000000000000000000000000000000000000000000000000000000a1ca0a928719a67ff346732bfacd82d8c3d5f50490f57a9edd0c92438714bd6815cd4a0713e0577939049551bf0d4f66bacd2cf4ac371daa16f904f57d804101dcc6ee7", signedMessage);
}
}
}

0 comments on commit 2f68f61

Please sign in to comment.