GithubHelp home page GithubHelp logo

libitx / txforge Goto Github PK

View Code? Open in Web Editor NEW
62.0 62.0 21.0 1.88 MB

Modern Bitcoin transaction builder, capable of supporting any non-standard and custom script type.

License: Apache License 2.0

JavaScript 100.00%
bitcoin bsv javascript

txforge's People

Contributors

bvqbao avatar f1r3hydr4nt avatar geopic avatar libitx avatar mathiasrw avatar merlinb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

txforge's Issues

P2PKH.js - ReferenceError: casts is not defined (Unable to find module within Nimble)

Dear Community,

Sorry is me again. I'm referring to - nimble/classes/p2pkh.js

Have solved the first "import" issue that is to replace with - const { forgeTx } =require('txforge') and in the package.json, I've added "module":"true"

Right now, the next line problem is the:

const { P2PKH, OpReturn } =casts
^

ReferenceError: casts is not defined

I did add the word "require" --> const { P2PKH, OpReturn } =require('casts')
then the new error is:

node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'casts'
Require stack:

Question - how to search for "casts" module within nimble?

Kindly refer to the screenshot for your easy reference, thanks.

Screenshot 2022-08-12 at 8 42 59 PM

Screenshot 2022-08-12 at 8 44 57 PM

Format for 'myPrivateKey' in Example

Which Format must the 'myPrivateKey' be in the example forge Transaction?

I'm currently trying with bsv v2: const privKey = bsv.PrivKey.fromWif(myPrivateKey) but it does not work.

Maybe you could add a "real" privateKey as an example.

Can't run tests for the library

Hi,

I would like to modify the txforge library but I cannot run any test.
Here is the error:

npm run test

> [email protected] test /home/baobui/txforge
> mocha "test/**/*.test.js" --require esm


/home/baobui/txforge/test/cast.test.js:1
TypeError: Cannot read property 'OpCode' of undefined
    at Object.<anonymous> (/home/baobui/txforge/test/cast.test.js:8:17)
    at Generator.next (<anonymous>)
    at Object.exports.requireOrImport (/home/baobui/txforge/node_modules/mocha/lib/esm-utils.js:42:12)
    at Object.exports.loadFilesAsync (/home/baobui/txforge/node_modules/mocha/lib/esm-utils.js:55:34)
    at Mocha.loadFilesAsync (/home/baobui/txforge/node_modules/mocha/lib/mocha.js:473:19)
    at singleRun (/home/baobui/txforge/node_modules/mocha/lib/cli/run-helpers.js:125:15)
    at exports.runMocha (/home/baobui/txforge/node_modules/mocha/lib/cli/run-helpers.js:190:10)
    at Object.exports.handler (/home/baobui/txforge/node_modules/mocha/lib/cli/run.js:362:11)
    at /home/baobui/txforge/node_modules/yargs/build/index.cjs:443:71
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:60:5)
    at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `mocha "test/**/*.test.js" --require esm`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/baobui/.npm/_logs/2021-07-06T18_57_31_462Z-debug.log

I tried to run the tests for txforge on both Ubuntu and Windows. Same error!

It seems that there are problems with the bsv library. Is there any special setup that I missed in order to run the tests?

Thanks,

Error in build logic missing changeScript in some instances

In some cases the changeScript is not built despite it being set.

Issue appears to be here as length is undefined on a Script instance. Need to measure length of the binary script.

const changeSize = this.changeScript.length +

Dont understand why this works some times but not others. Should fail all the time. Needs more digging.

Review fee calculation logic

Reports that sometimes the fee gets calculated at 0.499 s/b. Review the fee calculation logic.
Possibly the feeEstimate function is just wrong. Possibly the p2pkh input size is wrong (check sig size).

Confused Between RunonBitcoin and TxForge - Unsolved Same Syntax Error

Dear Community,

I think I need help as I'm quite confused with the @runonbitcoin/nimble and TxForge. Yes, I downloaded TxForge via NPM into my MacBook. I found that there are 2 separate folders --> 1. @runonbitcoin/nimble and 2. TxForge.

