Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rpcproxy
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
vicotor
rpcproxy
Commits
e0885355
Commit
e0885355
authored
Oct 21, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code
parent
71b8af45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
37 deletions
+13
-37
blacklist.go
blacklist.go
+13
-37
No files found.
blacklist.go
View file @
e0885355
package
main
package
main
import
(
import
(
"code.wuban.net.cn/luxueqian/rpcproxy/contracts/blacklist"
"context"
"context"
"fmt"
"fmt"
"
math/big
"
"
github.com/ethereum/go-ethereum/accounts/abi/bind
"
"strings"
"strings"
"sync"
"sync"
"time"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethclient"
)
)
...
@@ -40,46 +39,23 @@ func IsInBlacklist(client *ethclient.Client, contract common.Address, addr commo
...
@@ -40,46 +39,23 @@ func IsInBlacklist(client *ethclient.Client, contract common.Address, addr commo
if
client
==
nil
{
if
client
==
nil
{
return
false
,
fmt
.
Errorf
(
"nil ethclient"
)
return
false
,
fmt
.
Errorf
(
"nil ethclient"
)
}
}
contraction
,
err
:=
blacklist
.
NewBlacklist
(
contract
,
client
)
parsed
,
err
:=
abi
.
JSON
(
strings
.
NewReader
(
blacklistABI
))
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"failed to
parse ABI
: %w"
,
err
)
return
false
,
fmt
.
Errorf
(
"failed to
bind contract
: %w"
,
err
)
}
}
opts
:=
&
bind
.
CallOpts
{
data
,
err
:=
parsed
.
Pack
(
"inBlacklist"
,
addr
)
From
:
addr
,
if
err
!=
nil
{
BlockNumber
:
nil
,
return
false
,
fmt
.
Errorf
(
"failed to pack params: %w"
,
err
)
Context
:
context
.
Background
(),
}
}
results
,
err
:=
contraction
.
InBlackList
(
opts
,
[]
common
.
Address
{
addr
})
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
res
,
err
:=
client
.
CallContract
(
ctx
,
ethereum
.
CallMsg
{
To
:
&
contract
,
Data
:
data
,
},
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"c
all contract
failed: %w"
,
err
)
return
false
,
fmt
.
Errorf
(
"c
ontract call
failed: %w"
,
err
)
}
}
if
len
(
results
)
>
0
&&
results
[
0
]
{
// Unpack into a slice of interfaces
return
true
,
nil
var
out
[]
interface
{}
if
err
:=
parsed
.
UnpackIntoInterface
(
&
out
,
"inBlacklist"
,
res
);
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"failed to unpack result: %w"
,
err
)
}
if
len
(
out
)
==
0
{
return
false
,
fmt
.
Errorf
(
"empty result from contract"
)
}
b
,
ok
:=
out
[
0
]
.
(
bool
)
if
!
ok
{
// Some ABI versions may return type *big.Int for booleans encoded as uint8; handle that just in case
if
bi
,
ok2
:=
out
[
0
]
.
(
*
big
.
Int
);
ok2
{
return
bi
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
,
nil
}
return
false
,
fmt
.
Errorf
(
"unexpected result type: %T"
,
out
[
0
])
}
}
return
b
,
nil
return
false
,
nil
}
}
// CachedIsInBlacklist checks an in-memory cache before calling the contract.
// CachedIsInBlacklist checks an in-memory cache before calling the contract.
...
...
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