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

Commit

Permalink
ask for more headers when all caught up.
Browse files Browse the repository at this point in the history
  • Loading branch information
localhuman committed Aug 30, 2017
1 parent 3bd71f9 commit 931a995
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion neo/IO/BinaryReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def Read2000256List(self):
return items

def ReadHashes(self, maximum=16):
len = self.ReadUInt8()
len = self.ReadVarInt()
items = []
for i in range(0, len):
ba = bytearray(self.ReadBytes(32))
Expand Down
6 changes: 4 additions & 2 deletions neo/IO/BinaryWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from autologging import logged
from neo.UInt160 import UInt160
from neo.UInt256 import UInt256
import sys,os
import inspect

def swap32(i):
return struct.unpack("<I", struct.pack(">I", i))[0]
Expand Down Expand Up @@ -48,7 +50,6 @@ def WriteBytes(self, value):
self.stream.write(value)

def pack(self, fmt, data):
byts = struct.pack(fmt, data)
return self.WriteBytes(struct.pack(fmt, data))

def WriteChar(self, value, endian="<"):
Expand All @@ -64,6 +65,7 @@ def WriteInt8(self, value, endian="<"):
return self.pack('%sb' % endian, value)

def WriteUInt8(self, value, endian="<"):
print("writing uint 8 %s " % value)
return self.pack('%sB' % endian, value)

def WriteBool(self, value, endian="<"):
Expand Down Expand Up @@ -169,7 +171,7 @@ def Write2000256List(self, arr):

def WriteHashes(self, arr):
length = len(arr)
self.WriteUInt8(length)
self.WriteVarInt(length)
for item in arr:
ba = bytearray(binascii.unhexlify(item))
ba.reverse()
Expand Down
10 changes: 9 additions & 1 deletion neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,18 @@ def ShowAllContracts(self):

def GetContract(self, hash):

if type(hash) is str:
try:
hash = hash.encode('utf-8')
except Exception as e:
self.__log.debug("could not convert argument to bytes :%s " % e)
return None

sn = self._db.snapshot()
contracts = DBCollection(self._db, sn, DBPrefix.ST_Contract, ContractState)
contract = contracts.TryGet(keyval=hash)
sn.close()
return contracts.TryGet(keyval=hash)
return contract


def GetAllSpentCoins(self):
Expand Down
1 change: 1 addition & 0 deletions neo/Network/NeoNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def DoAskForMoreBlocks(self):
self.SendSerializedMessage(message)
else:
self.Log("all caught up!!!!!! hashes is zero")
self.AskForMoreHeaders()
reactor.callLater(20, self.DoAskForMoreBlocks)

def RequestPeerInfo(self):
Expand Down
39 changes: 25 additions & 14 deletions neo/SmartContract/StateMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
from neo.Core.State.ValidatorState import ValidatorState
from neo.Core.AssetType import AssetType
from neo.Cryptography.Crypto import Crypto
from neo.Cryptography.ECCurve import EllipticCurve,ECDSA
from neo.Cryptography.ECCurve import ECDSA
from neo.UInt160 import UInt160
from neo.UInt256 import UInt256
from neo.Fixed8 import Fixed8
from neo.VM.InteropService import StackItem
from neo.SmartContract.StorageContext import StorageContext
from neo.SmartContract.StateReader import StateReader
from neo.IO.BinaryReader import BinaryReader
from neo.IO.BinaryWriter import BinaryWriter
from neo.IO.MemoryStream import StreamManager

import sys
import json
import binascii

from autologging import logged

Expand Down Expand Up @@ -143,21 +139,24 @@ def Account_SetVotes(self, engine):
balance = account.BalanceFor( Blockchain.SystemShare().Hash)

if balance == Fixed8.Zero() and len(vote_list) > 0:
print("no balance, return false!")
return False

# disable setting votes for now until further testing to make sure we're not duplicating votes
#
# acct = self._accounts.GetAndChange(account.AddressBytes)
# voteset = set()
# for v in vote_list:
# voteset.add(v.GetByteArray())
# acct.Votes = list(voteset)
# self.__log.debug("SET ACCOUNT VOTES %s " % json.dumps(acct.ToJson(), indent=4))
print("Setting votes!!!")

acct = self._accounts.GetAndChange(account.AddressBytes)
voteset = set()
for v in vote_list:
voteset.add(v.GetByteArray())
acct.Votes = list(voteset)
print("*****************************************************")
print("SET ACCOUNT VOTES %s " % json.dumps(acct.ToJson(), indent=4))
print("*****************************************************")
return True


def Validator_Register(self, engine):
#Not Implemented

pubkey = ECDSA.decode_secp256r1( engine.EvaluationStack.Pop().GetByteArray())
if pubkey.IsInfinity:
return False
Expand Down Expand Up @@ -234,6 +233,9 @@ def Asset_Create(self, engine):

asset = self._assets.GetOrAdd(tx.Hash.ToBytes(), new_asset)

print("*****************************************************")
print("CREATED ASSET %s " % tx.Hash.ToBytes())
print("*****************************************************")
engine.EvaluationStack.PushT(StackItem.FromInterface(asset))

return True
Expand Down Expand Up @@ -317,6 +319,10 @@ def Contract_Create(self, engine):
self._contracts_created[hash.ToBytes()] = UInt160( data = engine.CurrentContext.ScriptHash())

engine.EvaluationStack.PushT(StackItem.FromInterface(contract))

print("*****************************************************")
print("CREATED CONTRACT %s " % hash.ToBytes())
print("*****************************************************")
return True


Expand Down Expand Up @@ -381,6 +387,11 @@ def Contract_Migrate(self, engine):
self._storages.Add(key, item)

engine.EvaluationStack.PushT(StackItem.FromInterface(contract))

print("*****************************************************")
print("MIGRATED CONTRACT %s " % hash.ToBytes())
print("*****************************************************")

return True

def Contract_GetStorageContext(self, engine):
Expand Down
2 changes: 1 addition & 1 deletion protocol.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
},
"ApplicationConfiguration": {
"DataDirectoryPath": "./Chains/Chain1",
"DataDirectoryPath": "./Chains/ChainMainYo",
"NodePort": 10333,
"WsPort": 10334,
"UriPrefix": [ "http://*:10332" ],
Expand Down

0 comments on commit 931a995

Please sign in to comment.