-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabriel Cardona
committed
Sep 22, 2019
1 parent
8febc0d
commit 73fdd1f
Showing
4 changed files
with
170 additions
and
71 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { BITBOX } from "bitbox-sdk" | ||
import { ECPair, HDNode } from "bitcoincashjs-lib" | ||
import { Contract, Instance } from "cashscript" | ||
import * as path from "path" | ||
import { PriceOracle } from "./src/routes/v1/PriceOracle" | ||
|
||
run() | ||
export async function run(): Promise<void> { | ||
// Initialise BITBOX | ||
const network: string = "testnet" | ||
const bitbox: BITBOX = new BITBOX({ | ||
restURL: "https://trest.bitcoin.com/v2/" | ||
}) | ||
|
||
// Initialise HD node and owner's keypair | ||
const rootSeed: Buffer = bitbox.Mnemonic.toSeed("") | ||
const hdNode: HDNode = bitbox.HDNode.fromSeed(rootSeed, network) | ||
const owner: ECPair = bitbox.HDNode.toKeyPair(bitbox.HDNode.derive(hdNode, 0)) | ||
|
||
// Initialise price oracle with a keypair | ||
const oracle: PriceOracle = new PriceOracle( | ||
bitbox.HDNode.toKeyPair(bitbox.HDNode.derive(hdNode, 1)) | ||
) | ||
|
||
// Compile and instantiate HODL Vault | ||
const HodlVault: Contract = Contract.fromCashFile( | ||
path.join(__dirname, "./src/routes/v1/contracts/hodl_vault.cash"), | ||
"testnet" | ||
) | ||
const instance: Instance = HodlVault.new( | ||
bitbox.ECPair.toPublicKey(owner), | ||
bitbox.ECPair.toPublicKey(oracle.keypair), | ||
597000, | ||
30000 | ||
) | ||
|
||
// Get contract balance & output address + balance | ||
const contractBalance: number = await instance.getBalance() | ||
console.log("contract address:", instance.address) | ||
console.log("contract balance:", contractBalance) | ||
|
||
// Produce new oracle message and signature | ||
// const oracleMessage: Buffer = oracle.createMessage(597000, 30000) | ||
// const oracleSignature: Buffer = oracle.signMessage(oracleMessage) | ||
|
||
// // Spend from the vault | ||
// const tx: TxnDetailsResult = await instance.functions | ||
// .spend(new Sig(owner, 0x01), oracleSignature, oracleMessage) | ||
// .send(instance.address, 1000) | ||
|
||
// console.log(tx) | ||
} |
Oops, something went wrong.