Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitcoin-util-fee

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcoin-util-fee - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

11

index.js

@@ -44,2 +44,6 @@ 'use strict'

TxFees.p2pkh_tx_calc_byte = function(input_num, output_num){
return TxFees.tx_calc_byte(TxFees.p2pkh_calc_input_byte(), input_num, output_num)
}
TxFees.p2sh_tx_calc_fee_create = function(m, n){

@@ -51,1 +55,8 @@ var input_byte = TxFees.p2sh_calc_input_byte(m, n)

}
TxFees.p2sh_tx_calc_byte_create = function(m, n){
var input_byte = TxFees.p2sh_calc_input_byte(m, n)
return function(input_num, output_num){
return TxFees.tx_calc_byte(input_byte, input_num, output_num)
}
}

2

package.json
{
"author": "Yuki Akiyama",
"name": "bitcoin-util-fee",
"version": "0.0.3",
"version": "0.0.4",
"private": false,

@@ -6,0 +6,0 @@ "dependencies": {

@@ -13,47 +13,36 @@ # node-bitcoin-fee-util

## 手数料の求め方
## simple transaction-fee calculate usage
ビットコインの手数料はトランザクションの送信バイト数によって決まる
please install [bitcoinfees-21co](https://www.npmjs.com/package/bitcoinfees-21co)
送信バイト数は以下の要因によって増加する
```
npm i bitcoinfees-21co
```
* 送金に使用する未使用トランザクションの数
* マルチシグであれば鍵の数、署名の数
* 混雑状況(MEMPOOL SIZE)
## 例:P2PKH
### P2PKH
一つの入力から一つの出力のパターン
```
var util = require('../');
var getBaseTransactionFees = function(input_num){
return util.tx_calc_fee(
util.tx_calc_byte(util.p2pkh_calc_input_byte(), input_num, 1),
util.getBaseBytePerSatoshi()
)
}
console.log(getBaseTransactionFees(1))
```
'use strict'
const bitcoinfees = require('bitcoinfees-21co');
const feeutil = require('bitcoin-util-fee');
## 例:P2SH
const getCurrentFees = () =>
bitcoinfees.FeesApi.recommended().then(res => res.fastestFee)
一つの入力から一つの出力のパターン
const process = () => {
const number_of_input = 1;
const number_of_output = 2;
const satoshi = feeutil.p2pkh_tx_calc_fee(number_of_input, number_of_output)
console.log("P2PKH fee %d satoshi", satoshi)
}
getCurrentFees().then(fee => {
feeutil.BASE_BYTE_PER_SATOSHI = fee; // initialize satoshi/byte rate
process()
})
```
var util = require('../');
var KEY_NUM = 3; // 鍵の数
var KEY_SIGN_NUM = 2; // 署名の数
var getBaseTransactionFees = function(m, n, input_num){
return util.tx_calc_fee(
util.tx_calc_byte(util.p2sh_calc_input_byte(m,n), input_num, 1),
util.getBaseBytePerSatoshi()
)
}
console.log(getBaseTransactionFees(KEY_SIGN_NUM, KEY_NUM, 1))
```
## ネットワークの混雑状況から最適な手数料を得る
### P2SH n-of-m multisig
21.coが混雑状況に合わせた手数料レートをAPI公開しているのでそれを使う

@@ -63,16 +52,25 @@ ```

const bitcoinfees = require('bitcoinfees-21co');
const util = require('../');
const MIN_FEE = 10000;
const feeutil = require('bitcoin-fee-util');
const getCurrentFees = () => bitcoinfees.FeesApi.recommended().then(res => res.hourFee)
const getCurrentFees = () =>
bitcoinfees.FeesApi.recommended().then(res => res.fastestFee)
const getTransactionFees = input_num => getCurrentFees().then( satoshi =>
Math.max(util.tx_calc_fee( util.tx_calc_byte(util.p2pkh_calc_input_byte(), input_num, 1), satoshi ), MIN_FEE)
)
const process = () => {
const number_of_input = 1;
const number_of_output = 2;
const p2sh_tx_calc_fee_2of3 = feeutil.p2sh_tx_calc_fee_create(2, 3);
const satoshi = p2sh_tx_calc_fee_2of3(number_of_input, number_of_output)
console.log("2of3 multisig fee %s satoshi", satoshi)
}
getTransactionFees(1).then(console.log)
getCurrentFees().then(fee => {
feeutil.BASE_BYTE_PER_SATOSHI = fee; // initialize satoshi/byte rate
process()
})
```
## LICENSE
MIT LICENSE

@@ -9,3 +9,3 @@ 'use strict';

describe('p2pkh test', function () {
it('p2pkh', function () {
it('p2pkh fee', function () {
assert.equal(util.p2pkh_tx_calc_fee(1, 1), 192)

@@ -15,2 +15,7 @@ assert.equal(util.p2pkh_tx_calc_fee(1, 2), 226)

})
it('p2pkh byte', function () {
assert.equal(util.p2pkh_tx_calc_byte(1, 1), 192)
assert.equal(util.p2pkh_tx_calc_byte(1, 2), 226)
assert.equal(util.p2pkh_tx_calc_byte(2, 2), 374)
})
})

@@ -21,9 +26,28 @@ describe('p2sh test', function () {

var p2sh_tx_calc_fee_2of3 = util.p2sh_tx_calc_fee_create(2, 3);
it('p2sh 1 of 1', function () {
var p2sh_tx_calc_byte_1of1 = util.p2sh_tx_calc_byte_create(1, 1);
var p2sh_tx_calc_byte_1of2 = util.p2sh_tx_calc_byte_create(1, 2);
var p2sh_tx_calc_byte_2of3 = util.p2sh_tx_calc_byte_create(2, 3);
it('p2sh 1 of 1 fee', function () {
assert.equal(p2sh_tx_calc_fee_1of1(1, 1), 198)
assert.equal(p2sh_tx_calc_fee_1of1(1, 2), 232)
assert.equal(p2sh_tx_calc_fee_1of1(2, 2), 386)
})
it('p2sh 1 of 1 byte', function () {
assert.equal(p2sh_tx_calc_byte_1of1(1, 1), 198)
assert.equal(p2sh_tx_calc_byte_1of1(1, 2), 232)
assert.equal(p2sh_tx_calc_byte_1of1(2, 2), 386)
})
it('p2sh 1 of 2', function () {
assert.equal(p2sh_tx_calc_fee_1of2(1, 1), 232)
assert.equal(p2sh_tx_calc_fee_1of2(1, 2), 266)
assert.equal(p2sh_tx_calc_fee_1of2(2, 2), 454)
})
it('p2sh 2 of 3', function () {
assert.equal(p2sh_tx_calc_fee_2of3(1, 1), 339)
assert.equal(p2sh_tx_calc_fee_2of3(1, 2), 373)
assert.equal(p2sh_tx_calc_fee_2of3(2, 2), 668)
assert.equal(p2sh_tx_calc_fee_2of3(3, 2), 963)
assert.equal(p2sh_tx_calc_fee_2of3(10, 2), 3028)
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc