Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colin/exit pos #144

Merged
merged 5 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions client/plasmacli/eth/getExits.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func displayExit(key *big.Int, addr ethcmn.Address, deposits bool) (err error) {
State uint8
}

position := plasma.FromExitKey(key, deposits)

if deposits {
exit, err = rc.contract.DepositExits(nil, key)
} else {
Expand All @@ -153,10 +155,9 @@ func displayExit(key *big.Int, addr ethcmn.Address, deposits bool) (err error) {
if !utils.IsZeroAddress(addr) && exit.Owner != addr {
return nil
}

state := parseState(exit.State)
fmt.Printf("Owner: 0x%x\nAmount: %d\nState: %s\nCommitted Fee: %d\nCreated: %v\n\n",
exit.Owner, exit.Amount, state, exit.CommittedFee, time.Unix(exit.CreatedAt.Int64(), 0))
fmt.Printf("Owner: 0x%x\nAmount: %d\nState: %s\nCommitted Fee: %d\nCreated: %v\nPosition %s\n\n",
exit.Owner, exit.Amount, state, exit.CommittedFee, time.Unix(exit.CreatedAt.Int64(), 0), position)
if state == "Pending" {
timeLeft := time.Until(time.Unix(exit.CreatedAt.Int64(), 0).Add(time.Hour * oneWeek))
if timeLeft > 0 {
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ github.com/syndtr/goleveldb v0.0.0-20190226153722-4217c9f31f58 h1:DLVQCtatLabge7
github.com/syndtr/goleveldb v0.0.0-20190226153722-4217c9f31f58/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
github.com/tendermint/btcd v0.1.0 h1:2bR8bGTlOLEiO9eoz81Upbs8LFSRF2MVT42WiyW88eU=
github.com/tendermint/btcd v0.1.0/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U=
github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5 h1:u8i49c+BxloX3XQ55cvzFNXplizZP/q00i+IlttUjAU=
github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk=
github.com/tendermint/go-amino v0.14.1 h1:o2WudxNfdLNBwMyl2dqOJxiro5rfrEaU0Ugs6offJMk=
github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso=
Expand Down
9 changes: 9 additions & 0 deletions plasma/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,12 @@ func FromPositionString(posStr string) (Position, error) {
pos := NewPosition(blkNum, txIndex, oIndex, depositNonce)
return pos, pos.ValidateBasic()
}

// Return the position of a utxo given the exit key
func FromExitKey(key *big.Int, deposit bool) Position {
if deposit {
return NewPosition(big.NewInt(0), 0, 0, key)
} else {
return NewPosition(new(big.Int).Div(key, big.NewInt(blockIndexFactor)), uint16(key.Int64()%blockIndexFactor/txIndexFactor), uint8(key.Int64()%2), big.NewInt(0))
}
}
10 changes: 10 additions & 0 deletions plasma/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ func TestPositionValidation(t *testing.T) {
require.Errorf(t, pos.ValidateBasic(), "invalid position: %s", posStr)
}
}

func TestPositionFromKey(t *testing.T) {
utxoKey := big.NewInt(133*blockIndexFactor + 14*txIndexFactor)
utxo := FromExitKey(utxoKey, false)
require.Equal(t, utxo, NewPosition(big.NewInt(133), 14, 0, big.NewInt(0)), "error retrieving correct position from exit key")

depositKey := big.NewInt(10)
deposit := FromExitKey(depositKey, true)
require.Equal(t, deposit, NewPosition(big.NewInt(0), 0, 0, depositKey), "error retrieving correct position from deposit exit key")
}