mirror of https://github.com/qortal/qortal
catbref
5 years ago
2 changed files with 122 additions and 16 deletions
@ -0,0 +1,105 @@
|
||||
package org.qora; |
||||
|
||||
import java.security.Security; |
||||
|
||||
import org.bitcoinj.core.Base58; |
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider; |
||||
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider; |
||||
import org.qora.block.BlockChain; |
||||
import org.qora.controller.Controller; |
||||
import org.qora.data.account.RewardShareData; |
||||
import org.qora.gui.Gui; |
||||
import org.qora.repository.DataException; |
||||
import org.qora.repository.Repository; |
||||
import org.qora.repository.RepositoryFactory; |
||||
import org.qora.repository.RepositoryManager; |
||||
import org.qora.repository.hsqldb.HSQLDBRepositoryFactory; |
||||
import org.qora.settings.Settings; |
||||
import org.qora.transform.block.BlockTransformer; |
||||
import org.roaringbitmap.IntIterator; |
||||
|
||||
import io.druid.extendedset.intset.ConciseSet; |
||||
|
||||
public class DecodeOnlineAccounts { |
||||
|
||||
private static void usage() { |
||||
System.err.println("Usage: DecodeOnlineAccounts [<settings-file>] <base58-encoded-accounts>"); |
||||
System.err.println("Example: DecodeOnlineAccounts 4GmR5B"); |
||||
System.err.println("Example: DecodeOnlineAccounts settings-test.json 4GmR5B"); |
||||
System.exit(1); |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
if (args.length < 1 || args.length > 2) |
||||
usage(); |
||||
|
||||
byte[] encodedOnlineAccounts = Base58.decode(args[args.length - 1]); |
||||
|
||||
ConciseSet accountIndexes = BlockTransformer.decodeOnlineAccounts(encodedOnlineAccounts); |
||||
|
||||
String delimiter = ""; |
||||
System.out.print("Account indexes: "); |
||||
|
||||
IntIterator iterator = accountIndexes.iterator(); |
||||
while (iterator.hasNext()) { |
||||
int accountIndex = iterator.next(); |
||||
|
||||
System.out.print(String.format("%s%d", delimiter, accountIndex)); |
||||
delimiter = ", "; |
||||
} |
||||
System.out.println(); |
||||
|
||||
Security.insertProviderAt(new BouncyCastleProvider(), 0); |
||||
Security.insertProviderAt(new BouncyCastleJsseProvider(), 1); |
||||
|
||||
// Load/check settings, which potentially sets up blockchain config, etc.
|
||||
try { |
||||
if (args.length > 1) |
||||
Settings.fileInstance(args[0]); |
||||
else |
||||
Settings.getInstance(); |
||||
} catch (Throwable t) { |
||||
Gui.getInstance().fatalError("Settings file", t.getMessage()); |
||||
return; // Not System.exit() so that GUI can display error
|
||||
} |
||||
|
||||
try { |
||||
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(Controller.getRepositoryUrl()); |
||||
RepositoryManager.setRepositoryFactory(repositoryFactory); |
||||
} catch (DataException e) { |
||||
System.err.println("Couldn't connect to repository: " + e.getMessage()); |
||||
System.exit(2); |
||||
} |
||||
|
||||
try { |
||||
BlockChain.validate(); |
||||
} catch (DataException e) { |
||||
System.err.println("Couldn't validate repository: " + e.getMessage()); |
||||
System.exit(2); |
||||
} |
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) { |
||||
iterator = accountIndexes.iterator(); |
||||
while (iterator.hasNext()) { |
||||
int accountIndex = iterator.next(); |
||||
|
||||
RewardShareData rewardShareData = repository.getAccountRepository().getRewardShareByIndex(accountIndex); |
||||
|
||||
System.out.println(String.format("Reward-share public key: %s, minter: %s, recipient: %s, share: %s", |
||||
Base58.encode(rewardShareData.getRewardSharePublicKey()), |
||||
rewardShareData.getMintingAccount(), rewardShareData.getRecipient(), |
||||
rewardShareData.getSharePercent().toPlainString())); |
||||
} |
||||
} catch (DataException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
try { |
||||
RepositoryManager.closeRepositoryFactory(); |
||||
} catch (DataException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue