public VirtualChain(NeoAPI api, KeyPair owner)
        {
            this.Time = DateTime.UtcNow.ToTimestamp();

            var scripthash = new UInt160(owner.signatureHash.ToArray());

            var txs = new List <Transaction>();

            foreach (var entry in NeoAPI.Assets)
            {
                var symbol  = entry.Key;
                var assetID = NeoAPI.GetAssetID(symbol);
                _assetMap[assetID] = new Asset()
                {
                    hash = new UInt256(assetID), name = symbol
                };

                var tx = new Transaction();
                tx.outputs = new Transaction.Output[] { new Transaction.Output()
                                                        {
                                                            assetID = assetID, scriptHash = scripthash, value = 1000000000
                                                        } };
                tx.inputs = new Transaction.Input[] { };
                txs.Add(tx);
            }
            GenerateBlock(txs);
        }
Exemple #2
0
        public static Transaction MintTokens(NEP5 token, KeyPair buyer_key, string symbol, decimal amount)
        {
            var attachs = new List <Transaction.Output>();

            attachs.Add(new Transaction.Output()
            {
                assetID = NeoAPI.GetAssetID(symbol), scriptHash = token.scriptHash, value = amount
            });
            var response = token.api.CallContract(buyer_key, token.scriptHash, "mintTokens", new object[] { }, symbol, attachs);

            return(response);
        }
Exemple #3
0
        public Transaction ClaimGas(KeyPair ownerKey)
        {
            var targetScriptHash = new UInt160(ownerKey.address.AddressToScriptHash());

            decimal amount;
            var     claimable = GetClaimable(targetScriptHash, out amount);

            var references = new List <Transaction.Input>();

            foreach (var entry in claimable)
            {
                references.Add(new Transaction.Input()
                {
                    prevHash = entry.hash, prevIndex = entry.index
                });
            }

            if (amount <= 0)
            {
                throw new ArgumentException("No GAS to claim at this address");
            }

            List <Transaction.Input>  inputs;
            List <Transaction.Output> outputs;

            GenerateInputsOutputs(ownerKey, "GAS", null, out inputs, out outputs);

            outputs.Add(
                new Transaction.Output()
            {
                scriptHash = targetScriptHash,
                assetID    = NeoAPI.GetAssetID("GAS"),
                value      = amount
            });

            Transaction tx = new Transaction()
            {
                type            = TransactionType.ClaimTransaction,
                version         = 0,
                script          = null,
                gas             = -1,
                claimReferences = references.ToArray(),
                inputs          = inputs.ToArray(),
                outputs         = outputs.ToArray(),
            };

            tx.Sign(ownerKey);

            var ok = SendTransaction(tx);

            return(ok ? tx : null);
        }
Exemple #4
0
        protected override void Reset()
        {
            base.Reset();

            foreach (var entry in NeoAPI.Assets)
            {
                var symbol  = entry.Key;
                var assetID = NeoAPI.GetAssetID(symbol);
                _assetMap[assetID] = new Asset()
                {
                    hash = new UInt256(assetID), name = symbol
                };
            }
        }
Exemple #5
0
        // claim from contract, without having private key
        public Transaction ClaimGas(KeyPair ownerKey, UInt160 fromScripthash, byte[] verificationScript)
        {
            var check = verificationScript.ToScriptHash();

            if (check != fromScripthash)
            {
                throw new ArgumentException("Invalid verification script");
            }

            decimal amount;
            var     claimable = GetClaimable(fromScripthash, out amount);

            var references = new List <Transaction.Input>();

            foreach (var entry in claimable)
            {
                references.Add(new Transaction.Input()
                {
                    prevHash = entry.hash, prevIndex = entry.index
                });
            }

            if (amount <= 0)
            {
                throw new ArgumentException("No GAS to claim at this address");
            }

            List <Transaction.Input>  inputs;
            List <Transaction.Output> outputs;

            GenerateInputsOutputs(ownerKey, "GAS", null, out inputs, out outputs);

            outputs.Add(
                new Transaction.Output()
            {
                scriptHash = fromScripthash,
                assetID    = NeoAPI.GetAssetID("GAS"),
                value      = amount
            });

            Transaction tx = new Transaction()
            {
                type            = TransactionType.ClaimTransaction,
                version         = 0,
                script          = null,
                gas             = -1,
                claimReferences = references.ToArray(),
                inputs          = inputs.ToArray(),
                outputs         = outputs.ToArray(),
            };

            var witness = new Witness {
                invocationScript = ("0014" + ownerKey.address.AddressToScriptHash().ByteToHex()).HexToBytes(), verificationScript = verificationScript
            };

            tx.Sign(ownerKey, new Witness[] { witness });

            var ok = SendTransaction(tx);

            return(ok ? tx : null);
        }