Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Register
Sign in
Toggle navigation
Menu
Open sidebar
Tiger Ton
osmosis
Commits
6c83d3f5
Commit
6c83d3f5
authored
3 years ago
by
ValarDragon
Browse files
Options
Download
Email Patches
Plain Diff
Add cmd for outputting all locks into a json
parent
cfc2d344
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
x/lockup/client/cli/query.go
+89
-0
x/lockup/client/cli/query.go
with
89 additions
and
0 deletions
+89
-0
x/lockup/client/cli/query.go
+
89
-
0
View file @
6c83d3f5
package
cli
import
(
"encoding/json"
"fmt"
"io/ioutil"
"strconv"
"strings"
"time"
...
...
@@ -12,6 +14,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
sdk
"github.com/cosmos/cosmos-sdk/types"
"github.com/osmosis-labs/osmosis/x/lockup/types"
)
...
...
@@ -40,6 +44,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
GetCmdAccountLockedLongerDuration
(),
GetCmdAccountLockedLongerDurationNotUnlockingOnly
(),
GetCmdAccountLockedLongerDurationDenom
(),
GetCmdOutputLocksJson
(),
)
return
cmd
...
...
@@ -571,3 +576,87 @@ $ %s query lockup account-locked-pasttime <address> <duration> <denom>
return
cmd
}
// GetCmdAccountLockedLongerDurationDenom returns account's locked records for a denom with longer duration
func
GetCmdOutputLocksJson
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"output-all-locks <max lock ID>"
,
Short
:
"output all locks into a json file"
,
Long
:
strings
.
TrimSpace
(
fmt
.
Sprintf
(
`Output all locks into a json file.
Example:
$ %s query lockup output-all-locks <max lock ID>
`
,
version
.
AppName
,
),
),
Args
:
cobra
.
ExactArgs
(
1
),
RunE
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
clientCtx
,
err
:=
client
.
GetClientQueryContext
(
cmd
)
if
err
!=
nil
{
return
err
}
maxLockID
,
err
:=
strconv
.
ParseInt
(
args
[
0
],
10
,
32
)
if
err
!=
nil
{
return
err
}
// status
const
(
doesnt_exist_status
=
iota
unbonding_status
bonded_status
)
type
LockResult
struct
{
id
int
status
int
// one of {doesnt_exist, }
denom
string
amount
sdk
.
Int
address
string
unbondEndTime
time
.
Time
}
queryClient
:=
types
.
NewQueryClient
(
clientCtx
)
results
:=
[]
LockResult
{}
for
i
:=
0
;
i
<=
int
(
maxLockID
);
i
++
{
curLockResult
:=
LockResult
{
id
:
i
}
res
,
err
:=
queryClient
.
LockedByID
(
cmd
.
Context
(),
&
types
.
LockedRequest
{
LockId
:
uint64
(
i
)})
if
err
!=
nil
{
curLockResult
.
status
=
doesnt_exist_status
results
=
append
(
results
,
curLockResult
)
continue
}
// 1527019420 is hardcoded time well before launch, but well after year 1
if
res
.
Lock
.
EndTime
.
Before
(
time
.
Unix
(
1527019420
,
0
))
{
curLockResult
.
status
=
bonded_status
}
else
{
curLockResult
.
status
=
unbonding_status
curLockResult
.
unbondEndTime
=
res
.
Lock
.
EndTime
curLockResult
.
denom
=
res
.
Lock
.
Coins
[
0
]
.
Denom
curLockResult
.
amount
=
res
.
Lock
.
Coins
[
0
]
.
Amount
curLockResult
.
address
=
res
.
Lock
.
Owner
}
results
=
append
(
results
,
curLockResult
)
}
bz
,
err
:=
json
.
Marshal
(
results
)
if
err
!=
nil
{
return
err
}
err
=
ioutil
.
WriteFile
(
"lock_export.json"
,
[]
byte
(
bz
),
0777
)
if
err
!=
nil
{
return
err
}
fmt
.
Println
(
"Writing to lock_export.json"
)
return
nil
},
}
flags
.
AddQueryFlagsToCmd
(
cmd
)
return
cmd
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment