Skip to content

Commit d24296e

Browse files
committed
Merge pull request #38 from achamely/master
Update for tx70
2 parents 7b6adbd + 2c18ea0 commit d24296e

File tree

3 files changed

+65
-16
lines changed

3 files changed

+65
-16
lines changed

mscutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_TxType(text_type):
3636
"Create Property - Manual": 54,
3737
"Grant Property Tokens": 55,
3838
"Revoke Property Tokens": 56,
39-
"Change Issuer Address": -1,
39+
"Change Issuer Address": 70,
4040
"Notification": -1
4141
}
4242
return convert[text_type]

patches/omniDB.v27.patch

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
alter type addressrole add value 'payer';
22
alter type addressrole add value 'feepayer';
3+
update addressesintxs atx SET addressrole='sender' from transactions tx where tx.txdbserialnum=atx.txdbserialnum and tx.txtype=-51 and atx.propertyid=1 and atx.addressrole='participant';
4+
update addressesintxs atx SET addressrole='recipient' from transactions tx where tx.txdbserialnum=atx.txdbserialnum and tx.txtype=-51 and atx.propertyid=1 and atx.addressrole='issuer';
5+
update addressesintxs atx SET addressrole='sender' from transactions tx where tx.txdbserialnum=atx.txdbserialnum and tx.txtype=-51 and atx.propertyid=2 and atx.addressrole='participant';
6+
update addressesintxs atx SET addressrole='recipient' from transactions tx where tx.txdbserialnum=atx.txdbserialnum and tx.txtype=-51 and atx.propertyid=2 and atx.addressrole='issuer';
7+
update addressesintxs atx SET addressrole='sender' from transactions tx where tx.txdbserialnum=atx.txdbserialnum and tx.txtype=-51 and atx.propertyid=24 and atx.addressrole='participant';
8+
update addressesintxs atx SET addressrole='recipient' from transactions tx where tx.txdbserialnum=atx.txdbserialnum and tx.txtype=-51 and atx.propertyid=24 and atx.addressrole='issuer';

sql.py

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def reorgRollback(block):
116116
#remove entries from the property history table only
117117
dbExecute("delete from propertyhistory where txdbserialnum=%s and propertyid=%s and protocol=%s",
118118
(TxDbSerialNum,PropertyID,Protocol))
119+
elif txtype == 70 and Role == "issuer":
120+
updateProperty(PropertyID, Protocol, linkedtxdbserialnum)
121+
119122
#/end for entry in addressesintxs
120123
#/end if txstate='valid'
121124

@@ -843,9 +846,10 @@ def expireCrowdsales(BlockTime, Protocol):
843846

844847
else:
845848
#find the offers that are ready to expire and credit the 'accepted' amount back to the sellers sale
846-
expiring=dbSelect("select propertyid from smartproperties as sp inner join transactions as tx on "
847-
"(sp.createtxdbserialnum=tx.txdbserialnum) where tx.txtype=51 and sp.protocol=%s and "
848-
"cast(propertydata::json->>'endedtime' as numeric) < %s and propertydata::json->>'active'='true'", (Protocol, BlockTime))
849+
expiring=dbSelect("select propertyid from smartproperties as sp inner join transactions as tx on (sp.createtxdbserialnum=tx.txdbserialnum) "
850+
"where tx.txtype=51 and sp.protocol=%s and propertydata::json->>'active'='true' and "
851+
"( cast(propertydata::json->>'deadline' as numeric) < %s or cast(propertydata::json->>'endedtime' as numeric) < %s)",
852+
(Protocol, BlockTime, BlockTime))
849853

850854
#Process all the crowdsales that should have expired by now
851855
for property in expiring:
@@ -869,8 +873,10 @@ def updateProperty(PropertyID, Protocol, LastTxDBSerialNum=None):
869873
TxType = get_TxType(rawtx['result']['type'])
870874
rawprop = PropertyDataJson['result']
871875
Ecosystem = getEcosystem(PropertyID)
876+
Issuer = rawprop['issuer']
872877

873-
if TxType == 51 or TxType == 53:
878+
#if TxType == 51 or TxType == 53:
879+
try:
874880
#get additional json info for crowdsales
875881
rawprop = dict(rawprop.items() + getcrowdsale_MP(PropertyID)['result'].items())
876882
#closed/ended crowdsales can generate extra tokens for issuer. handle that here
@@ -885,18 +891,24 @@ def updateProperty(PropertyID, Protocol, LastTxDBSerialNum=None):
885891
rawprop['active']='true'
886892
else:
887893
updateBalance(issuer, Protocol, PropertyID, Ecosystem, addedissuertokens, 0, 0, LastTxDBSerialNum)
888-
elif TxType > 53 and TxType < 57:
894+
except Exception:
895+
printdebug("Updating Property. Property not created with crowdsale", 8)
896+
897+
#elif TxType > 53 and TxType < 57:
898+
try:
889899
rawprop = dict(rawprop.items() + getgrants_MP(PropertyID)['result'].items())
900+
except Exception:
901+
printdebug("Updating Property. Not a Managed Property", 8)
890902

891903
#if we where called with a tx update that otherwise just update json (expired by time update)
892904
if LastTxDBSerialNum == None:
893-
dbExecute("update smartproperties set PropertyData=%s "
905+
dbExecute("update smartproperties set PropertyData=%s, Issuer=%s "
894906
"where Protocol=%s and PropertyID=%s",
895-
(json.dumps(rawprop), Protocol, PropertyID))
907+
(json.dumps(rawprop), Issuer, Protocol, PropertyID))
896908
else:
897-
dbExecute("update smartproperties set LastTxDBSerialNum=%s, PropertyData=%s "
909+
dbExecute("update smartproperties set LastTxDBSerialNum=%s, PropertyData=%s, Issuer=%s "
898910
"where Protocol=%s and PropertyID=%s",
899-
(LastTxDBSerialNum, json.dumps(rawprop), Protocol, PropertyID))
911+
(LastTxDBSerialNum, json.dumps(rawprop), Issuer, Protocol, PropertyID))
900912

901913

902914
def insertProperty(rawtx, Protocol, PropertyID=None):
@@ -916,12 +928,23 @@ def insertProperty(rawtx, Protocol, PropertyID=None):
916928
PropertyDataJson = getproperty_MP(PropertyID)
917929
rawprop = PropertyDataJson['result']
918930

919-
if TxType == 51 or TxType == 53:
931+
#if TxType == 51 or TxType == 53:
920932
#get additional json info for crowdsales
921-
rawprop = dict(rawprop.items() + getcrowdsale_MP(PropertyID)['result'].items())
922-
elif TxType > 53 and TxType < 57:
933+
# rawprop = dict(rawprop.items() + getcrowdsale_MP(PropertyID)['result'].items())
934+
#elif TxType > 53 and TxType < 57:
935+
# rawprop = dict(rawprop.items() + getgrants_MP(PropertyID)['result'].items())
936+
937+
try:
938+
#get additional json info for crowdsales if exists
939+
rawprop = dict(rawprop.items() + getcrowdsale_MP(PropertyID)['result'].items())
940+
except Exception:
941+
printdebug("Inserting Property. Property not created with crowdsale", 8)
942+
943+
try:
944+
#get additional json info for grants if exists
923945
rawprop = dict(rawprop.items() + getgrants_MP(PropertyID)['result'].items())
924-
946+
except Exception:
947+
printdebug("Inserting Property. Property not created with grant", 8)
925948

926949
Issuer = rawprop['issuer']
927950
Ecosystem = getEcosystem(PropertyID)
@@ -1264,7 +1287,7 @@ def insertTxAddr(rawtx, Protocol, TxDBSerialNum, Block):
12641287

12651288
elif txtype == -51:
12661289
#First deduct the amount the participant sent to 'buyin' (BTC Amount might need to be excluded?)
1267-
AddressRole = 'participant'
1290+
AddressRole = 'sender'
12681291
BalanceAvailableCreditDebit = value_neg
12691292

12701293
dbExecute("insert into addressesintxs "
@@ -1275,7 +1298,7 @@ def insertTxAddr(rawtx, Protocol, TxDBSerialNum, Block):
12751298
updateBalance(Address, Protocol, PropertyID, Ecosystem, BalanceAvailableCreditDebit, BalanceReservedCreditDebit, BalanceAcceptedCreditDebit, TxDBSerialNum)
12761299

12771300
#Credit the buy in to the issuer
1278-
AddressRole = 'issuer'
1301+
AddressRole = 'recipient'
12791302
BalanceAvailableCreditDebit = value
12801303
Address= rawtx['result']['referenceaddress']
12811304
dbExecute("insert into addressesintxs "
@@ -1365,6 +1388,26 @@ def insertTxAddr(rawtx, Protocol, TxDBSerialNum, Block):
13651388
#update smart property table
13661389
insertProperty(rawtx, Protocol)
13671390

1391+
elif txtype == 70:
1392+
#change ownership of grant
1393+
if Valid:
1394+
#grab the original issuer of property
1395+
AddressRole = "issuer"
1396+
BalanceAvailableCreditDebit=None
1397+
1398+
#update smart property table
1399+
#insertProperty(rawtx, Protocol)
1400+
updateProperty(PropertyID, Protocol, TxDBSerialNum)
1401+
1402+
dbExecute("insert into addressesintxs "
1403+
"(Address, PropertyID, Protocol, TxDBSerialNum, AddressTxIndex, AddressRole, BalanceAvailableCreditDebit, BalanceReservedCreditDebit, BalanceAcceptedCreditDebit, linkedtxdbserialnum)"
1404+
"values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
1405+
(Address, PropertyID, Protocol, TxDBSerialNum, AddressTxIndex, AddressRole, BalanceAvailableCreditDebit, BalanceReservedCreditDebit, BalanceAcceptedCreditDebit, linkedtxdbserialnum))
1406+
Address = rawtx['result']['referenceaddress']
1407+
AddressRole = 'recipient'
1408+
1409+
#end if/elif txtype switch
1410+
13681411
#write output of the address details
13691412
dbExecute("insert into addressesintxs "
13701413
"(Address, PropertyID, Protocol, TxDBSerialNum, AddressTxIndex, AddressRole, BalanceAvailableCreditDebit, BalanceReservedCreditDebit, BalanceAcceptedCreditDebit, linkedtxdbserialnum)"

0 commit comments

Comments
 (0)