Skip to content

Commit

Permalink
Merge pull request #282 from interlay/dan/issue-util
Browse files Browse the repository at this point in the history
refactor: Add network param to issue util
  • Loading branch information
nud3l authored May 4, 2021
2 parents 0c41663 + 6f53be4 commit 1e82cad
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interlay/polkabtc",
"version": "0.14.2",
"version": "0.14.3",
"description": "JavaScript library to interact with PolkaBTC",
"main": "build/index.js",
"typings": "build/index.d.ts",
Expand Down Expand Up @@ -47,13 +47,10 @@
"regtest-client": "^0.2.0",
"sinon": "^9.0.3",
"ts-mock-imports": "^1.3.0",
"@polkadot/api": "3.11.1",
"@polkadot/typegen": "3.11.1",
"@polkadot/api": "4.8.1",
"@polkadot/typegen": "4.8.1",
"bitcoin-core": "^3.0.0"
},
"peerDependencies": {
"@polkadot/api": "3.11.1"
},
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/chai-as-promised": "^7.1.3",
Expand Down
2 changes: 1 addition & 1 deletion src/polkabtc-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Network, networks } from "bitcoinjs-lib";
export * from "./factory";
export * from "./parachain/transaction";

function getBitcoinNetwork(network: string = "mainnet"): Network {
export function getBitcoinNetwork(network: string = "mainnet"): Network {
switch (network) {
case "mainnet":
return networks.bitcoin;
Expand Down
2 changes: 0 additions & 2 deletions src/utils/bitcoin-core-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export class BitcoinCoreClient {
throw new Error("Client needs to be initialized before usage");
}

const paidOutput: { [key: string]: string } = {};
paidOutput[recipient] = amount.toString();
const raw = await this.client.command(
"createrawtransaction",
[],
Expand Down
9 changes: 5 additions & 4 deletions src/utils/issue.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ApiPromise } from "@polkadot/api";
import { KeyringPair } from "@polkadot/keyring/types";
import * as bitcoinjs from "bitcoinjs-lib";
import Big from "big.js";

import { btcToSat, satToBTC, IssueRequestExt } from "..";
import { btcToSat, satToBTC, IssueRequestExt, getBitcoinNetwork } from "..";
import { ElectrsAPI } from "../external/electrs";
import { DefaultCollateralAPI } from "../parachain/collateral";
import { IssueRequestResult, DefaultIssueAPI } from "../parachain/issue";
Expand All @@ -26,10 +25,12 @@ export async function issue(
amount: Big,
vaultAddress?: string,
autoExecute = true,
triggerRefund = false
triggerRefund = false,
network = "regtest",
): Promise<IssueResult> {
const treasuryAPI = new DefaultTreasuryAPI(api);
const issueAPI = new DefaultIssueAPI(api, bitcoinjs.networks.regtest, electrsAPI);
const bitcoinjsNetwork = getBitcoinNetwork(network);
const issueAPI = new DefaultIssueAPI(api, bitcoinjsNetwork, electrsAPI);
const collateralAPI = new DefaultCollateralAPI(api);

issueAPI.setAccount(issuingAccount);
Expand Down
6 changes: 2 additions & 4 deletions test/integration/parachain/release/redeem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ describe("redeem", () => {
let keyring: Keyring;
// alice is the root account
let alice: KeyringPair;
let ferdie: KeyringPair;

before(async () => {
api = await createPolkadotAPI(defaultParachainEndpoint);
keyring = new Keyring({ type: "sr25519" });
ferdie = keyring.addFromUri("//Ferdie");
alice = keyring.addFromUri("//Alice");
electrsAPI = new DefaultElectrsAPI("http://0.0.0.0:3002");
});
Expand All @@ -50,7 +48,7 @@ describe("redeem", () => {
"rpcuser",
"rpcpassword",
"18443",
vaultToLiquidate.address
"Bob"
);

// Steal some bitcoin (spend from the vault's account)
Expand All @@ -61,7 +59,7 @@ describe("redeem", () => {
await DefaultTransactionAPI.waitForEvent(api, api.events.stakedRelayers.VaultTheft, 17 * 60000);

// Burn PolkaBTC for a premium, to restore peg
redeemAPI.setAccount(ferdie);
redeemAPI.setAccount(alice);
await redeemAPI.burn(amount);

// it takes about 15 mins for the theft to be reported
Expand Down

0 comments on commit 1e82cad

Please sign in to comment.