-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from EscanBE/imp/add-more-util-methods
imp: add more util methods
- Loading branch information
Showing
8 changed files
with
270 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
package utils | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"fmt" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
) | ||
|
||
// Keccak256Hash computes and returns Keccak-256 value of an input string | ||
func Keccak256Hash(input string) string { | ||
return hex.EncodeToString(crypto.Keccak256Hash([]byte(input)).Bytes()) | ||
} | ||
|
||
// Sha256 returns SHA256 checksum string value of an input string | ||
func Sha256(input string) string { | ||
return fmt.Sprintf("%x", sha256.Sum256([]byte(input))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// BuildIbcDenom returns IBC denom based on algorithm provided by IBC docs: Sha256(path/baseDenom) | ||
func BuildIbcDenom(path, baseDenom string) string { | ||
return fmt.Sprintf("ibc/%s", strings.ToUpper(Sha256(fmt.Sprintf("%s/%s", path, baseDenom)))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestBuildIbcDenom(t *testing.T) { | ||
//goland:noinspection SpellCheckingInspection | ||
tests := []struct { | ||
path string | ||
baseDenom string | ||
want string | ||
}{ | ||
{ | ||
path: "transfer/channel-0", | ||
baseDenom: "uosmo", | ||
want: "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518", | ||
}, | ||
{ | ||
path: "transfer/channel-3", | ||
baseDenom: "uatom", | ||
want: "ibc/A4DB47A9D3CF9A068D454513891B526702455D3EF08FB9EB558C561F9DC2B701", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(fmt.Sprintf("%s/%s", tt.path, tt.baseDenom), func(t *testing.T) { | ||
if got := BuildIbcDenom(tt.path, tt.baseDenom); got != tt.want { | ||
t.Errorf("BuildIbcDenom() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters