segment
Definition
A segment has tokenId, coin start and coin end.
In the chamber's source-code, segment is uint256 type, it include 8 bytes tokenId, 8 byte start and 8 byte end.
TokenId
token id is just increnental number. it represent ERC20 token type id and it is mapped in RootChain.vy.
code:py
@public
def listToken(
tokenAddress: address,
denomination: uint256
):
tokenId: uint256 = self.listingNonce
self.listingstokenId.decimalOffset = denomination self.listingstokenId.tokenAddress = tokenAddress self.listingNonce += 1
# init the new token exitable ranges
self.exitabletokenId0.isAvailable = True log.ListingEvent(tokenId, tokenAddress)
segment decoder and encoder
code:py
@public
@constant
def parseSegment(
segment: uint256
) -> (uint256, uint256, uint256):
tokenId: uint256 = bitwise_and(shift(segment, - 16 * 8), MASK8BYTES)
start: uint256 = bitwise_and(shift(segment, - 8 * 8), MASK8BYTES)
end: uint256 = bitwise_and(segment, MASK8BYTES)
return (tokenId, start, end)
@public
@constant
def encodeSegment(
tokenId: uint256,
start: uint256,
end: uint256
) -> uint256:
return tokenId * (2 ** 128) + start * (2 ** 64) + end