Search in sources :

Example 6 with Address

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();
}
Also used : Address(io.nuls.kernel.model.Address)

Example 7 with Address

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();
            }*/
    }
}
Also used : Address(io.nuls.kernel.model.Address) BigInteger(java.math.BigInteger) ECKey(io.nuls.core.tools.crypto.ECKey) Test(org.junit.Test)

Example 8 with Address

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();
}
Also used : Address(io.nuls.kernel.model.Address)

Example 9 with Address

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();
    }
}
Also used : Address(io.nuls.kernel.model.Address) CryptoException(io.nuls.core.tools.crypto.Exception.CryptoException) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) NulsException(io.nuls.kernel.exception.NulsException) Result(io.nuls.kernel.model.Result)

Example 10 with Address

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()));
        }
    }
}
Also used : ContractAddressInfoPo(io.nuls.contract.storage.po.ContractAddressInfoPo) Account(io.nuls.account.model.Account) Address(io.nuls.kernel.model.Address) LedgerUtil.asString(io.nuls.ledger.util.LedgerUtil.asString)

Aggregations

Address (io.nuls.kernel.model.Address)10 NulsException (io.nuls.kernel.exception.NulsException)4 Result (io.nuls.kernel.model.Result)4 IOException (java.io.IOException)3 Account (io.nuls.account.model.Account)2 ECKey (io.nuls.core.tools.crypto.ECKey)2 CryptoException (io.nuls.core.tools.crypto.Exception.CryptoException)2 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)2 Script (io.nuls.kernel.script.Script)2 BigInteger (java.math.BigInteger)2 SignatureException (java.security.SignatureException)2 AccountPo (io.nuls.account.storage.po.AccountPo)1 AliasPo (io.nuls.account.storage.po.AliasPo)1 ContractAddressInfoPo (io.nuls.contract.storage.po.ContractAddressInfoPo)1 LedgerUtil.asString (io.nuls.ledger.util.LedgerUtil.asString)1 Test (org.junit.Test)1