This repository was archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Adds endpoint for client.queryStorageDeal #67
Merged
alanshaw
merged 4 commits into
filecoin-shipyard:master
from
hazmatzo:api/client/query-storage-deal
Aug 30, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||||||||||
const toUri = require('../../lib/multiaddr-to-uri') | ||||||||||||||
const { ok } = require('../../lib/fetch') | ||||||||||||||
const toCamel = require('../../lib/to-camel') | ||||||||||||||
|
||||||||||||||
module.exports = (fetch, config) => { | ||||||||||||||
return async (cid, options) => { | ||||||||||||||
options = options || {} | ||||||||||||||
|
||||||||||||||
const url = `${toUri(config.apiAddr)}/api/client/query-storage-deal?arg=${encodeURIComponent(cid)}` | ||||||||||||||
const res = await ok(fetch(url, { signal: options.signal })) | ||||||||||||||
|
||||||||||||||
const storageDeal = toCamel(await res.json()) | ||||||||||||||
|
||||||||||||||
if (storageDeal.proposalCid) { | ||||||||||||||
storageDeal.proposalCid = storageDeal.proposalCid['/'] | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (storageDeal.proofInfo) { | ||||||||||||||
storageDeal.proofInfo = toCamel(storageDeal.proofInfo) | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to fix the CID here too!
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added it as part of the commit. |
||||||||||||||
|
||||||||||||||
if (storageDeal.proofInfo && storageDeal.proofInfo.commitmentMessage) { | ||||||||||||||
storageDeal.proofInfo.commitmentMessage = storageDeal.proofInfo.commitmentMessage['/'] | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return storageDeal | ||||||||||||||
} | ||||||||||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"State":7, | ||
"Message":"", | ||
"ProposalCid": | ||
{ | ||
"/":"zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT" | ||
}, | ||
"ProofInfo": | ||
{ | ||
"SectorID":1, | ||
"CommitmentMessage": | ||
{ | ||
"/":"zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R" | ||
}, | ||
"PieceInclusionProof":"EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw==" | ||
}, | ||
"Signature":"c2lnbmF0dXJycmVlZQ==" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const test = require('ava') | ||
const Filecoin = require('../../../../src') | ||
const Fixtures = require('./query-storage-deal.fixtures.json') | ||
|
||
test('should list the storage deal info for a particular cid', async t => { | ||
const cid = 'zDPWYqFCuTNxiwRkt1iDJWEy6qKPGCunMGHrP1ojsMrZDWKYsgzF' | ||
|
||
const fetch = () => ({ ok: true, json: () => Fixtures }) | ||
const fc = Filecoin(fetch) | ||
|
||
const res = await fc.client.queryStorageDeal(cid) | ||
|
||
const proofInfo = { | ||
sectorID: 1, | ||
commitmentMessage: 'zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R', | ||
pieceInclusionProof: 'EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw==' | ||
} | ||
|
||
t.deepEqual(res, { | ||
state: 7, | ||
message: '', | ||
proposalCid: 'zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT', | ||
proofInfo: proofInfo, | ||
signature: 'c2lnbmF0dXJycmVlZQ==' | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this more idiomatic for JS users we should convert the root and
ProofInfo
to camel case using thetoCamel
utility.e.g.
res.ProofInfo.PieceInclusionProof
should be accessed likeres.proofInfo.pieceInclusionProof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!