Skip to content
This repository was archived by the owner on Aug 23, 2021. It is now read-only.

Adds endpoint for client.queryStorageDeal #67

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* [client.listAsks](#clientlistasks)
* [client.payments](#clientpayments)
* [client.proposeStorageDeal](#clientproposestoragedeal)
* client.queryStorageDeal
* [client.queryStorageDeal](#clientquerystoragedeal)
* [config.get](#configget)
* [config.set](#configset)
* [dag.get](#dagget)
Expand Down Expand Up @@ -492,6 +492,50 @@ const storageDealProposal = await fc.client.proposeStorageDeal(miner, cid, askId
*/
```

## `client.queryStorageDeal`

> Query a storage deal's status

### `client.queryStorageDeal(dealCid, [options])`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| dealCid | `String` | CID of deal to query |
| options | `Object` | Optional options |
| options.signal | [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | A signal that can be used to abort the request |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<Object>` | Storage deal |

#### Example

```js
const dealCid = 'zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT'
const storageDeal = await fc.client.queryStorageDeal(dealCid)
console.log(storageDeal)

/*
{
"state": 7,
"message": "",
"proposalCid": "zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT",
"proofInfo":
{
"sectorID": 1,
"commitmentMessage": "zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R",
"pieceInclusionProof": "EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw=="
},
"signature": "c2lnbmF0dXJycmVlZQ=="
}
Copy link
Member

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 the toCamel utility.

e.g. res.ProofInfo.PieceInclusionProof should be accessed like res.proofInfo.pieceInclusionProof

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

*/
```


## `config.get`

> Get config values
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $ filecoin config api.accessControlAllowOrigin '["http://example.com"]'
* [client.listAsks](API.md#clientlistasks)
* [client.payments](API.md#clientpayments)
* [client.proposeStorageDeal](API.md#clientproposestoragedeal)
* client.queryStorageDeal
* [client.queryStorageDeal](API.md#clientquerystoragedeal)
* [config.get](API.md#configget)
* [config.set](API.md#configset)
* [dag.get](API.md#dagget)
Expand Down
28 changes: 28 additions & 0 deletions src/cmd/client/query-storage-deal.js
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)
}
Copy link
Member

Choose a reason for hiding this comment

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

Need to fix the CID here too!

Suggested change
}
}
if (storageDeal.proofInfo && storageDeal.proofInfo.commitmentMessage) {
storageDeal.proofInfo.commitmentMessage = storageDeal.proofInfo.commitmentMessage['/']
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
}
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = (fetch, config) => {
import: require('./cmd/client/import')(fetch, config),
listAsks: require('./cmd/client/list-asks')(fetch, config),
payments: require('./cmd/client/payments')(fetch, config),
proposeStorageDeal: require('./cmd/client/propose-storage-deal')(fetch, config)
proposeStorageDeal: require('./cmd/client/propose-storage-deal')(fetch, config),
queryStorageDeal: require('./cmd/client/query-storage-deal')(fetch, config)
},
config: {
get: require('./cmd/config/get')(fetch, config),
Expand Down
18 changes: 18 additions & 0 deletions test/unit/cmd/client/query-storage-deal.fixtures.json
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=="
}
26 changes: 26 additions & 0 deletions test/unit/cmd/client/query-storage-deal.test.js
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=='
})
})