コード例 #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            var scripthash = textBox1.Text;

            var fromscripthash = GetScriptHashFromAddress(label5.Text);
            var num            = new System.Numerics.BigInteger(decimal.Parse(textBox6.Text) * (decimal)amount);
            var p1             = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
            {
                Value = "use"
            };
            var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
            {
                Value = new ContractParameter[]
                {
                    new ContractParameter(Neo.SmartContract.ContractParameterType.ByteArray)
                    {
                        Value = fromscripthash
                    },
                    new ContractParameter(Neo.SmartContract.ContractParameterType.Integer)
                    {
                        Value = num
                    }
                }
            };
            var script = MakeAppCallScript(scripthash, p1, p2);

            CallScript(script);
        }
コード例 #2
0
 private void button8_Click(object sender, EventArgs e)
 {
     var scripthash     = textBox1.Text;
     var addrscripthash = GetScriptHashFromAddress(textBox5.Text);
     {
         var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
         {
             Value = "newBonus"
         };
         var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
         {
         };
         var script = MakeAppCallScript(scripthash, p1, p2);
         var ts     = CallScript(script, true);
         var sitem  = ts.EvaluationStack.Pop();
         if (sitem == null)
         {
             listBox2.Items.Add("no Bonus.");
         }
         else
         {
             var tss = sitem.GetBigInteger();
             listBox2.Items.Add("to bonus:" + tss);
         }
     }
 }
コード例 #3
0
 private void button2_Click(object sender, EventArgs e)
 {
     var scripthash     = textBox1.Text;
     var addrscripthash = GetScriptHashFromAddress(textBox5.Text);
     {
         var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
         {
             Value = "balanceOfDetail"
         };
         var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
         {
             Value = new ContractParameter[]
             {
                 new ContractParameter(Neo.SmartContract.ContractParameterType.ByteArray)
                 {
                     Value = addrscripthash
                 }
             }
         };
         var script      = MakeAppCallScript(scripthash, p1, p2);
         var ts          = TestCallScript(script);
         var tss         = ts as Neo.VM.Types.Array;
         var cash        = (decimal)tss[0].GetBigInteger() / (decimal)amount;
         var saving      = tss[1].GetBigInteger();
         var savingblock = tss[2].GetBigInteger();
         var balance     = (decimal)tss[3].GetBigInteger() / (decimal)amount;
         label10.Text = "balance:" + balance;
         label12.Text = "cash(不可领奖部分):" + cash;
         label13.Text = "saving(可领奖部分):" + saving + " block:[" + savingblock + "]";
     }
 }
コード例 #4
0
 private void button3_Click(object sender, EventArgs e)
 {
     var scripthash     = textBox1.Text;
     var addrscripthash = GetScriptHashFromAddress(textBox2.Text);
     {
         var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
         {
             Value = "balanceOf"
         };
         var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
         {
             Value = new ContractParameter[]
             {
                 new ContractParameter(Neo.SmartContract.ContractParameterType.ByteArray)
                 {
                     Value = addrscripthash
                 }
             }
         };
         var script = MakeAppCallScript(scripthash, p1, p2);
         var ts     = TestCallScript(script);
         var n      = (decimal)ts.GetBigInteger() / (decimal)amount;
         label3.Text = "balance:" + n;
     }
 }
コード例 #5
0
ファイル: WhoAmi.cs プロジェクト: NewEconoLab/dapp_whoami
        private void button3_Click(object sender, EventArgs e)
        {
            var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
            {
                Value = textBoxName.Text
            };
            var script = plugin_whoami.MakeAppCallScript(plugin_whoami.whoami_scripthash, this.textBoxPubKey.Text, p1);

            plugin_whoami.CallScript(script);
        }
コード例 #6
0
 public static ContextItem FromJson(JObject json)
 {
     TR.Enter();
     return(TR.Exit(new ContextItem
     {
         Script = json["script"]?.AsString().HexToBytes(),
         Parameters = ((JArray)json["parameters"]).Select(p => ContractParameter.FromJson(p)).ToArray(),
         Signatures = json["signatures"]?.Properties.Select(p => new
         {
             PublicKey = ECPoint.Parse(p.Key, ECCurve.Secp256r1),
             Signature = p.Value.AsString().HexToBytes()
         }).ToDictionary(p => p.PublicKey, p => p.Signature)
     }));
 }
