Skip to content
Open
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
69 changes: 48 additions & 21 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"lint:fix": "npm run lint --if-present --workspaces -- --fix",
"prepare": "husky",
"test:rerun": "node ./scripts/rerun-failed.js",
"test:compile:mocha": "npm run compile:test --if-present --workspace=@bitcoin-computer/lib --workspace=@bitcoin-computer/swap --workspace=@bitcoin-computer/TBC20 --workspace=@bitcoin-computer/TBC721 --workspace=@bitcoin-computer/nodejs-template --workspace=@bitcoin-computer/nakamotojs",
"test:compile:mocha": "npm run build:test --if-present --workspaces",
"test:mocha:all": "npm run test:compile:mocha && BITCOIN_RPC_HOST=127.0.0.1 BCN_CHAIN=LTC BCN_NETWORK=regtest POSTGRES_HOST=127.0.0.1 BITCOIN_RPC_HOST=127.0.0.1 BCN_ZMQ_URL=tcp://127.0.0.1:28332 mocha --config .mocharc.json",
"test:puppeteer:build": "npm run test:puppeteer:build --if-present --workspace=@bitcoin-computer/vite-template",
"prepublishOnly": "./scripts/check-obfuscation.sh && npm run test",
Expand Down
6 changes: 3 additions & 3 deletions packages/TBC20/build/src/token.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract } from '@bitcoin-computer/lib';
import { Computer } from '@bitcoin-computer/lib';
export declare class Token extends Contract {
amount: bigint;
name: string;
Expand All @@ -19,9 +19,9 @@ export interface ITBC20 {
export declare class TokenHelper implements ITBC20 {
name: string;
symbol: string;
computer: any;
computer: Computer;
mod: string;
constructor(computer: any, mod?: string);
constructor(computer: Computer, mod?: string);
deploy(): Promise<string>;
mint(publicKey: string, amount: bigint, name: string, symbol: string): Promise<string | undefined>;
totalSupply(root: string): Promise<bigint>;
Expand Down
6 changes: 2 additions & 4 deletions packages/TBC20/build/src/token.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Contract } from '@bitcoin-computer/lib';
export class Token extends Contract {
constructor(to, amount, name, symbol = '') {
super({ _owners: [to], amount, name, symbol });
Expand Down Expand Up @@ -37,12 +36,11 @@ export class TokenHelper {
return this.mod;
}
async mint(publicKey, amount, name, symbol) {
const args = [publicKey, amount, name, symbol];
const token = await this.computer.new(Token, args, this.mod);
const token = await this.computer.new(Token, [publicKey, amount, name, symbol], this.mod);
return token._root;
}
async totalSupply(root) {
const rootBag = await this.computer.sync(root);
const rootBag = (await this.computer.sync(root));
return rootBag.amount;
}
async getBags(publicKey, root) {
Expand Down
4 changes: 1 addition & 3 deletions packages/TBC20/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ export default tseslint.config(
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
// remove them later
'@typescript-eslint/ban-ts-comment': 'off',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
)
2 changes: 1 addition & 1 deletion packages/TBC20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build:watch": "tsc -w -p tsconfig.release.json",
"clean": "rm -rf coverage build tmp",
"clean:logs": "rm -f *.log 2> /dev/null",
"compile:test": "rm -rf dist && tsc -p tsconfig.test.json",
"build:test": "rm -rf dist && tsc -p tsconfig.test.json",
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,md}\"",
"lint": "eslint src test --ext .ts,.tsx",
"lint:fix": "eslint src test --ext .ts,.tsx --fix",
Expand Down
12 changes: 6 additions & 6 deletions packages/TBC20/src/token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Contract } from '@bitcoin-computer/lib'
import { Computer } from '@bitcoin-computer/lib'

// eslint-disable-next-line
type Constructor<T> = new (...args: any[]) => T

export class Token extends Contract {
Expand Down Expand Up @@ -52,10 +53,10 @@ export interface ITBC20 {
export class TokenHelper implements ITBC20 {
name: string
symbol: string
computer: any
computer: Computer
mod: string

constructor(computer: any, mod?: string) {
constructor(computer: Computer, mod?: string) {
this.computer = computer
this.mod = mod
}
Expand All @@ -71,13 +72,12 @@ export class TokenHelper implements ITBC20 {
name: string,
symbol: string,
): Promise<string | undefined> {
const args = [publicKey, amount, name, symbol]
const token = await this.computer.new(Token, args, this.mod)
const token = await this.computer.new(Token, [publicKey, amount, name, symbol], this.mod)
return token._root
}

async totalSupply(root: string): Promise<bigint> {
const rootBag = await this.computer.sync(root)
const rootBag = (await this.computer.sync(root)) as Token
return rootBag.amount
}

Expand Down
2 changes: 1 addition & 1 deletion packages/TBC20/test/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('TokenHelper', () => {
})

it('Should mint a root token', async () => {
const rootToken: any = await sender.sync(root)
const rootToken = (await sender.sync(root)) as Token
expect(rootToken).not.to.be.undefined
expect(rootToken._id).to.eq(root)
expect(rootToken._rev).to.eq(root)
Expand Down
5 changes: 3 additions & 2 deletions packages/TBC721/build/src/nft.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Computer } from '@bitcoin-computer/lib';
export declare class NFT extends Contract {
name: string;
artist: string;
Expand All @@ -16,9 +17,9 @@ export interface ITBC721 {
transfer(to: string, tokenId: string): Promise<void>;
}
export declare class NftHelper implements ITBC721 {
computer: any;
computer: Computer;
mod: string | undefined;
constructor(computer: any, mod?: string);
constructor(computer: Computer, mod?: string);
deploy(): Promise<string>;
mint(name: string, artist: string, url: string): Promise<NFT>;
balanceOf(publicKey: string): Promise<number>;
Expand Down
10 changes: 5 additions & 5 deletions packages/TBC721/build/src/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ export class NftHelper {
return this.mod;
}
async mint(name, artist, url) {
const { tx, effect } = await this.computer.encode({
const { tx, effect } = (await this.computer.encode({
exp: `new NFT("${name}", "${artist}", "${url}")`,
mod: this.mod,
});
}));
await this.computer.broadcast(tx);
return effect.res;
}
async balanceOf(publicKey) {
const { mod } = this;
const revs = await this.computer.getOUTXOs({ publicKey, mod });
const objects = await Promise.all(revs.map((rev) => this.computer.sync(rev)));
const objects = (await Promise.all(revs.map((rev) => this.computer.sync(rev))));
return objects.length;
}
async ownersOf(tokenId) {
const rev = await this.computer.latest(tokenId);
const obj = await this.computer.sync(rev);
const obj = (await this.computer.sync(rev));
return obj._owners;
}
async transfer(to, tokenId) {
const rev = await this.computer.latest(tokenId);
const obj = await this.computer.sync(rev);
const obj = (await this.computer.sync(rev));
await obj.transfer(to);
}
}
5 changes: 1 addition & 4 deletions packages/TBC721/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import js from '@eslint/js'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist', 'build'] },
{
Expand All @@ -15,10 +14,8 @@ export default tseslint.config(
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
// remove them later
'@typescript-eslint/ban-ts-comment': 'off',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
)
2 changes: 1 addition & 1 deletion packages/TBC721/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build:watch": "tsc -w -p tsconfig.release.json",
"clean": "rm -rf coverage build tmp",
"clean:logs": "rm -f *.log 2> /dev/null",
"compile:test": "rm -rf dist && tsc -p tsconfig.test.json",
"build:test": "rm -rf dist && tsc -p tsconfig.test.json",
"deploy": "npx tsx src/deploy.ts",
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,md}\"",
"lint": "eslint --fix . --ext .ts,.tsx --ignore-pattern build/",
Expand Down
18 changes: 11 additions & 7 deletions packages/TBC721/src/nft.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Computer } from '@bitcoin-computer/lib'

export class NFT extends Contract {
name: string
artist: string
Expand Down Expand Up @@ -28,10 +30,10 @@ export interface ITBC721 {
}

export class NftHelper implements ITBC721 {
computer: any
computer: Computer
mod: string | undefined

constructor(computer: any, mod?: string) {
constructor(computer: Computer, mod?: string) {
this.computer = computer
this.mod = mod
}
Expand All @@ -42,30 +44,32 @@ export class NftHelper implements ITBC721 {
}

async mint(name: string, artist: string, url: string): Promise<NFT> {
const { tx, effect } = await this.computer.encode({
const { tx, effect } = (await this.computer.encode({
exp: `new NFT("${name}", "${artist}", "${url}")`,
mod: this.mod,
})
})) as { tx; effect }
await this.computer.broadcast(tx)
return effect.res
}

async balanceOf(publicKey: string): Promise<number> {
const { mod } = this
const revs = await this.computer.getOUTXOs({ publicKey, mod })
const objects: NFT[] = await Promise.all(revs.map((rev: string) => this.computer.sync(rev)))
const objects: NFT[] = (await Promise.all(
revs.map((rev: string) => this.computer.sync(rev)),
)) as NFT[]
return objects.length
}

async ownersOf(tokenId: string): Promise<string[]> {
const rev = await this.computer.latest(tokenId)
const obj = await this.computer.sync(rev)
const obj = (await this.computer.sync(rev)) as NFT
return obj._owners
}

async transfer(to: string, tokenId: string): Promise<void> {
const rev = await this.computer.latest(tokenId)
const obj = await this.computer.sync(rev)
const obj = (await this.computer.sync(rev)) as NFT
await obj.transfer(to)
}
}
4 changes: 2 additions & 2 deletions packages/TBC721/test/nft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const network = process.env.BCN_NETWORK
const artist = ''
const imageUrl = ''

// eslint-disable-next-line
const isString = (x: any) => typeof x === 'string'
// eslint-disable-next-line
const isArray = (x: any) => Array.isArray(x)

export const meta = {
Expand Down Expand Up @@ -56,7 +58,6 @@ describe('NFT', () => {

it('Sender mints an NFT', async () => {
nft = await sender.new(NFT, ['Test'])
// @ts-ignore
expect(nft).matchPattern({ name: 'Test', artist, url: imageUrl, ...meta })

// Property _owners is a singleton array with minters public key
Expand All @@ -77,7 +78,6 @@ describe('NFT', () => {

// Sender transfers the NFT to receiver
await nft.transfer(receiver.getPublicKey())
// @ts-ignore
expect(nft).to.matchPattern({ name: 'Test', artist, url: imageUrl, ...meta })

// The id does not change
Expand Down
4 changes: 2 additions & 2 deletions packages/chess-contracts/build/src/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/chess-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"@bitcoin-computer/lib": "^0.26.0-beta.0",
"@bitcoin-computer/nakamotojs": "^0.26.0-beta.0",
"@bitcoin-computer/secp256k1": "^0.26.0-beta.0",
"assert": "^2.0.0",
"bip32": "^4.0.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/components/built/ActionButtons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
const actionButtonPadding = 'py-1.5 px-2';
const actionButtonFocus = 'focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-800';
const actionButtonDisabled = 'disabled:opacity-50 disabled:cursor-not-allowed';
// Shared SVG loader component
const Loader = () => (_jsxs("svg", { "aria-hidden": "true", role: "status", className: "inline w-4 h-4 ml-3 text-white animate-spin dark:text-gray-400", viewBox: "0 0 100 101", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("path", { d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z", fill: "currentColor" }), _jsx("path", { d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z", fill: "currentColor" })] }));
// Primary Action Button (Blue button)
Expand All @@ -16,7 +19,7 @@ export const PrimaryActionButton = ({ text, onClick, disabled = false, className
setIsLoading(false);
}
};
return (_jsxs("button", { type: "button", className: `text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center me-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 inline-flex items-center disabled:bg-gray-400 disabled:text-gray-700 disabled:cursor-not-allowed dark:disabled:bg-gray-600 dark:disabled:text-gray-300 ${className}`, onClick: handleClick, disabled: isLoading || disabled, children: [text, isLoading && _jsx(Loader, {})] }));
return (_jsxs("button", { type: "button", className: `inline-flex items-center justify-center rounded-lg text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 ${actionButtonPadding} ${actionButtonFocus} focus:ring-blue-500 dark:bg-blue-600 dark:hover:bg-blue-700 ${actionButtonDisabled} ${className}`, onClick: handleClick, disabled: isLoading || disabled, children: [text, isLoading && _jsx(Loader, {})] }));
};
// Secondary Action Button (Gray/Alternative button)
export const SecondaryActionButton = ({ text, onClick, disabled = false, className = '', }) => {
Expand All @@ -32,5 +35,5 @@ export const SecondaryActionButton = ({ text, onClick, disabled = false, classNa
setIsLoading(false);
}
};
return (_jsxs("button", { type: "button", className: `py-2.5 px-5 me-2 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 inline-flex items-center disabled:bg-gray-200 disabled:text-gray-500 disabled:cursor-not-allowed dark:disabled:bg-gray-700 dark:disabled:text-gray-400 ${className}`, onClick: handleClick, disabled: isLoading || disabled, children: [text, isLoading && _jsx(Loader, {})] }));
return (_jsxs("button", { type: "button", className: `inline-flex items-center justify-center rounded-lg border border-gray-200 bg-white text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white ${actionButtonPadding} ${actionButtonFocus} focus:ring-gray-400 dark:focus:ring-gray-600 ${actionButtonDisabled} ${className}`, onClick: handleClick, disabled: isLoading || disabled, children: [text, isLoading && _jsx(Loader, {})] }));
};
4 changes: 4 additions & 0 deletions packages/components/built/DecodeTransaction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare function DecodedransactionComponent(): import("react/jsx-runtime").JSX.Element;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rename in all relevant files:

  • DecodedransactionComponent -> DecodeTransactionComponent
  • Decodedransaction -> DecodeTransaction

export declare const Decodedransaction: {
Component: typeof DecodedransactionComponent;
};
40 changes: 40 additions & 0 deletions packages/components/built/DecodeTransaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useContext, useEffect, useState } from 'react';
import { useLocation, useParams } from 'react-router-dom';
import { Transaction as BCTransaction } from '@bitcoin-computer/lib';
import { ComputerContext } from './ComputerContext';
import { inputsComponent, outputsComponent, transitionComponent } from './Transaction';
export function DecodedransactionComponent() {
const location = useLocation();
const params = useParams();
const computer = useContext(ComputerContext);
const [txnData, setTxnData] = useState(null);
const [rpcTxnData, setRPCTxnData] = useState(null);
const [transition, setTransition] = useState(null);
useEffect(() => {
const fetch = async () => {
const txnDeserialized = BCTransaction.deserialize(params.txn);
setTxnData(txnDeserialized);
const { result } = await computer.rpc('decoderawtransaction', `${txnDeserialized.toHex()} false`);
setRPCTxnData(result);
};
fetch();
}, [computer, location, params.txn]);
useEffect(() => {
const fetch = async () => {
try {
if (txnData) {
setTransition(await computer.decode(txnData));
}
}
catch (err) {
if (err instanceof Error) {
setTransition('');
}
}
};
fetch();
}, [computer, txnData]);
return (_jsx(_Fragment, { children: _jsxs("div", { className: "pt-8", children: [_jsx("h1", { className: "mb-2 text-5xl font-extrabold dark:text-white", children: "Decoded Transaction" }), transition && transitionComponent({ transition }), rpcTxnData?.vin && inputsComponent({ rpcTxnData, checkForSpentInput: true }), rpcTxnData?.vout && outputsComponent({ rpcTxnData, txn: undefined })] }) }));
}
export const Decodedransaction = { Component: DecodedransactionComponent };
11 changes: 11 additions & 0 deletions packages/components/built/Transaction.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
export declare const outputsComponent: ({ rpcTxnData, txn, }: {
rpcTxnData: any;
txn: string | undefined;
}) => import("react/jsx-runtime").JSX.Element;
export declare const inputsComponent: ({ rpcTxnData, checkForSpentInput, }: {
rpcTxnData: any;
checkForSpentInput: boolean;
}) => import("react/jsx-runtime").JSX.Element;
export declare const transitionComponent: ({ transition }: {
transition: any;
}) => import("react/jsx-runtime").JSX.Element;
export declare function TransactionComponent(): import("react/jsx-runtime").JSX.Element;
export declare const Transaction: {
Component: typeof TransactionComponent;
Expand Down
Loading