mirror of
https://github.com/hackku21/loc-chain-backend.git
synced 2024-10-27 20:34:03 +00:00
Add debug output
This commit is contained in:
parent
7fcde77bbe
commit
63a172209c
@ -224,6 +224,7 @@ export class Blockchain extends Unit {
|
|||||||
*/
|
*/
|
||||||
public async getPeerSubmit(peer: Peer): Promise<Block[] | undefined> {
|
public async getPeerSubmit(peer: Peer): Promise<Block[] | undefined> {
|
||||||
try {
|
try {
|
||||||
|
this.logging.verbose(`Making request to: ${peer.host}api/v1/chain/submit`)
|
||||||
const result = await fetch(`${peer.host}api/v1/chain/submit`).then(res => res.json())
|
const result = await fetch(`${peer.host}api/v1/chain/submit`).then(res => res.json())
|
||||||
const blocks: unknown = result.data?.data?.records
|
const blocks: unknown = result.data?.data?.records
|
||||||
if ( Array.isArray(blocks) && blocks.every(block => {
|
if ( Array.isArray(blocks) && blocks.every(block => {
|
||||||
@ -319,11 +320,16 @@ export class Blockchain extends Unit {
|
|||||||
this.logging.debug('Called refresh().')
|
this.logging.debug('Called refresh().')
|
||||||
|
|
||||||
const peers = this.getPeers()
|
const peers = this.getPeers()
|
||||||
|
this.logging.debug({peers})
|
||||||
|
|
||||||
let longestChain: Block[] = []
|
let longestChain: Block[] = []
|
||||||
const chains = await Promise.all(
|
const chains = await Promise.all(
|
||||||
peers.map(peer => this.getPeerSubmit(peer))
|
peers.map(peer => this.getPeerSubmit(peer))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.logging.debug('Got peer chain info:')
|
||||||
|
this.logging.debug(chains)
|
||||||
|
|
||||||
for ( const chain of chains ) {
|
for ( const chain of chains ) {
|
||||||
if (
|
if (
|
||||||
chain
|
chain
|
||||||
@ -331,6 +337,8 @@ export class Blockchain extends Unit {
|
|||||||
&& await this.validate(chain)
|
&& await this.validate(chain)
|
||||||
) {
|
) {
|
||||||
longestChain = chain
|
longestChain = chain
|
||||||
|
} else {
|
||||||
|
this.logging.debug('Failed validation!')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user