forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tronprotocol#680 from tronprotocol/develop-evan-up…
…dataccount Develop evan updataccount
- Loading branch information
Showing
14 changed files
with
719 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.tron.core.db; | ||
|
||
import com.google.protobuf.ByteString; | ||
import java.util.Objects; | ||
import org.apache.commons.lang3.ArrayUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Component; | ||
import org.tron.core.capsule.AccountCapsule; | ||
import org.tron.core.capsule.BytesCapsule; | ||
|
||
@Component | ||
public class AccountIndexStore extends TronStoreWithRevoking<BytesCapsule> { | ||
|
||
@Autowired | ||
public AccountIndexStore(@Qualifier("account-index") String dbName) { | ||
super(dbName); | ||
} | ||
|
||
private static AccountIndexStore instance; | ||
|
||
public static void destroy() { | ||
instance = null; | ||
} | ||
|
||
/** | ||
* create fun. | ||
* | ||
* @param dbName the name of database | ||
*/ | ||
public static AccountIndexStore create(String dbName) { | ||
if (instance == null) { | ||
synchronized (AccountIndexStore.class) { | ||
if (instance == null) { | ||
instance = new AccountIndexStore(dbName); | ||
} | ||
} | ||
} | ||
return instance; | ||
} | ||
|
||
public void put(AccountCapsule accountCapsule) { | ||
put(accountCapsule.getAccountName().toByteArray(), | ||
new BytesCapsule(accountCapsule.getAddress().toByteArray())); | ||
} | ||
|
||
public byte[] get(ByteString name) { | ||
BytesCapsule bytesCapsule = get(name.toByteArray()); | ||
if (Objects.nonNull(bytesCapsule)) { | ||
return bytesCapsule.getData(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public BytesCapsule get(byte[] key) { | ||
byte[] value = dbSource.getData(key); | ||
if (ArrayUtils.isEmpty(value)) { | ||
return null; | ||
} | ||
return new BytesCapsule(value); | ||
} | ||
|
||
@Override | ||
public boolean has(byte[] key) { | ||
byte[] value = dbSource.getData(key); | ||
if (ArrayUtils.isEmpty(value)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.