Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Merge branch 'development' of github.com:CityOfZion/neo-python into n…
Browse files Browse the repository at this point in the history
…eocore-imports

* 'development' of github.com:CityOfZion/neo-python:
  Add reference
  typo
  Resolve pycodestyle
  Document /neo/Core/TX/
  • Loading branch information
metachris committed Jan 2, 2018
2 parents b3f276e + ca1d715 commit 5f7998e
Show file tree
Hide file tree
Showing 9 changed files with 633 additions and 132 deletions.
62 changes: 56 additions & 6 deletions neo/Core/TX/ClaimTransaction.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
import sys
from itertools import groupby
from logzero import logger

from neo.Core.TX.Transaction import *
from neocore.Fixed8 import Fixed8
from neo.Core.Blockchain import Blockchain
from neo.Core.CoinReference import CoinReference


class ClaimTransaction(Transaction):

Claims = set()

@property
def Size(self):
"""
Get the total size in bytes of the object.
Returns:
int: size.
"""
return super(ClaimTransaction, self).Size() + sys.getsizeof(self.Claims)

def __init__(self, *args, **kwargs):
"""
Create an instance.
Args:
*args:
**kwargs:
"""
super(ClaimTransaction, self).__init__(*args, **kwargs)

self.Type = TransactionType.ClaimTransaction

def NetworkFee(self):
"""
Get the network fee for a claim transaction.
Returns:
Fixed8: currently fixed to 0.
"""
return Fixed8(0)

def DeserializeExclusiveData(self, reader):
"""
Deserialize full object.
Args:
reader (neo.IO.BinaryReader):
Raises:
Exception: If the transaction type is incorrect or if there are no claims.
"""
self.Type = TransactionType.ClaimTransaction
if self.Version != 0:
raise Exception('Format Exception')
Expand All @@ -43,6 +65,15 @@ def DeserializeExclusiveData(self, reader):
raise Exception('Format Exception')

def GetScriptHashesForVerifying(self):
"""
Get a list of script hashes for verifying transactions.
Raises:
Exception: if there are no valid transactions to claim from.
Returns:
list: of UInt160 type script hashes.
"""
hashes = super(ClaimTransaction, self).GetScriptHashesForVerifying()

for hash, group in groupby(self.Claims, lambda x: x.PrevHash):
Expand All @@ -65,19 +96,37 @@ def GetScriptHashesForVerifying(self):
return hashes

def SerializeExclusiveData(self, writer):
"""
Serialize object.
Args:
writer (neo.IO.BinaryWriter):
"""
writer.WriteSerializableArray(self.Claims)

def ToJson(self):
"""
Convert object members to a dictionary that can be parsed as JSON.
Returns:
dict:
"""
json = super(ClaimTransaction, self).ToJson()

json['claims'] = [claim.ToJson() for claim in self.Claims]

return json

def Verify(self, mempool):
"""
Verify the transaction.
Args:
mempool:
Returns:
bool: True if verified. False otherwise.
"""
if not super(ClaimTransaction, self).Verify(mempool):
return False

Expand All @@ -95,7 +144,8 @@ def Verify(self, mempool):
otherclaimTxs = [tx for tx in mempool if tx is ClaimTransaction and tx is not self]
for other in otherclaimTxs:
# check to see if the length of the intersection between this objects claim's and the other txs claims is > 0
if len([list(filter(lambda x: x in self.Claims, otherClaims)) for otherClaims in other.Claims]): return False
if len([list(filter(lambda x: x in self.Claims, otherClaims)) for otherClaims in other.Claims]):
return False

txResult = None
for tx in self.GetTransactionResults():
Expand Down
46 changes: 41 additions & 5 deletions neo/Core/TX/EnrollmentTransaction.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,74 @@


from neo.Core.TX.Transaction import Transaction, TransactionType
import sys
import binascii
from neo.Cryptography.ECCurve import EllipticCurve, ECDSA
from neo.Cryptography.ECCurve import ECDSA
from neo.Settings import settings
from neocore.Fixed8 import Fixed8


class EnrollmentTransaction(Transaction):

PublicKey = None
_script_hash = None

def __init__(self, *args, **kwargs):
"""
Create an instance.
Args:
*args:
**kwargs:
"""
super(EnrollmentTransaction, self).__init__(*args, **kwargs)
self.Type = TransactionType.EnrollmentTransaction