コード例 #7
0
ファイル: WhoAmiEx.cs プロジェクト: NewEconoLab/dapp_whoami
        private void button4_Click(object sender, EventArgs e)
        {
            var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.ByteArray)
            {
                Value = new byte[] { 0x02 }
            };
            var p2 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.ByteArray)
            {
                Value = files
            };
            var script = plugin_whoami.MakeAppCallScript(plugin_whoami.microblog_scripthash, this.textBoxPubKey.Text, p1, p2);

            plugin_whoami.CallScript(script);
        }
コード例 #8
0
ファイル: WhoAmiEx.cs プロジェクト: NewEconoLab/dapp_whoami
        private void button3_Click(object sender, EventArgs e)
        {
            var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.ByteArray)
            {
                Value = new byte[] { 0x01 }
            };
            var p2 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.ByteArray)
            {
                Value = System.Text.Encoding.UTF8.GetBytes(textBoxName.Text)
            };
            var script = plugin_whoami.MakeAppCallScript(plugin_whoami.microblog_scripthash, this.textBoxPubKey.Text, p1, p2);

            plugin_whoami.CallScript(script);
        }
コード例 #9
0
ファイル: ContractParameter.cs プロジェクト: vovietanh/neo
        public static ContractParameter FromJson(JObject json)
        {
            ContractParameter parameter = new ContractParameter
            {
                Type = json["type"].AsEnum <ContractParameterType>()
            };
            JObject value = json["value"];

            if (value != null)
            {
                switch (parameter.Type)
                {
                case ContractParameterType.Signature:
                case ContractParameterType.ByteArray:
                    parameter.Value = json["value"].AsString().HexToBytes();
                    break;

                case ContractParameterType.Boolean:
                    parameter.Value = json["value"].AsBoolean();
                    break;

                case ContractParameterType.Integer:
                    parameter.Value = BigInteger.Parse(json["value"].AsString());
                    break;

                case ContractParameterType.Hash160:
                    parameter.Value = UInt160.Parse(json["value"].AsString());
                    break;

                case ContractParameterType.Hash256:
                    parameter.Value = UInt256.Parse(json["value"].AsString());
                    break;

                case ContractParameterType.PublicKey:
                    parameter.Value = ECPoint.Parse(json["value"].AsString(), ECCurve.Secp256r1);
                    break;

                case ContractParameterType.String:
                    parameter.Value = json["value"].AsString();
                    break;

                case ContractParameterType.Array:
                    parameter.Value = ((JArray)json["value"]).Select(p => FromJson(p)).ToArray();
                    break;
                }
            }
            return(parameter);
        }
コード例 #10
0
        public static byte[] MakeAppCallScript(string script_hash, string _pubkey, params ContractParameter[] _params)
        {
            //拼合调用脚本
            byte[] script = null;
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                var pkeybytes = FromHexString(_pubkey);
                var pubkey    = Neo.Cryptography.ECC.ECPoint.FromBytes(pkeybytes, Neo.Cryptography.ECC.ECCurve.Secp256r1);
                ContractParameter[] parameters = new Neo.SmartContract.ContractParameter[] {
                    new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.PublicKey)
                    {
                        Value = pubkey
                    },
                };
                var newparams = parameters.Concat(_params).ToArray();

                var hash = Neo.UInt160.Parse(script_hash);
                Neo.VM.Helper.EmitAppCall(sb, hash, newparams);
                script = sb.ToArray();
            }
            return(script);
        }
コード例 #11
0
        private void button9_Click(object sender, EventArgs e)
        {
            var scripthash = textBox1.Text;

            var fromscripthash = GetScriptHashFromAddress(label5.Text);
            var p1             = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
            {
                Value = "getBonus"
            };
            var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
            {
                Value = new ContractParameter[]
                {
                    new ContractParameter(Neo.SmartContract.ContractParameterType.ByteArray)
                    {
                        Value = fromscripthash
                    }
                }
            };
            var script = MakeAppCallScript(scripthash, p1, p2);

            CallScript(script);
        }
コード例 #12
0
        public static ContractParametersContext FromJson(JObject json)
        {
            IVerifiable verifiable = typeof(ContractParametersContext).GetTypeInfo().Assembly.CreateInstance(json["type"].AsString()) as IVerifiable;

            if (verifiable == null)
            {
                throw new FormatException();
            }
            using (MemoryStream ms = new MemoryStream(json["hex"].AsString().HexToBytes(), false))
                using (BinaryReader reader = new BinaryReader(ms, Encoding.UTF8))
                {
                    verifiable.DeserializeUnsigned(reader);
                }
            return(new ContractParametersContext(verifiable)
            {
                Script = json["script"]?.AsString().HexToBytes(),
                Parameters = ((JArray)json["parameters"])?.Select(p => ContractParameter.FromJson(p)).ToArray(),
                Signatures = json["signatures"]?.Properties.Select(p => new
                {
                    PublicKey = ECPoint.Parse(p.Key, ECCurve.Secp256r1),
                    Signature = p.Value.AsString().HexToBytes()
                }).ToDictionary(p => p.PublicKey, p => p.Signature)
            });
        }
コード例 #13
0
        private void button6_Click(object sender, EventArgs e)
        {
            var script_hash = UInt160.Parse(textBox1.Text);
            var key         = System.Text.Encoding.ASCII.GetBytes("!pool");
            var bchain      = Neo.Core.Blockchain.Default;

            var skey = new Neo.Core.StorageKey();

            skey.Key        = key;
            skey.ScriptHash = script_hash;

            listBox2.Items.Clear();

            var item = bchain.GetStorageItem(skey);

            if (item == null)
            {
                listBox2.Items.Add("pool empty");
            }
            else
            {
                listBox2.Items.Add("pool balance=" + (decimal) new System.Numerics.BigInteger(item.Value) / (decimal)amount);
            }

            var scripthash     = textBox1.Text;
            var addrscripthash = GetScriptHashFromAddress(textBox5.Text);
            {
                var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
                {
                    Value = "checkBonus"
                };
                var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
                {
                };
                var script = MakeAppCallScript(scripthash, p1, p2);
                var ts     = TestCallScript(script);
                if (ts == null)
                {
                    listBox2.Items.Add("no Bonus.");
                }
                else
                {
                    try
                    {
                        var tss = ts as Neo.VM.Types.Array;
                        for (var i = 0; i < tss.Count; i++)
                        {
                            var titme = tss[i];
                            if (titme is  Neo.VM.Types.Array)
                            {
                                var arr = titme as Neo.VM.Types.Array;

                                listBox2.Items.Add(i + "领奖block=" + arr[0].GetBigInteger());
                                listBox2.Items.Add(i + "奖池总数=" + (decimal)arr[1].GetBigInteger() / (decimal)amount);
                                listBox2.Items.Add(i + "领奖比例=" + (decimal)arr[2].GetBigInteger() / (decimal)amount);
                            }
                        }
                    }
                    catch
                    {
                        listBox2.Items.Add("no bonus");
                    }
                }
            }
        }
コード例 #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            var scripthash = textBox1.Text;

            amount = 1;
            //查询
            {
                var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
                {
                    Value = "decimals"
                };
                var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
                {
                    Value = new ContractParameter[0]
                };
                var script = MakeAppCallScript(scripthash, p1, p2);
                var ts     = TestCallScript(script);
                var n      = ts.GetBigInteger();
                listBox1.Items.Add("decimals=" + n);
                for (var i = 0; i < n; i++)
                {
                    amount *= 10;
                }
            }
            {
                var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
                {
                    Value = "name"
                };
                var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
                {
                    Value = new ContractParameter[0]
                };
                var script = MakeAppCallScript(scripthash, p1, p2);
                var ts     = TestCallScript(script);
                var n      = ts.GetString();
                listBox1.Items.Add("name=" + n);
            }
            {
                var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
                {
                    Value = "symbol"
                };
                var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
                {
                    Value = new ContractParameter[0]
                };
                var script = MakeAppCallScript(scripthash, p1, p2);
                var ts     = TestCallScript(script);
                var n      = ts.GetString();
                listBox1.Items.Add("symbol=" + n);
            }
            {
                var p1 = new Neo.SmartContract.ContractParameter(Neo.SmartContract.ContractParameterType.String)
                {
                    Value = "totalSupply"
                };
                var p2 = new ContractParameter(Neo.SmartContract.ContractParameterType.Array)
                {
                    Value = new ContractParameter[0]
                };
                var script = MakeAppCallScript(scripthash, p1, p2);
                var ts     = TestCallScript(script);
                var n      = (double)ts.GetBigInteger() / (double)amount;
                listBox1.Items.Add("totalSupply=" + n);
            }
        }
