Skip to content

Instantly share code, notes, and snippets.

@shd101wyy
Last active April 16, 2018 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shd101wyy/ab1af58913f5c8defa54f1c83c514412 to your computer and use it in GitHub Desktop.
Save shd101wyy/ab1af58913f5c8defa54f1c83c514412 to your computer and use it in GitHub Desktop.
My solidity smart contract.
pragma solidity ^0.4.0;
// pragma experimental ABIEncoderV2;
// https://medium.com/daox/three-methods-to-transfer-funds-in-ethereum-by-means-of-solidity-5719944ed6e9
contract Decent {
mapping (bytes32 => mapping(bytes1 => uint256)) state;
mapping (address => bytes32) previousArticleTransactionHashMap;
mapping (bytes32 => bytes32) previousCommentTransactionHashMap;
mapping (bytes32 => bytes32) previousTagTransactionHashMap;
address owner;
function Decent() public {
owner = msg.sender;
}
function updateState(bytes32 transactionHash, bytes1 field, uint256 value) external {
state[transactionHash][field] = state[transactionHash][field] + value;
}
function getState(bytes32 transactionHash, bytes1 field) external constant returns (uint256) {
return state[transactionHash][field];
}
// 0, "Hello", 0xbf9eece36694d370f932d771db28eda83f9eb289092287e3d18e9093dff939c7, ["0x9cf4df7feca338c3d5957f305398db95ba3ac6b204dea352249c6b103b8efbb1"], ["0x9cf4df7feca338c3d5957f305398db95ba3ac6b204dea352249c6b103b8efbb1"]
event PostArticleEvent(uint version, string message, bytes32 previousArticleTransactionHash);
event PostTagEvent(bytes32 tag, bytes32 previousTagTransactionHash);
function postArticle(uint version, string message, bytes32 previousArticleTransactionHash, bytes32[] tags, bytes32[] previousTagTransactionHashes) external {
require(previousArticleTransactionHash != previousArticleTransactionHashMap[msg.sender]); // make sure there is no conflicts.
previousArticleTransactionHashMap[msg.sender] = previousArticleTransactionHash;
emit PostArticleEvent(version, message, previousArticleTransactionHash);
for (uint i = 0; i < tags.length; i++) {
previousTagTransactionHashMap[tags[i]] = previousTagTransactionHashes[i];
emit PostTagEvent(tags[i], previousTagTransactionHashes[i]);
}
}
event PostCommentEvent(uint version, bytes32 parentTransactionHash, string message, bytes32 previousCommentTransactionHash);
function postComment(uint version, bytes32 parentTransactionHash, string message, bytes32 previousCommentTransactionHash, bytes32[] tags, bytes32[] previousTagTransactionHashes) external {
require(previousCommentTransactionHash != previousCommentTransactionHashMap[parentTransactionHash]); // make sure there is no conflicts.
previousCommentTransactionHashMap[parentTransactionHash] = previousCommentTransactionHash;
emit PostCommentEvent(version, parentTransactionHash, message, previousCommentTransactionHash);
for (uint i = 0; i < tags.length; i++) {
previousTagTransactionHashMap[tags[i]] = previousTagTransactionHashes[i];
emit PostTagEvent(tags[i], previousCommentTransactionHash[i]);
}
}
function sendEther(bytes32 transactionHash, address postAutherAddress, uint amount1, address appAuthorAddress, uint amount2) payable external {
state[transactionHash][0x0] = state[transactionHash][0x0] + amount1;
if (amount1 > 0) {
postAutherAddress.transfer(amount1);
}
if (amount2 > 0) {
appAuthorAddress.transfer(amount2);
}
}
function getPreviousArticleTransactionHash(address addr) external constant returns (bytes32) {
return previousArticleTransactionHashMap[addr];
}
function getPreviousCommentTransactionHash(bytes32 parent) external constant returns (bytes32) {
return previousCommentTransactionHashMap[parent];
}
function getPreviousTagTransactionHash(bytes32 tag) external constant returns(bytes32) {
return previousTagTransactionHashMap[tag];
}
}
pragma solidity ^0.4.0;
// pragma experimental ABIEncoderV2;
// https://medium.com/daox/three-methods-to-transfer-funds-in-ethereum-by-means-of-solidity-5719944ed6e9
contract Gua {
address owner;
mapping (bytes32 => mapping(bytes1 => uint256)) state;
mapping (address => string) metaDataJSONStringMap;
mapping (address => uint) currentArticleTransactionBlockNumberMap;
mapping (bytes32 => uint) currentCommentTransactionHashMap;
mapping (bytes32 => uint) currentTagTransactionHashMap;
function Decent() public {
owner = msg.sender;
}
function updateState(bytes32 transactionHash, bytes1 field, uint256 value) external {
state[transactionHash][field] = state[transactionHash][field] + value;
}
function getState(bytes32 transactionHash, bytes1 field) external constant returns (uint256) {
return state[transactionHash][field];
}
function setMetaDataJSONStringMap(address addr, string value) external {
metaDataJSONStringMap[addr] = value;
}
function getMetaDataJSONStringValue(address addr) external constant returns (string) {
return metaDataJSONStringMap[addr];
}
event PostArticleEvent(uint version, uint timestamp, string message, bytes32 previousArticleTransactionHash);
event PostTagEvent(bytes32 tag, bytes32 previousTagTransactionHash);
function postArticle(uint version, uint timestamp, string message, bytes32 previousArticleTransactionHash, bytes32[] tags, bytes32[] previousTagTransactionHashes) external {
emit PostArticleEvent(version, timestamp, message, previousArticleTransactionHash);
currentArticleTransactionBlockNumberMap[msg.sender] = block.number;
for (uint i = 0; i < tags.length; i++) {
currentTagTransactionHashMap[tags[i]] = block.number;
emit PostTagEvent(tags[i], previousTagTransactionHashes[i]);
}
}
function getCurrentArticleTransactionBlockNumber(address authorAddress) external constant returns (uint) {
return currentArticleTransactionBlockNumberMap[authorAddress];
}
function sendEther(bytes32 transactionHash, address postAutherAddress, uint amount1, address appAuthorAddress, uint amount2) payable external {
state[transactionHash][0x0] = state[transactionHash][0x0] + amount1;
if (amount1 > 0) {
postAutherAddress.transfer(amount1);
}
if (amount2 > 0) {
appAuthorAddress.transfer(amount2);
}
}
/*
// 0, "Hello", 0xbf9eece36694d370f932d771db28eda83f9eb289092287e3d18e9093dff939c7, ["0x9cf4df7feca338c3d5957f305398db95ba3ac6b204dea352249c6b103b8efbb1"], ["0x9cf4df7feca338c3d5957f305398db95ba3ac6b204dea352249c6b103b8efbb1"]
event PostArticleEvent(uint version, string message, bytes32 previousArticleTransactionHash);
event PostTagEvent(bytes32 tag, bytes32 previousTagTransactionHash);
function postArticle(uint version, string message, bytes32 previousArticleTransactionHash, bytes32[] tags, bytes32[] previousTagTransactionHashes) external {
require(previousArticleTransactionHash != previousArticleTransactionHashMap[msg.sender]); // make sure there is no conflicts.
previousArticleTransactionHashMap[msg.sender] = previousArticleTransactionHash;
emit PostArticleEvent(version, message, previousArticleTransactionHash);
for (uint i = 0; i < tags.length; i++) {
previousTagTransactionHashMap[tags[i]] = previousTagTransactionHashes[i];
emit PostTagEvent(tags[i], previousTagTransactionHashes[i]);
}
}
event PostCommentEvent(uint version, bytes32 parentTransactionHash, string message, bytes32 previousCommentTransactionHash);
function postComment(uint version, bytes32 parentTransactionHash, string message, bytes32 previousCommentTransactionHash, bytes32[] tags, bytes32[] previousTagTransactionHashes) external {
require(previousCommentTransactionHash != previousCommentTransactionHashMap[parentTransactionHash]); // make sure there is no conflicts.
previousCommentTransactionHashMap[parentTransactionHash] = previousCommentTransactionHash;
emit PostCommentEvent(version, parentTransactionHash, message, previousCommentTransactionHash);
for (uint i = 0; i < tags.length; i++) {
previousTagTransactionHashMap[tags[i]] = previousTagTransactionHashes[i];
emit PostTagEvent(tags[i], previousCommentTransactionHash[i]);
}
}
function getPreviousArticleTransactionHash(address addr) external constant returns (bytes32) {
return previousArticleTransactionHashMap[addr];
}
function getPreviousCommentTransactionHash(bytes32 parent) external constant returns (bytes32) {
return previousCommentTransactionHashMap[parent];
}
function getPreviousTagTransactionHash(bytes32 tag) external constant returns(bytes32) {
return previousTagTransactionHashMap[tag];
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment