Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
plugin
Commits
9e2e6eb8
Commit
9e2e6eb8
authored
Dec 08, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support different decimal
parent
5b964942
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
8 deletions
+74
-8
chain33.go
plugin/dapp/cross2eth/ebrelayer/relayer/chain33/chain33.go
+19
-4
ethereum.go
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
+22
-4
utils.go
plugin/dapp/cross2eth/ebrelayer/utils/utils.go
+14
-0
utils_test.go
plugin/dapp/cross2eth/ebrelayer/utils/utils_test.go
+19
-0
No files found.
plugin/dapp/cross2eth/ebrelayer/relayer/chain33/chain33.go
View file @
9e2e6eb8
...
@@ -406,10 +406,25 @@ func (chain33Relayer *Relayer4Chain33) relayLockBurnToChain33(claim *ebTypes.Eth
...
@@ -406,10 +406,25 @@ func (chain33Relayer *Relayer4Chain33) relayLockBurnToChain33(claim *ebTypes.Eth
}
}
}
}
//因为发行的合约的精度为8,所以需要缩小,在进行burn的时候,再进行倍乘,在函数ParseBurnLock4chain33进行
//因为发行的合约的精度为8,所以需要进行相应的缩放
if
18
==
claim
.
Decimal
{
if
8
!=
claim
.
Decimal
{
bigAmount
.
Div
(
bigAmount
,
big
.
NewInt
(
int64
(
1e10
)))
if
claim
.
Decimal
>
8
{
claim
.
Amount
=
bigAmount
.
String
()
dist
:=
claim
.
Decimal
-
8
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
if
!
exist
{
panic
(
fmt
.
Sprintf
(
"does support for decimal, %d"
,
claim
.
Decimal
))
}
bigAmount
.
Div
(
bigAmount
,
big
.
NewInt
(
value
))
claim
.
Amount
=
bigAmount
.
String
()
}
else
{
dist
:=
8
-
claim
.
Decimal
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
if
!
exist
{
panic
(
fmt
.
Sprintf
(
"does support for decimal, %d"
,
claim
.
Decimal
))
}
bigAmount
.
Mul
(
bigAmount
,
big
.
NewInt
(
value
))
claim
.
Amount
=
bigAmount
.
String
()
}
}
}
parameter
:=
fmt
.
Sprintf
(
"newOracleClaim(%d, %s, %s, %s, %s, %s, %s, %s)"
,
parameter
:=
fmt
.
Sprintf
(
"newOracleClaim(%d, %s, %s, %s, %s, %s, %s, %s)"
,
...
...
plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethereum.go
View file @
9e2e6eb8
...
@@ -496,16 +496,34 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
...
@@ -496,16 +496,34 @@ func (ethRelayer *Relayer4Ethereum) handleChain33Msg(chain33Msg *events.Chain33M
tokenAddr
=
common
.
HexToAddress
(
addr
)
tokenAddr
=
common
.
HexToAddress
(
addr
)
}
}
}
else
{
}
else
{
locked
TokenInfo
,
exist
:=
ethRelayer
.
symbol2LockAddr
[
prophecyClaim
.
Symbol
]
burnFromChain33
TokenInfo
,
exist
:=
ethRelayer
.
symbol2LockAddr
[
prophecyClaim
.
Symbol
]
if
!
exist
{
if
!
exist
{
//因为是burn操作,必须从允许lock的token地址中进行查询
//因为是burn操作,必须从允许lock的token地址中进行查询
relayerLog
.
Error
(
"handleChain33Msg"
,
"Failed to fetch locked Token Info for symbol"
,
prophecyClaim
.
Symbol
)
relayerLog
.
Error
(
"handleChain33Msg"
,
"Failed to fetch locked Token Info for symbol"
,
prophecyClaim
.
Symbol
)
return
return
}
}
tokenAddr
=
common
.
HexToAddress
(
lockedTokenInfo
.
Address
)
tokenAddr
=
common
.
HexToAddress
(
burnFromChain33TokenInfo
.
Address
)
if
lockedTokenInfo
.
Decimal
==
18
{
//if lockedTokenInfo.Decimal == 18 {
prophecyClaim
.
Amount
=
prophecyClaim
.
Amount
.
Mul
(
prophecyClaim
.
Amount
,
big
.
NewInt
(
int64
(
1e10
)))
// prophecyClaim.Amount = prophecyClaim.Amount.Mul(prophecyClaim.Amount, big.NewInt(int64(1e10)))
//}
//从chain33进行withdraw回来的token需要根据精度进行相应的缩放
if
8
!=
burnFromChain33TokenInfo
.
Decimal
{
if
burnFromChain33TokenInfo
.
Decimal
>
8
{
dist
:=
burnFromChain33TokenInfo
.
Decimal
-
8
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
if
!
exist
{
panic
(
fmt
.
Sprintf
(
"does support for decimal, %d"
,
burnFromChain33TokenInfo
.
Decimal
))
}
prophecyClaim
.
Amount
.
Mul
(
prophecyClaim
.
Amount
,
big
.
NewInt
(
value
))
}
else
{
dist
:=
8
-
burnFromChain33TokenInfo
.
Decimal
value
,
exist
:=
utils
.
Decimal2value
[
int
(
dist
)]
if
!
exist
{
panic
(
fmt
.
Sprintf
(
"does support for decimal, %d"
,
burnFromChain33TokenInfo
.
Decimal
))
}
prophecyClaim
.
Amount
.
Div
(
prophecyClaim
.
Amount
,
big
.
NewInt
(
value
))
}
}
}
}
}
...
...
plugin/dapp/cross2eth/ebrelayer/utils/utils.go
View file @
9e2e6eb8
...
@@ -34,6 +34,20 @@ const (
...
@@ -34,6 +34,20 @@ const (
nullAddress
=
"0x0000000000000000000000000000000000000000"
nullAddress
=
"0x0000000000000000000000000000000000000000"
)
)
var
Decimal2value
=
map
[
int
]
int64
{
1
:
1e1
,
2
:
1e2
,
3
:
1e3
,
4
:
1e4
,
5
:
1e5
,
6
:
1e6
,
7
:
1e7
,
8
:
1e8
,
9
:
1e9
,
10
:
1e10
,
11
:
1e11
,
}
var
log
=
log15
.
New
(
"module"
,
"utils"
)
var
log
=
log15
.
New
(
"module"
,
"utils"
)
// IsZeroAddress : checks an Ethereum address and returns a bool which indicates if it is the null address
// IsZeroAddress : checks an Ethereum address and returns a bool which indicates if it is the null address
...
...
plugin/dapp/cross2eth/ebrelayer/utils/utils_test.go
0 → 100644
View file @
9e2e6eb8
package
utils
import
(
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func
Test_decimals
(
t
*
testing
.
T
)
{
value2comp
:=
10
for
i
:=
1
;
i
<=
10
;
i
++
{
value
,
ok
:=
Decimal2value
[
i
]
require
.
Equal
(
t
,
value
,
int64
(
value2comp
))
require
.
Equal
(
t
,
ok
,
true
)
fmt
.
Println
(
"value="
,
value
)
value2comp
=
value2comp
*
10
}
}
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