commit aaf5821bd2bba6d427a2705d2a04e746404bb0c3
parent cd1a752a47016aafa9fbfe7740393001b9f74b06
Author: lash <dev@holbrook.no>
Date: Sat, 18 Feb 2023 19:14:38 +0000
Add solidity documentation
Diffstat:
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py
@@ -112,7 +112,6 @@ class Test(EthTesterCase):
self.assertEqual(mh[4:68], strip_0x(ZERO_CONTENT))
-
if __name__ == '__main__':
unittest.main()
diff --git a/solidity/Msg.sol b/solidity/Msg.sol
@@ -3,7 +3,8 @@ pragma solidity >=0.6.0;
// SPDX-License-Identifier: GPL-3.0-or-later
contract EventMsg {
-
+
+ // Represents a multicodec item
struct MultiHash {
uint8 l;
uint8 codecRLength;
@@ -12,8 +13,13 @@ contract EventMsg {
bytes8 codec;
}
+ // All registered multicodecs
mapping (uint256 => MultiHash) public multiCodecs;
+
+ // Currently used multicodec
uint256 msgCodec;
+
+ // Latest persisted message
bytes currentMsg;
// Implements Sealer
@@ -30,6 +36,7 @@ contract EventMsg {
currentMsg = new bytes(32);
}
+ // Set the latest pesistent message on contract
function setMsg(bytes memory _digest) public {
MultiHash storage _hsh;
@@ -40,10 +47,12 @@ contract EventMsg {
emit Msg(getMsg());
}
+ // Return a multihash of the latest persistent message
function getMsg() public view returns(bytes memory) {
return toHash(currentMsg);
}
+ // Add a multicodec that can later be set as current codec
function addCodec(uint8 _length, uint64 _codecId, string memory _uriPrefix) public {
require(sealState & CODECLIST_STATE == 0, 'ERR_SEAL_CODECLIST');
bytes memory prefixBytes;
@@ -70,6 +79,7 @@ contract EventMsg {
multiCodecs[uint256(_codecId)] = _hsh;
}
+ // Set the current multicodec to use for multihash generation
function setMsgCodec(uint256 _codec) public {
require(sealState & CODECLIST_STATE == 0, 'ERR_SEAL_CODEC');
MultiHash storage _hsh;
@@ -101,6 +111,7 @@ contract EventMsg {
return _state & sealState == _state;
}
+ // Generate a multihash from the given digest and current selected multicodec
function toHash(bytes memory _digest) public view returns(bytes memory) {
MultiHash storage m;
bytes memory r;
@@ -121,6 +132,8 @@ contract EventMsg {
return r;
}
+ // Generate a URI representing the digest and the string prefix representation
+ // of the currently selected multicodec
function toUri(bytes memory _digest) public view returns(string memory) {
MultiHash storage m;
@@ -144,7 +157,9 @@ contract EventMsg {
return string(codecString);
}
-
+
+ // TODO: move to internal library method
+ // bytes to hex conversion
function toHex(bytes memory _data) public pure returns(bytes memory) {
bytes memory out;
uint8 t;