Skip to content

Commit b61b609

Browse files
authored
Colin/exit pos (#144)
* get position from exit calculation * add print statement * move calc to position file * deposit position fixed * added test
1 parent dee03e9 commit b61b609

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

client/plasmacli/eth/getExits.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ func displayExit(key *big.Int, addr ethcmn.Address, deposits bool) (err error) {
140140
State uint8
141141
}
142142

143+
position := plasma.FromExitKey(key, deposits)
144+
143145
if deposits {
144146
exit, err = rc.contract.DepositExits(nil, key)
145147
} else {
@@ -153,10 +155,9 @@ func displayExit(key *big.Int, addr ethcmn.Address, deposits bool) (err error) {
153155
if !utils.IsZeroAddress(addr) && exit.Owner != addr {
154156
return nil
155157
}
156-
157158
state := parseState(exit.State)
158-
fmt.Printf("Owner: 0x%x\nAmount: %d\nState: %s\nCommitted Fee: %d\nCreated: %v\n\n",
159-
exit.Owner, exit.Amount, state, exit.CommittedFee, time.Unix(exit.CreatedAt.Int64(), 0))
159+
fmt.Printf("Owner: 0x%x\nAmount: %d\nState: %s\nCommitted Fee: %d\nCreated: %v\nPosition %s\n\n",
160+
exit.Owner, exit.Amount, state, exit.CommittedFee, time.Unix(exit.CreatedAt.Int64(), 0), position)
160161
if state == "Pending" {
161162
timeLeft := time.Until(time.Unix(exit.CreatedAt.Int64(), 0).Add(time.Hour * oneWeek))
162163
if timeLeft > 0 {

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ github.com/syndtr/goleveldb v0.0.0-20190226153722-4217c9f31f58 h1:DLVQCtatLabge7
160160
github.com/syndtr/goleveldb v0.0.0-20190226153722-4217c9f31f58/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
161161
github.com/tendermint/btcd v0.1.0 h1:2bR8bGTlOLEiO9eoz81Upbs8LFSRF2MVT42WiyW88eU=
162162
github.com/tendermint/btcd v0.1.0/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U=
163+
github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5 h1:u8i49c+BxloX3XQ55cvzFNXplizZP/q00i+IlttUjAU=
163164
github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk=
164165
github.com/tendermint/go-amino v0.14.1 h1:o2WudxNfdLNBwMyl2dqOJxiro5rfrEaU0Ugs6offJMk=
165166
github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso=

plasma/position.go

+9
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,12 @@ func FromPositionString(posStr string) (Position, error) {
194194
pos := NewPosition(blkNum, txIndex, oIndex, depositNonce)
195195
return pos, pos.ValidateBasic()
196196
}
197+
198+
// Return the position of a utxo given the exit key
199+
func FromExitKey(key *big.Int, deposit bool) Position {
200+
if deposit {
201+
return NewPosition(big.NewInt(0), 0, 0, key)
202+
} else {
203+
return NewPosition(new(big.Int).Div(key, big.NewInt(blockIndexFactor)), uint16(key.Int64()%blockIndexFactor/txIndexFactor), uint8(key.Int64()%2), big.NewInt(0))
204+
}
205+
}

plasma/position_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,13 @@ func TestPositionValidation(t *testing.T) {
7474
require.Errorf(t, pos.ValidateBasic(), "invalid position: %s", posStr)
7575
}
7676
}
77+
78+
func TestPositionFromKey(t *testing.T) {
79+
utxoKey := big.NewInt(133*blockIndexFactor + 14*txIndexFactor)
80+
utxo := FromExitKey(utxoKey, false)
81+
require.Equal(t, utxo, NewPosition(big.NewInt(133), 14, 0, big.NewInt(0)), "error retrieving correct position from exit key")
82+
83+
depositKey := big.NewInt(10)
84+
deposit := FromExitKey(depositKey, true)
85+
require.Equal(t, deposit, NewPosition(big.NewInt(0), 0, 0, depositKey), "error retrieving correct position from deposit exit key")
86+
}

0 commit comments

Comments
 (0)