private static byte[] putRequest(byte[] chainID, BigInteger requestID, CrossChainTxParameter para) { byte[] requestKey = requestPreifx.Concat(chainID).Concat(requestID.ToByteArray()); Storage.Put(Storage.CurrentContext, requestKey, WriteCrossChainTxParameter(para)); requestID = requestID + 1; Storage.Put(Storage.CurrentContext, requestIDPrefix.Concat(chainID), requestID); return(requestKey); }
private static byte[] WriteCrossChainTxParameter(CrossChainTxParameter para) { byte[] result = new byte[] { }; result = writeVarBytes(result, para.txHash); result = writeVarBytes(result, para.crossChainID); result = writeVarBytes(result, para.fromContract); byte[] toChainIDBytes = padRight(para.toChainID, 8); result = result.Concat(toChainIDBytes); result = writeVarBytes(result, para.toContract); result = writeVarBytes(result, para.method); result = writeVarBytes(result, para.args); return(result); }
/// <summary> /// Tested, 反序列化跨链交易参数 /// </summary> /// <param name="Source"></param> /// <param name="offset"></param> /// <returns></returns> private static CrossChainTxParameter deserializCrossChainTxParameter(byte[] Source, int offset) { CrossChainTxParameter txParameter = new CrossChainTxParameter(); //get txHash ByteString rawTxParameter; (rawTxParameter, offset) = readVarBytes(Source, offset); txParameter.txHash = (byte[])rawTxParameter; //get crossChainId ByteString rawCrossChainId; (rawCrossChainId, offset) = readVarBytes(Source, offset); txParameter.crossChainID = (byte[])rawCrossChainId; //get fromContract ByteString rawFromContract; (rawFromContract, offset) = readVarBytes(Source, offset); txParameter.fromContract = (byte[])rawFromContract; //get toChainID txParameter.toChainID = Source.Range(offset, 8); offset = offset + 8; //get toContract ByteString rawToContract; (rawToContract, offset) = readVarBytes(Source, offset); txParameter.toContract = (byte[])rawToContract; //get method ByteString rawMethod; (rawMethod, offset) = readVarBytes(Source, offset); txParameter.method = (byte[])rawMethod; //get params ByteString rawArgs; (rawArgs, offset) = readVarBytes(Source, offset); txParameter.args = (byte[])rawArgs; return(txParameter); }
public static bool crossChain(BigInteger toChainID, byte[] toChainAddress, byte[] functionName, byte[] args, byte[] caller) { var tx = (Transaction)Runtime.ScriptContainer; var IdAsByte = toChainID.ToByteArray(); CrossChainTxParameter para = new CrossChainTxParameter { toChainID = IdAsByte, toContract = toChainAddress, method = functionName, args = args, txHash = (byte[])tx.Hash, crossChainID = (byte[])CryptoLib.Sha256((ByteString)((byte[])Runtime.ExecutingScriptHash).Concat((byte[])tx.Hash)), fromContract = caller }; BigInteger requestId = getRequestID(IdAsByte); var resquestKey = putRequest(IdAsByte, requestId, para); //event CrossChainLockEvent(caller, para.fromContract, toChainID, resquestKey, para.args); return(true); }