Skip to content

Commit

Permalink
added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh committed Apr 16, 2021
1 parent f612dfc commit 9d65a6b
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 14 deletions.
24 changes: 10 additions & 14 deletions packages/jellyfish-api-core/src/category/rawtx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ export class RawTx {
}

/**
* Create a transaction spending the given inputs and creating new outputs.
* Returns hex-encoded raw transaction.
* Note that the transaction's inputs are not signed, and
* it is not stored in the wallet or transmitted to the network.
* Create a transaction spending the given inputs and creating new outputs that returns a hex-encoded raw transaction.
* Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network.
*
* @param {CreateRawTxIn[]} inputs array of inputs
* @param {CreateRawTxOut[]} outputs array with outputs
Expand All @@ -45,11 +43,9 @@ export class RawTx {
}

/**
* Sign inputs for raw transaction (serialized, hex-encoded).
* The second argument is an array of base58-encoded private
* keys that will be the only keys used to sign the transaction.
* The third optional argument (may be null) is an array of previous transaction outputs that
* this transaction depends on but may not yet be in the block chain.
* Sign inputs for raw transaction (serialized, hex-encoded), Providing an array of base58-encoded private keys that
* will be the keys used to sign the transaction. An optional array of previous transaction outputs that this
* transaction depends on but may not yet be in the blockchain.
*
* @param {string} rawTx unsigned raw transaction
* @param {string[]} privKeys array of base58-encoded private keys for signing (WIF)
Expand All @@ -72,7 +68,8 @@ export class RawTx {

/**
* Returns result of mempool acceptance tests indicating if raw transaction would be accepted by mempool.
* This checks if the transaction violates the consensus or policy rules.
* This checks if the transaction violates the consensus or policy rules. The fee rate is expressed is DFI/kB,
* using the vSize of the transaction.
*
* @param {string} signedTx signed raw transaction
* @param {BigNumber} maxFeeRate Reject transactions whose fee rate is higher than the specified value. in DFI/kB
Expand All @@ -89,10 +86,9 @@ export class RawTx {
}

/**
* Submit a raw transaction (serialized, hex-encoded) to connected node and network.
* Note that the transaction will be sent unconditionally to all peers, so using this
* for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
* nodes will normally not rebroadcast non-wallet transactions already in their mempool.
* Submit a raw transaction (serialized, hex-encoded) to the connected node and network. The transaction will be sent
* unconditionally to all peers, so using this for manual rebroadcast may degrade privacy by leaking the transaction's
* origin, as nodes will normally not rebroadcast non-wallet transactions already in their mempool.
*
* @param {string} signedTx signed raw transaction
* @param {BigNumber} maxFeeRate Reject transactions whose fee rate is higher than the specified value. in DFI/kB
Expand Down
121 changes: 121 additions & 0 deletions website/docs/jellyfish/api/rawtx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
id: rawtx
title: Raw Transaction API
sidebar_label: RawTx API
slug: /jellyfish/api/rawtx
---

```js
import {Client} from '@defichain/jellyfish'
const client = new Client()

// Using client.rawtx.
const something = await client.rawtx.method()
```

## createRawTransaction

Create a transaction spending the given inputs and creating new outputs that returns a hex-encoded raw transaction.
Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network.

```ts title="client.rawtx.createRawTransaction()"
interface rawtx {
createRawTransaction (
inputs: CreateRawTxIn[],
outputs: CreateRawTxOut,
options: CreateRawTxOptions = {}
): Promise<string>
}

interface CreateRawTxOptions {
locktime?: number
replaceable?: boolean
}

interface CreateRawTxIn {
txid: string
vout: number
sequence?: number
}

interface CreateRawTxOut {
[address: string]: BigNumber
}
```


## signRawTransactionWithKey

Sign inputs for raw transaction (serialized, hex-encoded), Providing an array of base58-encoded private keys that will
be the keys used to sign the transaction. An optional array of previous transaction outputs that this transaction
depends on but may not yet be in the blockchain.

```ts title="client.rawtx.signRawTransactionWithKey()"
interface rawtx {
signRawTransactionWithKey (
rawTx: string,
privKeys: string[],
prevTxs?: SignRawTxWithKeyPrevTx[],
options: SignRawTxWithKeyOptions = {}
): Promise<SignRawTxWithKeyResult>
}

interface SignRawTxWithKeyPrevTx {
txid: string
vout: number
scriptPubKey: string
redeemScript?: string
witnessScript?: string
amount?: BigNumber
}

interface SignRawTxWithKeyOptions {
sigHashType?: SigHashType
}

enum SigHashType {
ALL = 'ALL',
NONE = 'NONE',
SINGLE = 'SINGLE',
ALL_ANYONECANPAY = 'ALL|ANYONECANPAY',
NONE_ANYONECANPAY = 'NONE|ANYONECANPAY',
SINGLE_ANYONECANPAY = 'SINGLE|ANYONECANPAY',
}
```

## testMempoolAccept

Returns result of mempool acceptance tests indicating if raw transaction would be accepted by mempool.
This checks if the transaction violates the consensus or policy rules. The fee rate is expressed is DFI/kB, using the
vSize of the transaction.

```ts title="client.rawtx.testMempoolAccept()"
interface rawtx {
testMempoolAccept (
signedTx: string,
maxFeeRate: BigNumber = new BigNumber('0')
): Promise<TestMempoolAcceptResult>
}

interface TestMempoolAcceptResult {
txid: string
allowed: boolean
'reject-reason'?: string
}

```

## sendRawTransaction

Submit a raw transaction (serialized, hex-encoded) to the connected node and network. The transaction will be sent
unconditionally to all peers, so using this for manual rebroadcast may degrade privacy by leaking the transaction's
origin, as nodes will normally not rebroadcast non-wallet transactions already in their mempool.

```ts title="client.rawtx.sendRawTransaction()"
interface rawtx {
sendRawTransaction (
signedTx: string,
maxFeeRate: BigNumber = new BigNumber('0')
): Promise<string>
}
```
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
items: [
'jellyfish/api/blockchain',
'jellyfish/api/mining',
'jellyfish/api/rawtx',
'jellyfish/api/wallet'
]
}
Expand Down

0 comments on commit 9d65a6b

Please sign in to comment.