Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
12ac0ea
Changes data representation to bigInt
ltardivo Mar 10, 2025
fdfbe25
Removes commented code
ltardivo Mar 11, 2025
d0987a1
Adds safety check for writing big integers without losing precision
ltardivo Mar 12, 2025
58f5930
Adds back typeforce checks
ltardivo Mar 12, 2025
2c965d1
Removes satoshi checks
ltardivo Mar 12, 2025
ac1b177
Reads and writes unsigned integers. Adds boundary tests
ltardivo Mar 14, 2025
638acf4
Adds more instructions to chat README.md
ltardivo Mar 17, 2025
9c3799b
Lint
ltardivo Mar 17, 2025
38f51e5
Changes types to bigint (truncate to Number if needed)
ltardivo Mar 17, 2025
5d92826
Changes tsconfig target to es2020
ltardivo Mar 17, 2025
2ebda12
Update computer.d.ts types to support bigint
ltardivo Mar 17, 2025
8cb3da5
Fixes test
ltardivo Mar 18, 2025
1a4fe11
Fixes test funding for PEPE
ltardivo Mar 20, 2025
3129a63
Upload bundles
ltardivo Mar 21, 2025
f311aa3
Merge main into branch
ltardivo Mar 24, 2025
95dcbb7
Update docs. Sets _amount to bigint
ltardivo Mar 24, 2025
011499c
Increase time before running integration tests
ltardivo Mar 24, 2025
b380719
Update types
ltardivo Mar 24, 2025
5f93e04
Adds types to lib tests
ltardivo Mar 24, 2025
ff2afdb
Adds back typecheck
ltardivo Mar 25, 2025
3a910c9
Adds PATH to Auth
ltardivo Mar 25, 2025
767fdc0
Fixes bigint exception
ltardivo Mar 25, 2025
34ab715
Improves NFT deploy.ts script. Adds path. Checked on testnet
ltardivo Mar 25, 2025
96ed5aa
Fixes nakamotoJs integration tests
ltardivo Mar 25, 2025
98d08cf
Changes constant variable
ltardivo Mar 25, 2025
d6ebc9a
Adds back satoshi test
ltardivo Mar 25, 2025
486682a
Adds function formatBalance to components
ltardivo Mar 26, 2025
1ee04da
Displays satoshis in deploy scripts
ltardivo Mar 26, 2025
23a4b4b
Removes unneeded script
ltardivo Mar 26, 2025
c3bbc8f
Adds VITE_PATH to apps
ltardivo Mar 27, 2025
4cacb08
Adds utils functions bigInt2Str and str2BigInt
ltardivo Mar 27, 2025
95dac79
Uses bigInt constructor in constants
ltardivo Mar 27, 2025
e0c835d
Adds test to components package. Changes type to "module"
ltardivo Mar 27, 2025
edfaa7d
Uses new utils functions
ltardivo Mar 27, 2025
31eca96
Includes path in Auth component
ltardivo Mar 27, 2025
630e62e
Rename app title
ltardivo Mar 27, 2025
db4934f
Use number instead of bigint constant
ltardivo Mar 27, 2025
719b0e9
Removes unused command
ltardivo Mar 27, 2025
e3d3da7
Fixes test
ltardivo Mar 27, 2025
b1c2b75
Fixes str2BigInt function and tests
ltardivo Mar 31, 2025
bf67fbc
Fixes str2BigInt function and tests
ltardivo Apr 1, 2025
e69eecb
Upload bundles
ltardivo Apr 1, 2025
4393be5
Fixes value parsing for Dogecoin mainnet
ltardivo Apr 3, 2025
82ec572
Changes default log level to 4 (all logs) in .env.examples
ltardivo Apr 4, 2025
019015d
Upload node bundles
ltardivo Apr 4, 2025
ea8bc66
Reverts type module to components
ltardivo Apr 4, 2025
7dbd994
Upload lib bundles
ltardivo Apr 4, 2025
43abb4d
Changes keyword _amount by _satoshis
ltardivo Apr 7, 2025
c901063
Upload bundles
ltardivo Apr 7, 2025
33706a9
Adds logs to sync services
ltardivo Apr 8, 2025
a33d656
Fixes sync for failing txs BTC and LTC mainnet
ltardivo Apr 15, 2025
044e5b5
Update rpc-call.test.ts
ClemensLey May 1, 2025
e5c9df4
Update .env.local.example
ClemensLey May 1, 2025
f3f4253
Update .env.remote.example
ClemensLey May 1, 2025
7e9e0f7
Adds script to create indexes post syncing
ltardivo Jun 2, 2025
7b0b3c0
Upload bundles
ltardivo Jun 5, 2025
7864ba1
Removes db indexes for faster syncing
ltardivo Jun 5, 2025
297e8d5
Upload bundles
ltardivo Jun 9, 2025
2672891
Renames bigInt2Str to bigIntToStr
ltardivo Jun 10, 2025
8dd21b7
Removes constant
ltardivo Jun 10, 2025
a1b7a1f
Translate from bash to javascript
ltardivo Jun 10, 2025
eb0feae
Lint-fix
ltardivo Jun 10, 2025
b9b978b
Renames str2BigInt to strToBigInt, bigInt2Str to bigIntToStr
ltardivo Jun 10, 2025
ed5af9e
Upload bundles
ltardivo Jun 10, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
- name: Run integration tests
working-directory: packages/node
run: |
npm run test
sleep 30; npm run test

- name: Clear DockerHub credentials
run: |
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/TBC20/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"error",
{
"allowAfterThis": true,
"allow": ["_readers", "_owners", "_amount", "_id", "_rev", "_root"]
"allow": ["_readers", "_owners", "_satoshis", "_id", "_rev", "_root"]
}
]
}
Expand Down
22 changes: 11 additions & 11 deletions packages/TBC20/build/src/token.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
export declare class Token extends Contract {
amount: number;
amount: bigint;
name: string;
symbol: string;
_owners: string[];
constructor(to: string, amount: number, name: string, symbol?: string);
transfer(to: string, amount?: number): Token | undefined;
constructor(to: string, amount: bigint, name: string, symbol?: string);
transfer(to: string, amount?: bigint): Token | undefined;
burn(): void;
merge(tokens: Token[]): void;
}
export interface ITBC20 {
deploy(): Promise<string>;
mint(publicKey: string, amount: number, name: string, symbol: string): Promise<string>;
totalSupply(root: string): Promise<number>;
balanceOf(publicKey: string, root: string): Promise<number>;
transfer(to: string, amount: number, root: string): Promise<void>;
mint(publicKey: string, amount: bigint, name: string, symbol: string): Promise<string>;
totalSupply(root: string): Promise<bigint>;
balanceOf(publicKey: string, root: string): Promise<bigint>;
transfer(to: string, amount: bigint, root: string): Promise<void>;
}
export declare class TokenHelper implements ITBC20 {
name: string;
Expand All @@ -22,9 +22,9 @@ export declare class TokenHelper implements ITBC20 {
mod: string;
constructor(computer: any, mod?: string);
deploy(): Promise<string>;
mint(publicKey: string, amount: number, name: string, symbol: string): Promise<string | undefined>;
totalSupply(root: string): Promise<number>;
mint(publicKey: string, amount: bigint, name: string, symbol: string): Promise<string | undefined>;
totalSupply(root: string): Promise<bigint>;
private getBags;
balanceOf(publicKey: string, root: string): Promise<number>;
transfer(to: string, amount: number, root: string): Promise<void>;
balanceOf(publicKey: string, root: string): Promise<bigint>;
transfer(to: string, amount: bigint, root: string): Promise<void>;
}
8 changes: 4 additions & 4 deletions packages/TBC20/build/src/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class Token extends Contract {
throw new Error('Insufficient funds');
}
burn() {
this.amount = 0;
this.amount = 0n;
}
merge(tokens) {
let total = 0;
let total = 0n;
tokens.forEach((token) => {
total += token.amount;
token.burn();
Expand Down Expand Up @@ -52,7 +52,7 @@ export class TokenHelper {
if (typeof root === 'undefined')
throw new Error('Please pass a root into balanceOf.');
const bags = await this.getBags(publicKey, root);
return bags.reduce((prev, curr) => prev + curr.amount, 0);
return bags.reduce((prev, curr) => prev + curr.amount, 0n);
}
async transfer(to, amount, root) {
let _amount = amount;
Expand All @@ -61,7 +61,7 @@ export class TokenHelper {
const results = [];
while (_amount > 0 && bags.length > 0) {
const [bag] = bags.splice(0, 1);
const available = Math.min(_amount, bag.amount);
const available = _amount < bag.amount ? _amount : bag.amount;
results.push(await bag.transfer(to, available));
_amount -= available;
}
Expand Down
1 change: 0 additions & 1 deletion packages/TBC20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"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",
"start": "node build/src/main.js",
"test": "rm -rf dist && tsc -p tsconfig.test.json && mocha --config .mocharc.json",
"test:show": "npm run test 2>&1 | tee TBC20-test.log; if [ ${PIPESTATUS[0]} -ne 0 ]; then open TBC20-test.log; fi",
"types": "tsc --noEmit"
Expand Down
31 changes: 16 additions & 15 deletions packages/TBC20/src/token.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* eslint-disable max-classes-per-file */
/* eslint-disable no-underscore-dangle */

export class Token extends Contract {
amount: number
amount: bigint
name: string
symbol: string
_owners: string[]

constructor(to: string, amount: number, name: string, symbol = '') {
constructor(to: string, amount: bigint, name: string, symbol = '') {
super({ _owners: [to], amount, name, symbol })
}

transfer(to: string, amount?: number): Token | undefined {
transfer(to: string, amount?: bigint): Token | undefined {
if (typeof amount === 'undefined') {
// Send entire amount
this._owners = [to]
Expand All @@ -25,11 +26,11 @@ export class Token extends Contract {
}

burn() {
this.amount = 0
this.amount = 0n
}

merge(tokens: Token[]) {
let total = 0
let total = 0n
tokens.forEach((token) => {
total += token.amount
token.burn()
Expand All @@ -40,10 +41,10 @@ export class Token extends Contract {

export interface ITBC20 {
deploy(): Promise<string>
mint(publicKey: string, amount: number, name: string, symbol: string): Promise<string>
totalSupply(root: string): Promise<number>
balanceOf(publicKey: string, root: string): Promise<number>
transfer(to: string, amount: number, root: string): Promise<void>
mint(publicKey: string, amount: bigint, name: string, symbol: string): Promise<string>
totalSupply(root: string): Promise<bigint>
balanceOf(publicKey: string, root: string): Promise<bigint>
transfer(to: string, amount: bigint, root: string): Promise<void>
}

export class TokenHelper implements ITBC20 {
Expand All @@ -64,7 +65,7 @@ export class TokenHelper implements ITBC20 {

async mint(
publicKey: string,
amount: number,
amount: bigint,
name: string,
symbol: string,
): Promise<string | undefined> {
Expand All @@ -73,7 +74,7 @@ export class TokenHelper implements ITBC20 {
return token._root
}

async totalSupply(root: string): Promise<number> {
async totalSupply(root: string): Promise<bigint> {
const rootBag = await this.computer.sync(root)
return rootBag.amount
}
Expand All @@ -84,20 +85,20 @@ export class TokenHelper implements ITBC20 {
return bags.flatMap((bag: Token & { _root: string }) => (bag._root === root ? [bag] : []))
}

async balanceOf(publicKey: string, root: string): Promise<number> {
async balanceOf(publicKey: string, root: string): Promise<bigint> {
if (typeof root === 'undefined') throw new Error('Please pass a root into balanceOf.')
const bags = await this.getBags(publicKey, root)
return bags.reduce((prev, curr) => prev + curr.amount, 0)
return bags.reduce((prev, curr) => prev + curr.amount, 0n)
}

async transfer(to: string, amount: number, root: string): Promise<void> {
async transfer(to: string, amount: bigint, root: string): Promise<void> {
let _amount = amount
const owner = this.computer.getPublicKey()
const bags = await this.getBags(owner, root)
const results = []
while (_amount > 0 && bags.length > 0) {
const [bag] = bags.splice(0, 1)
const available = Math.min(_amount, bag.amount)
const available = _amount < bag.amount ? _amount : bag.amount
// eslint-disable-next-line no-await-in-loop
results.push(await bag.transfer(to, available))
_amount -= available
Expand Down
60 changes: 30 additions & 30 deletions packages/TBC20/test/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('Token', async () => {

describe('mint', async () => {
it('Sender mints 3 tokens', async () => {
token1 = await sender.new(Token, [sender.getPublicKey(), 3, 'test'])
token1 = await sender.new(Token, [sender.getPublicKey(), 3n, 'test'])
})

it('The meta data should be set', async () => {
expect(token1.amount).to.eq(3)
expect(token1.amount).to.eq(3n)
expect(token1._owners).deep.equal([sender.getPublicKey()])
expect(token1.name).to.eq('test')
expect(token1.symbol).to.eq('')
Expand All @@ -48,11 +48,11 @@ describe('Token', async () => {
let token2After: Token

it('Sender transfers 1 token to Receiver', async () => {
token2 = (await token1.transfer(receiver.getPublicKey(), 1)) as Token
token2 = (await token1.transfer(receiver.getPublicKey(), 1n)) as Token
})

it('The meta data of token should be set correctly', () => {
expect(token1.amount).to.eq(2)
expect(token1.amount).to.eq(2n)
expect(token1._owners).deep.equal([sender.getPublicKey()])
expect(token1.name).to.eq('test')
expect(token1.symbol).to.eq('')
Expand All @@ -62,7 +62,7 @@ describe('Token', async () => {
})

it('The meta data of newToken should be set correctly', () => {
expect(token2.amount).to.eq(1)
expect(token2.amount).to.eq(1n)
expect(token2._owners).deep.equal([receiver.getPublicKey()])
expect(token2.name).to.eq('test')
expect(token2.symbol).to.eq('')
Expand All @@ -75,12 +75,12 @@ describe('Token', async () => {
const senderRevs = await sender.query({ publicKey: sender.getPublicKey() })
expect(senderRevs.length).eq(1)
const senderToken = (await sender.sync(senderRevs[0])) as Token
expect(senderToken.amount).eq(2)
expect(senderToken.amount).eq(2n)

const receiverRevs = await receiver.query({ publicKey: receiver.getPublicKey() })
expect(receiverRevs.length).eq(1)
const receiverTokens = (await receiver.sync(receiverRevs[0])) as Token
expect(receiverTokens.amount).eq(1)
expect(receiverTokens.amount).eq(1n)
})

it('Receiver send token2 back to sender', async () => {
Expand Down Expand Up @@ -121,24 +121,24 @@ describe('Token', async () => {

it('Sender merges their two tokens', async () => {
await token1.merge([token2After])
expect(token1.amount).eq(3)
expect(token2After.amount).eq(0)
expect(token1.amount).eq(3n)
expect(token2After.amount).eq(0n)
})

it('Should burn a token', async () => {
await token1.burn()
expect(token1.amount).eq(0)
expect(token1.amount).eq(0n)

await token2.burn()
expect(token2.amount).eq(0)
expect(token2.amount).eq(0n)
})

it('Should update the revisions correctly', async () => {
const computer = new Computer({ url, chain, network })
await computer.faucet(2e8)
const t1 = await computer.new(Token, [computer.getPublicKey(), 3, 'test'])
const t1 = await computer.new(Token, [computer.getPublicKey(), 3n, 'test'])
const rev1 = t1._rev
const t2 = await t1.transfer(computer.getPublicKey(), 1)
const t2 = await t1.transfer(computer.getPublicKey(), 1n)
expect(t1!._rev).not.eq(rev1)
const rev2 = t2!._rev
await t2!.transfer(computer.getPublicKey())
Expand All @@ -153,7 +153,7 @@ describe('TokenHelper', () => {
let root: string
it('Should create the tokenHelper object', async () => {
const publicKey = tokenHelper.computer.getPublicKey()
root = await tokenHelper.mint(publicKey, 200, 'test', 'TST')
root = await tokenHelper.mint(publicKey, 200n, 'test', 'TST')
expect(root).not.to.be.undefined
expect(typeof root).to.eq('string')
expect(root.length).to.be.greaterThan(64)
Expand All @@ -165,7 +165,7 @@ describe('TokenHelper', () => {
expect(rootToken._id).to.eq(root)
expect(rootToken._rev).to.eq(root)
expect(rootToken._root).to.eq(root)
expect(rootToken.amount).to.eq(200)
expect(rootToken.amount).to.eq(200n)
expect(rootToken.name).to.eq('test')
expect(rootToken.symbol).to.eq('TST')
})
Expand All @@ -175,9 +175,9 @@ describe('TokenHelper', () => {
it('Should return the supply of tokens', async () => {
const tokenHelper = new TokenHelper(sender)
const publicKey = tokenHelper.computer.getPublicKey()
const root = await tokenHelper.mint(publicKey, 200, 'test', 'TST')
const root = await tokenHelper.mint(publicKey, 200n, 'test', 'TST')
const supply = await tokenHelper.totalSupply(root)
expect(supply).to.eq(200)
expect(supply).to.eq(200n)
})
})

Expand All @@ -198,10 +198,10 @@ describe('TokenHelper', () => {
it('Should compute the balance', async () => {
const tokenHelper = new TokenHelper(sender)
const publicKey = tokenHelper.computer.getPublicKey()
const root = await tokenHelper.mint(publicKey, 200, 'test', 'TST')
const root = await tokenHelper.mint(publicKey, 200n, 'test', 'TST')
await sleep(200)
const res = await tokenHelper.balanceOf(publicKey, root)
expect(res).to.eq(200)
expect(res).to.eq(200n)
})
})

Expand All @@ -210,29 +210,29 @@ describe('TokenHelper', () => {
const computer2 = new Computer({ url, chain, network })
const tokenHelper = new TokenHelper(sender)
const publicKey = tokenHelper.computer.getPublicKey()
const root = await tokenHelper.mint(publicKey, 200, 'test', 'TST')
const root = await tokenHelper.mint(publicKey, 200n, 'test', 'TST')
await sleep(200)
await tokenHelper.transfer(computer2.getPublicKey(), 20, root)
await tokenHelper.transfer(computer2.getPublicKey(), 20n, root)
await sleep(200)
const res = await tokenHelper.balanceOf(publicKey, root)
expect(res).to.eq(180)
expect(res).to.eq(180n)
})

it('Should transfer random amounts to different people', async () => {
const computer2 = new Computer({ url, chain, network })
const computer3 = new Computer({ url, chain, network })
const tokenHelper = new TokenHelper(sender)
const publicKey = tokenHelper.computer.getPublicKey()
const root = await tokenHelper.mint(publicKey, 200, 'multiple', 'MULT')
const amount2 = Math.floor(Math.random() * 100)
const amount3 = Math.floor(Math.random() * 100)
const root = await tokenHelper.mint(publicKey, 200n, 'multiple', 'MULT')
const amount2 = BigInt(Math.floor(Math.random() * 100))
const amount3 = BigInt(Math.floor(Math.random() * 100))
await sleep(200)
await tokenHelper.transfer(computer2.getPublicKey(), amount2, root)
await sleep(200)
await tokenHelper.transfer(computer3.getPublicKey(), amount3, root)
await sleep(200)
const res = await tokenHelper.balanceOf(publicKey, root)
expect(res).to.eq(200 - amount2 - amount3)
expect(res).to.eq(200n - amount2 - amount3)

const res2 = await tokenHelper.balanceOf(computer2.getPublicKey(), root)
expect(res2).to.eq(amount2)
Expand All @@ -245,10 +245,10 @@ describe('TokenHelper', () => {
const computer2 = new Computer({ url, chain, network })
const tokenHelper = new TokenHelper(sender)
const publicKey = tokenHelper.computer.getPublicKey()
const root = await tokenHelper.mint(publicKey, 200, 'test', 'TST')
const root = await tokenHelper.mint(publicKey, 200n, 'test', 'TST')
await sleep(200)
try {
await tokenHelper.transfer(computer2.getPublicKey(), 201, root)
await tokenHelper.transfer(computer2.getPublicKey(), 201n, root)
expect(true).to.eq('false')
} catch (err) {
expect(err.message).to.eq('Could not send entire amount')
Expand All @@ -258,10 +258,10 @@ describe('TokenHelper', () => {
const computer3 = new Computer({ url, chain, network })
const tbc20 = new TokenHelper(sender)
const pKey = tbc20.computer.getPublicKey()
const r = await tbc20.mint(pKey, 200, 'test', 'TST')
const r = await tbc20.mint(pKey, 200n, 'test', 'TST')
await sleep(200)
try {
await tbc20.transfer(computer3.getPublicKey(), 201, r)
await tbc20.transfer(computer3.getPublicKey(), 201n, r)
expect(true).to.eq('false')
} catch (err) {
expect(err.message).to.eq('Could not send entire amount')
Expand Down
Loading