org.web3j.abi.datatypes.BytesType Java Examples
The following examples show how to use
org.web3j.abi.datatypes.BytesType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultFunctionReturnDecoder.java From web3j with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public <T extends Type> Type decodeEventParameter( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { Class<Bytes> bytesClass = (Class<Bytes>) Class.forName(type.getName()); return TypeDecoder.decodeBytes(input, bytesClass); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } }
Example #2
Source File: Proposal.java From client-sdk-java with Apache License 2.0 | 6 votes |
public List<Type> getSubmitInputParameters() { if (proposalType == ProposalType.TEXT_PROPOSAL) { return Arrays.asList(new BytesType(Numeric.hexStringToByteArray(this.verifier)), new Utf8String(this.piPid)); } else if (proposalType == ProposalType.VERSION_PROPOSAL) { return Arrays.asList(new BytesType(Numeric.hexStringToByteArray(this.verifier)), new Utf8String(this.piPid), new Uint32(this.newVersion), new Uint64(this.endVotingBlock)); } else if (proposalType == ProposalType.CANCEL_PROPOSAL) { return Arrays.asList(new BytesType(Numeric.hexStringToByteArray(this.verifier)), new Utf8String(this.piPid), new Uint64(this.endVotingBlock), new BytesType(Numeric.hexStringToByteArray(this.toBeCanceled))); } else if (proposalType == ProposalType.PARAM_PROPOSAL) { return Arrays.asList(new BytesType(Numeric.hexStringToByteArray(this.verifier)), new Utf8String(this.piPid), new Utf8String(this.module), new Utf8String(this.name), new Utf8String(this.newValue)); } return new ArrayList<>(); }
Example #3
Source File: StakingParam.java From client-sdk-java with Apache License 2.0 | 6 votes |
public List<Type> getSubmitInputParameters() { return Arrays.<Type>asList(new Uint16(stakingAmountType.getValue()) , new BytesType(Numeric.hexStringToByteArray(benifitAddress)) , new BytesType(Numeric.hexStringToByteArray(nodeId)) , new Utf8String(externalId) , new Utf8String(nodeName) , new Utf8String(webSite) , new Utf8String(details) , new Int256(amount) , new Uint16(rewardPer) , new Uint32(processVersion.getProgramVersion()) , new BytesType(Numeric.hexStringToByteArray(processVersion.getProgramVersionSign())) , new BytesType(Numeric.hexStringToByteArray(blsPubKey)) , new BytesType(Numeric.hexStringToByteArray(blsProof)) ); }
Example #4
Source File: ProposalContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
private Function createVoteFunction(ProgramVersion programVersion, String proposalID, String verifier, VoteOption voteOption) { Function function = new Function(FunctionType.VOTE_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(verifier)), new BytesType(Numeric.hexStringToByteArray(proposalID)), new Uint8(voteOption.getValue()), new Uint32(programVersion.getProgramVersion()), new BytesType(Numeric.hexStringToByteArray(programVersion.getProgramVersionSign())))); return function; }
Example #5
Source File: TypeEncoder.java From web3j with Apache License 2.0 | 5 votes |
static String encodeBytes(BytesType bytesType) { byte[] value = bytesType.getValue(); int length = value.length; int mod = length % MAX_BYTE_LENGTH; byte[] dest; if (mod != 0) { int padding = MAX_BYTE_LENGTH - mod; dest = new byte[length + padding]; System.arraycopy(value, 0, dest, 0, length); } else { dest = value; } return Numeric.toHexStringNoPrefix(dest); }
Example #6
Source File: TypeEncoder.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
static String encodeBytes(BytesType bytesType) { byte[] value = bytesType.getValue(); int length = value.length; int mod = length % MAX_BYTE_LENGTH; byte[] dest; if (mod != 0) { int padding = MAX_BYTE_LENGTH - mod; dest = new byte[length + padding]; System.arraycopy(value, 0, dest, 0, length); } else { dest = value; } return Numeric.toHexStringNoPrefix(dest); }
Example #7
Source File: StakingContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
private Function createAddStakingFunction(String nodeId, StakingAmountType stakingAmountType, BigInteger amount) { Function function = new Function(FunctionType.ADD_STAKING_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(nodeId)), new Uint16(stakingAmountType.getValue()), new Uint256(amount))); return function; }
Example #8
Source File: RewardContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
/** * 查询当前账户地址所委托的节点的NodeID和质押Id * * @param address 查询的地址 * @param nodeList 节点id列表 * @return */ public RemoteCall<CallResponse<List<Reward>>> getDelegateReward(String address,List<String> nodeList) { List<NodeId> bytesTypeList = nodeList.stream().map(nodeId -> new NodeId(nodeId)).collect(Collectors.toList()); CustomStaticArray<NodeId> dynamicArray = new CustomStaticArray<>(bytesTypeList); Function function = new Function(FunctionType.GET_DELEGATE_REWARD_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(address)), dynamicArray)); return executeRemoteCallListValueReturn(function, Reward.class); }
Example #9
Source File: ProposalContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
private Function createDeclareVersionFunction(ProgramVersion programVersion, String verifier) { Function function = new Function(FunctionType.DECLARE_VERSION_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(verifier)), new Uint32(programVersion.getProgramVersion()), new BytesType(Numeric.hexStringToByteArray(programVersion.getProgramVersionSign())))); return function; }
Example #10
Source File: RestrictingPlanContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
/** * 获取锁仓信息 * * @param account 锁仓释放到账账户 * @return */ public RemoteCall<CallResponse<RestrictingItem>> getRestrictingInfo(String account) { Function function = new Function( FunctionType.GET_RESTRICTINGINFO_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(account)))); return executeRemoteCallObjectValueReturn(function, RestrictingItem.class); }
Example #11
Source File: UpdateStakingParam.java From client-sdk-java with Apache License 2.0 | 5 votes |
public List<Type> getSubmitInputParameters() { return Arrays.asList(new BytesType(Numeric.hexStringToByteArray(benifitAddress)), new BytesType(Numeric.hexStringToByteArray(nodeId)), new Uint16(rewardPer), new Utf8String(externalId), new Utf8String(nodeName), new Utf8String(webSite), new Utf8String(details)); }
Example #12
Source File: DelegateContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
/** * 查询当前单个委托信息 * * @param nodeId 验证人的节点Id * @param delAddr 委托人账户地址 * @param stakingBlockNum 发起质押时的区块高度 * @return */ public RemoteCall<CallResponse<Delegation>> getDelegateInfo(String nodeId, String delAddr, BigInteger stakingBlockNum) { Function function = new Function(FunctionType.GET_DELEGATEINFO_FUNC_TYPE, Arrays.asList(new Uint64(stakingBlockNum) , new BytesType(Numeric.hexStringToByteArray(delAddr)) , new BytesType(Numeric.hexStringToByteArray(nodeId)))); return executeRemoteCallObjectValueReturn(function, Delegation.class); }
Example #13
Source File: DelegateContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
private Function createUnDelegateFunction(String nodeId, BigInteger stakingBlockNum, BigInteger amount) { Function function = new Function(FunctionType.WITHDREW_DELEGATE_FUNC_TYPE, Arrays.asList(new Uint64(stakingBlockNum) , new BytesType(Numeric.hexStringToByteArray(nodeId)) , new Uint256(amount))); return function; }
Example #14
Source File: DelegateContract.java From client-sdk-java with Apache License 2.0 | 5 votes |
private Function createDelegateFunction(String nodeId, StakingAmountType stakingAmountType, BigInteger amount) { Function function = new Function(FunctionType.DELEGATE_FUNC_TYPE, Arrays.asList(new Uint16(stakingAmountType.getValue()) , new BytesType(Numeric.hexStringToByteArray(nodeId)) , new Uint256(amount))); return function; }
Example #15
Source File: TypeEncoder.java From client-sdk-java with Apache License 2.0 | 5 votes |
static String encodeBytes(BytesType bytesType) { byte[] value = bytesType.getValue(); int length = value.length; int mod = length % MAX_BYTE_LENGTH; byte[] dest; if (mod != 0) { int padding = MAX_BYTE_LENGTH - mod; dest = new byte[length + padding]; System.arraycopy(value, 0, dest, 0, length); } else { dest = value; } return Numeric.toHexStringNoPrefix(dest); }
Example #16
Source File: RestrictingPlanContract.java From client-sdk-java with Apache License 2.0 | 4 votes |
private Function createRestrictingPlanFunction(String account, List<RestrictingPlan> restrictingPlanList) { Function function = new Function( FunctionType.CREATE_RESTRICTINGPLAN_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(account)), new CustomStaticArray<RestrictingPlan>(restrictingPlanList))); return function; }
Example #17
Source File: FunctionReturnDecoder.java From client-sdk-java with Apache License 2.0 | 4 votes |
/** * <p>Decodes an indexed parameter associated with an event. Indexed parameters are individually * encoded, unlike non-indexed parameters which are encoded as per ABI-encoded function * parameters and return values.</p> * * <p>If any of the following types are indexed, the Keccak-256 hashes of the values are * returned instead. These are returned as a bytes32 value.</p> * * <ul> * <li>Arrays</li> * <li>Strings</li> * <li>Bytes</li> * </ul> * * <p>See the * <a href="http://solidity.readthedocs.io/en/latest/contracts.html#events"> * Solidity documentation</a> for further information.</p> * * @param rawInput ABI encoded input * @param typeReference of expected result type * @param <T> type of TypeReference * @return the decode value */ @SuppressWarnings("unchecked") public static <T extends Type> Type decodeIndexedValue( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName())); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } }
Example #18
Source File: StakingContract.java From client-sdk-java with Apache License 2.0 | 4 votes |
private Function createUnStakingFunction(String nodeId) { Function function = new Function(FunctionType.WITHDREW_STAKING_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(nodeId)))); return function; }
Example #19
Source File: TypeDecoder.java From web3j with Apache License 2.0 | 4 votes |
static Type instantiateAtomicType(Class<?> referenceClass, Object value) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException { Object constructorArg = null; if (NumericType.class.isAssignableFrom(referenceClass)) { constructorArg = asBigInteger(value); } else if (BytesType.class.isAssignableFrom(referenceClass)) { if (value instanceof byte[]) { constructorArg = value; } else if (value instanceof BigInteger) { constructorArg = ((BigInteger) value).toByteArray(); } else if (value instanceof String) { constructorArg = Numeric.hexStringToByteArray((String) value); } } else if (Utf8String.class.isAssignableFrom(referenceClass)) { constructorArg = value.toString(); } else if (Address.class.isAssignableFrom(referenceClass)) { if (value instanceof BigInteger || value instanceof Uint160) { constructorArg = value; } else { constructorArg = value.toString(); } } else if (Bool.class.isAssignableFrom(referenceClass)) { if (value instanceof Boolean) { constructorArg = value; } else { BigInteger bival = asBigInteger(value); constructorArg = bival == null ? null : !bival.equals(BigInteger.ZERO); } } if (constructorArg == null) { throw new InstantiationException( "Could not create type " + referenceClass + " from arg " + value.toString() + " of type " + value.getClass()); } Class<?>[] types = new Class[] {constructorArg.getClass()}; Constructor cons = referenceClass.getConstructor(types); return (Type) cons.newInstance(constructorArg); }
Example #20
Source File: SlashContract.java From client-sdk-java with Apache License 2.0 | 3 votes |
/** * 查询节点是否已被举报过多签 * * @param doubleSignType 代表双签类型,1:prepare,2:viewChange * @param address 举报的节点地址 * @param blockNumber 多签的块高 * @return */ public RemoteCall<CallResponse<String>> checkDoubleSign(DuplicateSignType doubleSignType, String address, BigInteger blockNumber) { Function function = new Function(FunctionType.CHECK_DOUBLESIGN_FUNC_TYPE, Arrays.asList(new Uint32(doubleSignType.getValue()) , new BytesType(Numeric.hexStringToByteArray(address)) , new Uint64(blockNumber))); return executeRemoteCallObjectValueReturn(function, String.class); }
Example #21
Source File: FunctionReturnDecoder.java From etherscan-explorer with GNU General Public License v3.0 | 3 votes |
/** * <p>Decodes an indexed parameter associated with an event. Indexed parameters are individually * encoded, unlike non-indexed parameters which are encoded as per ABI-encoded function * parameters and return values.</p> * * <p>If any of the following types are indexed, the Keccak-256 hashes of the values are * returned instead. These are returned as a bytes32 value.</p> * * <ul> * <li>Arrays</li> * <li>Strings</li> * <li>Bytes</li> * </ul> * * <p>See the * <a href="http://solidity.readthedocs.io/en/latest/contracts.html#events"> * Solidity documentation</a> for further information.</p> * * @param rawInput ABI encoded input * @param typeReference of expected result type * @param <T> type of TypeReference * @return the decode value */ @SuppressWarnings("unchecked") public static <T extends Type> Type decodeIndexedValue( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName())); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } }
Example #22
Source File: ProposalContract.java From client-sdk-java with Apache License 2.0 | 2 votes |
/** * 查询提案 * * @param proposalId * @return */ public RemoteCall<CallResponse<Proposal>> getProposal(String proposalId) { Function function = new Function(FunctionType.GET_PROPOSAL_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(proposalId)))); return executeRemoteCallObjectValueReturn(function, Proposal.class); }
Example #23
Source File: ProposalContract.java From client-sdk-java with Apache License 2.0 | 2 votes |
/** * 查询提案结果 * * @param proposalId * @return */ public RemoteCall<CallResponse<TallyResult>> getTallyResult(String proposalId) { Function function = new Function(FunctionType.GET_TALLY_RESULT_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(proposalId)))); return executeRemoteCallObjectValueReturn(function, TallyResult.class); }
Example #24
Source File: ProposalContract.java From client-sdk-java with Apache License 2.0 | 2 votes |
/** * 查询提案的累积可投票人数 * * @param proposalId 提案ID * @param blockHash 块hash * @return */ public RemoteCall<CallResponse<List<BigInteger>>> getAccuVerifiersCount(String proposalId, String blockHash) { Function function = new Function(FunctionType.GET_ACCUVERIFIERS_COUNT, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(proposalId)), new BytesType(Numeric.hexStringToByteArray(blockHash)))); return executeRemoteCallListValueReturn(function, BigInteger.class); }
Example #25
Source File: DelegateContract.java From client-sdk-java with Apache License 2.0 | 2 votes |
/** * 查询当前账户地址所委托的节点的NodeID和质押Id * * @param address * @return */ public RemoteCall<CallResponse<List<DelegationIdInfo>>> getRelatedListByDelAddr(String address) { Function function = new Function(FunctionType.GET_DELEGATELIST_BYADDR_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(address)))); return executeRemoteCallListValueReturn(function, DelegationIdInfo.class); }
Example #26
Source File: StakingContract.java From client-sdk-java with Apache License 2.0 | 2 votes |
/** * 获取质押信息 * * @param nodeId * @return */ public RemoteCall<CallResponse<Node>> getStakingInfo(String nodeId) { Function function = new Function(FunctionType.GET_STAKINGINFO_FUNC_TYPE, Arrays.asList(new BytesType(Numeric.hexStringToByteArray(nodeId)))); return executeRemoteCallObjectValueReturn(function, Node.class); }