コード例 #1
0
        public static Transaction MakeTransferTransaction(string tokentype, string fromaddress, string toaddress, string value, string privatekey)
        {
            var state = new State {
                from = fromaddress, to = toaddress
            };

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

            state.value = valueToSend;

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

            transfer.states = states;

            var contract = new Contract {
                address = _ontContract, method = "transfer", args = transfer.serialize()
            };

            var tx = new Transaction
            {
                version = 0x00,
                type    = Crypto.HexToInteger(TxType.Invoke),
                nonce   = Crypto.ByteArrayToHexString(Crypto.GetSecureRandomByteArray(4))
            };

            //inovke
            var code = string.Empty;

            //TODO: change with token type

            code += contract.serialize();
            var vmcode = new VmCode {
                code = code, vmType = VmType.NativeVM
            };
            var invokeCode = new InvokeCode {
                code = vmcode
            };

            tx.payload = invokeCode;

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

            return(tx);
        }
コード例 #2
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 {
                address = hash, args = args, method = ""
            };

            var code = contract.serialize();

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

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

            return(invokeCode);
        }