コード例 #15
0
ファイル: ContractParameter.cs プロジェクト: jz263/neo
        private static string ToString(ContractParameter parameter, HashSet <ContractParameter> context)
        {
            switch (parameter.Value)
            {
            case null:
                return("(null)");

            case byte[] data:
                return(data.ToHexString());

            case IList <ContractParameter> data:
                if (context is null)
                {
                    context = new HashSet <ContractParameter>();
                }
                if (context.Contains(parameter))
                {
                    return("(array)");
                }
                else
                {
                    context.Add(parameter);
                    StringBuilder sb = new StringBuilder();
                    sb.Append('[');
                    foreach (ContractParameter item in data)
                    {
                        sb.Append(ToString(item, context));
                        sb.Append(", ");
                    }
                    if (data.Count > 0)
                    {
                        sb.Length -= 2;
                    }
                    sb.Append(']');
                    return(sb.ToString());
                }

            case IList <KeyValuePair <ContractParameter, ContractParameter> > data:
                if (context is null)
                {
                    context = new HashSet <ContractParameter>();
                }
                if (context.Contains(parameter))
                {
                    return("(map)");
                }
                else
                {
                    context.Add(parameter);
                    StringBuilder sb = new StringBuilder();
                    sb.Append('[');
                    foreach (var item in data)
                    {
                        sb.Append('{');
                        sb.Append(ToString(item.Key, context));
                        sb.Append(',');
                        sb.Append(ToString(item.Value, context));
                        sb.Append('}');
                        sb.Append(", ");
                    }
                    if (data.Count > 0)
                    {
                        sb.Length -= 2;
                    }
                    sb.Append(']');
                    return(sb.ToString());
                }

            default:
                return(parameter.Value.ToString());
            }
        }
コード例 #16
0
ファイル: ContractParameter.cs プロジェクト: jz263/neo
        private static JObject ToJson(ContractParameter parameter, HashSet <ContractParameter> context)
        {
            JObject json = new JObject();

            json["type"] = parameter.Type;
            if (parameter.Value != null)
            {
                switch (parameter.Type)
                {
                case ContractParameterType.Signature:
                case ContractParameterType.ByteArray:
                    json["value"] = Convert.ToBase64String((byte[])parameter.Value);
                    break;

                case ContractParameterType.Boolean:
                    json["value"] = (bool)parameter.Value;
                    break;

                case ContractParameterType.Integer:
                case ContractParameterType.Hash160:
                case ContractParameterType.Hash256:
                case ContractParameterType.PublicKey:
                case ContractParameterType.String:
                    json["value"] = parameter.Value.ToString();
                    break;

                case ContractParameterType.Array:
                    if (context is null)
                    {
                        context = new HashSet <ContractParameter>();
                    }
                    else if (context.Contains(parameter))
                    {
                        throw new InvalidOperationException();
                    }
                    context.Add(parameter);
                    json["value"] = new JArray(((IList <ContractParameter>)parameter.Value).Select(p => ToJson(p, context)));
                    break;

                case ContractParameterType.Map:
                    if (context is null)
                    {
                        context = new HashSet <ContractParameter>();
                    }
                    else if (context.Contains(parameter))
                    {
                        throw new InvalidOperationException();
                    }
                    context.Add(parameter);
                    json["value"] = new JArray(((IList <KeyValuePair <ContractParameter, ContractParameter> >)parameter.Value).Select(p =>
                    {
                        JObject item  = new JObject();
                        item["key"]   = ToJson(p.Key, context);
                        item["value"] = ToJson(p.Value, context);
                        return(item);
                    }));
                    break;
                }
            }
            return(json);
        }