Q1. I find this concept to be very confusing, when should I be using watch, call or get to listen to an event? how are they different and when should they be used?
Also,
var event1 = newInst.getSupplier({'OwnAdd': someaddr},{fromBlock:'latest, toBlock:'pending'}, function(error, result) {
console.log("listening bro1");
if (!error)
console.log(result.args);
});
It returns me the structure twice.
{OwnAdd: "0xfd4e38348590a41e91b5ee57b69b99e746783990", _NameoProd: "lime", _QuantityoProd: BigNumber, _MnfofProd: "Done", _toSrv: "Meh", …}OwnAdd: "0xfd4e38348590a41e91b5ee57b69b99e746783990"_MnfofProd: "Done"_NameoProd: "lime"_QuantityoProd: BigNumber {s: 1, e: 1, c: Array(1)}_comments: "Bajaj"_status: "Saul "_toSrv: "Meh"__proto__: Object
eventwatcher.html:327 listening bro1
eventwatcher.html:329 {OwnAdd: "0xfd4e38348590a41e91b5ee57b69b99e746783990", _NameoProd: "lime", _QuantityoProd: BigNumber, _MnfofProd: "Done", _toSrv: "Meh", …}OwnAdd: "0xfd4e38348590a41e91b5ee57b69b99e746783990"_MnfofProd: "Done"_NameoProd: "lime"_QuantityoProd: BigNumber {s: 1, e: 1, c: Array(1)}_comments: "Bajaj"_status: "Saul "_toSrv: "Meh"__proto__: Object
Q2. I can't figure out why it sends me twice, can anyone figure this out? Note: I am just trying to get the pending data and not all the records with the above event
Smart Contract:
pragma solidity ^0.4.20;
contract Supplier{
struct supply{
string NameoProd;
uint QuantityoProd;
string MnfofProd;
string toSrv;
string stat;
string comments;
}
uint SaleID=100000;
mapping (uint=>supply) fmr;
event getSupplier( address indexed OwnAdd, string _NameoProd,
uint _QuantityoProd,
string _MnfofProd,
string _toSrv,
string _status,
string _comments);
function setSupply(string _NameoProd,
uint _QuantityoProd,
string _MnfofProd,
string _toSrv,
string _status,
string _comments) public{
address snd = msg.sender;
fmr[SaleID]=supply(_NameoProd,_QuantityoProd,_MnfofProd,_toSrv,_status,_comments);
emit getSupplier(snd, _NameoProd,_QuantityoProd,_MnfofProd,_toSrv,_status,_comments);
SaleID++;
}
function getSomething(uint ID) public view returns (string , uint , string , string , string ,
string ){
supply a=fmr[ID];
return (a.NameoProd, a.QuantityoProd, a.MnfofProd, a.toSrv, a.stat, a.comments);
}
function update(uint ID, string rpf) public {
supply b =fmr[ID];
b.stat=rpf;
fmr[ID]=b;
emit getSupplier(msg.sender, b.NameoProd,b.QuantityoProd,b.MnfofProd,b.toSrv,b.stat,b.comments);
}
}
Q3. To get values back to a UI is it more feasible to get the data ID by ID or is it better to use events (what I am trying to achieve now). If I use events then when I call update I will get all the records from the events on page reload. I will have the old records as well as new record for that SupplyID. I can write a filter on the Dapp but can something else be done?