Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rawtx): add decodeRawTransaction function #1963

Merged
merged 8 commits into from
Jan 13, 2023

Conversation

DocteurPing
Copy link

What this PR does / why we need it:

This PR adds the function decodeRawTransaction.

@github-actions github-actions bot added area/packages kind/feature New feature request labels Jan 11, 2023
@codeclimate
Copy link

codeclimate bot commented Jan 11, 2023

Code Climate has analyzed commit 50c1e3f and detected 0 issues on this pull request.

View more on Code Climate.

@netlify
Copy link

netlify bot commented Jan 11, 2023

Deploy Preview for jellyfishsdk ready!

Name Link
🔨 Latest commit 50c1e3f
🔍 Latest deploy log https://app.netlify.com/sites/jellyfishsdk/deploys/63c12948c43f0a0008c1e437
😎 Deploy Preview https://deploy-preview-1963--jellyfishsdk.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codecov
Copy link

codecov bot commented Jan 11, 2023

Codecov Report

Base: 90.62% // Head: 92.13% // Increases project coverage by +1.51% 🎉

Coverage data is based on head (50c1e3f) compared to base (5abb393).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1963      +/-   ##
==========================================
+ Coverage   90.62%   92.13%   +1.51%     
==========================================
  Files         365      367       +2     
  Lines       10757    10779      +22     
  Branches     1378     1377       -1     
==========================================
+ Hits         9748     9931     +183     
+ Misses        953      810     -143     
+ Partials       56       38      -18     
Impacted Files Coverage Δ
packages/jellyfish-api-core/src/category/rawtx.ts 100.00% <100.00%> (ø)
packages/whale-api-client/src/api/oracles.ts 22.22% <0.00%> (-77.78%) ⬇️
apps/ocean-api/src/modules/PlaygroundModule.ts 42.30% <0.00%> (-53.85%) ⬇️
apps/whale-api/src/module.api/oracle.controller.ts 44.00% <0.00%> (-44.00%) ⬇️
packages/whale-api-client/src/api/masternodes.ts 71.42% <0.00%> (-28.58%) ⬇️
...action-builder/src/txn/txn_builder_icxorderbook.ts 71.42% <0.00%> (-28.58%) ⬇️
...ellyfish-transaction/src/script/dftx/dftx_token.ts 74.41% <0.00%> (-25.59%) ⬇️
...jellyfish-transaction/src/script/dftx/dftx_misc.ts 75.00% <0.00%> (-25.00%) ⬇️
packages/jellyfish-api-core/src/category/spv.ts 64.44% <0.00%> (-17.78%) ⬇️
packages/jellyfish-testing/src/icxorderbook.ts 85.48% <0.00%> (-14.52%) ⬇️
... and 58 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@github-actions
Copy link

github-actions bot commented Jan 11, 2023

Docker build preview for jellyfish/apps is ready!

Built with commit 285b933

  • ghcr.io/jellyfishsdk/legacy-api:pr-1963
  • ghcr.io/jellyfishsdk/ocean-api:pr-1963
  • ghcr.io/jellyfishsdk/playground-api:pr-1963
  • ghcr.io/jellyfishsdk/status-api:pr-1963
  • ghcr.io/jellyfishsdk/whale-api:pr-1963

You can also get an immutable image with the commit hash

  • ghcr.io/jellyfishsdk/legacy-api:285b93384fbf0cfbef3185837be6ef423167485e
  • ghcr.io/jellyfishsdk/ocean-api:285b93384fbf0cfbef3185837be6ef423167485e
  • ghcr.io/jellyfishsdk/playground-api:285b93384fbf0cfbef3185837be6ef423167485e
  • ghcr.io/jellyfishsdk/status-api:285b93384fbf0cfbef3185837be6ef423167485e
  • ghcr.io/jellyfishsdk/whale-api:285b93384fbf0cfbef3185837be6ef423167485e

@DocteurPing DocteurPing changed the title feat(rawtx): add updatepoolpair function feat(rawtx): add decodeRawTransaction function Jan 11, 2023
Comment on lines 18 to 33
it('should decode a witness transaction', async () => {
const encrawtx = '010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000102616100000000'
const decrawtx = await client.rawtx.decodeRawTransaction(encrawtx, true)
expect(decrawtx.vout[0].value).toStrictEqual(1)
})

it('should throw an error when for decode as non-witness a witness transaction', async () => {
const encrawtx = '010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000102616100000000'
await expect(client.rawtx.decodeRawTransaction(encrawtx, false)).rejects.toThrow(RpcApiError)
})

it('should decode a non-witness transaction', async () => {
const encrawtx = '01000000010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f505000000000000000000'
const decrawtx = await client.rawtx.decodeRawTransaction(encrawtx, true)
expect(decrawtx.vout[0].value).toStrictEqual(1)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Assert everything, you need to assert how each rawtx get decoded into explicitly.

@DocteurPing DocteurPing marked this pull request as ready for review January 12, 2023 01:21
Comment on lines 22 to 36
expect(decrawtx.txid).toStrictEqual('d006b4ece5d4adbd6f46b3a6f65f4a230caf6c44d8510e4340d0f26b7ceeb44a')
expect(decrawtx.hash).toStrictEqual('23f0c1f68f0a43bb434494933a5a0f6f9636261f33b036b7700d96e264aceeda')
expect(decrawtx.version).toStrictEqual(1)
expect(decrawtx.size).toStrictEqual(66)
expect(decrawtx.vsize).toStrictEqual(62)
expect(decrawtx.weight).toStrictEqual(246)
expect(decrawtx.locktime).toStrictEqual(0)
expect(decrawtx.vin[0].txid).toStrictEqual('000000000019d6689c085ae165831e934ff763ae46a2a6c17200000000000000')
expect(decrawtx.vin[0].vout).toStrictEqual(0)
expect(decrawtx.vin[0].scriptSig.asm).toStrictEqual('')
expect(decrawtx.vin[0].scriptSig.hex).toStrictEqual('')
expect(decrawtx.vin[0].txinwitness).toStrictEqual(['6161'])
expect(decrawtx.vin[0].sequence).toStrictEqual(4294967295)
expect(decrawtx.vout[0].value).toStrictEqual(1)
expect(decrawtx.vout[0].n).toStrictEqual(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

expect(object).toStrictEqual({
  pool: '',
  ABC: expect.any(String),
  txid: expect.stringMatching(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
})


Prefer we use an object matcher assertion, we started to deprecate the use of individual assertions.

Comment on lines 76 to 98
expect.objectContaining({
txid: '000000000019d6689c085ae165831e934ff763ae46a2a6c17200000000000000',
vout: 0,
scriptSig:
expect.objectContaining({
asm: '',
hex: ''
}),
sequence: 4294967295
})
],
vout: [
expect.objectContaining({
value: 1,
n: 0,
scriptPubKey:
expect.objectContaining({
asm: '',
hex: '',
type: 'nonstandard'
})
})
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be explicitly defined instead of expect.objectContaining()? What was the reason for using expect.objectContaining()?

import { ContainerAdapterClient } from '../../container_adapter_client'
import { RpcApiError } from '../../../src'

describe('poolpair update', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong description

@fuxingloh fuxingloh merged commit 22b1246 into main Jan 13, 2023
@fuxingloh fuxingloh deleted the cedric/decoderawtransaction branch January 13, 2023 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants