fix stratum tree rendering with different branch lengths
This commit is contained in:
		
							parent
							
								
									703241acf0
								
							
						
					
					
						commit
						4e735cc8b0
					
				| @ -8,8 +8,10 @@ import { SinglePoolStats } from '../../../interfaces/node-api.interface'; | |||||||
| 
 | 
 | ||||||
| type MerkleCellType = ' ' | '┬' | '├' | '└' | '│' | '─' | 'leaf'; | type MerkleCellType = ' ' | '┬' | '├' | '└' | '│' | '─' | 'leaf'; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| interface TaggedStratumJob extends StratumJob { | interface TaggedStratumJob extends StratumJob { | ||||||
|   tag: string; |   tag: string; | ||||||
|  |   merkleBranchIds: string[]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| interface MerkleCell { | interface MerkleCell { | ||||||
| @ -46,6 +48,18 @@ function parseTag(scriptSig: string): string { | |||||||
|   return (ascii.match(/\/.*\//)?.[0] || ascii).trim(); |   return (ascii.match(/\/.*\//)?.[0] || ascii).trim(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function getMerkleBranchIds(merkleBranches: string[], numBranches: number): string[] { | ||||||
|  |   let lastHash = ''; | ||||||
|  |   const ids: string[] = []; | ||||||
|  |   for (let i = 0; i < numBranches; i++) { | ||||||
|  |     if (merkleBranches[i]) { | ||||||
|  |       lastHash = merkleBranches[i]; | ||||||
|  |     } | ||||||
|  |     ids.push(`${i}-${lastHash}`); | ||||||
|  |   } | ||||||
|  |   return ids; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: 'app-stratum-list', |   selector: 'app-stratum-list', | ||||||
|   templateUrl: './stratum-list.component.html', |   templateUrl: './stratum-list.component.html', | ||||||
| @ -81,16 +95,15 @@ export class StratumList implements OnInit, OnDestroy { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   processJobs(rawJobs: Record<string, StratumJob>): PoolRow[] { |   processJobs(rawJobs: Record<string, StratumJob>): PoolRow[] { | ||||||
|  |     const numBranches = Math.max(...Object.values(rawJobs).map(job => job.merkleBranches.length)); | ||||||
|     const jobs: Record<string, TaggedStratumJob> = {}; |     const jobs: Record<string, TaggedStratumJob> = {}; | ||||||
|     for (const [id, job] of Object.entries(rawJobs)) { |     for (const [id, job] of Object.entries(rawJobs)) { | ||||||
|       jobs[id] = { ...job, tag: parseTag(job.scriptsig) }; |       jobs[id] = { ...job, tag: parseTag(job.scriptsig), merkleBranchIds: getMerkleBranchIds(job.merkleBranches, numBranches) }; | ||||||
|     } |     } | ||||||
|     if (Object.keys(jobs).length === 0) { |     if (Object.keys(jobs).length === 0) { | ||||||
|       return []; |       return []; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const numBranches = Math.max(...Object.values(jobs).map(job => job.merkleBranches.length)); |  | ||||||
| 
 |  | ||||||
|     let trees: MerkleTree[] = Object.keys(jobs).map(job => ({ |     let trees: MerkleTree[] = Object.keys(jobs).map(job => ({ | ||||||
|       job, |       job, | ||||||
|       size: 1, |       size: 1, | ||||||
| @ -100,12 +113,13 @@ export class StratumList implements OnInit, OnDestroy { | |||||||
|     for (let col = numBranches - 1; col >= 0; col--) { |     for (let col = numBranches - 1; col >= 0; col--) { | ||||||
|       const groups: Record<string, MerkleTree[]> = {}; |       const groups: Record<string, MerkleTree[]> = {}; | ||||||
|       for (const tree of trees) { |       for (const tree of trees) { | ||||||
|         const hash = jobs[tree.job].merkleBranches[col]; |         const branchId = jobs[tree.job].merkleBranchIds[col]; | ||||||
|         if (!groups[hash]) { |         if (!groups[branchId]) { | ||||||
|           groups[hash] = []; |           groups[branchId] = []; | ||||||
|         } |         } | ||||||
|         groups[hash].push(tree); |         groups[branchId].push(tree); | ||||||
|       } |       } | ||||||
|  | 
 | ||||||
|       trees = Object.values(groups).map(group => ({ |       trees = Object.values(groups).map(group => ({ | ||||||
|         hash: jobs[group[0].job].merkleBranches[col], |         hash: jobs[group[0].job].merkleBranches[col], | ||||||
|         job: group[0].job, |         job: group[0].job, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user