From ac386e7533778ff3ddbb99e4c0274c8346949ddd Mon Sep 17 00:00:00 2001 From: mongolsteppe <75075420+mongolsteppe@users.noreply.github.com> Date: Wed, 23 Jun 2021 21:49:33 +0300 Subject: [PATCH] [Docs] Updated solidity example to modern syntax Replaced the old constructor function syntax with the modern one, added 'emit' to event calls, added pragma, added a valid bytes32 value and updated the JSON ABI. --- docs/glossary.rst | 60 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/docs/glossary.rst b/docs/glossary.rst index d3b1967b934..7aad6f63d5a 100644 --- a/docs/glossary.rst +++ b/docs/glossary.rst @@ -51,47 +51,51 @@ Example .. code-block:: javascript + pragma solidity ^0.8.4; contract Test { uint a; - address d = 0x12345678901234567890123456789012; + address d = 0xdCad3a6d3569DF655070DEd06cb7A1b2Ccd1D3AF; - function Test(uint testInt) { a = testInt;} + constructor(uint testInt) { a = testInt;} event Event(uint indexed b, bytes32 c); event Event2(uint indexed b, bytes32 c); - function foo(uint b, bytes32 c) returns(address) { - Event(b, c); + function foo(uint b, bytes32 c) public returns(address) { + emit Event(b, c); return d; } } + // would result in the JSON: - [{ - "type":"constructor", - "payable":false, - "stateMutability":"nonpayable" - "inputs":[{"name":"testInt","type":"uint256"}], - },{ - "type":"function", - "name":"foo", - "constant":false, - "payable":false, - "stateMutability":"nonpayable", - "inputs":[{"name":"b","type":"uint256"}, {"name":"c","type":"bytes32"}], - "outputs":[{"name":"","type":"address"}] - },{ - "type":"event", - "name":"Event", - "inputs":[{"indexed":true,"name":"b","type":"uint256"}, {"indexed":false,"name":"c","type":"bytes32"}], - "anonymous":false - },{ - "type":"event", - "name":"Event2", - "inputs":[{"indexed":true,"name":"b","type":"uint256"},{"indexed":false,"name":"c","type":"bytes32"}], - "anonymous":false - }] + [ + { + "type": "constructor" + "stateMutability": "nonpayable", + "inputs": [{"internalType":"uint256","name":"testInt","type":"uint256"}], + }, + { + "type": "event" + "name": "Event", + "inputs": [{"indexed":true,"internalType":"uint256","name":"b","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"c","type":"bytes32"}], + "anonymous": false, + }, + { + "type": "event" + "name": "Event2", + "inputs": [{"indexed":true,"internalType":"uint256","name":"b","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"c","type":"bytes32"}], + "anonymous": false, + }, + { + "type": "function" + "name": "foo", + "stateMutability": "nonpayable", + "inputs": [{"internalType":"uint256","name":"b","type":"uint256"},{"internalType":"bytes32","name":"c","type":"bytes32"}], + "outputs": [{"internalType":"address","name":"","type":"address"}], + } + ] ------------------------------------------------------------------------------