public void TestEncode(string hex, int code, string name) { var ob = Hex.Decode(hex); var nb = Binary.Varint.GetBytes((uint)code).Concat(Binary.Varint.GetBytes((uint)ob.Length)).Concat(ob).ToArray(); var encoded = Multihash.Encode(ob, (HashType)code); Assert.Equal(encoded, nb); var h = TestCastToMultihash(hex, code, name); Assert.Equal((byte[])h, nb); }
/// <summary> /// /// </summary> /// <param name="contractBindingModel"></param> /// <returns></returns> public async Task <ResponseModel> AddContract(ContractBindingModel contractBindingModel) { var amountToSend = new HexBigInteger(1000000000000000000); string keccak = Multihash.Encode(contractBindingModel.Token1 + contractBindingModel.Token2, HashType.KECCAK_256); byte[] keccak2 = Multihash.Encode(contractBindingModel.Token1 + contractBindingModel.Token2, HashType.KECCAK_256); var web3 = new Web3(_account, _blockChainUrl); var deployment = CreateGenericContract(Guid.NewGuid(), contractBindingModel); deployment.Gas = DefaultGasAmount; var transactionHash = await GenericContractService.DeployContractAsync(web3, deployment); //var addAttachment = await service.AddAttachmentHashRequestAndWaitForReceiptAsync(new AddAttachmentHashFunction //{ // FromAddress = _account.Address, // Hash = contractBindingModel.FileChecksum, // Gas = DefaultGasAmount //}); var contractId = transactionHash; var abi = _contractRepository.GetAbi(); var bin = _contractRepository.GetBin(); var responseModel = new ResponseModel(contractBindingModel.ContextId, contractId, bin, abi); _ = BenChainClientApi.Client.Signator.BenChainUpdateWithHttpMessagesAsync(new SignatoryModel { BenChainABI = abi, BenChainBytescode = bin, BenChainContractId = contractId, ContextId = contractBindingModel.ContextId }); return(responseModel); }
public static Cid AsShaToCid(this byte[] sha) { var hash = Multihash.Encode(sha, HashType.SHA1); return(new Cid(MulticodecCode.Git, hash)); // @todo: is it Git or GitRaw? }