Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. contract Product{
  2. address public owner;
  3. string public title;
  4. mapping (address => uint) quantity;
  5.  
  6. event Transferred(address from, address to, uint quantity);
  7.  
  8. // Constructor
  9. function Product(string _title, uint _quantity){
  10. owner = msg.sender;
  11. title = _title;
  12. quantity[msg.sender] = _quantity;
  13. }
  14.  
  15. function getQuantity(address _user) constant returns (uint _quantity){
  16. return quantity[_user];
  17. }
  18.  
  19. function changeQuantity(uint _quantity) returns (bool success){
  20. quantity[msg.sender] = _quantity;
  21. return true;
  22. }
  23.  
  24. function transfer(address _to, uint _quantity) returns (bool success){
  25. if (quantity[msg.sender] < _quantity){
  26. return false;
  27. }
  28.  
  29. owner = _to;
  30. quantity[msg.sender] -= _quantity;
  31. quantity[_to] += _quantity;
  32. Transferred(msg.sender, _to, _quantity);
  33. return true;
  34. }
  35. }
  36.  
  37. Filter {
  38. requestManager:
  39. RequestManager {
  40. provider: HttpProvider { host: 'http://localhost:8545', timeout: 0 },
  41. polls: {},
  42. timeout: null },
  43. options:
  44. { topics: [ '0x6f8b0853f4c56c6a9faec2151763bdc803a695c1ce09b45d3036186c5ae14c47' ],
  45. from: undefined,
  46. to: undefined,
  47. address: '0x570a704dded5379eb21b064cc7750741348e8860',
  48. fromBlock: '0x0',
  49. toBlock: 'latest' },
  50. implementation:
  51. { newFilter: { [Function: send] request: [Function: bound ], call: [Function: newFilterCall] },
  52. uninstallFilter: { [Function: send] request: [Function: bound ], call: 'eth_uninstallFilter' },
  53. getLogs: { [Function: send] request: [Function: bound ], call: 'eth_getFilterLogs' },
  54. poll: { [Function: send] request: [Function: bound ], call: 'eth_getFilterChanges' } },
  55. filterId: '0x0b',
  56. callbacks: [],
  57. getLogsCallbacks: [],
  58. pollFilters: [],
  59. formatter: [Function: outputLogFormatter] }
  60.  
  61. let transferEvent = product.Transferred({}, {fromBlock: 0, toBlock: 'latest'})
  62. transferEvent.get((error, logs) => {
  63. // we have the logs, now print them
  64. logs.forEach(log => console.log(log.args))
  65. })
  66.  
  67. { from: '0xc7d748654199d3594239a244d806e51331ca14b5',
  68. to: '0x3c11b23b4d5adb2d534d262cf83cee773c9b1c0a',
  69. quantity: { [String: '1'] s: 1, e: 0, c: [ 1 ] } }
  70. { from: '0xc7d748654199d3594239a244d806e51331ca14b5',
  71. to: '0x3c11b23b4d5adb2d534d262cf83cee773c9b1c0a',
  72. quantity: { [String: '3'] s: 1, e: 0, c: [ 3 ] } }
  73.  
  74. let events = product.allEvents({fromBlock: 0, toBlock: 'latest'})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement