Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
validator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
validator
Commits
f3508f06
Commit
f3508f06
authored
May 24, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update api
parent
d7218749
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
8 deletions
+73
-8
api.go
api/api.go
+62
-3
router.go
api/router.go
+11
-5
No files found.
api/api.go
View file @
f3508f06
...
...
@@ -111,13 +111,19 @@ func getRecord(c *gin.Context) {
}
func
getWithdrawProof
(
c
*
gin
.
Context
)
{
address
:=
c
.
Query
(
"address"
)
if
!
common
.
IsHexAddress
(
address
)
||
len
(
address
)
!=
42
{
tmp
:=
struct
{
Address
string
`json:"address"`
}{}
if
err
:=
c
.
ShouldBindJSON
(
&
tmp
);
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
InvalidParams
))
return
}
if
!
common
.
IsHexAddress
(
tmp
.
Address
)
||
len
(
tmp
.
Address
)
!=
42
{
c
.
JSON
(
200
,
withError
(
InvalidParams
))
return
}
amount
,
proofs
:=
validator
.
GetMerkleProof
(
common
.
HexToAddress
(
a
ddress
),
""
)
amount
,
proofs
:=
validator
.
GetMerkleProof
(
common
.
HexToAddress
(
tmp
.
A
ddress
),
""
)
c
.
JSON
(
200
,
withSuccess
(
gin
.
H
{
"amount"
:
amount
,
...
...
@@ -125,6 +131,59 @@ func getWithdrawProof(c *gin.Context) {
}))
}
func
getMerkleNodes
(
c
*
gin
.
Context
)
{
tmp
:=
struct
{
Date
string
`json:"date"`
Depth
uint
`json:"depth"`
RootHash
string
`json:"rootHash"`
}{}
if
err
:=
c
.
ShouldBindJSON
(
&
tmp
);
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
InvalidParams
))
return
}
_
,
err
:=
time
.
Parse
(
time
.
DateOnly
,
tmp
.
Date
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
InvalidParams
))
return
}
if
tmp
.
Depth
==
0
{
tmp
.
Depth
=
3
}
nodes
:=
validator
.
GetDailyMerkleNodes
(
tmp
.
Date
,
int
(
tmp
.
Depth
),
common
.
HexToHash
(
tmp
.
RootHash
))
c
.
JSON
(
200
,
withSuccess
(
nodes
))
}
func
getMerkleSumNodes
(
c
*
gin
.
Context
)
{
tmp
:=
struct
{
Date
string
`json:"date"`
Depth
uint
`json:"depth"`
RootHash
string
`json:"rootHash"`
}{}
if
err
:=
c
.
ShouldBindJSON
(
&
tmp
);
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
InvalidParams
))
return
}
_
,
err
:=
time
.
Parse
(
time
.
DateOnly
,
tmp
.
Date
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
InvalidParams
))
return
}
if
tmp
.
Depth
==
0
{
tmp
.
Depth
=
3
}
nodes
,
vals
:=
validator
.
GetDailyMerkleSumNodes
(
tmp
.
Date
,
int
(
tmp
.
Depth
),
common
.
HexToHash
(
tmp
.
RootHash
))
c
.
JSON
(
200
,
withSuccess
(
gin
.
H
{
"nodes"
:
nodes
,
"vals"
:
vals
,
}))
}
func
withSuccess
(
data
interface
{})
interface
{}
{
return
map
[
string
]
interface
{}{
"code"
:
0
,
...
...
api/router.go
View file @
f3508f06
package
api
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
)
func
initRouter
(
engine
*
gin
.
Engine
)
{
g
:=
engine
.
Group
(
"/api/v1"
)
g
.
POST
(
"/workload"
,
getWorkload
)
...
...
@@ -12,6 +12,12 @@ func initRouter(engine *gin.Engine) {
proof
:=
g
.
Group
(
"/proof"
)
{
proof
.
GET
(
"/withdraw"
,
getWithdrawProof
)
proof
.
POST
(
"/withdraw"
,
getWithdrawProof
)
}
tree
:=
g
.
Group
(
"/tree"
)
{
tree
.
POST
(
"/merkleNodes"
,
getMerkleNodes
)
tree
.
POST
(
"/merkleSumNodes"
,
getMerkleSumNodes
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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