@leofcoin/peernet
v1.1.80
Published
```js import Peernet from '@leofcoin/peernet'
Downloads
52
Readme
peernet
Usage
import Peernet from '@leofcoin/peernet'
const config = {
network: 'leofcoin:peach',
networkVersion: 'peach',
stars: ['wss://peach.leofcoin.org']
}
const node = await new Peernet(config)
// ... setup some things
await node.start()
console.log(globalThis.peernet)
API
addRequestHandler
examples
peernet.addRequestHandler('lastBlock', () => {
let response;
const height = await chainStore.get('localIndex')
const hash = await chainStore.get('localBlock')
response = JSON.stringify({ height: height.toString(), hash: hash.toString() })
return new ResponseMessage({ response })
// or
return new peernet.protos['peernet-response']({ response })
})
peernet.addRequestHandler('hello', () => {
return new ResponseMessage({ response: 'hi' })
// or
return new peernet.protos['peernet-response']({ response: 'hi' })
})
add version to peer
peernet.addRequestHandler('version', () => {
return new ResponseMessage({ response: {version: 1} })
})
Development
note: you need to install jsproject
npm i -g @vandeurenglenn/project
watch
npm run w
compile
npm run c
serve html
npm run demo