public static Transaction makeTransferTransaction(string tokentype, string fromaddress, string toaddress, string value, string privatekey)
        {
            var state = new State();

            state.from = fromaddress;
            state.to   = toaddress;

            var valueToSend = BigInteger.Parse(value).ToString();

            state.value = valueToSend;

            var transfer = new Transfers();
            var states   = new List <State>();

            states.Add(state);
            transfer.states = states;

            var contract = new Contract();

            contract.address = ONT_CONTRACT;
            contract.method  = "transfer";
            contract.args    = transfer.serialize();

            var tx = new Transaction();

            tx.version = 0x00;
            tx.type    = Crypto.HexToInteger(Common.Enums.TxType.Invoke);
            tx.nonce   = Crypto.ByteArrayToHexString(Crypto.GetSecureRandomByteArray(4));

            //inovke
            var code = "";

            //TODO: change with token type

            code += contract.serialize();
            var vmcode = new VmCode();

            vmcode.code   = code;
            vmcode.vmType = VmType.NativeVM;
            var invokeCode = new InvokeCode();

            invokeCode.code = vmcode;
            tx.payload      = invokeCode;

            if (privatekey != null)
            {
                tx = signTransaction(tx, privatekey);
            }

            return(tx);
        }
        public static InvokeCode makeInvokeCode(string funcname, JArray parameters, string hash, VmType vmtype = VmType.NativeVM)
        {
            var invokeCode = new InvokeCode();
            var vmCode     = new VmCode();
            var code       = buildSmartContractParam(funcname, parameters);

            //Console.WriteLine("code:" + code);
            code           += Crypto.NumberToHex(Crypto.HexToInteger(OPCODE.TAILCALL));
            code           += hash;
            vmCode.code     = code;
            vmCode.vmType   = vmtype;
            invokeCode.code = vmCode;

            return(invokeCode);
        }
Example #3
0
        public static InvokeCode makeInvokeCode(string funcname, JArray parameters, string hash, VmType vmtype = VmType.NativeVM)
        {
            var invokeCode = new InvokeCode();
            var vmCode     = new VmCode();
            var args       = buildSmartContractParam(funcname, parameters);
            //Console.WriteLine("code:" + code);

            var contract = new Contract();

            contract.address = hash;
            contract.args    = args;
            contract.method  = "";

            var code = contract.serialize();

            code = Crypto.NumberToHex(Crypto.HexToInteger(OPCODE.APPCALL)) + code;

            vmCode.code     = code;
            vmCode.vmType   = vmtype;
            invokeCode.code = vmCode;

            return(invokeCode);
        }