mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-23 20:36:44 +00:00
truncate labels over 255 chars before persisting to db
This commit is contained in:
parent
74b4f51640
commit
8f7f0d4c61
4 changed files with 26 additions and 10 deletions
|
@ -45,16 +45,20 @@ public interface BlockTransactionDao {
|
|||
Map<Sha256Hash, BlockTransaction> existing = getForTxId(txid.getBytes());
|
||||
|
||||
if(existing.isEmpty() && blkTx.getId() == null) {
|
||||
long id = insertBlockTransaction(txid.getBytes(), blkTx.getHash().getBytes(), blkTx.getHeight(), blkTx.getDate(), blkTx.getFee(), blkTx.getLabel(),
|
||||
long id = insertBlockTransaction(txid.getBytes(), blkTx.getHash().getBytes(), blkTx.getHeight(), blkTx.getDate(), blkTx.getFee(), truncate(blkTx.getLabel()),
|
||||
blkTx.getTransaction() == null ? null : blkTx.getTransaction().bitcoinSerialize(),
|
||||
blkTx.getBlockHash() == null ? null : blkTx.getBlockHash().getBytes(), wallet.getId());
|
||||
blkTx.setId(id);
|
||||
} else {
|
||||
Long existingId = existing.get(txid) != null ? existing.get(txid).getId() : blkTx.getId();
|
||||
updateBlockTransaction(txid.getBytes(), blkTx.getHash().getBytes(), blkTx.getHeight(), blkTx.getDate(), blkTx.getFee(), blkTx.getLabel(),
|
||||
updateBlockTransaction(txid.getBytes(), blkTx.getHash().getBytes(), blkTx.getHeight(), blkTx.getDate(), blkTx.getFee(), truncate(blkTx.getLabel()),
|
||||
blkTx.getTransaction() == null ? null : blkTx.getTransaction().bitcoinSerialize(),
|
||||
blkTx.getBlockHash() == null ? null : blkTx.getBlockHash().getBytes(), wallet.getId(), existingId);
|
||||
blkTx.setId(existingId);
|
||||
}
|
||||
}
|
||||
|
||||
default String truncate(String label) {
|
||||
return (label != null && label.length() > 255 ? label.substring(0, 255) : label);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public interface KeystoreDao {
|
|||
}
|
||||
}
|
||||
|
||||
long id = insert(keystore.getLabel(), keystore.getSource().ordinal(), keystore.getWalletModel().ordinal(),
|
||||
long id = insert(truncate(keystore.getLabel()), keystore.getSource().ordinal(), keystore.getWalletModel().ordinal(),
|
||||
keystore.hasPrivateKey() ? null : keystore.getKeyDerivation().getMasterFingerprint(),
|
||||
keystore.getKeyDerivation().getDerivationPath(),
|
||||
keystore.hasPrivateKey() ? null : keystore.getExtendedPublicKey().toString(),
|
||||
|
@ -99,4 +99,8 @@ public interface KeystoreDao {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
default String truncate(String label) {
|
||||
return (label != null && label.length() > 255 ? label.substring(0, 255) : label);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public interface WalletDao {
|
|||
setSchema(schema);
|
||||
createPolicyDao().addPolicy(wallet.getDefaultPolicy());
|
||||
|
||||
long id = insert(wallet.getName(), wallet.getNetwork().ordinal(), wallet.getPolicyType().ordinal(), wallet.getScriptType().ordinal(), wallet.getStoredBlockHeight(), wallet.gapLimit(), wallet.getBirthDate(), wallet.getDefaultPolicy().getId());
|
||||
long id = insert(truncate(wallet.getName()), wallet.getNetwork().ordinal(), wallet.getPolicyType().ordinal(), wallet.getScriptType().ordinal(), wallet.getStoredBlockHeight(), wallet.gapLimit(), wallet.getBirthDate(), wallet.getDefaultPolicy().getId());
|
||||
wallet.setId(id);
|
||||
|
||||
createKeystoreDao().addKeystores(wallet);
|
||||
|
@ -103,4 +103,8 @@ public interface WalletDao {
|
|||
setSchema(DbPersistence.DEFAULT_SCHEMA);
|
||||
}
|
||||
}
|
||||
|
||||
default String truncate(String label) {
|
||||
return (label != null && label.length() > 255 ? label.substring(0, 255) : label);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,10 +58,10 @@ public interface WalletNodeDao {
|
|||
|
||||
default void addWalletNodes(Wallet wallet) {
|
||||
for(WalletNode purposeNode : wallet.getPurposeNodes()) {
|
||||
long purposeNodeId = insertWalletNode(purposeNode.getDerivationPath(), purposeNode.getLabel(), wallet.getId(), null);
|
||||
long purposeNodeId = insertWalletNode(purposeNode.getDerivationPath(), truncate(purposeNode.getLabel()), wallet.getId(), null);
|
||||
purposeNode.setId(purposeNodeId);
|
||||
for(WalletNode addressNode : purposeNode.getChildren()) {
|
||||
long addressNodeId = insertWalletNode(addressNode.getDerivationPath(), addressNode.getLabel(), wallet.getId(), purposeNodeId);
|
||||
long addressNodeId = insertWalletNode(addressNode.getDerivationPath(), truncate(addressNode.getLabel()), wallet.getId(), purposeNodeId);
|
||||
addressNode.setId(addressNodeId);
|
||||
addTransactionOutputs(addressNode);
|
||||
}
|
||||
|
@ -84,22 +84,22 @@ public interface WalletNodeDao {
|
|||
if(txo.isSpent()) {
|
||||
BlockTransactionHashIndex spentBy = txo.getSpentBy();
|
||||
if(spentBy.getId() == null) {
|
||||
spentById = insertBlockTransactionHashIndex(spentBy.getHash().getBytes(), spentBy.getHeight(), spentBy.getDate(), spentBy.getFee(), spentBy.getLabel(), spentBy.getIndex(), spentBy.getValue(),
|
||||
spentById = insertBlockTransactionHashIndex(spentBy.getHash().getBytes(), spentBy.getHeight(), spentBy.getDate(), spentBy.getFee(), truncate(spentBy.getLabel()), spentBy.getIndex(), spentBy.getValue(),
|
||||
spentBy.getStatus() == null ? null : spentBy.getStatus().ordinal(), null, addressNode.getId());
|
||||
spentBy.setId(spentById);
|
||||
} else {
|
||||
updateBlockTransactionHashIndex(spentBy.getHash().getBytes(), spentBy.getHeight(), spentBy.getDate(), spentBy.getFee(), spentBy.getLabel(), spentBy.getIndex(), spentBy.getValue(),
|
||||
updateBlockTransactionHashIndex(spentBy.getHash().getBytes(), spentBy.getHeight(), spentBy.getDate(), spentBy.getFee(), truncate(spentBy.getLabel()), spentBy.getIndex(), spentBy.getValue(),
|
||||
spentBy.getStatus() == null ? null : spentBy.getStatus().ordinal(), null, addressNode.getId(), spentBy.getId());
|
||||
spentById = spentBy.getId();
|
||||
}
|
||||
}
|
||||
|
||||
if(txo.getId() == null) {
|
||||
long txoId = insertBlockTransactionHashIndex(txo.getHash().getBytes(), txo.getHeight(), txo.getDate(), txo.getFee(), txo.getLabel(), txo.getIndex(), txo.getValue(),
|
||||
long txoId = insertBlockTransactionHashIndex(txo.getHash().getBytes(), txo.getHeight(), txo.getDate(), txo.getFee(), truncate(txo.getLabel()), txo.getIndex(), txo.getValue(),
|
||||
txo.getStatus() == null ? null : txo.getStatus().ordinal(), spentById, addressNode.getId());
|
||||
txo.setId(txoId);
|
||||
} else {
|
||||
updateBlockTransactionHashIndex(txo.getHash().getBytes(), txo.getHeight(), txo.getDate(), txo.getFee(), txo.getLabel(), txo.getIndex(), txo.getValue(),
|
||||
updateBlockTransactionHashIndex(txo.getHash().getBytes(), txo.getHeight(), txo.getDate(), txo.getFee(), truncate(txo.getLabel()), txo.getIndex(), txo.getValue(),
|
||||
txo.getStatus() == null ? null : txo.getStatus().ordinal(), spentById, addressNode.getId(), txo.getId());
|
||||
}
|
||||
}
|
||||
|
@ -113,4 +113,8 @@ public interface WalletNodeDao {
|
|||
clearSpentHistory(wallet.getId());
|
||||
clearHistory(wallet.getId());
|
||||
}
|
||||
|
||||
default String truncate(String label) {
|
||||
return (label != null && label.length() > 255 ? label.substring(0, 255) : label);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue