public static bool VerifyUserBranches(ProofBlindBranch[] branches, string userName, decimal userBalance, string tophash, decimal sumFunds) { if (branches[branches.Length - 1].hash != tophash) { return(false); } if (branches[branches.Length - 1].balance > sumFunds) { return(false); } string userhash = new ProofUser(userName, userBalance).GetHash(); if (branches[0].hash != userhash) { return(false); } for (int i = 0; i < branches.Length - 1; i++) { var pb1 = ProofBranch.MakeBranch(branches[i].hash, branches[i].GetNeighbours()[0].hash, branches[i].balance, branches[i].GetNeighbours()[0].balance, new List <ProofUser>()); var pb2 = ProofBranch.MakeBranch(branches[i].GetNeighbours()[0].hash, branches[i].hash, branches[i].GetNeighbours()[0].balance, branches[i].balance, new List <ProofUser>()); if (pb1.hash != branches[i + 1].hash && pb2.hash != branches[i + 1].hash) { return(false); } if (branches[i].GetNeighbours()[0].balance < 0) { return(false); } } return(true); }
public static ProofBranch MakeLeaf(ProofUser u, decimal balance) => new ProofBranch(u.GetHash(), balance, new List <ProofUser> { u });