Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
c8dca0eb
Commit
c8dca0eb
authored
Sep 21, 2019
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push on several ipfs nodes
parent
b11d1e6d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
+12
-3
publishOnIpfs.js
src/lib/publishOnIpfs.js
+12
-3
No files found.
src/lib/publishOnIpfs.js
View file @
c8dca0eb
...
@@ -2,8 +2,11 @@
...
@@ -2,8 +2,11 @@
const
async
=
require
(
'async'
)
const
async
=
require
(
'async'
)
const
IpfsClient
=
require
(
'ipfs-mini'
)
const
IpfsClient
=
require
(
'ipfs-mini'
)
const
host
=
'ipfs.komputing.org'
const
ipfs
=
new
IpfsClient
({
host
,
port
:
443
,
protocol
:
'https'
})
const
ipfsNodes
=
[
new
IpfsClient
({
host
:
'ipfs.komputing.org'
,
port
:
443
,
protocol
:
'https'
}),
new
IpfsClient
({
host
:
'ipfs.infura.io'
,
port
:
5001
,
protocol
:
'https'
})
]
module
.
exports
=
(
contract
,
fileManager
,
cb
,
ipfsVerifiedPublishCallBack
)
=>
{
module
.
exports
=
(
contract
,
fileManager
,
cb
,
ipfsVerifiedPublishCallBack
)
=>
{
// gather list of files to publish
// gather list of files to publish
...
@@ -89,7 +92,7 @@ module.exports = (contract, fileManager, cb, ipfsVerifiedPublishCallBack) => {
...
@@ -89,7 +92,7 @@ module.exports = (contract, fileManager, cb, ipfsVerifiedPublishCallBack) => {
async
function
ipfsVerifiedPublish
(
content
,
expectedHash
,
cb
)
{
async
function
ipfsVerifiedPublish
(
content
,
expectedHash
,
cb
)
{
try
{
try
{
const
results
=
await
ipfs
.
add
(
content
)
const
results
=
await
severalGatewaysPush
(
content
)
if
(
results
!==
expectedHash
)
{
if
(
results
!==
expectedHash
)
{
cb
(
null
,
{
message
:
'hash mismatch between solidity bytecode and uploaded content.'
,
url
:
'dweb:/ipfs/'
+
results
,
hash
:
results
})
cb
(
null
,
{
message
:
'hash mismatch between solidity bytecode and uploaded content.'
,
url
:
'dweb:/ipfs/'
+
results
,
hash
:
results
})
}
else
{
}
else
{
...
@@ -99,3 +102,9 @@ async function ipfsVerifiedPublish (content, expectedHash, cb) {
...
@@ -99,3 +102,9 @@ async function ipfsVerifiedPublish (content, expectedHash, cb) {
cb
(
error
)
cb
(
error
)
}
}
}
}
function
severalGatewaysPush
(
content
)
{
const
invert
=
p
=>
new
Promise
((
resolve
,
reject
)
=>
p
.
then
(
reject
).
catch
(
resolve
))
// Invert res and rej
const
promises
=
ipfsNodes
.
map
((
node
)
=>
invert
(
node
.
add
(
content
)))
return
invert
(
Promise
.
all
(
promises
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment