use of io.nuls.kernel.model.Address in project nuls by nuls-io.
the class AddressTool method getAddress.
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();
}
use of io.nuls.kernel.model.Address in project nuls by nuls-io.
the class AccountTest method privateKeyTest.
// 测试私钥
@Test
public void privateKeyTest() {
for (int i = 1; i < 1000000000; i++) {
ECKey ecKey = new ECKey();
String prikey = Hex.encode(ecKey.getPrivKeyBytes());
ECKey ecKey2 = ECKey.fromPrivate(new BigInteger(1, Hex.decode(prikey)));
ECKey ecKey3 = ECKey.fromPrivate(new BigInteger(Hex.decode(prikey)));
if (!Arrays.equals(ecKey.getPubKey(), ecKey3.getPubKey())) {
// 1.0.1的bug, 导入私钥BigInteger少传参数, 如果不等说明问题大了。
System.out.println("error: " + prikey);
Address address1 = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, SerializeUtils.sha256hash160(ecKey.getPubKey()));
Address address3 = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, SerializeUtils.sha256hash160(ecKey3.getPubKey()));
System.out.println("原始地址: " + address1.getBase58());
System.out.println("导入后地址3: " + address3.getBase58());
try {
System.out.println("原始ecKey: " + JSONUtils.obj2json(ecKey));
System.out.println("导入后ecKey3: " + JSONUtils.obj2json(ecKey3));
} catch (Exception e) {
e.printStackTrace();
}
break;
}
if (!Arrays.equals(ecKey.getPubKey(), ecKey2.getPubKey())) {
System.out.println("error: " + prikey);
Address address1 = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, SerializeUtils.sha256hash160(ecKey.getPubKey()));
Address address2 = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, SerializeUtils.sha256hash160(ecKey2.getPubKey()));
System.out.println("原始地址: " + address1.getBase58());
System.out.println("导入后地址: " + address2.getBase58());
try {
System.out.println("原始ecKey: " + JSONUtils.obj2json(ecKey));
System.out.println("导入后ecKey: " + JSONUtils.obj2json(ecKey2));
} catch (Exception e) {
e.printStackTrace();
}
break;
} else {
System.out.println(i + " ok: " + prikey);
Address addr = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, SerializeUtils.sha256hash160(ecKey.getPubKey()));
if (addr.getBase58().endsWith("lichao") || addr.getBase58().endsWith("Charlie")) {
System.out.println(" yeah yeah yeah: " + addr.getBase58());
System.out.println(" yeah yeah yeah: " + prikey);
break;
}
}
/* try {
Thread.sleep(1L);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
}
}
use of io.nuls.kernel.model.Address in project nuls by nuls-io.
the class AddressTest method getAddress.
private String getAddress(short chainId, byte[] publicKey) {
if (publicKey == null) {
return null;
}
byte[] hash160 = SerializeUtils.sha256hash160(publicKey);
Address address = new Address(chainId, (byte) 1, hash160);
System.out.println(Hex.encode(address.getAddressBytes()));
return address.getBase58();
}
use of io.nuls.kernel.model.Address in project nuls by nuls-io.
the class AccountServiceImpl method removeMultiSigAccount.
/**
* 从数据库中删除该账户
*/
@Override
public Result<Boolean> removeMultiSigAccount(String address) {
try {
Address addressObj = Address.fromHashs(address);
Result result = this.multiSigAccountStorageService.getAccount(addressObj);
if (result.isFailed() || result.getData() == null) {
return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST);
}
return this.multiSigAccountStorageService.removeAccount(addressObj);
} catch (Exception e) {
Log.error(e);
return Result.getFailed();
}
}
use of io.nuls.kernel.model.Address in project nuls by nuls-io.
the class ContractBalanceManager method initAllTokensForAllAccounts.
public void initAllTokensForAllAccounts() {
Result<Collection<Account>> result = accountService.getAccountList();
if (result.isFailed()) {
return;
}
Result<List<ContractAddressInfoPo>> allContractInfoListResult = contractAddressStorageService.getAllNrc20ContractInfoList();
if (allContractInfoListResult.isFailed()) {
return;
}
List<ContractAddressInfoPo> contractAddressInfoPoList = allContractInfoListResult.getData();
Collection<Account> list = result.getData();
for (Account account : list) {
Address address = account.getAddress();
String addressStr = address.getBase58();
for (ContractAddressInfoPo po : contractAddressInfoPoList) {
initialContractToken(addressStr, AddressTool.getStringAddressByBytes(po.getContractAddress()));
}
}
}
Aggregations