Skip to content

Instantly share code, notes, and snippets.

View KardanovIR's full-sized avatar
🥸
Focusing

Inal Kardanov KardanovIR

🥸
Focusing
View GitHub Profile
{-# STDLIB_VERSION 4 #-}
{-# CONTENT_TYPE EXPRESSION #-}
{-# SCRIPT_TYPE ACCOUNT #-}
# specifying the ID of a token issued for this team
let assetId = base58'...'
# the address of an account in which the dApp and team members’ account list will be stored
let whiteListAddress = "..."
match tx {
@Callable(i)
func startFunding(id: Int, fundraisingEndTimestamp: Int, implmenetationEndTimestamp: Int, targetSum: Int) = {
# current time
let lastBlockTimestamp = lastBlock.timestamp
# The campaign end cannot be less than 60 seconds
if (fundraisingEndTimestamp - lastBlockTimestamp - 60 < 0) then throw("End time should at least 60 seconds more than the last block time") else
# The campaign end time cannot be less than the project execution time
if (implmenetationEndTimestamp < fundraisingEndTimestamp) then throw("Implementation end time should more or equal to endTimestamp") else
func keyFunding (id: Int) = "funding_" + id.toString()
func keyEndTimestamp(id: Int) = keyFunding(id) + "_timestamp"
func keyImplEndTimestamp(id: Int) = keyFunding(id) + "_impl_timestamp"
func keyTargetSum(id: Int) = keyFunding(id) + "_targetSum"
func keyOwner(id: Int) = keyFunding(id) + "_owner"
func keyRaised(id: Int) = keyFunding(id) + "_raised"
func keyReleaseVotes(id: Int) = keyFunding(id) + "_release_votes"
func keyReleasedTokens(id: Int) = keyFunding(id) + "_released"
@Callable(i)
func fund(id: Int) = {
# receiving an attached payment; if there is no payment, an exception will be created
let pmt = i.payments[0].extract()
# receiving campaign parameters
let targetSum = getIntegerValue(this, keyTargetSum(id))
let endTimestamp = getIntegerValue(this, keyEndTimestamp(id))
let owner = getStringValue(this, keyOwner(id))
@Callable(i)
func voteForRelease(id: Int) = {
# receiving campaign parameters
let endTimestamp = getIntegerValue(this, keyEndTimestamp(id))
let implEndTimestamp = getIntegerValue(this, keyImplEndTimestamp(id))
let votePower = getIntegerValue(this, keyUserFunded(id, i.callerPublicKey.toBase58String()))
let targetSum = getIntegerValue(this, keyTargetSum(id))
let raised = getIntegerValue(this, keyRaised(id))
let released = getBooleanValue(this, keyReleasedTokens(id))
@Callable(i)
func refundUser(id: Int) = {
# receiving campaign parameters
let endTimestamp = getIntegerValue(this, keyEndTimestamp(id))
let targetSum = getIntegerValue(this, keyTargetSum(id))
let raised = getIntegerValue(this, keyRaised(id))
# receiving the number of tokens sent by the current investor
let fundedAmount = getIntegerValue(this, keyUserFunded(id, i.callerPublicKey.toBase58String()))
pragma solidity ^0.5.11;
contract HelloWorld {
uint public myFavoriteNumber = 1610;
//define a new variable "yourFavoriteNumber" here
function myFavoriteNumberPlusYourFavoriteNumber() public view returns (uint) {
return myFavoriteNumber + yourFavoriteNumber;
}
modifier myModifier() {
//do something before the function calls
runningFunction = true;
_;
//do something after the function calls
runningFunction = false;
}
function coolFunction() public payable myModifier() {
// function body here
library GetCode {
function at(address _addr) public view returns (bytes memory o_code) {
assembly {
// retrieve the size of the code, this needs assembly
let size := extcodesize(_addr)
// allocate output byte array - this could also be done without assembly
// by using o_code = new bytes(size)
o_code := mload(0x40)
// new "memory end" including padding
mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
pragma solidity ^0.5.10;
// based on the skeleton file TicTacToe.sol by
// https://github.com/spidfire
contract TicTacToe {
uint[] board = new uint[](9);
address player1;
address player2;
uint whoseTurn = 1;