As per the instruction after downloading (I'm using VSCode), I open the Nimble folder to "Run" the p2pkh.js but seems that there's an unsolved error, that is, "SyntaxError: The requested module '@runonbitcoin/nimble' does not provide an export named 'default'

import nimble from '@runonbitcoin/nimble'
^^^^^^

The source file of the error comes from ./txforge/src/classes/tape.js:1

Fyi, I did go back to the TxForge folder and then direct locate to src/classes/tape.js:1 --> inside of the code, I did input the following code, export default nimble

import nimble from '@runonbitcoin/nimble'
export default nimble

I did save but when I go back to Nimble/classes/p2pkh.js --> the SyntaxError remains the same.

I'm confused because 2 separate folders are unable to call each other even though I have put the 'export default' code.

Have attached the screenshot for your easy reference.

Please guide me, thanks.
Screenshot 2022-08-11 at 5 14 59 PM
Screenshot 2022-08-11 at 5 19 44 PM
Screenshot 2022-08-11 at 8 52 28 PM

Support nlocktime

Need to add a config attribute that is used in build() to set the nlocktime value.

Replace dust limit constant with dynamically calculated dust threshold

PR #7 by @freddiehonohan allowed the hardcoded dust limit to be overridden by the user with a dustLimit config option. This has been merged but not released yet.

Propose reverting this change and replacing the dust limit constant with a function that is determined by output script size and miner relay fee.

See https://github.com/bitcoin-sv/bitcoin-sv/blob/master/src/primitives/transaction.h#L188-L208 for reference.

Correct function should be:

dustLimit = 3 * (lockingScriptSize + 148) * minRelayTxFee / 1000

Required changes:

  1. rates config option should include mine and relay figures. User can provide their own rates object straight from minercraft. Care needed to ensure this isn't a breaking change for some.
  2. the build() function should calculate the dustLimit for each output programatically - as per function above
  3. no need for dust limit constant or config option

node:internal/modules/cjs/loader:936

I'm using VSCode on p2pkh.js but it seems that the code content itself requires Identification and Function, which is why the code p2pkh.js becomes like this below:

const { forgeTx } =require('txforge')

// We'll use these Casts in our transaction
const casts = () => { P2PKH, OpReturn }

// You'll need UTXOs to fund a transaction. Use the toUTXO helper to turn
// your UTXO data into the required objects.
const utxo = () => toUTXO({
txid, // utxo transaction id
vout, // utxo output index
satoshis, // utxo amount
script // utxo lock script
})

// Forge a transaction
const P2PKH = () => { P2PKH }
const myPrivateKey = () => { myPrivateKey }

const tx = forgeTx({

inputs: [
function unlock() {
P2PKH.unlock(utxo, { privkey: myPrivateKey })
}
],
outputs: [
function lock() {
P2PKH.lock(5000, { address: '1DBz6V6CmvjZTvfjvWpvvwuM1X7GkRmWEq' }),
OpReturn.lock(0, { data: ['meta', '1DBz6V6CmvjZTvfjvWpvvwuM1X7GkRmWEq', txid] })
}
],
change: { address: '1Nro9WkpaKm9axmcfPVp79dAJU1Gx7VmMZ' }
})

// And behold! Forged by the Gods and found by a King - a transaction is born.
console.log(tx.toHex())

  • When I "Run" the above the error prompted as:

node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module '/Users/jsjs77/node_modules/@runonbitcoin/nimble/classes/p2pkhs.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []

Any solution for the above? Note that my VScode in Mac unable to Import, that's why use "const"

Thanks

Expose dustThreshold function

The function dustThreshold is currently internal but is actually pretty useful.

Considering exposing utility functions as part of the package.

Transaction Version Number

Sometimes TxForge creates transactions which have their version byte set to 00 rather than 01.

I cannot figure out why (so far).

readme fix

now we got a

// Assuming the UTXO is a P2PKH input, we can sign it with a KeyPair
forge1
  .buld()
  .sign({ keyPair }) 

buld() --> build()

I guess that is a typo.

Throw helpful error when wrong version of bsv is required within txforge

TypeError: Cannot read property 'OP_RETURN' of undefined at Object. (/workspace/node_modules/txforge/dist/txforge.cjs.js:354:18) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) at Module.load (internal/modules/cjs/loader.js:977:32) at Function.Module._load (internal/modules/cjs/loader.js:877:14) at Module.require (internal/modules/cjs/loader.js:1019:19) at require (internal/modules/cjs/helpers.js:77:18) at Object. (/workspace/hybrid-server.js:35:19) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)

npm version 0.1.7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.