Advertisement
Guest User

Untitled

a guest
Sep 24th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. web3 = require('web3');
  2. web3.setProvider(new web3.providers.HttpProvider('http://localhost:8546'));
  3.  
  4. var eventtestContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"signedInput","type":"int256"},{"name":"unsignedInput","type":"uint256"}],"name":"intTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"test","type":"bool"}],"name":"booleanTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"byt","type":"bytes32"}],"name":"Bytes32Test","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"byt","type":"bytes2[]"}],"name":"Bytes2ArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"str","type":"string"}],"name":"StringTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"signedInput","type":"int256[]"},{"name":"unsignedInput","type":"uint256[]"}],"name":"IntArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"byt","type":"bytes2"}],"name":"Bytes2Test","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"signedInput","type":"int8[]"},{"name":"unsignedInput","type":"uint8[]"}],"name":"Int8ArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"signedInput","type":"int32"},{"name":"unsignedInput","type":"uint32"}],"name":"Int32Test","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"signedInput","type":"int40"},{"name":"unsignedInput","type":"uint40"}],"name":"Int40Test","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"signedInput","type":"int32[]"},{"name":"unsignedInput","type":"uint32[]"}],"name":"Int32ArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"byt","type":"bytes1"}],"name":"Bytes1Test","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"byt","type":"bytes32[]"}],"name":"Bytes32ArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"signedInput","type":"int8"},{"name":"unsignedInput","type":"uint8"}],"name":"Int8Test","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"arr","type":"uint8[]"}],"name":"EnumArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"input","type":"bool[]"}],"name":"BooleanArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"signedInput","type":"int40[]"},{"name":"unsignedInput","type":"uint40[]"}],"name":"Int40ArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"enu","type":"uint8"}],"name":"EnumTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"AddressTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"byt","type":"bytes1[]"}],"name":"Bytes1ArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address[]"}],"name":"AddressArrayTest","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"byt","type":"bytes"}],"name":"BytesTest","outputs":[],"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bool"}],"name":"BooleanTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"signedInput","type":"int256"},{"indexed":false,"name":"unsignedInput","type":"uint256"}],"name":"IntTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"signedInput","type":"int8"},{"indexed":false,"name":"unsignedInput","type":"uint8"}],"name":"Int8TestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"signedInput","type":"int32"},{"indexed":false,"name":"unsignedInput","type":"uint32"}],"name":"Int32TestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"signedInput","type":"int40"},{"indexed":false,"name":"unsignedInput","type":"uint40"}],"name":"Int40TestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"address"}],"name":"AddressTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bytes1"}],"name":"Bytes1TestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bytes2"}],"name":"Bytes2TestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bytes32"}],"name":"Bytes32TestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bytes"}],"name":"BytesTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"string"}],"name":"StringTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"enum TestEnum"}],"name":"EnumTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bool[]"}],"name":"BooleanArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"signedInput","type":"int256[]"},{"indexed":false,"name":"unsignedInput","type":"uint256[]"}],"name":"IntArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"signedInput","type":"int8[]"},{"indexed":false,"name":"unsignedInput","type":"uint8[]"}],"name":"Int8ArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"signedInput","type":"int32[]"},{"indexed":false,"name":"unsignedInput","type":"uint32[]"}],"name":"Int32ArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"signedInput","type":"int40[]"},{"indexed":false,"name":"unsignedInput","type":"uint40[]"}],"name":"Int40ArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"address[]"}],"name":"AddressArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bytes1[]"}],"name":"Bytes1ArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bytes2[]"}],"name":"Bytes2ArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"bytes32[]"}],"name":"Bytes32ArrayTestEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"enum TestEnum[]"}],"name":"EnumArrayTestEvent","type":"event"}]);
  5.  
  6. // Contract mined! address: 0xa5fa4c56bec5dc4e3ff3e26edabf638e23348410 transactionHash: 0xac1486b1b494e73ba5da867091ae1750a6db3b71b6fd5ec465137eba8a62ba20
  7. eventtestAddress = "0xa5fa4c56bec5dc4e3ff3e26edabf638e23348410"; // on my testnet.
  8. eventtestInstance = eventtestContract.at(eventtestAddress);
  9.  
  10. oneInputPrint = function oneInputPrint (error, result) {
  11.   if(!error) {
  12.     var input = result.args["input"];
  13.     var type = Object.prototype.toString.call(input).slice(8, -1);
  14.     var constrName = input.constructor.name;
  15.     console.log(new Date());
  16.     console.log(JSON.stringify(result, null, 4));
  17.     console.log(input + " (" + type + "/" + constrName + ")\n");
  18.    
  19.   } else {
  20.     console.error(new Date() + " " + error);
  21.   }
  22. }
  23.  
  24. twoInputPrint = function twoInputPrint (error, result) {
  25.   if(!error) {
  26.     var unsigned     = result.args["unsignedInput"];
  27.     var unsignedType = Object.prototype.toString.call(unsigned).slice(8, -1);
  28.     var unsignedConstrName = unsigned.constructor.name;
  29.     var signed       = result.args["signedInput"];
  30.     var signedType   = Object.prototype.toString.call(signed).slice(8, -1);
  31.     var signedConstrName = signed.constructor.name;
  32.    
  33.     console.log(new Date());
  34.     console.log(JSON.stringify(result, null, 4));
  35.     console.log("unsigned: " + unsigned + " (" + unsignedType + "/" + unsignedConstrName + ") signed: " + signed + " (" + unsignedType + "/" + unsignedConstrName + ")\n");
  36.   } else {
  37.     console.error(new Date() + " " + error);
  38.   }
  39. }
  40.  
  41. boolEvent = eventtestInstance.BooleanTestEvent( {}, oneInputPrint);
  42. intEvent = eventtestInstance.IntTestEvent({}, twoInputPrint);
  43. int8Event = eventtestInstance.Int8TestEvent({}, twoInputPrint);
  44. int32Event = eventtestInstance.Int32TestEvent({}, twoInputPrint);
  45. int40Event = eventtestInstance.Int40TestEvent({}, twoInputPrint);
  46. addressEvent = eventtestInstance.AddressTestEvent({}, oneInputPrint);
  47. bytesEvent = eventtestInstance.BytesTestEvent({}, oneInputPrint);
  48. bytes1Event = eventtestInstance.Bytes1TestEvent({}, oneInputPrint);
  49. bytes2Event = eventtestInstance.Bytes2TestEvent({}, oneInputPrint);
  50. bytes32Event = eventtestInstance.Bytes32TestEvent({}, oneInputPrint);
  51. stringEvent = eventtestInstance.StringTestEvent({}, oneInputPrint);
  52. enumEvent = eventtestInstance.EnumTestEvent({}, oneInputPrint);
  53.  
  54. boolArrayEvent = eventtestInstance.BooleanArrayTestEvent( {}, oneInputPrint);
  55. intArrayEvent = eventtestInstance.IntArrayTestEvent({}, twoInputPrint);
  56. int8ArrayEvent = eventtestInstance.Int8ArrayTestEvent({}, twoInputPrint);
  57. int32ArrayEvent = eventtestInstance.Int32ArrayTestEvent({}, twoInputPrint);
  58. int40ArrayEvent = eventtestInstance.Int40ArrayTestEvent({}, twoInputPrint);
  59. addressArrayEvent = eventtestInstance.AddressArrayTestEvent({}, oneInputPrint);
  60. bytes1ArrayEvent = eventtestInstance.Bytes1ArrayTestEvent({}, oneInputPrint);
  61. bytes2ArrayEvent = eventtestInstance.Bytes2ArrayTestEvent({}, oneInputPrint);
  62. bytes32ArrayEvent = eventtestInstance.Bytes32ArrayTestEvent({}, oneInputPrint);
  63. enumArrayEvent = eventtestInstance.EnumArrayTestEvent({}, oneInputPrint);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement