Colored Coins Metadata Handler
Currently only works on node version 0.12.2 and above.
Installation
$ npm i cc-metadata-handler
Initialize
var MetadataHandler = require('cc-metadata-handler')
var settings = {
"swarm": {
maxPeers: Number,
maxConns: Number
},
"folders": {
data: String,
spvData: String,
fullNodeData: String,
torrents: String,
capSize: Number/String
},
"client": {
peerId: String,
port: Number
},
"server": {
udp: Boolean,
http: Boolean,
ws: Boolean,
hostname: String,
port: Number
}
}
var handler = new MetadataHandler(settings)
Fetch Metadata
Params:
- torrentHash - The torrent infoHash of the metadata.
- metadataSHA2 - The sha256 of the metadata json.
- importent - A boolean flag which determines if the metadata will be saved forever or possibly deleted when folder reaches max limit size.
var torrentHash = '5add2b0ce8f7da372c856d4efe6b9b6e8584919e'
var metadataSHA2 = '6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4'
var importent = true
handler.getMetadata(torrentHash, metadataSHA2, importent, function (err, metadata) {
if (err) return console.error(err)
console.log(metadata)
})
You can also use this method together with an event listner like this:
handler.on('downloads/'+torrentHash, function (metadata) {
console.log(metadata)
})
handler.getMetadata(torrentHash, metadataSHA2, importent)
Add new Metadata
Params:
- metadata - A new metadata json we just created and we plan on sharing with other people.
handler.addMetadata(metadata, function (err, hashes) {
if (err) return console.error(err)
console.log(hashes.torrentHash)
console.log(hashes.sha2)
})
Share Metadata
Params:
- torrentHash - The torrent info hash of the metadata we want to share with other people
handler.on('uploads/'+torrentHash, function (peer) {
console.log(peer)
})
handler.shareMetadata(torrentHash, function (err) {
if (err) console.log(err)
})
Other Events
handler.on('downloads', function (metadata) {
console.log(metadata)
})
handler.on('uploads', function (peer) {
console.log(peer.info)
console.log(peer.file)
})
handler.on('error', function (err) {
console.error(err)
})
Testing
$ cd /"module-path"/cc-metadata-handler
$ mocha
License
MIT