async Task test_raise_xxx_sell() { subPrintLine("input value"); var value = Console.ReadLine(); subPrintLine("raise 1 for [xxx]." + this.root + ". input xxx:"); var subname = Console.ReadLine(); var roothash = nns_tools.nameHash(this.root); var fullhash = nns_tools.nameHashSub(roothash, subname); //得到注册器 var info = await nns_tools.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + roothash.ToString()); var reg_sc = new Hash160(info.value.subItem[0].subItem[1].data); subPrintLine("reg=" + reg_sc.ToString()); //得到拍卖ID var info3 = await nns_tools.api_InvokeScript(reg_sc, "getAuctionStateByFullhash", "(hex256)" + fullhash.ToString()); var id = info3.value.subItem[0].subItem[0].AsHash256(); var who = this.scriptHash; var result = await nns_tools.api_SendTransaction(this.prikey, reg_sc, "raise", "(hex160)" + who.ToString(), //参数1 who "(hex256)" + id.ToString(), //参数2 交易id "(int)" + value //参数3,加价多少 //"(int)1"//参数3,加价多少 ); subPrintLine("result=" + result); }
async Task test_collectDomain() { subPrintLine("get [xxx]." + this.root + " domain. input xxx:"); var subname = Console.ReadLine(); var roothash = nns_tools.nameHash(this.root); var fullhash = nns_tools.nameHashSub(roothash, subname); //得到注册器 var info = await nns_tools.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + roothash.ToString()); var reg_sc = new Hash160(info.value.subItem[0].subItem[1].data); subPrintLine("reg=" + reg_sc.ToString()); //得到拍卖ID var info3 = await nns_tools.api_InvokeScript(reg_sc, "getAuctionStateByFullhash", "(hex256)" + fullhash.ToString()); var id = info3.value.subItem[0].subItem[0].AsHash256(); var who = this.scriptHash; var result = await nns_tools.api_SendTransaction(prikey, reg_sc, "collectDomain", "(hex160)" + who.ToString(), //参数1 who "(hex256)" + id.ToString() //参数2 交易id ); subPrintLine("result=" + result); }
async Task test_set_resolver() { subPrintLine("get domain info:input domain like a.b.c~"); var domain = Console.ReadLine(); string[] strs = domain.Split('.'); var mh = nns_tools.nameHash(strs[strs.Length - 1]); for (var i = strs.Length - 2; i >= 0; i--) { mh = nns_tools.nameHashSub(mh, strs[i]); } subPrintLine("mh=" + mh.ToString()); byte[] prikey = ThinNeo.Helper.GetPrivateKeyFromWIF(Config.test_wif); byte[] pubkey = ThinNeo.Helper.GetPublicKeyFromPrivateKey(prikey); Hash160 hash = ThinNeo.Helper.GetScriptHashFromPublicKey(pubkey); var resolver = new Hash160("0x6e2aea28af9c5febea0774759b1b76398e3167f1"); var result = await nns_tools.api_SendTransaction(prikey, Config.sc_nns, "owner_SetResolver", "(hex160)" + hash.ToString(), //参数1 所有者 "(hex256)" + mh.ToString(), //参数2 域名fullhash "(hex160)" + resolver.ToString() //参数3 解析器地址 ); subPrintLine("result=" + result); }
async Task test_startAuction_xxx_sell() { subPrintLine("startAuction [xxx]." + this.root + ". input xxx:"); var subname = Console.ReadLine(); var roothash = nns_tools.nameHash(this.root); //得到注册器 var info = await nns_tools.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + roothash.ToString()); var reg_sc = new Hash160(info.value.subItem[0].subItem[1].data); subPrintLine("reg=" + reg_sc.ToString()); var who = this.scriptHash; var result = await nns_tools.api_SendTransaction(prikey, reg_sc, "startAuction", "(hex160)" + who.ToString(), "(hex256)" + roothash.ToString(), "(string)" + subname ); subPrintLine("result=" + result); }
async Task test_config_resolve_1_xxx_yyy() { subPrintLine("config resolve 1.[xxx].[yyy] input xxx.yyy:"); var readline = Console.ReadLine().Split("."); var subname = readline[0]; var rootname = readline[1]; var testhash = nns_common.nameHash(rootname); var subhash = nns_common.nameHashSub(testhash, subname); var _result = await nns_common.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + subhash.ToString()); var resolver = new Hash160(_result.value.subItem[0].subItem[2].data); subPrintLine("resolver=" + resolver.ToString()); var owner = new Hash160(_result.value.subItem[0].subItem[0].data); //string testwif = nnc_1.testwif; byte[] prikey = ThinNeo.Helper.GetPrivateKeyFromWIF(Config.test_wif); byte[] pubkey = ThinNeo.Helper.GetPublicKeyFromPrivateKey(prikey); Hash160 hash = ThinNeo.Helper.GetScriptHashFromPublicKey(pubkey); if (owner.Equals(hash) == false) { subPrintLine("this is not your domain."); return; } var newowner = ThinNeo.Helper.GetPublicKeyHashFromAddress("ALjSnMZidJqd18iQaoCgFun6iqWRm2cVtj"); var result = await nns_common.api_SendTransaction(prikey, resolver, "setResolveData", "(hex160)" + hash.ToString(), //参数1 所有者 "(hex256)" + subhash.ToString(), //参数2 域名fullhash "(string)" + "1", //参数3 要设置的子域名 "(string)" + "text", //参数4 协议 "(string)" + "hello world" //解析内容 ); subPrintLine("result=" + result); }
async Task test_owner_change() { subPrintLine("owner chaange [xxx].[yyy] input xxx.yyy:"); var readline = Console.ReadLine().Split("."); var subname = readline[0]; var rootname = readline[1]; byte[] prikey = ThinNeo.Helper.GetPrivateKeyFromWIF(Config.test_wif); byte[] pubkey = ThinNeo.Helper.GetPublicKeyFromPrivateKey(prikey); Hash160 hash = ThinNeo.Helper.GetScriptHashFromPublicKey(pubkey); var newowner = ThinNeo.Helper.GetPublicKeyHashFromAddress("ALjSnMZidJqd18iQaoCgFun6iqWRm2cVtj"); var testhash = nns_tools.nameHash(rootname); var subhash = nns_tools.nameHashSub(testhash, subname); var result = await nns_tools.api_SendTransaction(prikey, Config.sc_nns, "owner_SetOwner", "(hex160)" + hash.ToString(), //参数1 所有者 "(hex256)" + subhash.ToString(), //参数2 域名fullhash "(hex160)" + newowner.ToString() //参数3 新所有者 ); subPrintLine("result=" + result); }
async Task test_set_resolver() { subPrintLine("set resolver [xxx].[yyy] input xxx.yyy:"); var readline = Console.ReadLine().Split("."); var subname = readline[0]; var rootname = readline[1]; byte[] prikey = ThinNeo.Helper.GetPrivateKeyFromWIF(Config.test_wif); byte[] pubkey = ThinNeo.Helper.GetPublicKeyFromPrivateKey(prikey); Hash160 hash = ThinNeo.Helper.GetScriptHashFromPublicKey(pubkey); var resolver = new Hash160("0xabb0f1f3f035dd7ad80ca805fce58d62c517cc6b"); var testhash = nns_common.nameHash(rootname); var subhash = nns_common.nameHashSub(testhash, subname); var result = await nns_common.api_SendTransaction(prikey, Config.sc_nns, "owner_SetResolver", "(hex160)" + hash.ToString(), //参数1 所有者 "(hex256)" + subhash.ToString(), //参数2 域名fullhash "(hex160)" + resolver.ToString() //参数3 解析器地址 ); subPrintLine("result=" + result); }
//public const string sc_nnc = "0xbab964febd82c9629cc583596975f51811f25f47";//nnc 合约地址 //public const string api = "https://api.nel.group/api/testnet"; //public const string testwif = "L4ZntdDCocMJi4ozpTw4uTtxtAFNNCP2mX6m3P9CMJN66Dt2YJqP";//"L3tDHnEAvwnnPE4sY4oXpTvNtNhsVhbkY4gmEmWmWWf1ebJhVPVW"; public async Task Demo() { this.prikey = ThinNeo.Helper.GetPrivateKeyFromWIF(Config.test_wif); this.pubkey = ThinNeo.Helper.GetPublicKeyFromPrivateKey(prikey); this.address = ThinNeo.Helper.GetAddressFromPublicKey(pubkey); this.scriptHash = ThinNeo.Helper.GetPublicKeyHashFromAddress(address); var roothash = nns_common.nameHash("sell"); var fullhash = nns_common.nameHashSub(roothash, "helloworld"); //得到注册器 var info = await nns_common.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + roothash.ToString()); var reg_sc = new Hash160(info.value.subItem[0].subItem[1].data); Console.WriteLine("reg=" + reg_sc.ToString()); Console.WriteLine("address=" + address); string addressto = ThinNeo.Helper.GetAddressFromScriptHash(reg_sc); Console.WriteLine("addressto=" + addressto); //获取地址的资产列表 Dictionary <string, List <Utxo> > dir = await Helper.GetBalanceByAddress(Nep55_1.api, address); if (dir.ContainsKey(Nep55_1.id_GAS) == false) { Console.WriteLine("no gas"); return; } //MakeTran ThinNeo.Transaction tran = null; { var who = this.scriptHash; //得到拍卖ID var info3 = await nns_common.api_InvokeScript(reg_sc, "getSellingStateByFullhash", "(hex256)" + fullhash.ToString()); var id = info3.value.subItem[0].subItem[0].AsHash256(); byte[] script = null; using (var sb = new ThinNeo.ScriptBuilder()) { var array2 = new MyJson.JsonNode_Array(); array2.AddArrayValue("(hex160)" + who.ToString()); array2.AddArrayValue("(hex256)" + id.ToString()); array2.AddArrayValue("(int)10" + "00000000"); sb.EmitParamJson(array2); //参数倒序入 sb.EmitPushString("addPrice"); //参数倒序入 sb.EmitAppCall(new ThinNeo.Hash160(reg_sc)); //nep5脚本 var array = new MyJson.JsonNode_Array(); array.AddArrayValue("(addr)" + address); //from array.AddArrayValue("(addr)" + addressto); //to array.AddArrayValue("(int)10" + "00000000"); //value sb.EmitParamJson(array); //参数倒序入 sb.EmitPushString("transfer"); //参数倒序入 sb.EmitAppCall(new ThinNeo.Hash160(nnc_1.sc_nnc)); //nep5脚本 //这个方法是为了在同一笔交易中转账并充值 //当然你也可以分为两笔交易 //插入下述两条语句,能得到txid sb.EmitSysCall("System.ExecutionEngine.GetScriptContainer"); sb.EmitSysCall("Neo.Transaction.GetHash"); //把TXID包进Array里 sb.EmitPushNumber(1); sb.Emit(ThinNeo.VM.OpCode.PACK); sb.EmitPushString("setmoneyin"); sb.EmitAppCall(new ThinNeo.Hash160(reg_sc)); script = sb.ToArray(); } tran = Helper.makeTran(dir[Nep55_1.id_GAS], null, new ThinNeo.Hash256(Nep55_1.id_GAS), 0); tran.type = ThinNeo.TransactionType.InvocationTransaction; var idata = new ThinNeo.InvokeTransData(); tran.extdata = idata; idata.script = script; idata.gas = 0; } //sign and broadcast var signdata = ThinNeo.Helper.Sign(tran.GetMessage(), prikey); tran.AddWitness(signdata, pubkey, address); var trandata = tran.GetRawData(); var strtrandata = ThinNeo.Helper.Bytes2HexString(trandata); byte[] postdata; var url = Helper.MakeRpcUrlPost(nnc_1.api, "sendrawtransaction", out postdata, new MyJson.JsonNode_ValueString(strtrandata)); var result = await Helper.HttpPost(url, postdata); Console.WriteLine(result); }
async Task test_get_xxx_sell_info() { subPrintLine("get [xxx]." + this.root + " 's info:input xxx:"); var subname = Console.ReadLine(); var r_test = await nns_tools.api_InvokeScript(Config.sc_nns, "nameHash", "(string)" + this.root); var hash_test = r_test.value.subItem[0].AsHash256(); var r_abc_test = await nns_tools.api_InvokeScript(Config.sc_nns, "nameHashSub", "(hex256)" + r_test.value.subItem[0].AsHash256().ToString(), "(string)" + subname); subPrintLine("得到:" + r_abc_test.value.subItem[0].AsHash256()); var roothash = nns_tools.nameHash(this.root); var fullhash = nns_tools.nameHashSub(roothash, subname); subPrintLine("calc=" + fullhash.ToString()); var info = await nns_tools.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + fullhash.ToString()); var sh = info.value.subItem[0].subItem[0].AsHash160(); if (sh != null) { var owner = ThinNeo.Helper.GetAddressFromScriptHash(sh); subPrintLine("getinfo owner=" + owner); } else { subPrintLine("getinfo owner="); } subPrintLine("getinfo register=" + info.value.subItem[0].subItem[1].AsHash160()); subPrintLine("getinfo resovler=" + info.value.subItem[0].subItem[2].AsHash160()); subPrintLine("getinfo ttl=" + info.value.subItem[0].subItem[3].AsInteger()); subPrintLine("getinfo parentOwner=" + info.value.subItem[0].subItem[4].AsHash160()); subPrintLine("getinfo domain=" + info.value.subItem[0].subItem[5].AsString()); subPrintLine("getinfo parentHash=" + info.value.subItem[0].subItem[6].AsHash256()); subPrintLine("getinfo root=" + info.value.subItem[0].subItem[7].AsInteger()); //得到注册器 var info_reg = await nns_tools.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + roothash.ToString()); var reg_sc = new Hash160(info_reg.value.subItem[0].subItem[1].data); subPrintLine("reg=" + reg_sc.ToString()); var info2 = await nns_tools.api_InvokeScript(reg_sc, "getDomainUseState", "(hex256)" + fullhash.ToString()); subPrintLine("getDomainUseState=" + info2.value.subItem[0].AsInteger()); var info3 = await nns_tools.api_InvokeScript(reg_sc, "getAuctionStateByFullhash", "(hex256)" + fullhash.ToString()); subPrintLine("getAuctionStateByFullhash id=" + info3.value.subItem[0].subItem[0].AsHash256()); subPrintLine("getAuctionStateByFullhash auctionstarter=" + ThinNeo.Helper.GetAddressFromScriptHash(info3.value.subItem[0].subItem[1].AsHash160())); subPrintLine("getAuctionStateByFullhash parenthash=" + info3.value.subItem[0].subItem[2].AsHash256()); subPrintLine("getAuctionStateByFullhash domain=" + info3.value.subItem[0].subItem[3].AsString()); subPrintLine("getAuctionStateByFullhash domainTTL=" + info3.value.subItem[0].subItem[4].AsInteger()); subPrintLine("getAuctionStateByFullhash startBlockSelling=" + info3.value.subItem[0].subItem[5].AsInteger()); subPrintLine("getAuctionStateByFullhash endBlock=" + info3.value.subItem[0].subItem[6].AsInteger()); subPrintLine("getAuctionStateByFullhash maxPrice=" + info3.value.subItem[0].subItem[7].AsInteger()); subPrintLine("getAuctionStateByFullhash maxBuyer=" + ThinNeo.Helper.GetAddressFromScriptHash(info3.value.subItem[0].subItem[8].AsHash160())); subPrintLine("getAuctionStateByFullhash lastBlock=" + info3.value.subItem[0].subItem[9].AsInteger()); var id = info3.value.subItem[0].subItem[0].AsHash256(); var who = this.scriptHash; var info4 = await nns_tools.api_InvokeScript(reg_sc, "balanceOf", "(hex160)" + who.ToString()); subPrintLine("balanceOf=" + info4.value.subItem[0].AsInteger()); var info5 = await nns_tools.api_InvokeScript(reg_sc, "balanceOfSelling", "(hex160)" + who.ToString(), "(hex256)" + id.ToString()); subPrintLine("balanceOfSelling=" + info5.value.subItem[0].AsInteger()); }
public string testwif = Config.test_wif;//"L3tDHnEAvwnnPE4sY4oXpTvNtNhsVhbkY4gmEmWmWWf1ebJhVPVW"; public async Task Demo() { byte[] prikey = ThinNeo.Helper.GetPrivateKeyFromWIF(testwif); byte[] pubkey = ThinNeo.Helper.GetPublicKeyFromPrivateKey(prikey); string address = ThinNeo.Helper.GetAddressFromPublicKey(pubkey); byte[] scripthash = ThinNeo.Helper.GetPublicKeyHashFromAddress(address); //得到注册器 var info_reg = await nns_common.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + nns_common.nameHash("sell").ToString()); var reg_sc = new Hash160(info_reg.value.subItem[0].subItem[1].data); Console.WriteLine("reg=" + reg_sc.ToString()); Console.WriteLine("address=" + address); {//查balance string script = null; using (var sb = new ThinNeo.ScriptBuilder()) { var array = new MyJson.JsonNode_Array(); array.AddArrayValue("(bytes)" + ThinNeo.Helper.Bytes2HexString(scripthash)); sb.EmitParamJson(array); //参数倒序入 sb.EmitParamJson(new MyJson.JsonNode_ValueString("(str)balanceOf")); //参数倒序入 ThinNeo.Hash160 shash = new ThinNeo.Hash160(sc_nnc); sb.EmitAppCall(shash); //nep5脚本 sb.EmitParamJson(array); //参数倒序入 sb.EmitParamJson(new MyJson.JsonNode_ValueString("(str)balanceOf")); //参数倒序入 sb.EmitAppCall(reg_sc); var data = sb.ToArray(); script = ThinNeo.Helper.Bytes2HexString(data); } byte[] postdata; var url = Helper.MakeRpcUrlPost(api, "invokescript", out postdata, new MyJson.JsonNode_ValueString(script)); var result = await Helper.HttpPost(url, postdata); Console.WriteLine("得到的结果是:" + result); var json = MyJson.Parse(result).AsDict(); if (json.ContainsKey("result")) { var resultv = json["result"].AsList()[0].AsDict()["stack"].AsList()[0].AsDict(); var rtype = resultv["type"].AsString(); var rvalue = resultv["value"].AsString(); Console.WriteLine("type=" + rtype + " value=" + rvalue); if (rtype == "Integer") { decimal num = decimal.Parse(rvalue) / (decimal)100000000; Console.WriteLine("value dec=" + num.ToString()); } else { var n = new System.Numerics.BigInteger(ThinNeo.Helper.HexString2Bytes(rvalue)); decimal num = (decimal)n / (decimal)100000000; Console.WriteLine("value dec=" + num.ToString()); } } } }
public async Task Demo() { byte[] prikey = ThinNeo.Helper.GetPrivateKeyFromWIF(Config.test_wif); byte[] pubkey = ThinNeo.Helper.GetPublicKeyFromPrivateKey(prikey); string address = ThinNeo.Helper.GetAddressFromPublicKey(pubkey); byte[] scripthash = ThinNeo.Helper.GetPublicKeyHashFromAddress(address); Console.WriteLine("address=" + address); //得到注册器 var info_reg = await nns_tools.api_InvokeScript(Config.sc_nns, "getOwnerInfo", "(hex256)" + nns_tools.nameHash("sell").ToString()); var reg_sc = new Hash160(info_reg.value.subItem[0].subItem[1].data); Console.WriteLine("reg=" + reg_sc.ToString()); string addressto = ThinNeo.Helper.GetAddressFromScriptHash(reg_sc); Console.WriteLine("addressFrom=" + addressto); //获取地址的资产列表 Dictionary <string, List <Utxo> > dir = await Helper.GetBalanceByAddress(Nep55_1.api, address); if (dir.ContainsKey(Nep55_1.id_GAS) == false) { Console.WriteLine("no gas"); return; } //MakeTran ThinNeo.Transaction tran = null; { byte[] script = null; using (var sb = new ThinNeo.ScriptBuilder()) { var array = new MyJson.JsonNode_Array(); array.AddArrayValue("(addr)" + address); //who array.AddArrayValue("(int)10000000000"); //value sb.EmitParamJson(array); //参数倒序入 sb.EmitParamJson(new MyJson.JsonNode_ValueString("(str)getmoneyback")); //参数倒序入 sb.EmitAppCall(reg_sc); script = sb.ToArray(); } tran = Helper.makeTran(dir[Nep55_1.id_GAS], address, new ThinNeo.Hash256(Nep55_1.id_GAS), 0); tran.type = ThinNeo.TransactionType.InvocationTransaction; var idata = new ThinNeo.InvokeTransData(); tran.extdata = idata; idata.script = script; } //sign and broadcast var signdata = ThinNeo.Helper.Sign(tran.GetMessage(), prikey); tran.AddWitness(signdata, pubkey, address); var trandata = tran.GetRawData(); var strtrandata = ThinNeo.Helper.Bytes2HexString(trandata); byte[] postdata; var url = Helper.MakeRpcUrlPost(Nep55_1.api, "sendrawtransaction", out postdata, new MyJson.JsonNode_ValueString(strtrandata)); var result = await Helper.HttpPost(url, postdata); Console.WriteLine("得到的结果是:" + result); }