本文整理了Java中io.nuls.kernel.model.Address
类的一些代码示例,展示了Address
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address
类的具体详情如下:
包路径:io.nuls.kernel.model.Address
类名称:Address
暂无
代码示例来源:origin: nuls-io/nuls
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj instanceof Address) {
Address other = (Address) obj;
return ArraysTool.arrayEquals(this.addressBytes, other.getAddressBytes());
}
return false;
}
代码示例来源:origin: nuls-io/nuls
/**
* 初始化缓存本地所有账户的余额信息
*/
public void initAccountBalance() {
balanceMap.clear();
Collection<Account> accounts = accountService.getAccountList().getData();
if (accounts == null) {
return;
}
for (Account account : accounts) {
try {
calBalanceByAddress(account.getAddress().getAddressBytes());
} catch (NulsException e) {
Log.info("getbalance of address[" + account.getAddress().getBase58() + "] error");
}
}
}
代码示例来源:origin: nuls-io/nuls
public static byte[] getAddress(byte[] publicKey) {
if (publicKey == null) {
return null;
}
byte[] hash160 = SerializeUtils.sha256hash160(publicKey);
Address address = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, hash160);
return address.getAddressBytes();
}
代码示例来源:origin: nuls-io/nuls
public Address(String address) {
try {
byte[] bytes = AddressTool.getAddress(address);
Address addressTmp = Address.fromHashs(bytes);
this.chainId = addressTmp.getChainId();
this.addressType = addressTmp.getAddressType();
this.hash160 = addressTmp.getHash160();
this.addressBytes = calcAddressbytes();
} catch (Exception e) {
Log.error(e);
}
}
代码示例来源:origin: nuls-io/nuls
/**
* 获取脚本中的公钥生成地址
*/
public static String getScriptAddress(List<ScriptChunk> chunks) {
if (chunks.get(0).opcode == ScriptOpCodes.OP_0) {
byte[] redeemByte = chunks.get(chunks.size() - 1).data;
Script redeemScript = new Script(redeemByte);
Address address = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.P2SH_ADDRESS_TYPE, SerializeUtils.sha256hash160(redeemScript.getProgram()));
return address.toString();
} else {
return AddressTool.getStringAddressByBytes(AddressTool.getAddress(chunks.get(1).data));
}
}
代码示例来源:origin: nuls-io/nuls
public void removeAccount(Address address) {
this.cacheMap.remove(address.getBase58());
}
代码示例来源:origin: nuls-io/nuls
@Override
public String toString() {
StringBuilder str = new StringBuilder();
for (MeetingMember member : this.getMemberList()) {
str.append(Address.fromHashs(member.getPackingAddress()).getBase58());
str.append(" ,order:" + member.getPackingIndexOfRound());
str.append(",packTime:" + new Date(member.getPackEndTime()));
str.append(",creditVal:" + member.getRealCreditVal());
str.append("\n");
}
if (null == this.getPreRound()) {
return ("round:index:" + this.getIndex() + " , start:" + new Date(this.getStartTime())
+ ", netTime:(" + new Date(TimeService.currentTimeMillis()).toString() + ") , totalWeight : " + totalWeight + " ,members:\n :" + str);
} else {
return ("round:index:" + this.getIndex() + " ,preIndex:" + this.getPreRound().getIndex() + " , start:" + new Date(this.getStartTime())
+ ", netTime:(" + new Date(TimeService.currentTimeMillis()).toString() + ") , totalWeight : " + totalWeight + " , members:\n :" + str);
}
}
}
代码示例来源:origin: nuls-io/nuls
private void initGengsisTxs(Map<String, Object> jsonMap) throws Exception {
List<Map<String, Object>> list = (List<Map<String, Object>>) jsonMap.get(CONFIG_FILED_TXS);
if (null == list || list.isEmpty()) {
throw new NulsRuntimeException(KernelErrorCode.CONFIG_ERROR);
}
CoinData coinData = new CoinData();
for (Map<String, Object> map : list) {
String address = (String) map.get(CONFIG_FILED_ADDRESS);
AssertUtil.canNotEmpty(address, KernelErrorCode.NULL_PARAMETER.getMsg());
Double amount = Double.valueOf("" + map.get(CONFIG_FILED_AMOUNT));
AssertUtil.canNotEmpty(amount, KernelErrorCode.NULL_PARAMETER.getMsg());
Long lockTime = Long.valueOf("" + map.get(CONFIG_FILED_LOCK_TIME));
Address ads = Address.fromHashs(address);
Coin coin = new Coin(ads.getAddressBytes(), Na.parseNuls(amount), lockTime == null ? 0 : lockTime.longValue());
coinData.addTo(coin);
}
CoinBaseTransaction tx = new CoinBaseTransaction();
tx.setTime(this.blockTime);
tx.setCoinData(coinData);
String remark = (String) jsonMap.get(CONFIG_FILED_REMARK);
if (StringUtils.isNotBlank(remark)) {
tx.setRemark(Hex.decode(remark));
}
tx.setHash(NulsDigestData.calcDigestData(tx.serializeForHash()));
List<Transaction> txlist = new ArrayList<>();
txlist.add(tx);
setTxs(txlist);
}
代码示例来源:origin: nuls-io/nuls
return Result.getFailed(AccountErrorCode.FAILED);
account.setAddress(new Address(keyStore.getAddress()));
if (null != aliasDb && account.getAddress().toString().equals(AddressTool.getStringAddressByBytes(aliasDb.getAddress()))) {
account.setAlias(aliasDb.getAlias());
} else {
for (AliasPo aliasPo : list) {
if (AddressTool.getStringAddressByBytes(aliasPo.getAddress()).equals(account.getAddress().toString())) {
account.setAlias(aliasPo.getAlias());
break;
return result;
accountCacheService.localAccountMaps.put(account.getAddress().getBase58(), account);
accountLedgerService.importLedgerByAddress(account.getAddress().getBase58());
return Result.getSuccess().setData(account);
代码示例来源:origin: nuls-io/nuls
Account acc = getAccountByAddress(account.getAddress().toString());
if (null == acc) {
List<AliasPo> list = aliasStorageService.getAliasList().getData();
for (AliasPo aliasPo : list) {
if (AddressTool.getStringAddressByBytes(aliasPo.getAddress()).equals(account.getAddress().toString())) {
account.setAlias(aliasPo.getAlias());
break;
account.setAlias(acc.getAlias());
Result res = accountLedgerService.importLedgerByAddress(account.getAddress().getBase58());
if (res.isFailed()) {
return res;
return result;
accountCacheService.localAccountMaps.put(account.getAddress().getBase58(), account);
代码示例来源:origin: nuls-io/nuls
public static Address fromHashs(byte[] hashs) {
if (hashs == null || hashs.length != ADDRESS_LENGTH) {
throw new NulsRuntimeException(KernelErrorCode.DATA_ERROR);
}
short chainId = SerializeUtils.bytes2Short(hashs);
byte addressType = hashs[2];
byte[] content = new byte[LENGTH];
System.arraycopy(hashs, 3, content, 0, LENGTH);
Address address = new Address(chainId, addressType, content);
return address;
}
代码示例来源:origin: nuls-io/nuls
@Override
public Result<Account> getAccount(Address address) {
if (null == address) {
return Result.getFailed(AccountErrorCode.NULL_PARAMETER);
}
return getAccount(address.toString());
}
代码示例来源:origin: nuls-io/nuls
public static Address fromHashs(String address) throws Exception {
byte[] bytes = AddressTool.getAddress(address);
return fromHashs(bytes);
}
代码示例来源:origin: nuls-io/nuls
public byte[] getHash160() {
return this.getAddress().getHash160();
}
代码示例来源:origin: nuls-io/nuls
/**
* 缓存一个账户
* Cache an account
*
* @param account Account to be cached
*/
public void putAccount(Account account) {
this.cacheMap.put(account.getAddress().getBase58(), account);
}
代码示例来源:origin: nuls-io/nuls
public BlockDto(BlockHeader header) throws IOException {
long bestBlockHeight = NulsContext.getInstance().getBestBlock().getHeader().getHeight();
this.hash = header.getHash().getDigestHex();
this.preHash = header.getPreHash().getDigestHex();
this.merkleHash = header.getMerkleHash().getDigestHex();
this.time = header.getTime();
this.height = header.getHeight();
this.txCount = header.getTxCount();
this.packingAddress = Address.fromHashs(header.getPackingAddress()).getBase58();
this.scriptSign = Hex.encode(header.getBlockSignature().serialize());
this.extend = Hex.encode(header.getExtend());
this.confirmCount = bestBlockHeight - this.height;
try {
BlockExtendsData roundData = new BlockExtendsData(header.getExtend());
this.roundIndex = roundData.getRoundIndex();
this.roundStartTime = roundData.getRoundStartTime();
this.consensusMemberCount = roundData.getConsensusMemberCount();
this.packingIndexOfRound = roundData.getPackingIndexOfRound();
if(roundData.getStateRoot() != null) {
this.stateRoot = Hex.encode(roundData.getStateRoot());
}
} catch (Exception e) {
Log.error(e);
}
}
代码示例来源:origin: nuls-io/nuls
/**
* 根据地址获取本地存储的多签账户的详细信息
* Get the details of the locally stored multi-sign account based on the address
*
* @param address 多签地址
* @return 多签账户的详细信息
*/
@Override
public Result<MultiSigAccount> getMultiSigAccount(String address) throws Exception {
byte[] bytes = this.multiSigAccountStorageService.getAccount(Address.fromHashs(address)).getData();
if (null == bytes) {
return Result.getFailed(KernelErrorCode.DATA_NOT_FOUND);
}
MultiSigAccount account = new MultiSigAccount();
account.parse(new NulsByteBuffer(bytes, 0));
List<AliasPo> list = aliasStorageService.getAliasList().getData();
for (AliasPo aliasPo : list) {
if (aliasPo.getAddress()[2] != NulsContext.P2SH_ADDRESS_TYPE) {
continue;
}
if (Arrays.equals(aliasPo.getAddress(), account.getAddress().getAddressBytes())) {
account.setAlias(aliasPo.getAlias());
break;
}
}
return Result.getSuccess().setData(account);
}
代码示例来源:origin: nuls-io/nuls
if (!account.getAddress().getBase58().equals(keyStore.getAddress())) {
return Result.getFailed(AccountErrorCode.PRIVATE_KEY_WRONG);
if (!account.getAddress().getBase58().equals(keyStore.getAddress())) {
return Result.getFailed(AccountErrorCode.PASSWORD_IS_WRONG);
aliasDb = aliasService.getAlias(keyStore.getAlias());
if (null != aliasDb && AddressTool.getStringAddressByBytes(aliasDb.getAddress()).equals(account.getAddress().toString())) {
account.setAlias(aliasDb.getAlias());
} else {
for (AliasPo aliasPo : list) {
if (AddressTool.getStringAddressByBytes(aliasPo.getAddress()).equals(account.getAddress().toString())) {
account.setAlias(aliasPo.getAlias());
break;
return result;
accountCacheService.localAccountMaps.put(account.getAddress().getBase58(), account);
accountLedgerService.importLedgerByAddress(account.getAddress().getBase58());
return Result.getSuccess().setData(account);
代码示例来源:origin: nuls-io/nuls
return Result.getFailed(AccountErrorCode.PARAMETER_ERROR).toRpcClientResult();
Address address = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, SerializeUtils.sha256hash160(key.getPubKey()));
Account account = accountService.getAccount(address).getData();
if (null != account) {
Account account = (Account) result.getData();
Map<String, String> map = new HashMap<>();
map.put("value", account.getAddress().toString());
result.setData(map);
代码示例来源:origin: nuls-io/nuls
public static Address newAddress(byte[] publicKey) throws NulsException {
return new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, SerializeUtils.sha256hash160(publicKey));
}
内容来源于网络,如有侵权,请联系作者删除!