These are chat archives for Nethereum/Nethereum

10th
Dec 2018
Nguyễn Minh Tuấn
@MoonSmileDev
Dec 10 2018 04:00
This message was deleted
image.png
hello everyone... i encounter an issue when i implement an example of "smart contract" on youtube.
how can i solve it??? help me
hessam94
@hessam94
Dec 10 2018 04:18

CAN i get the required error message? this is my part of function function SetBet(int amount) public
{
if (IsGameStarted ==true)
{
require(Balance[msg.sender] >= amount,"balance is not enough");
....
}}

Nethereum throws an exception when the condition is not satisfied but the message it not returned! how can i get "balance is ...." (the message)? thanks

RevVivek
@RevVivek
Dec 10 2018 04:35

Hello @juanfranblanco ,

I have problem with trezor signer. I have sign the transaction with Trezor and then I am sending the same to the Nethereum. But it give me this error.

cannot unmarshal hex string of odd length into Go value of type hexutil.Bytes

RevVivek
@RevVivek
Dec 10 2018 04:50
And this one also
rlp: expected input list for types.txdata
image.png
This is the code block
Juan Blanco
@juanfranblanco
Dec 10 2018 05:29
@hessam94 you cannot get the return message, it is not supported by the geth or parity (maybe in the future)
hey @RevVivek
is this due to the upgrade of the firmware?
are you using Nethereum ? or directly the api
Juan Blanco
@juanfranblanco
Dec 10 2018 05:39
this is a sample for tokenTransfer
instead of just signing you could do SendRequest and everything will be handled for you
RevVivek
@RevVivek
Dec 10 2018 05:52
Thanks you sir @juanfranblanco .
turtlewen
@turtlewen
Dec 10 2018 06:27
hi
any one here??
i meet some question
my .sol file contain 3 smart contract
my 3rd contract wanna use the struct of second and first contract
function setDataAddress(address addr, address addr2)public{
   data = devops_data(addr); 
   data = devops_data(addr2);

}
i implement through like that
but the problem is
bool checkingresult = false;
bool result= await setOthersContractForComplianceChecking();
            string date = DateTime.Now.ToString("yyyy-MM-dd");
            string time = DateTime.Now.ToString("hh:mm:ss");

            var contract = await createComplianceCheckingObject();
            var checkingFunction = contract.GetFunction("complianceChecking");



            var transactionHash = await checkingFunction.SendTransactionAsync(senderAddress, new HexBigInteger(900000), null, ID, date, time, name);

            //if (transactionHash == null || (transactionHash.Status.Value != BigInteger.One))
            //    checkingresult= false;
            //else
                checkingresult = true;

        return checkingresult;
when i execute this function it coming out fail

mean it keep go inside to this if statement

if(transactionHash == null || (transactionHash.Status.Value != BigInteger.One))

public static async Task<bool> setOthersContractForComplianceChecking()
{
var contract = await createComplianceCheckingObject();
var setDataFunction = contract.GetFunction("setDataAddress");
var transactionHash = await setDataFunction.SendTransactionAndWaitForReceiptAsync(senderAddress, new HexBigInteger(900000), new HexBigInteger(0), null, devops_dataAddress,devops_data2Address);
        if (transactionHash == null || (transactionHash.Status.Value != BigInteger.One))
            return false;
        else
            return true;

    }
can i use nethereum send transaction with parameter of string , but smart contract there accept for address
Juan Blanco
@juanfranblanco
Dec 10 2018 06:34
the address is a string in Netherum
i don't know about the other parameters
hence using the code generator will help you there
turtlewen
@turtlewen
Dec 10 2018 06:38
what mean code generator??
turtlewen
@turtlewen
Dec 10 2018 07:43
i tested using truffle console to submit same transaction, in console it submitted successful
but when come to front end using nethereum it keep cannot ><
Juan Blanco
@juanfranblanco
Dec 10 2018 07:43
yeah that might be an issue with the parameters
you can use named parameters to avoid confusion
or you can used the typed functions as described on the docs
with the help of the code generator
(as it is easier )
turtlewen
@turtlewen
Dec 10 2018 07:48
@StefH @juanfranblanco finally , thanks with ur hint. it is because ID parameter make it confusing
so i change to requestID
Juan Blanco
@juanfranblanco
Dec 10 2018 07:49
yes @StefH is pretty good :)
feel free to add a pull to the docs to list it btw
Stef Heyenrath
@StefH
Dec 10 2018 07:58
btw I did not have time yet to check if my generated C# code will work with Nethereum 3. And I still have to investigate if the passing complex types does work in solidity 0.5.0 and how to generate code for that...
Juan Blanco
@juanfranblanco
Dec 10 2018 08:19
yeah i have not done any code gen on complex types yet
the issue is that if you don't inspect directly the AST at the moment you will end up generating a type per function call, ending with some kind of class explosion
Tom Ryan
@a7coretryan
Dec 10 2018 17:41
@juanfranblanco -- I appreciate you checking and providing a resolution.
Tom Ryan
@a7coretryan
Dec 10 2018 19:45

