コード例 #1
0
 void dapp_EmitParam(ThinNeo.ScriptBuilder sb, MyJson.IJsonNode param)
 {
     if (param is MyJson.JsonNode_ValueNumber)//bool 或小整数
     {
         sb.EmitParamJson(param);
     }
     else if (param is MyJson.JsonNode_Array)
     {
         var list = param.AsList();
         for (var i = list.Count - 1; i >= 0; i--)
         {
             dapp_EmitParam(sb, list[i]);
         }
         sb.EmitPushNumber(param.AsList().Count);
         sb.Emit(ThinNeo.VM.OpCode.PACK);
     }
     else if (param is MyJson.JsonNode_ValueString)//复杂格式
     {
         var str   = param.AsString();
         var bytes = dapp_getCallParam(str);
         sb.EmitPushBytes(bytes);
     }
     else
     {
         throw new Exception("should not pass a {}");
     }
 }
コード例 #2
0
        public void NeoTransfer()
        {
            byte[] prikey  = ThinNeo.Helper.GetPrivateKeyFromWIF(wif);
            var    pubkey  = ThinNeo.Helper.GetPublicKeyFromPrivateKey(prikey);
            var    address = ThinNeo.Helper.GetAddressFromPublicKey(pubkey);

            using (var sb = new ThinNeo.ScriptBuilder())
            {
                var array = new MyJson.JsonNode_Array();
                array.AddArrayValue("(addr)" + from);
                array.AddArrayValue("(addr)" + "AMjCDmrbfcBxGPitHcdrUYRyPXD7DfC52c");//NeoBank address   AMjCDmrbfcBxGPitHcdrUYRyPXD7DfC52c
                array.AddArrayValue("(int)" + value);
                byte[] randomBytes = new byte[32];
                using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
                {
                    rng.GetBytes(randomBytes);
                }
                BigInteger randomNum = new BigInteger(randomBytes);
                sb.EmitPushNumber(randomNum);
                sb.Emit(ThinNeo.VM.OpCode.DROP);
                sb.EmitParamJson(array);                                                   //参数倒序入
                sb.EmitPushString("transfer");                                             //参数倒序入
                sb.EmitAppCall(new Hash160("0x04e31cee0443bb916534dad2adf508458920e66d")); //nep5脚本
                script = sb.ToArray();
            }

            ThinNeo.Transaction tran = new Transaction();
            tran.inputs              = new ThinNeo.TransactionInput[0];
            tran.outputs             = new TransactionOutput[0];
            tran.attributes          = new ThinNeo.Attribute[1];
            tran.attributes[0]       = new ThinNeo.Attribute();
            tran.attributes[0].usage = TransactionAttributeUsage.Script;
            tran.attributes[0].data  = ThinNeo.Helper.GetPublicKeyHashFromAddress(address);
            tran.version             = 1;
            tran.type = ThinNeo.TransactionType.InvocationTransaction;

            var idata = new ThinNeo.InvokeTransData();

            tran.extdata = idata;
            idata.script = script;
            idata.gas    = 0;

            byte[] msg    = tran.GetMessage();
            string msgstr = ThinNeo.Helper.Bytes2HexString(msg);

            byte[] signdata = ThinNeo.Helper.Sign(msg, prikey);
            tran.AddWitness(signdata, pubkey, address);
            string txid = tran.GetHash().ToString();

            byte[] data    = tran.GetRawData();
            string rawdata = ThinNeo.Helper.Bytes2HexString(data);

            byte[] postdata;
            var    url    = MakeRpcUrlPost(NeoRpcUrl, "sendrawtransaction", out postdata, new MyJson.JsonNode_ValueString(rawdata));
            var    result = HttpPost(url, postdata);

            Console.WriteLine(result + " txid: " + txid);
            return(result);
        }
コード例 #3
0
        static byte[] createNep5FindScript(string _assetid)
        {
            var asset = ThinNeo.Helper.HexString2Bytes(_assetid);

            ThinNeo.ScriptBuilder sb = new ThinNeo.ScriptBuilder();
            sb.EmitPushNumber(0);
            sb.Emit(ThinNeo.VM.OpCode.PACK);
            sb.EmitPushString("name"); //name//totalSupply//symbol//decimals
            sb.EmitAppCall(asset.Reverse().ToArray());

            sb.EmitPushNumber(0);
            sb.Emit(ThinNeo.VM.OpCode.PACK);
            sb.EmitPushString("symbol"); //name//totalSupply//symbol//decimals
            sb.EmitAppCall(asset.Reverse().ToArray());

            sb.EmitPushNumber(0);
            sb.Emit(ThinNeo.VM.OpCode.PACK);
            sb.EmitPushString("decimals"); //name//totalSupply//symbol//decimals
            sb.EmitAppCall(asset.Reverse().ToArray());

            return(sb.ToArray());
        }
コード例 #4
0
        decimal rpc_getNep5Balance(string nep5asset)
        {
            //make callscript
            var pubkey     = ThinNeo.Helper.GetPublicKeyFromPrivateKey(this.privatekey);
            var pubkeyhash = ThinNeo.Helper.GetScriptHashFromPublicKey(pubkey);

            var asset = ThinNeo.Helper.HexString2Bytes(nep5asset);

            ThinNeo.ScriptBuilder sb = new ThinNeo.ScriptBuilder();
            sb.EmitPushBytes(pubkeyhash);
            sb.EmitPushNumber(1);
            sb.Emit(ThinNeo.VM.OpCode.PACK);
            sb.EmitPushString("balanceOf"); //name//totalSupply//symbol//decimals
            sb.EmitAppCall(asset.Reverse().ToArray());

            var nep5 = Tools.CoinTool.assetNep5[nep5asset];

            var symbol    = ThinNeo.Helper.Bytes2HexString(sb.ToArray());
            var str       = WWW.MakeRpcUrl(labelRPC.Text, "invokescript", new MyJson.JsonNode_ValueString(symbol));
            var resultstr = WWW.GetWithDialog(this, str);
            var json      = MyJson.Parse(resultstr).AsDict()["result"].AsDict();

            if (json["state"].AsString().Contains("HALT") == false)
            {
                throw new Exception("error state");
            }
            var     value    = json["stack"].AsList()[0].AsDict();
            decimal outvalue = 0;

            if (value["type"].AsString() == "Integer")
            {
                outvalue = decimal.Parse(value["value"].AsString());
            }
            else
            {
                var bts = ThinNeo.Helper.HexString2Bytes(value["value"].AsString());
                var bi  = new System.Numerics.BigInteger(bts);
                outvalue = (decimal)bi;
            }
            for (var i = 0; i < nep5.decimals; i++)
            {
                outvalue /= 10;
            }
            return(outvalue);
        }
コード例 #5
0
ファイル: Key.cs プロジェクト: joshua0526/FindCoin
 public byte[] GetMultiContract()
 {
     if (!(1 <= this.MKey_NeedCount && MKey_NeedCount <= MKey_Pubkeys.Count && MKey_Pubkeys.Count <= 1024))
     {
         throw new ArgumentException();
     }
     using (ThinNeo.ScriptBuilder sb = new ThinNeo.ScriptBuilder())
     {
         sb.EmitPushNumber(MKey_NeedCount);
         foreach (var pkey in this.MKey_Pubkeys)
         {
             sb.EmitPushBytes(pkey);
         }
         sb.EmitPushNumber(MKey_Pubkeys.Count);
         sb.Emit(ThinNeo.VM.OpCode.CHECKMULTISIG);
         return(sb.ToArray());
     }
 }