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

Commit 8b896fb

Browse files
committed
Changes the API to be camelcase
* In order to be more idiomatic for JavaScript * Modified the incoming proposalCid, which was historically encoded in IPLD
1 parent de388a3 commit 8b896fb

File tree

4 files changed

+58
-34
lines changed

4 files changed

+58
-34
lines changed

API.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ const storageDealProposal = await fc.client.proposeStorageDeal(miner, cid, askId
495495
## `client.queryStorageDeal`
496496

497497
> Query a storage deal's status
498+
498499
### `client.queryStorageDeal(dealCid, [options])`
499500

500501
#### Parameters
@@ -520,22 +521,19 @@ console.log(storageDeal)
520521

521522
/*
522523
{
523-
"State":7,
524-
"Message":"",
525-
"ProposalCid":
526-
{
527-
"/":"zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT"
528-
},
529-
"ProofInfo":
524+
"state": 7,
525+
"message": "",
526+
"proposalCid": "zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT",
527+
"proofInfo":
530528
{
531-
"SectorID":1,
532-
"CommitmentMessage":
529+
"sectorID": 1,
530+
"commitmentMessage":
533531
{
534-
"/":"zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R"
532+
"/": "zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R"
535533
},
536-
"PieceInclusionProof":"EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw=="
534+
"pieceInclusionProof": "EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw=="
537535
},
538-
"Signature":"c2lnbmF0dXJycmVlZQ=="
536+
"signature": "c2lnbmF0dXJycmVlZQ=="
539537
}
540538
*/
541539
```

src/cmd/client/query-storage-deal.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const toUri = require('../../lib/multiaddr-to-uri')
22
const { ok } = require('../../lib/fetch')
3+
const toCamel = require('../../lib/to-camel')
34

45
module.exports = (fetch, config) => {
56
return async (cid, options) => {
@@ -8,7 +9,16 @@ module.exports = (fetch, config) => {
89
const url = `${toUri(config.apiAddr)}/api/client/query-storage-deal?arg=${encodeURIComponent(cid)}`
910
const res = await ok(fetch(url, { signal: options.signal }))
1011

11-
const data = await res.json()
12-
return data
12+
const storageDeal = toCamel(await res.json())
13+
14+
if (storageDeal.proposalCid) {
15+
storageDeal.proposalCid = storageDeal.proposalCid['/']
16+
}
17+
18+
if (storageDeal.proofInfo) {
19+
storageDeal.proofInfo = toCamel(storageDeal.proofInfo)
20+
}
21+
22+
return storageDeal
1323
}
1424
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"State":7,
3+
"Message":"",
4+
"ProposalCid":
5+
{
6+
"/":"zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT"
7+
},
8+
"ProofInfo":
9+
{
10+
"SectorID":1,
11+
"CommitmentMessage":
12+
{
13+
"/":"zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R"
14+
},
15+
"PieceInclusionProof":"EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw=="
16+
},
17+
"Signature":"c2lnbmF0dXJycmVlZQ=="
18+
}
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
const test = require('ava')
22
const Filecoin = require('../../../../src')
3+
const Fixtures = require('./query-storage-deal.fixtures.json')
34

45
test('should list the storage deal info for a particular cid', async t => {
56
const cid = "zDPWYqFCuTNxiwRkt1iDJWEy6qKPGCunMGHrP1ojsMrZDWKYsgzF"
6-
const storageDeal = {
7-
"State":7,
8-
"Message":"",
9-
"ProposalCid":
10-
{
11-
"/":"zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT"
12-
},
13-
"ProofInfo":
14-
{
15-
"SectorID":1,
16-
"CommitmentMessage":
17-
{
18-
"/":"zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R"
19-
},
20-
"PieceInclusionProof":"EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw=="
21-
},
22-
"Signature":"c2lnbmF0dXJycmVlZQ=="
23-
}
247

25-
const fetch = () => ({ ok: true, json: () => storageDeal })
8+
const fetch = () => ({ ok: true, json: () => Fixtures })
269
const fc = Filecoin(fetch)
2710

2811
const res = await fc.client.queryStorageDeal(cid)
2912

30-
t.is(storageDeal, res)
13+
const proofInfo = {
14+
"sectorID": 1,
15+
"commitmentMessage":
16+
{
17+
"/": "zDPWYqFCtHkWNkE2p6t6TeV1sPP5kbnKc5ajUhMVV8xvrw1u5F1R"
18+
},
19+
"pieceInclusionProof": "EiAbbOy4pChsCYqFYA6qJaUJYStlnwYMdQPHZX7YBkVXDD6vgmGTPnWrcdA9M0oAXQCzOq735YKySLUoTI6pAw=="
20+
}
21+
22+
t.deepEqual(res, {
23+
state: 7,
24+
message: '',
25+
proposalCid: 'zDPWYqFD8CNXu7Mo9qPSUANbTK2vi9vJBnvavF9S1pVGPHafVHpT',
26+
proofInfo: proofInfo,
27+
signature: 'c2lnbmF0dXJycmVlZQ=='
28+
})
3129
})

0 commit comments

Comments
 (0)