Skip to content

Instantly share code, notes, and snippets.

@tonyofbyteball
tonyofbyteball / oscript2.md
Last active June 11, 2020 11:46
Oscript 2.0

Changes in Oscript 2.0

Functions

$f = ($x) => {
	 $a = var['a'];
	 $x * $a
};

// one-line syntax for functions that have only one expression
const path = require('path')
// eslint-disable-next-line no-unused-vars
const { Testkit, Utils } = require('aa-testkit')
const { Network } = Testkit({
TESTDATA_DIR: path.join(__dirname, '../testdata'),
})
describe('Check 2 wallets', function () {
this.timeout(120 * 1000)
@tonyofbyteball
tonyofbyteball / gist:ca071b74babdb368c0435fdff94f6858
Created April 20, 2020 23:30
Uniswap-like market maker with single-token contributions
{
init: `{
$asset = 'n9y3VomFeWFeZZ2PcSEcmyBb/bI7kzZduBJigNetnkY=';
$mm_asset = var['mm_asset'];
}`,
messages: {
cases: [
{ // define share asset
if: `{ trigger.data.define AND !$mm_asset }`,
messages: [
@tonyofbyteball
tonyofbyteball / draw-winner-selection-algo.js
Last active January 6, 2019 21:27
Provably fair algorithm of selecting the winner based on bitcoin hash
// bitcoin_hash is the hash (in hex) of the latest Bitcoin block
// arrPoints is array of points of all addresses ordered by address [{address: "...", points: 1234}, ...]
// rows1 is array of balances of all addresses ordered by address [{address: "...", balance: 1234}, ...]
// sum is the sum of all points
// 1. winner by points
let hash = crypto.createHash('sha256').update(bitcoin_hash).digest('hex');
let number = new BigNumber(hash, 16);
let random = (number.div(new BigNumber(2).pow(256))).times(sum);