@juanfranblanco I was able to implement and test with no luck. Let me add a bit more details --
1) I have an event in my smartcontract: event OnPublish (address indexed publisher, string publisherData);
2) I created a DTO deriving from IEventDTO:
[Event("OnPublish")]
public class OnPublishEvent : IEventDTO
{
[Parameter ("address", "publisher", 1, true)]
public string Publisher { get; set; }

        [Parameter("string", "publisherData", 2, false)]
        public string PublisherData { get; set; }
    }

3)I create the filter --
var onPublishEvent = contract.GetEvent<OnPublishEvent>("OnPublish");
var pubinputfilter = onPublishEvent.CreateFilterInput(new[] { publisherAddress });
HexBigInteger filterid = await onPublishEvent.CreateFilterAsync(pubinputfilter);
all appears well.
4) I then call the contract that when calls the OnPublish Event (I receive the transaction receipt)
5) I then call to get the filtered data using the filterid above:
var onPublishEvent = contract.GetEvent<OnPublishEvent>("OnPublish");
var log = await onPublishEvent.GetFilterChanges(filterid);

** Nothing is returned -- always returns 0.

Tom Ryan
@a7coretryan
Dec 10 2018 19:54

@juanfranblanco if I make a call to GetAllChanges…
NewFilterInput allinputfilter = onPublishEvent.CreateFilterInput(BlockParameter.CreateEarliest(), BlockParameter.CreateLatest());
var log = await onPublishEvent.GetAllChanges(allinputfilter);

...I receive all 11 of my transactions.

Stef Heyenrath
@StefH
Dec 10 2018 19:54
@a7coretryan Maybe this example (solidity and dotnet console) can help you?
https://github.com/StefH/Solidity-Examples/tree/master/SmartContracts/Examples/Multiply
Tom Ryan
@a7coretryan
Dec 10 2018 20:02
thanks @StefH I see your DTO doesnt' use IEventDTO was this built with v2.5 or v3.0?
@StefH specifically talking about your Approval and Transfer DTOs in ArtifactOwnershipService.Generated.cs
Dave Whiffin
@Dave-Whiffin
Dec 10 2018 20:11
Hi Tom, would you mind posting the solidity code for the event so that I can see the exact signature and indexed fields? I’ll see if I can investigate for you.
Tom Ryan
@a7coretryan
Dec 10 2018 20:16
@Dave-Whiffin -- thanks Dave. I am working a simpler test case as I have middleware objects built around the above described scenario. But any help is much appreciated. Very simple contract code...will send in a couple minutes. Thanks again.
I changed the names in my example above from 'retailer' to 'publisher' and 'stdPromoJson' to 'publisherData' but all else is the same. Here is the solidity code...

pragma solidity ^"0.4.19";

import "./Ownable.sol";

contract StandardPromotion is Ownable {

event OnPublish (address indexed retailer, string stdPromoJson);

constructor () public {}

function publish (address retailer, string stdPromoJson) public onlyOwner
{
    require(bytes(stdPromoJson).length > 0, "Standard Promotion Json not provided.");
    require (retailer != address(0x0), "Retailer address must be specified.");

    emit OnPublish (retailer, stdPromoJson);
}

}

Dave Whiffin
@Dave-Whiffin
Dec 10 2018 20:59
@a7coretryan Tom - are you only interested in events related to transactions from a specific address? i.e. filtering by the caller?
Tom Ryan
@a7coretryan
Dec 10 2018 21:00
yes
Dave Whiffin
@Dave-Whiffin
Dec 10 2018 21:41

@a7coretryan

I'll double check this with Juan tomorrow to be sure - but from my tests it seems the filter can only pick up events from transactions sent to specific contract addresses (not the publisher address). I don't think this is specific to Nethereum, I think it's an Ethereum client thing.

You CAN filter by the from address if it is an indexed field on the event - as per the transfer examples. In that regard it becomes a Topic.

e.g.
event OnPublish (address indexed publisher, address indexed retailer, string stdPromoJson);
Dave Whiffin
@Dave-Whiffin
Dec 10 2018 21:53
Here's the code snippet I was testing with (using the Nethereum Geth test chain). This does successfully track the new events for a specific contract. But you can change the "Address" array on the filterInput variable to target many contract addresses.
        static async Task Main(string[] args)
        {
            var account = new Account("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7");
            var web3 = new Web3(account, "http://localhost:8545");

            const string retailer = "0x12890d2cce102216644c59dae5baed380d84830d"; // just a randomly generated address

            var service = await PublishTestService.DeployContractAndGetServiceAsync(web3, new PublishTestDeployment{});

            var onPublishEvent = service.ContractHandler.GetEvent<OnPublishEventDTO>();

            var filterInput = onPublishEvent.CreateFilterInput();

            var filterId = await onPublishEvent.CreateFilterAsync(filterInput);

            var receipt1 = await service.PublishRequestAndWaitForReceiptAsync(new PublishFunction
            {
                Retailer = retailer,
                StdPromoJson = "Promo20181210_1"
            });

            var changes1 = await onPublishEvent.GetFilterChanges(filterId);
            Console.WriteLine($"{changes1.Count} change/s detected.  First Tx: {changes1.FirstOrDefault().Log?.TransactionHash}");

            var receipt2 = await service.PublishRequestAndWaitForReceiptAsync(new PublishFunction
            {
                Retailer = retailer,
                StdPromoJson = "Promo20181210_2"
            });

            var changes2 = await onPublishEvent.GetFilterChanges(filterId);
            Console.WriteLine($"{changes2.Count} change/s detected.  First Tx: {changes2.FirstOrDefault().Log?.TransactionHash}");

            Console.ReadLine();

        }
