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.
- Loading branch information
Showing
19 changed files
with
627 additions
and
22 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
57 changes: 57 additions & 0 deletions
57
chainbase/src/main/java/org/tron/core/capsule/AccountTraceCapsule.java
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,57 @@ | ||
package org.tron.core.capsule; | ||
|
||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.tron.common.utils.StringUtil; | ||
import org.tron.core.exception.BadItemException; | ||
import org.tron.protos.contract.BalanceContract; | ||
import org.tron.protos.contract.BalanceContract.AccountTrace; | ||
import org.tron.protos.contract.BalanceContract.TransactionBalanceTrace; | ||
|
||
public class AccountTraceCapsule implements ProtoCapsule<AccountTrace> { | ||
private BalanceContract.AccountTrace accountTrace; | ||
|
||
public AccountTraceCapsule() { | ||
accountTrace = AccountTrace.newBuilder().build(); | ||
} | ||
|
||
public AccountTraceCapsule(long balance) { | ||
this(); | ||
accountTrace = accountTrace.toBuilder().setBalance(balance).build(); | ||
} | ||
|
||
public AccountTraceCapsule(AccountTrace accountTrace) { | ||
this.accountTrace = accountTrace; | ||
} | ||
|
||
public AccountTraceCapsule(byte[] data) throws BadItemException { | ||
try { | ||
this.accountTrace = AccountTrace.parseFrom(data); | ||
} catch (InvalidProtocolBufferException e) { | ||
throw new BadItemException("AccountTraceCapsule proto data parse exception"); | ||
} | ||
} | ||
|
||
public Long getBalance() { | ||
return accountTrace.getBalance(); | ||
} | ||
|
||
@Override | ||
public byte[] getData() { | ||
if (Objects.isNull(accountTrace)) { | ||
return null; | ||
} | ||
|
||
if (accountTrace.getBalance() == 0) { | ||
accountTrace = accountTrace.toBuilder().setPlaceholder(1).build(); | ||
} | ||
|
||
return accountTrace.toByteArray(); | ||
} | ||
|
||
@Override | ||
public AccountTrace getInstance() { | ||
return accountTrace; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
chainbase/src/main/java/org/tron/core/capsule/BlockBalanceTraceCapsule.java
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,81 @@ | ||
package org.tron.core.capsule; | ||
|
||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.tron.common.utils.StringUtil; | ||
import org.tron.core.exception.BadItemException; | ||
import org.tron.protos.contract.BalanceContract.BlockBalanceTrace; | ||
import org.tron.protos.contract.BalanceContract.TransactionBalanceTrace; | ||
|
||
import java.util.Objects; | ||
|
||
public class BlockBalanceTraceCapsule implements ProtoCapsule<BlockBalanceTrace> { | ||
private BlockBalanceTrace balanceTrace; | ||
|
||
public BlockBalanceTraceCapsule() { | ||
balanceTrace = BlockBalanceTrace.newBuilder().build(); | ||
} | ||
|
||
public BlockBalanceTraceCapsule(BlockCapsule blockCapsule) { | ||
this(); | ||
BlockBalanceTrace.BlockIdentifier blockIdentifier = BlockBalanceTrace.BlockIdentifier.newBuilder() | ||
.setHash(blockCapsule.getBlockId().getByteString()) | ||
.setNumber(blockCapsule.getNum()) | ||
.build(); | ||
|
||
balanceTrace = balanceTrace.toBuilder() | ||
.setBlockIdentifier(blockIdentifier) | ||
.setTimestamp(blockCapsule.getTimeStamp()) | ||
.build(); | ||
} | ||
|
||
public BlockBalanceTraceCapsule(byte[] data) throws BadItemException { | ||
try { | ||
this.balanceTrace = BlockBalanceTrace.parseFrom(data); | ||
} catch (InvalidProtocolBufferException e) { | ||
throw new BadItemException("TransactionInfoCapsule proto data parse exception"); | ||
} | ||
} | ||
|
||
public BlockBalanceTraceCapsule(BlockBalanceTrace blockBalanceTrace) { | ||
this.balanceTrace = blockBalanceTrace; | ||
} | ||
|
||
public void addTransactionBalanceTrace(TransactionBalanceTrace transactionBalanceTrace) { | ||
balanceTrace = balanceTrace.toBuilder() | ||
.addTransactionBalanceTrace(transactionBalanceTrace) | ||
.build(); | ||
} | ||
|
||
public void setTransactionBalanceTrace(int index, TransactionBalanceTrace transactionBalanceTrace) { | ||
balanceTrace = balanceTrace.toBuilder() | ||
.setTransactionBalanceTrace(index, transactionBalanceTrace) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public byte[] getData() { | ||
if (Objects.isNull(balanceTrace)) { | ||
return null; | ||
} | ||
return balanceTrace.toByteArray(); | ||
} | ||
|
||
@Override | ||
public BlockBalanceTrace getInstance() { | ||
return balanceTrace; | ||
} | ||
|
||
public BlockBalanceTrace.BlockIdentifier getBlockIdentifier() { | ||
return balanceTrace.getBlockIdentifier(); | ||
} | ||
|
||
public long getTimestamp() { | ||
return balanceTrace.getTimestamp(); | ||
} | ||
|
||
public List<TransactionBalanceTrace> getTransactions() { | ||
return balanceTrace.getTransactionBalanceTraceList(); | ||
} | ||
} |
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
Oops, something went wrong.