Example #1
0
    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
Example #2
0
    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()
Example #3
0
    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
Example #4
0
    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
Example #5
0
    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
Example #6
0
    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
Example #7
0
    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
Example #8
0
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
Example #9
0
    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)