-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
100 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
// BytesBlock tracks the amount of bytes available during execution of the transactions | ||
// in a block. The zero value is a block with zero bytes available. | ||
type BytesBlock uint64 | ||
|
||
// SetLimit makes bytes available to use. | ||
func (bp *BytesBlock) SetLimit(amount uint64) *BytesBlock { | ||
if uint64(*bp) > math.MaxUint64-amount { | ||
panic("block's bytes pushed above uint64") | ||
} | ||
*(*uint64)(bp) += amount | ||
return bp | ||
} | ||
|
||
// SubBytes deducts the given amount from the block if enough bytes are | ||
// available and returns an error otherwise. | ||
func (bp *BytesBlock) SubBytes(amount uint64) error { | ||
if uint64(*bp) < amount { | ||
return ErrBytesLimitReached | ||
} | ||
*(*uint64)(bp) -= amount | ||
return nil | ||
} | ||
|
||
// BytesLeft returns the amount of gas remaining in the pool. | ||
func (bp *BytesBlock) BytesLeft() uint64 { | ||
return uint64(*bp) | ||
} | ||
|
||
func (bp *BytesBlock) String() string { | ||
return fmt.Sprintf("%d", *bp) | ||
} |
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