def Size(self):
"""
Get the total size in bytes of the object.
Returns:
int: size.
"""
return self.Size() + sys.getsizeof(int)

def SystemFee(self):
"""
Get the enrollment fee.
Returns:
Fixed8:
"""
return Fixed8(int(settings.ENROLLMENT_TX_FEE))

def DeserializeExclusiveData(self, reader):
"""
Deserialize full object.
Args:
reader (neo.IO.BinaryReader):
Raises:
Exception: If the version read is incorrect.
"""
if self.Version is not 0:
raise Exception('Invalid format')

self.PublicKey = ECDSA.Deserialize_Secp256r1(reader)

def SerializeExclusiveData(self, writer):
"""
Serialize object.
Args:
writer (neo.IO.BinaryWriter):
"""
self.PublicKey.Serialize(writer, True)

def ToJson(self):
"""
Convert object members to a dictionary that can be parsed as JSON.
Returns:
dict:
"""
jsn = super(EnrollmentTransaction, self).ToJson()
jsn['pubkey'] = self.PublicKey.ToString()
return jsn
51 changes: 48 additions & 3 deletions neo/Core/TX/InvocationTransaction.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,52 @@


from neo.Core.TX.Transaction import Transaction, TransactionType
import sys
from neocore.Fixed8 import Fixed8


class InvocationTransaction(Transaction):

Script = None
Gas = None

def SystemFee(self):
"""
Get the system fee.
Returns:
Fixed8:
"""
return self.Gas // Fixed8.FD()

def __init__(self, *args, **kwargs):
"""
Create an instance.
Args:
*args:
**kwargs:
"""
super(InvocationTransaction, self).__init__(*args, **kwargs)
self.Gas = Fixed8(0)
self.Type = TransactionType.InvocationTransaction

def Size(self):
"""
Get the total size in bytes of the object.
Returns:
int: size.
"""
return self.Size() + sys.getsizeof(int)

def DeserializeExclusiveData(self, reader):
"""
Deserialize full object.
Args:
reader (neo.IO.BinaryReader):
Raises:
Exception: If the version read is incorrect.
"""
if self.Version > 1:
raise Exception('Invalid format')

Expand All @@ -39,16 +63,37 @@ def DeserializeExclusiveData(self, reader):
self.Gas = Fixed8(0)

def SerializeExclusiveData(self, writer):
"""
Serialize object.
Args:
writer (neo.IO.BinaryWriter):
"""
writer.WriteVarBytes(self.Script)
if self.Version >= 1:
writer.WriteFixed8(self.Gas)

def Verify(self, mempool):
"""
Verify the transaction.
Args:
mempool:
Returns:
bool: True if verified. False otherwise.
"""
if self.Gas.value % 100000000 != 0:
return False
return super(InvocationTransaction, self).Verify(mempool)

def ToJson(self):
"""
Convert object members to a dictionary that can be parsed as JSON.
Returns:
dict:
"""
jsn = super(InvocationTransaction, self).ToJson()
jsn['script'] = self.Script.hex()
jsn['gas'] = self.Gas.value
Expand Down
22 changes: 19 additions & 3 deletions neo/Core/TX/IssueTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,34 @@
from neo.Core.TX.IssueTransaction import IssueTransaction
"""
from neo.Core.TX.Transaction import Transaction, TransactionType

import random
from neo.Settings import settings
from neocore.Fixed8 import Fixed8
from neo.Blockchain import GetSystemCoin, GetSystemShare


class IssueTransaction(Transaction):

Nonce = None

"""docstring for IssueTransaction"""

def __init__(self, *args, **kwargs):
"""
Create an instance.
Args:
*args:
**kwargs:
"""
super(IssueTransaction, self).__init__(*args, **kwargs)
self.Type = TransactionType.IssueTransaction # 0x40

def SystemFee(self):
"""
Get the system fee.
Returns:
Fixed8:
"""
if self.Version >= 1:
return Fixed8.Zero()

Expand All @@ -42,6 +51,13 @@ def GetScriptHashesForVerifying(self):
pass

def DeserializeExclusiveData(self, reader):
"""
Deserialize full object.
Args:
reader (neo.IO.BinaryReader):
"""

self.Type = TransactionType.IssueTransaction

if self.Version > 1:
Expand Down
Loading

0 comments on commit 5f7998e

Please sign in to comment.