From 1cc011d7e54d35793552d69979c0d5a5aeeae4d8 Mon Sep 17 00:00:00 2001
From: Vincent Texier <vit@free.fr>
Date: Thu, 25 Jun 2015 20:40:42 +0200
Subject: [PATCH] referential calculation support blockchain without ud block
 yet

---
 src/cutecoin/core/account.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py
index 7dad16fc..245c5923 100644
--- a/src/cutecoin/core/account.py
+++ b/src/cutecoin/core/account.py
@@ -53,7 +53,12 @@ def quantitative_zerosum(units, community):
     :param cutecoin.core.community.Community community: Community instance
     :return: int
     """
-    average = community.monetary_mass / community.get_ud_block()['membersCount']
+    ud_block = community.get_ud_block()
+    if ud_block:
+        members = ud_block['membersCount']
+    else:
+        members = community.get_block(0)['membersCount']
+    average = community.monetary_mass / members
     return units - average
 
 
@@ -65,7 +70,12 @@ def relative_zerosum(units, community):
     :param cutecoin.core.community.Community community: Community instance
     :return: float
     """
-    median = community.monetary_mass / community.get_ud_block()['membersCount']
+    ud_block = community.get_ud_block()
+    if ud_block:
+        members = ud_block['membersCount']
+    else:
+        members = community.get_block(0)['membersCount']
+    median = community.monetary_mass / members
     relative_value = units / float(community.dividend)
     relative_median = median / community.dividend
     return relative_value - relative_median
-- 
GitLab