CIP No. | Title | Author | Status | Type | Created |
---|---|---|---|---|---|
19 |
KeyValue EventLog Standard |
Haizhou Wang <Haizhou@confluxnetwork.org> |
Draft |
Backward Compatible |
2020-08-10 |
A key value event log standard.
The following standard specifies a key value format event log which include "announcer", "address", "key", "value" fields. The standard makes it easy for users to use the block chain consensus mechanism to solve the identity and content verification problems of information publishers.
Although smart contract using block chain solves information distribution, validation and storage at the same time.
But for some DApp, storage are not strict requirements, using memory
to store data is very expensive and these DApp could storage them self.
This standard is proposed to standardize the format of such information in EventLog.
event Announce(address indexed announcer, bytes indexed keyHash, bytes key, bytes value);
- 1.Event MUST be
Announce(address,bytes,bytes,bytes)
, which signature MUST be0x14cb751d0950ff2788201931c45f715f7472443bc197311d9e3a7a0ba566b7e6
- 2.Event MUST NOT be
anonymous
- 3.Event
announcer
andkeyHash
MUST beindexed
,key
andvalue
MUST NOT beindexed
- 4.Event
keyHash
MUST bekeccak256
hash ofkey
Note: The standard only specifies the format, but not the specific implementation method.
- Data structure
Announce
event log:
{
"epochNumber": 1652588,
"logIndex": 0,
"transactionIndex": 0,
"transactionLogIndex": 0,
"address": "0x8bf8f3d98519dc933a0105356d080237a2e939a7",
"blockHash": "0xda45520d27897c164306e8f2e20e18e1f83d74f5015fbea663069767da65af71",
"data": "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000036b65790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000576616c7565000000000000000000000000000000000000000000000000000000",
"topics": [
"0x14cb751d0950ff2788201931c45f715f7472443bc197311d9e3a7a0ba566b7e6",
"0x0000000000000000000000001bd9e9be525ab967e633bcdaeac8bd5723ed4d6b",
"0x07855b46a623a8ecabac76ed697aa4e13631e3b6718c8a0d342860c13c30d2fc"
],
"transactionHash": "0xca05ebc9c8eb6c1f03ae82f008335f4e76c9f2a275f87c08defd448167790c8a"
}
explanation:
address: smart contract address
topics[0]: event log signature
topics[1]: address of announcer
topics[2]: keccak256 hash of key field
data: encode of key and value data, decoded as {key:0x6b6579, value:0x76616c7565}, which is {key:"key", value:"value"} in utf8 code.
- Gas cost
EventLog only stays in block chain node for a period of time, and the timeout information will not be found, nor will it occupy the node's storage resources indefinitely.
This standard does not need to occupy storageCollateralized
and the transaction costs can be minimized to include only the gas
portion.
- Application scenarios
Information distribution and validation for DApp. Real time chat application. News or stream media.
TBD
TBD
- mini implement of Announce:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.10;
contract Announcement {
event Announce(address indexed announcer, bytes indexed keyHash, bytes key, bytes value);
function announce(bytes calldata key, bytes calldata value) external {
emit Announce(msg.sender, key, key, value);
}
}
call announce()
with key
, value
and contract set msg.sender
to announcer
- The standard allows multiple
Announce
event log from one transaction, contract could generate multipleAnnounce
to reduce transaction as follows.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
contract Announcement {
struct Entry {
bytes key;
bytes value;
}
event Announce(address indexed announcer, bytes indexed keyHash, bytes key, bytes value);
function announce(Entry[] calldata array) external {
for (uint i = 0; i < array.length; i++) {
emit Announce(msg.sender, array[i].key, array[i].key, array[i].value);
}
}
}
- Standard can be embedded in other contracts, also can be extended.
- Conflux Transaction data length is limited, large key and value may cause the transaction fail.
- Standard not require
announcer
must bemsg.sender
.
Copyright and related rights waived via CC0.