Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/components/built/Auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Computer } from "@bitcoin-computer/lib";
import type { Chain, Network } from "./common/types";
import type { Chain, Network, ModuleStorageType } from "./common/types";
declare function isLoggedIn(): boolean;
declare function logout(): void;
declare function getCoinType(chain: string, network: string): number;
Expand All @@ -12,12 +12,14 @@ declare function loggedOutConfiguration(): {
chain: Chain;
network: Network;
url: string | undefined;
moduleStorageType: ModuleStorageType;
};
declare function loggedInConfiguration(): {
mnemonic: string | null;
chain: Chain;
network: Network;
url: string | undefined;
moduleStorageType: ModuleStorageType;
};
declare function getComputer(): Computer;
declare function LoginForm(): import("react/jsx-runtime").JSX.Element;
Expand Down
6 changes: 4 additions & 2 deletions packages/components/built/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ function loggedOutConfiguration() {
return {
chain: process.env.REACT_APP_CHAIN,
network: process.env.REACT_APP_NETWORK,
url: process.env.REACT_APP_URL
url: process.env.REACT_APP_URL,
moduleStorageType: process.env.REACT_APP_MODULE_STORAGE_TYPE
};
}
function loggedInConfiguration() {
return {
mnemonic: localStorage.getItem("BIP_39_KEY"),
chain: (localStorage.getItem("CHAIN") || process.env.REACT_APP_CHAIN),
network: (localStorage.getItem("NETWORK") || process.env.REACT_APP_NETWORK),
url: localStorage.getItem("URL") || process.env.REACT_APP_URL
url: localStorage.getItem("URL") || process.env.REACT_APP_URL,
moduleStorageType: process.env.REACT_APP_MODULE_STORAGE_TYPE
};
}
function getComputer() {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/built/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var LogOut = function () { return (_jsxs(_Fragment, { children: [_jsxs("div", __
export function Wallet(_a) {
var paymentModSpec = _a.paymentModSpec;
var computer = useContext(ComputerContext);
var Content = function () { return (_jsxs(_Fragment, { children: [_jsx("h4", __assign({ className: "text-2xl font-bold dark:text-white" }, { children: "Wallet" })), _jsx(Balance, { computer: computer, paymentModSpec: paymentModSpec }), _jsx(Address, { computer: computer }), _jsx(PublicKey, { computer: computer }), _jsx(Mnemonic, { computer: computer }), !process.env['REACT_APP_CHAIN'] && _jsx(Chain, { computer: computer }), !process.env['REACT_APP_NETWORK'] && _jsx(Network, { computer: computer }), !process.env['REACT_APP_URL'] && _jsx(Url, { computer: computer }), _jsx("hr", { className: "h-px my-6 bg-gray-200 border-0 dark:bg-gray-700" }), _jsx(LogOut, {})] })); };
var Content = function () { return (_jsxs(_Fragment, { children: [_jsx("h4", __assign({ className: "text-2xl font-bold dark:text-white" }, { children: "Wallet" })), _jsx(Balance, { computer: computer, paymentModSpec: paymentModSpec }), _jsx(Address, { computer: computer }), _jsx(PublicKey, { computer: computer }), _jsx(Mnemonic, { computer: computer }), !process.env.REACT_APP_CHAIN && _jsx(Chain, { computer: computer }), !process.env.REACT_APP_NETWORK && _jsx(Network, { computer: computer }), !process.env.REACT_APP_URL && _jsx(Url, { computer: computer }), _jsx("hr", { className: "h-px my-6 bg-gray-200 border-0 dark:bg-gray-700" }), _jsx(LogOut, {})] })); };
return _jsx(Drawer.Component, { Content: Content, id: "wallet-drawer" });
}
export var WalletComponents = {
Expand Down
1 change: 1 addition & 0 deletions packages/components/built/common/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type Chain = "LTC" | "BTC" | "DOGE" | "PEPE";
export type Network = "testnet" | "mainnet" | "regtest";
export type ModuleStorageType = "taproot" | "multisig";
8 changes: 5 additions & 3 deletions packages/components/src/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { initFlowbite } from "flowbite"
import { HiRefresh } from "react-icons/hi"
import { useUtilsComponents } from "./UtilsContext"
import { Modal } from "./Modal"
import type { Chain, Network } from "./common/types"
import type { Chain, Network, ModuleStorageType } from "./common/types"

function isLoggedIn(): boolean {
return !!localStorage.getItem("BIP_39_KEY")
Expand Down Expand Up @@ -39,7 +39,8 @@ function loggedOutConfiguration() {
return {
chain: process.env.REACT_APP_CHAIN as Chain,
network: process.env.REACT_APP_NETWORK as Network,
url: process.env.REACT_APP_URL
url: process.env.REACT_APP_URL,
moduleStorageType: process.env.REACT_APP_MODULE_STORAGE_TYPE as ModuleStorageType
}
}

Expand All @@ -48,7 +49,8 @@ function loggedInConfiguration() {
mnemonic: localStorage.getItem("BIP_39_KEY"),
chain: (localStorage.getItem("CHAIN") || process.env.REACT_APP_CHAIN) as Chain,
network: (localStorage.getItem("NETWORK") || process.env.REACT_APP_NETWORK) as Network,
url: localStorage.getItem("URL") || process.env.REACT_APP_URL
url: localStorage.getItem("URL") || process.env.REACT_APP_URL,
moduleStorageType: process.env.REACT_APP_MODULE_STORAGE_TYPE as ModuleStorageType
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/components/src/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type Chain = "LTC" | "BTC" | "DOGE" | "PEPE"
export type Network = "testnet" | "mainnet" | "regtest"
export type ModuleStorageType = "taproot" | "multisig"
6 changes: 4 additions & 2 deletions packages/docs/Lib/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ new (config: {
passphrase?: string
addressType?: 'p2pkh' | 'p2wpkh' | 'p2tr',
url?: string,
satPerByte?: number
dustRelayFee?: number
satPerByte?: number,
dustRelayFee?: number,
moduleStorageType?: 'taproot' | 'multisig'
}) => Computer
````

Expand All @@ -40,6 +41,7 @@ A configuration object
| url | Url of a Bitcoin Computer Node | https://rltc.node.bitcoincomputer.io |
| satPerByte | Fee in satoshi per byte | 2 |
| dustRelayFee | Dust relay fee | 30000 on LTC and 3000 on BTC |
| moduleStorageType | Store ES6 modules on Taproot or multisig scripts | taproot |


### Return Value
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/Lib/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The advantage of deploying your code is that it can save transaction fees: A lar
Please note that modules are not encrypted, even if objects that use them have the `_readers` property set.
!!!

There are two different modes to store a module on the blockchain: `taproot` or `multisig` mode. The default mode is `taproot`. The mode can be changed by passing the option `moduleStorageType` into the constructor of the `Computer` class. In Taproot mode, the module is stored in a Taproot script. This is cheeper and it enables you to store larger Javascript programs in a module. The multisig mode stores the module in multisig scripts. This is more expensive but compatible with chains that do not support Taproot.

### Type
```ts
(module: string) => Promise<string>
Expand Down
6 changes: 4 additions & 2 deletions packages/lib/computer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ declare class RestClient {
readonly keyPair: BIP32Interface;
readonly bcn: UrlFetch;
readonly dustRelayTxFee: number;
readonly moduleStorageType: ModuleStorageType;
satPerByte: number;
constructor({ chain, network, mnemonic, path, passphrase, addressType, url, satPerByte, dustRelayFee }?: ComputerOptions);
rpc(method: string, params: string): Promise<any>;
Expand Down Expand Up @@ -155,7 +156,7 @@ type ProgramMetaData = JObject &
_readers?: string[];
_url?: string;
}>;

type ModuleStorageType = 'multisig' | 'taproot';
interface FundOptions {
fund?: boolean;
include?: string[];
Expand All @@ -172,7 +173,7 @@ interface MockOptions {
[s: string]: Mock;
};
}
type InscriptionOptions = Partial<{
type ModuleOptions = Partial<{
commitAmount: number;
commitFee: number;
revealAmount: number;
Expand All @@ -191,6 +192,7 @@ type ComputerOptions = Partial<{
satPerByte: number;
dustRelayFee: number;
addressType: AddressType;
moduleStorageType: ModuleStorageType;
}>;

interface SecretOutput {
Expand Down
16 changes: 14 additions & 2 deletions packages/lib/dist/bc-lib.browser.min.mjs

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions packages/lib/dist/bc-lib.commonjs.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lib/dist/bc-lib.main.es.mjs

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions packages/lib/dist/bc-lib.module.es.mjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/nft/.env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ REACT_APP_URL=http://127.0.0.1:1031
# React Application Port
PORT=1034

# Module System Storage Type
REACT_APP_MODULE_STORAGE_TYPE=taproot

# Smart Contract Locations
# Run 'npm run deploy' and copy the output here
3 changes: 3 additions & 0 deletions packages/nft/.env.remote.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ REACT_APP_URL=http://127.0.0.1:1031
# React Application Port
PORT=1034

# Module System Storage Type
REACT_APP_MODULE_STORAGE_TYPE=taproot

# Smart Contract Locations
REACT_APP_NFT_MOD_SPEC=32ced85751dba336f47a46086e4df79e4b4925a30ebf0e39d2fbe0df4e4f5547:0
REACT_APP_OFFER_MOD_SPEC=575336fb0d7dc61579b0b65628b9d069e82c0cd0435085dc8a85c86167673add:0
Expand Down
3 changes: 3 additions & 0 deletions packages/nft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ REACT_APP_URL=http://127.0.0.1:1031
# Application Port
PORT=1034

# Module System Storage Type
REACT_APP_MODULE_STORAGE_TYPE=taproot

# Smart Contract Locations
REACT_APP_NFT_MOD_SPEC=32ced85751dba336f47a46086e4df79e4b4925a30ebf0e39d2fbe0df4e4f5547:0
REACT_APP_OFFER_MOD_SPEC=575336fb0d7dc61579b0b65628b9d069e82c0cd0435085dc8a85c86167673add:0
Expand Down
8 changes: 5 additions & 3 deletions packages/nft/scripts/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ const {
REACT_APP_CHAIN: chain,
REACT_APP_NETWORK: network,
REACT_APP_URL: url,
REACT_APP_MNEMONIC: mnemonic
REACT_APP_MNEMONIC: mnemonic,
REACT_APP_MODULE_STORAGE_TYPE: moduleStorageType,
} = process.env

if (network !== "regtest") {
if (!mnemonic) throw new Error("Please set MNEMONIC in the .env file")
computerProps["mnemonic"] = mnemonic
}

const computer = new Computer({ chain, network, mnemonic, url })
const computer = new Computer({ chain, network, mnemonic, url, moduleStorageType })
await computer.faucet(2e8)
const balance = await computer.wallet.getBalance()

Expand All @@ -31,7 +32,8 @@ Network \x1b[2m${network}\x1b[0m
Node Url \x1b[2m${url}\x1b[0m
Address \x1b[2m${computer.wallet.address}\x1b[0m
Mnemonic \x1b[2m${mnemonic}\x1b[0m
Balance \x1b[2m${balance.balance / 1e8}\x1b[0m`)
Balance \x1b[2m${balance.balance / 1e8}\x1b[0m
Module Storage Type \x1b[2m${computer.wallet.restClient.moduleStorageType}\x1b[0m`)

const answer = await rl.question("\nDo you want to deploy the contracts? \x1b[2m(y/n)\x1b[0m")
if (answer === "n") {
Expand Down
27 changes: 27 additions & 0 deletions packages/node/chain-setup/pepe-regtest/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,31 @@ services:
- CHAIN=PEPE
- BCN_URL=http://127.0.0.1:1031
restart: always
sync:
command: npm run sync
image: bitcoin-computer-node
env_file: .env
restart: always
environment:
- BCN_ENV=dev
- RPC_HOST=node
- RPC_PORT=19332
- NETWORK=regtest
- CHAIN=PEPE
- ZMQ_URL=tcp://node:28332
- BCN_URL=http://127.0.0.1:1031
- POSTGRES_PORT=5432
- POSTGRES_HOST=db
- RPC_PROTOCOL=http
- RPC_USER=${RPC_USER}
- RPC_PASSWORD=${RPC_PASSWORD}
- THREADS=${THREADS}
volumes:
- ./logs:/dist/packages/node/logs
depends_on:
- db
- node
networks:
- bitcoin
- bcn

4 changes: 2 additions & 2 deletions packages/nodejs-template/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Bitcoin Computer', () => {
_rev: _.isString,
_root: _.isString,
_amount: _.isNumber,
_owners: _.isArray,
_owners: _.isArray
})
})

Expand All @@ -66,7 +66,7 @@ describe('Bitcoin Computer', () => {
_rev: _.isString,
_root: _.isString,
_amount: _.isNumber,
_owners: _.isArray,
_owners: _.isArray
})
})
})
2 changes: 1 addition & 1 deletion packages/swap/build/src/buy.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Transaction } from '@bitcoin-computer/nakamotojs';
import { StaticSwapHelper } from './static-swap.js';
declare const Contract: typeof import("@bitcoin-computer/lib").Contract;
declare const Contract: typeof import("@bitcoin-computer/lib/computer.js").Contract;
export declare class Buy extends Contract {
amount: number;
constructor(price: number, amount: number, tokenRoot: string);
Expand Down
6 changes: 3 additions & 3 deletions packages/swap/build/src/sale.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* eslint-disable max-classes-per-file */
/// <reference types="node" />
import { Buffer } from 'buffer';
import type { Transaction as TransactionType } from '@bitcoin-computer/lib';
import { Payment, PaymentMock } from './payment.js';
declare const Contract: typeof import("@bitcoin-computer/lib").Contract;
declare const Contract: typeof import("@bitcoin-computer/lib/computer.js").Contract;
export declare class Sale extends Contract {
static exec(o: any, p: Payment): any[];
}

export declare class SaleHelper {
computer: any;
mod?: string;
constructor(computer: any, mod?: string);
deploy(): Promise<string>;
createSaleTx(object: any, payment: PaymentMock): any;
isSaleTx(tx: TransactionType): Promise<boolean>;
checkSaleTx(tx: TransactionType): Promise<number>;
static finalizeSaleTx(tx: TransactionType, payment: Payment, scriptPubKey: Buffer): TransactionType;
}
export {};
2 changes: 0 additions & 2 deletions packages/swap/build/src/sale.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Transaction } from '@bitcoin-computer/lib';
import { PaymentMock } from './payment.js';
const { Contract, Transaction } = await import('@bitcoin-computer/lib');
const sighashType = Transaction.SIGHASH_SINGLE | Transaction.SIGHASH_ANYONECANPAY;

export class Sale extends Contract {
static exec(o, p) {
const [ownerN] = o._owners;
Expand Down
1 change: 0 additions & 1 deletion packages/swap/src/sale.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable max-classes-per-file */
import { Buffer } from 'buffer'
import type { Transaction as TransactionType } from '@bitcoin-computer/lib'
import { Transaction } from '@bitcoin-computer/lib'
import { Payment, PaymentMock } from './payment.js'

const { Contract, Transaction } = await import('@bitcoin-computer/lib')
Expand Down