Update ipfs-http-client (for node >= 14)
Updates the client library and API usage to work with the latest version, and more importantly, with current node.js LTS.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"1337": {
|
||||
"Contributor": "0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07",
|
||||
"Contribution": "0x922D6956C99E12DFeB3224DEA977D0939758A1Fe",
|
||||
"Token": "0x5081a39b8A5f0E35a8D959395a630b68B74Dd30f",
|
||||
"Reimbursement": "0x1fA02b2d6A771842690194Cf62D91bdd92BfE28d"
|
||||
"Contributor": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
|
||||
"Contribution": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
|
||||
"Token": "0x0165878A594ca255338adfa4d48449f69242Eb8F",
|
||||
"Reimbursement": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"
|
||||
}
|
||||
}
|
||||
@@ -14,15 +14,6 @@ class Base {
|
||||
return this.contract.address;
|
||||
}
|
||||
|
||||
get ipfs () {
|
||||
if (!this._ipfsAPI) { throw new Error('IPFS API not configured; please set an ipfs instance'); }
|
||||
return this._ipfsAPI;
|
||||
}
|
||||
|
||||
set ipfs (ipfsAPI) {
|
||||
this._ipfsAPI = ipfsAPI;
|
||||
}
|
||||
|
||||
on (type, callback) {
|
||||
return this.contract.on(type, callback);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ class IPFS {
|
||||
config = { host: 'localhost', port: '5001', protocol: 'http' };
|
||||
}
|
||||
this._config = config;
|
||||
this._ipfsAPI = ipfsClient(config);
|
||||
this._ipfsAPI = ipfsClient.create(config);
|
||||
}
|
||||
|
||||
catAndMerge (contractData, deserialize) {
|
||||
async catAndMerge (contractData, deserialize) {
|
||||
let data = {...contractData}; // data from ethers.js is not extensible. this copy the attributes in a new object
|
||||
// if no hash details are found simply return the data; nothing to merge
|
||||
if (!data.hashSize || data.hashSize === 0) {
|
||||
@@ -22,20 +22,19 @@ class IPFS {
|
||||
|
||||
return this.cat(data.ipfsHash)
|
||||
.then(deserialize)
|
||||
.then((attributes) => {
|
||||
.then(attributes => {
|
||||
return Object.assign({}, data, attributes);
|
||||
});
|
||||
}
|
||||
|
||||
add (data) {
|
||||
return this._ipfsAPI
|
||||
.add(ipfsClient.Buffer.from(data))
|
||||
.then((res) => {
|
||||
return this.decodeHash(res[0].hash);
|
||||
async add (data) {
|
||||
return this._ipfsAPI.add(data)
|
||||
.then(res => {
|
||||
return this.decodeHash(res.path);
|
||||
});
|
||||
}
|
||||
|
||||
cat (hashData) {
|
||||
async cat (hashData) {
|
||||
let ipfsHash = hashData; // default - if it is a string
|
||||
if (Object.prototype.hasOwnProperty.call(hashData, 'hashSize')) {
|
||||
ipfsHash = this.encodeHash(hashData);
|
||||
@@ -43,7 +42,12 @@ class IPFS {
|
||||
if (this._config['gatewayUrl']) {
|
||||
return fetch(`${this._config['gatewayUrl']}/${ipfsHash}`).then(r => r.text());
|
||||
} else {
|
||||
return this._ipfsAPI.cat(ipfsHash);
|
||||
const res = this._ipfsAPI.cat(ipfsHash);
|
||||
let str = '';
|
||||
for await (const buffer of res) {
|
||||
str += buffer.toString();
|
||||
}
|
||||
return Promise.resolve(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +70,7 @@ class IPFS {
|
||||
}
|
||||
|
||||
encodeHash (hashData) {
|
||||
let digest = ipfsClient.Buffer.from(hashData.hashDigest.slice(2), 'hex');
|
||||
const digest = Buffer.from(hashData.hashDigest.slice(2), 'hex');
|
||||
return multihashes.encode(digest, hashData.hashFunction, hashData.hashSize);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user