def Deserialize(self, reader): super(AssetState, self).Deserialize(reader) self.AssetId = reader.ReadUInt256() self.AssetType = reader.ReadByte() self.Name = reader.ReadVarString() position = reader.stream.tell() try: self.Amount = reader.ReadFixed8(unsigned=True) except Exception as e: reader.stream.seek(position) self.Amount = reader.ReadFixed8() self.Available = reader.ReadFixed8(unsigned=True) self.Precision = reader.ReadByte() #fee mode reader.ReadByte() self.Fee = reader.ReadFixed8() self.FeeAddress = reader.ReadUInt160() self.Owner = ECDSA.Deserialize_Secp256r1(reader) self.Admin = reader.ReadUInt160() self.Issuer = reader.ReadUInt160() self.Expiration = reader.ReadUInt32() self.IsFrozen = reader.ReadBool()
def StandbyValidators(): if len(Blockchain.__validators) < 1: vlist = Settings.STANDBY_VALIDATORS for pkey in Settings.STANDBY_VALIDATORS: Blockchain.__validators.append(ECDSA.decode_secp256r1(pkey).G) return Blockchain.__validators
def SystemShare(): amount = Fixed8.FromDecimal(sum(Blockchain.GENERATION_AMOUNT) * Blockchain.DECREMENT_INTERVAL) owner = ECDSA.secp256r1().Curve.Infinity admin = Crypto.ToScriptHash(PUSHT) return RegisterTransaction([], [], AssetType.GoverningToken, "[{\"lang\":\"zh-CN\",\"name\":\"小蚁股\"},{\"lang\":\"en\",\"name\":\"AntShare\"}]", amount, 0, owner, admin)
def DeserializeExclusiveData(self, reader): self.Type = TransactionType.RegisterTransaction self.AssetType = reader.ReadByte() self.Name = reader.ReadVarString() self.Amount = reader.ReadFixed8() self.Precision = reader.ReadByte() self.Owner = ECDSA.Deserialize_Secp256r1(reader) # self.Owner = ecdsa.G self.Admin = reader.ReadUInt160()
def DeserializeExclusiveData(self, reader): self.Type = TransactionType.RegisterTransaction self.AssetType = reader.ReadByte() self.Name = reader.ReadVarString().decode('utf-8') self.Amount = Fixed8(reader.ReadInt64()) self.Precision = reader.ReadByte() pkey = reader.ReadBytes(33) ecdsa = ECDSA.decode_secp256r1(pkey) self.Owner = ecdsa.G self.Admin = reader.ReadUInt160()
def SystemCoin(): amount = Fixed8.FromDecimal(sum(Blockchain.GENERATION_AMOUNT) * Blockchain.DECREMENT_INTERVAL) owner = ECDSA.secp256r1().Curve.Infinity precision = 8 admin = Crypto.ToScriptHash(PUSHF) return RegisterTransaction([], [], AssetType.UtilityToken, "[{\"lang\":\"zh-CN\",\"name\":\"小蚁币\"},{\"lang\":\"en\",\"name\":\"AntCoin\"}]", amount, precision, owner, admin)
def Validator_Register(self, engine): #Not Implemented pubkey = ECDSA.decode_secp256r1( engine.EvaluationStack.Pop().GetByteArray()) if pubkey.IsInfinity: return False if not self.CheckWitnessPubkey(engine, pubkey): return False vstate = ValidatorState(pub_key=pubkey) validator = self._validators.GetOrAdd(pubkey.ToString(), vstate) engine.EvaluationStack.PushT(StackItem.FromInterface(validator)) return True
def Validator_Register(self, engine): pubkey = ECDSA.decode_secp256r1( engine.EvaluationStack.Pop().GetByteArray(), unhex=False, check_on_curve=True).G if pubkey.IsInfinity: return False if not self.CheckWitnessPubkey(engine, pubkey): return False vstate = ValidatorState(pub_key=pubkey) validator = self._validators.GetOrAdd(pubkey.ToBytes(), vstate) engine.EvaluationStack.PushT(StackItem.FromInterface(validator)) return True
def Deserialize(self, reader): super(AssetState, self).Deserialize(reader) self.AssetId = reader.ReadUInt256() self.AssetType = reader.ReadByte() self.Name = reader.ReadVarString() self.Amount = reader.ReadFixed8() self.Available = reader.ReadFixed8() self.Precision = reader.ReadByte() #fee mode reader.ReadByte() self.Fee = reader.ReadFixed8() self.FeeAddress = reader.ReadUInt160() self.Owner = ECDSA.Deserialize_Secp256r1(reader) self.Admin = reader.ReadUInt160() self.Issuer = reader.ReadUInt160() self.Expiration = reader.ReadUInt32() self.IsFrozen = reader.ReadBool()
def Runtime_CheckWitness(self, engine): hashOrPubkey = engine.EvaluationStack.Pop().GetByteArray() result = False if len(hashOrPubkey) == 20: result = self.CheckWitnessHash(engine, hashOrPubkey) elif len(hashOrPubkey) == 33: point = ECDSA.decode_secp256r1(hashOrPubkey) result = self.CheckWitnessPubkey(engine, point) else: result = False engine.EvaluationStack.PushT(result) return True
def __init__(self, priv_key): self.setup_curve() length = len(priv_key) if length != 32 and length != 96 and length != 104: raise Exception("Invalid private key") self.PrivateKey = bytearray(priv_key[-32:]) pubkey_encoded_not_compressed = None if length == 32: pubkey_encoded_not_compressed = bitcoin.privkey_to_pubkey(priv_key) elif length == 64 or length == 72: skip = length - 64 pubkey_encoded_not_compressed = bytearray( b'04').hex() + priv_key[skip:] elif length == 96 or length == 104: skip = length - 96 pubkey_encoded_not_compressed = bytearray(b'\x04') + bytearray( priv_key[skip:skip + 64]) if pubkey_encoded_not_compressed: pubkey_points = bitcoin.decode_pubkey( pubkey_encoded_not_compressed, 'bin') pubx = pubkey_points[0] puby = pubkey_points[1] edcsa = ECDSA.secp256r1() self.PublicKey = edcsa.Curve.point(pubx, puby) else: raise Exception("Could not determine public key") self.PublicKeyHash = Crypto.ToScriptHash( self.PublicKey.encode_point(True), unhex=True)
def Runtime_CheckWitness(self, engine): hashOrPubkey = engine.EvaluationStack.Pop().GetByteArray() if len(hashOrPubkey) == 66 or len(hashOrPubkey) == 40: hashOrPubkey = binascii.unhexlify(hashOrPubkey) result = False if len(hashOrPubkey) == 20: result = self.CheckWitnessHash(engine, UInt160(data=hashOrPubkey)) elif len(hashOrPubkey) == 33: point = ECDSA.decode_secp256r1(hashOrPubkey, unhex=False).G result = self.CheckWitnessPubkey(engine, point) else: result = False engine.EvaluationStack.PushT(result) return True
def DeserializeExclusiveData(self, reader): if self.Version is not 0: raise Exception('Invalid format') self.PublicKey = ECDSA.Deserialize_Secp256r1(reader)
def Deserialize(self, reader): super(ValidatorState, self).Deserialize(reader) self.PublicKey = ECDSA.Deserialize_Secp256r1(reader)
def CreateMultiSigContract(publicKeyHash, m, publicKeys): pk = [ECDSA.decode_secp256r1(p).G for p in publicKeys] return Contract(Contract.CreateMultiSigRedeemScript(m, pk), bytearray([ContractParameterType.Signature] * 3), publicKeyHash)
def Asset_Create(self, engine): tx = engine.ScriptContainer asset_type = int(engine.EvaluationStack.Pop().GetBigInteger()) if asset_type not in AssetType.AllTypes() or \ asset_type == AssetType.CreditFlag or \ asset_type == AssetType.DutyFlag or \ asset_type == AssetType.GoverningToken or \ asset_type == AssetType.UtilityToken: return False if len(engine.EvaluationStack.Peek().GetByteArray()) > 1024: return False name = engine.EvaluationStack.Pop().GetByteArray().decode('utf-8') amount = Fixed8(engine.EvaluationStack.Pop().GetBigInteger()) if amount == Fixed8.Zero() or amount < Fixed8.NegativeSatoshi(): return False if asset_type == AssetType.Invoice and amount != Fixed8.NegativeSatoshi( ): return False precision = int(engine.EvaluationStack.Pop().GetBigInteger()) if precision > 8: return False if asset_type == AssetType.Share and precision != 0: return False if amount != Fixed8.NegativeSatoshi() and amount.value % pow( 10, 8 - precision) != 0: return False ownerData = engine.EvaluationStack.Pop().GetByteArray() owner = ECDSA.decode_secp256r1(ownerData, unhex=False).G if owner.IsInfinity: return False if not self.CheckWitnessPubkey(engine, owner): logger.error("check witness false...") return False admin = UInt160(data=engine.EvaluationStack.Pop().GetByteArray()) issuer = UInt160(data=engine.EvaluationStack.Pop().GetByteArray()) new_asset = AssetState(asset_id=tx.Hash, asset_type=asset_type, name=name, amount=amount, available=Fixed8.Zero(), precision=precision, fee_mode=0, fee=Fixed8.Zero(), fee_addr=UInt160(), owner=owner, admin=admin, issuer=issuer, expiration=Blockchain.Default().Height + 1 + 2000000, is_frozen=False) 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
from neo.Wallets.Contract import Contract from neo import Settings from neo.Cryptography.Crypto import * from neo.Cryptography.Helper import * from collections import Counter from neo.Fixed8 import Fixed8 from datetime import datetime from events import Events from neo.Cryptography.ECCurve import ECDSA import pytz import traceback from neo.UInt160 import UInt160 from neo.UInt256 import UInt256 ### not sure of the origin of these Issuer = ECDSA.decode_secp256r1( '030fe41d11cc34a667cf1322ddc26ea4a8acad3b8eefa6f6c3f49c7673e4b33e4b').G Admin = b'Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt' class Blockchain(object): SECONDS_PER_BLOCK = 15 DECREMENT_INTERVAL = 2000000 GENERATION_AMOUNT = [ 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] __blockchain = None