Exemple #1
0
 internal static bool VerifySignature(this ISignable signable)
 {
     UInt160[] hashes;
     try
     {
         hashes = signable.GetScriptHashesForVerifying();
     }
     catch (InvalidOperationException)
     {
         return false;
     }
     if (hashes.Length != signable.Scripts.Length) return false;
     for (int i = 0; i < hashes.Length; i++)
     {
         if (hashes[i] != signable.Scripts[i].RedeemScript.ToScriptHash()) return false;
         ScriptEngine engine = new ScriptEngine(signable.Scripts[i], signable.GetHashForSigning());
         if (!engine.Execute()) return false;
     }
     return true;
 }
Exemple #2
0
        private bool ChainGetBlock(ScriptEngine engine)
        {
            if (engine.Stack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.Stack.Pop();

            byte[][]     data = x.GetBytesArray();
            List <Block> r    = new List <Block>();

            foreach (byte[] d in data)
            {
                switch (d.Length)
                {
                case sizeof(uint):
                    uint height = BitConverter.ToUInt32(d, 0);
                    if (Blockchain.Default != null)
                    {
                        r.Add(Blockchain.Default.GetBlock(height));
                    }
                    else if (height == 0)
                    {
                        r.Add(Blockchain.GenesisBlock);
                    }
                    else
                    {
                        r.Add(null);
                    }
                    break;

                case 32:
                    UInt256 hash = new UInt256(d);
                    if (Blockchain.Default != null)
                    {
                        r.Add(Blockchain.Default.GetBlock(hash));
                    }
                    else if (hash == Blockchain.GenesisBlock.Hash)
                    {
                        r.Add(Blockchain.GenesisBlock);
                    }
                    else
                    {
                        r.Add(null);
                    }
                    break;

                default:
                    return(false);
                }
            }
            if (x.IsArray)
            {
                engine.Stack.Push(new StackItem(r.ToArray()));
            }
            else
            {
                engine.Stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
Exemple #3
0
 private bool SystemCurrentScriptHash(ScriptEngine engine)
 {
     engine.Stack.Push(new StackItem(engine.ExecutingScript.ToScriptHash()));
     return(true);
 }
Exemple #4
0
 private bool SystemCurrentTx(ScriptEngine engine)
 {
     engine.Stack.Push(new StackItem(engine.Signable as Transaction));
     return(true);
 }
Exemple #5
0
 private bool SystemNow(ScriptEngine engine)
 {
     engine.Stack.Push(DateTime.Now.ToTimestamp());
     return(true);
 }
Exemple #6
0
        public bool Invoke(string method, ScriptEngine engine)
        {
            switch (method)
            {
            case "System.now":
                return(SystemNow(engine));

            case "System.currentTx":
                return(SystemCurrentTx(engine));

            case "System.currentScriptHash":
                return(SystemCurrentScriptHash(engine));

            case "Chain.height":
                return(ChainHeight(engine));

            case "Chain.getHeader":
                return(ChainGetHeader(engine));

            case "Chain.getBlock":
                return(ChainGetBlock(engine));

            case "Chain.getTx":
                return(ChainGetTx(engine));

            case "Header.hash":
                return(HeaderHash(engine));

            case "Header.version":
                return(HeaderVersion(engine));

            case "Header.prevHash":
                return(HeaderPrevHash(engine));

            case "Header.merkleRoot":
                return(HeaderMerkleRoot(engine));

            case "Header.timestamp":
                return(HeaderTimestamp(engine));

            case "Header.nonce":
                return(HeaderNonce(engine));

            case "Header.nextMiner":
                return(HeaderNextMiner(engine));

            case "Block.txCount":
                return(BlockTxCount(engine));

            case "Block.tx":
                return(BlockTx(engine));

            case "Block.getTx":
                return(BlockGetTx(engine));

            case "TX.hash":
                return(TxHash(engine));

            case "TX.type":
                return(TxType(engine));

            case "Asset.type":
                return(AssetType(engine));

            case "Asset.amount":
                return(AssetAmount(engine));

            case "Asset.issuer":
                return(AssetIssuer(engine));

            case "Asset.admin":
                return(AssetAdmin(engine));

            case "Enroll.pubkey":
                return(EnrollPubkey(engine));

            case "Vote.enrollments":
                return(VoteEnrollments(engine));

            case "TX.attributes":
                return(TxAttributes(engine));

            case "TX.inputs":
                return(TxInputs(engine));

            case "TX.outputs":
                return(TxOutputs(engine));

            case "Attribute.usage":
                return(AttrUsage(engine));

            case "Attribute.data":
                return(AttrData(engine));

            case "Input.hash":
                return(TxInHash(engine));

            case "Input.index":
                return(TxInIndex(engine));

            case "Output.asset":
                return(TxOutAsset(engine));

            case "Output.value":
                return(TxOutValue(engine));

            case "Output.scriptHash":
                return(TxOutScriptHash(engine));

            default:
                return(false);
            }
        }