This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
bsv, | |
buildContractClass, | |
getPreimage, | |
toHex, | |
num2bin, | |
SigHashPreimage, | |
signTx, | |
PubKey, | |
Sig, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "util.scrypt"; | |
contract TokenSellContract { | |
Ripemd160 bsvRecAddr; | |
int bsvRecAmount; | |
public function unlock( | |
SigHashPreimage txPreimage | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Backtrace { | |
static int DataLen = 46; | |
static function unpackunsigned(bytes b): int { | |
return unpack(b + b'00'); | |
} | |
static function readOutputScript(bytes tx, int outputIndex): bytes { | |
// first 4 bytes version | |
// 1 byte input num, only support max 253 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "util.scrypt"; | |
import "backtrace.scrypt"; | |
/** | |
* A token protocol based on UTXO model | |
*/ | |
contract Token { | |
public function split( | |
SigHashPreimage txPreimage, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract MerkleTree { | |
// TODO second preimage attack | |
static function calculateMerkleRoot(bytes leaf, bytes merklePath) : bytes { | |
int i = 0; | |
int merklePathLength = len(merklePath) / 33; | |
require(merklePathLength <= 5); | |
bytes merkleValue = leaf; | |
loop (5) { | |
if (i < merklePathLength) { | |
int left = unpack(merklePath[i * 33 + 32 : i * 33 + 33]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
bsv, | |
buildContractClass, | |
getPreimage, | |
toHex, | |
num2bin, | |
SigHashPreimage, | |
signTx, | |
PubKey, | |
Sig, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "util.scrypt"; | |
import "merkleTree2.scrypt"; | |
// the token swap has two merkle trees to save data. one for token user, one for pool and the pool token balance | |
contract TokenSwap { | |
// the contract init bsv amount | |
int initBsv; | |
// the swap pool first liquidity require amount | |
int firstSaveBsvAmount; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { bsv, buildContractClass, getPreimage, toHex, Ripemd160, num2bin, Bytes, SigHashPreimage } = require('scryptlib'); | |
const { DataLen, loadDesc, createUnlockingTx, createLockingTx, sendTx, showError } = require('../helper'); | |
const { | |
privateKey, | |
privateKey2 | |
} = require('../privateKey'); | |
(async() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "util.scrypt"; | |
contract BinaryOption { | |
int betPrice; | |
int rabinPubKey; | |
int timestamp; | |
Ripemd160 pubKeyHashA; | |
Ripemd160 pubKeyHashB; | |
function hash(bytes x): bytes { |