Skip to content
Permalink
Browse files

sample crowdfunding ATScript added

  • Loading branch information...
ATScriptDev committed Jan 31, 2018
1 parent 4ac9ed5 commit e5547d654a00b1c09f25d029c382885aef4c1dc9
Showing with 72 additions and 3 deletions.
  1. +6 −0 ATScompiler.js
  2. +65 −0 crowdfund.ats
  3. +1 −1 lib/ATScript-parser.js
  4. +0 −2 test.js
@@ -1,3 +1,9 @@
/***************************************************************************
ATScript compiler for BURST AT (Automated Transactions aka Smart Contracts).
See more at http://ATScript.net
***************************************************************************/

console.log("ATScript compiler. See more at http://atscript.net");
console.log("COPYRIGHT 2017 (c) ATScript Development Team");

@@ -0,0 +1,65 @@
/*************************************************************************************
Sample test code of ATScript for BURST AT (Automated Transactions aka Smart Contracts)

__NOT FOR USE IN PRODUCTION__

See more at http://ATScript.net
**************************************************************************************/

var timestamp;
var decision_time;
var txid;
var tx_amt;
var target_amt;
var target_acc;
var balance;
var tx_source;
var refund_time;

function funded(){
AT.transfer(balance, target_acc);
}

function refund(){
timestamp = refund_time;
txid = AT.getFirstTxAfterTimestamp(timestamp);
timestamp = AT.getTxTimestamp(txid);

while (txid) {
if (AT.getTxTarget(txid) == AT.getAddress()){
tx_source = AT.getTxSource(txid);
tx_amt = AT.getTxAmount(txid);
AT.transfer(tx_amt, tx_source);
}

txid = AT.getFirstTxAfterTimestamp(timestamp);
timestamp = AT.getTxTimestamp(txid);
}
}

function makeDecision(){
balance = AT.getBalance();

if (balance < target_amt){
refund();
} else {
funded();
}
}

timestamp = AT.getBlockTimestamp();
refund_time = timestamp;
decision_time = timestamp + 14*24*60*4; //decision_time in 14 days
target_amt = 10000;
target_acc = '...';

AT.loop(function () {
txid = AT.getFirstTxAfterTimestamp(timestamp);
timestamp = AT.getTxTimestamp(txid);

if(timestamp > decision_time){
makeDecision();
AT.halt();
}
});

@@ -1,5 +1,5 @@
/***********************************************************************
A ATScript parser for BURST AT (Automated Transactions aka Smart Contracts).
ATScript parser for BURST AT (Automated Transactions aka Smart Contracts).
See more at http://ATScript.net

This file was deleted.

Oops, something went wrong.

0 comments on commit e5547d6

Please sign in to comment.
You can’t perform that action at this time.