Tom Ryan
@a7coretryan
Dec 10 2018 21:55
Dave - I want to make sure we are on the same page. retailer is the 'from' address. As I stated Publisher = Retailer so I don't have Retailer and Publisher in the event.
I make the call to the contract using the address of the owner of the contract but use the Retailer address as the publisher of the promotion.
Dave Whiffin
@Dave-Whiffin
Dec 10 2018 21:56
@a7coretryan Haha! That's different then - let me adjust my sample and I'll send it over!
Tom Ryan
@a7coretryan
Dec 10 2018 21:57
@Dave-Whiffin -- thanks for your willingness to help out!
Dave Whiffin
@Dave-Whiffin
Dec 10 2018 22:29
@a7coretryan Sorry for the delay - here's a working sample. I am deliberately instantiating a new web3 and event handler when I get and print logs - just to demonstrate the filterId working - however I could have used the same instance of web3 and event.

/// generated event DTO code snippet
    public partial class OnPublishEventDTO : OnPublishEventDTOBase { }

    [Event("OnPublish")]
    public class OnPublishEventDTOBase : IEventDTO
    {
        [Parameter("address", "retailer", 1, true )]
        public virtual string Retailer { get; set; }
        [Parameter("string", "stdPromoJson", 2, false )]
        public virtual string StdPromoJson { get; set; }
    }


        static async Task Main(string[] args)
        {
            var account = new Account("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7");

            var web3 = new Web3(account, "http://localhost:8545");

            const string contractAddress = "0x4bb949df88af1a29448d5e9415cf150145e529d3";
            const string retailer = "0x12890d2cce102216644c59dae5baed380d84830d"; // just a randomly generated address

            var service = new PublishTestService(web3, contractAddress);

            var onPublishEvent = service.ContractHandler.GetEvent<OnPublishEventDTO>();

            var filterInput = onPublishEvent.CreateFilterInput(new object[]{retailer});

            var filterId = await onPublishEvent.CreateFilterAsync(filterInput);

            var receipt1 = await service.PublishRequestAndWaitForReceiptAsync(new PublishFunction
            {
                Retailer = retailer,
                StdPromoJson = "Promo20181210_1"
            });

            await GetAndPrintLogs(filterId);

            var receipt2 = await service.PublishRequestAndWaitForReceiptAsync(new PublishFunction
            {
                Retailer = retailer,
                StdPromoJson = "Promo20181210_2"
            });

            await GetAndPrintLogs(filterId);

            Console.ReadLine();

        }

        static async Task GetAndPrintLogs(HexBigInteger filterId)
        {
            var web3 = new Web3("http://localhost:8545");
            var onPublishEvent = new Event<OnPublishEventDTO>(web3.Client);
            var logs = await onPublishEvent.GetFilterChanges(filterId);
            Console.WriteLine($"tx: {logs.Count()}");
            foreach(var log in logs)
            {
                Console.WriteLine($"tx: {log.Log.TransactionHash}");
                Console.WriteLine($"Retailer: {log.Event.Retailer}");
                Console.WriteLine($"StdPromoJson: {log.Event.StdPromoJson}");
            }
        }
Tom Ryan
@a7coretryan
Dec 10 2018 22:30
@Dave-Whiffin So you were able to make it work with a local parityPOA node?
Dave Whiffin
@Dave-Whiffin
Dec 10 2018 22:32
@a7coretryan I am using Geth. In general Juan's advice is always to try geth first. If it works on geth you have a chance of it working elsewhere. If it doesn't work in Geth it's probably not going to work anywhere.
Tom Ryan
@a7coretryan
Dec 10 2018 22:34
@Dave-Whiffin ok - I'm using Azure Parity POA so I will setup a local node. Thanks for the help.
Dave Whiffin
@Dave-Whiffin
Dec 10 2018 22:35
@a7coretryan Good luck with it. It's getting late in the UK now so I'll be back in the morning and help where I can.

@a7coretryan If the event filters don't work on Parity (but do on Geth) you could retrieving logs another way - retrieving logs by a moving block range, then applying filtering for your publisher/retailer. There is a sample in our repo below:

https://github.com/Nethereum/Nethereum.BlockchainProcessing/blob/master/Nethereum.BlockchainProcessing.Samples/EventLogEnumeration.cs

Tom Ryan
@a7coretryan
Dec 10 2018 22:40
@Dave-Whiffin -- thanks - I will give this a try.