-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Asset Trigger * create KDA * broadcast tx * wallet from PEM file * hasher/marshalizer tools * calculate TX Hash * Update account * update demos
- Loading branch information
1 parent
948465e
commit 01c5691
Showing
30 changed files
with
1,136 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
*.pem* | ||
.DS_Store | ||
*.env* | ||
bin/ | ||
vendor | ||
.idea | ||
.vscode | ||
|
||
.vscode |
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,37 @@ | ||
# KKKKKKKKK KKKKKKKLLLLLLLLLLL EEEEEEEEEEEEEEEEEEEEEEVVVVVVVV VVVVVVVVEEEEEEEEEEEEEEEEEEEEEERRRRRRRRRRRRRRRRR | ||
# K:::::::K K:::::KL:::::::::L E::::::::::::::::::::EV::::::V V::::::VE::::::::::::::::::::ER::::::::::::::::R | ||
# K:::::::K K:::::KL:::::::::L E::::::::::::::::::::EV::::::V V::::::VE::::::::::::::::::::ER::::::RRRRRR:::::R | ||
# K:::::::K K::::::KLL:::::::LL EE::::::EEEEEEEEE::::EV::::::V V::::::VEE::::::EEEEEEEEE::::ERR:::::R R:::::R | ||
# KK::::::K K:::::KKK L:::::L E:::::E EEEEEE V:::::V V:::::V E:::::E EEEEEE R::::R R:::::R | ||
# K:::::K K:::::K L:::::L E:::::E V:::::V V:::::V E:::::E R::::R R:::::R | ||
# K::::::K:::::K L:::::L E::::::EEEEEEEEEE V:::::V V:::::V E::::::EEEEEEEEEE R::::RRRRRR:::::R | ||
# K:::::::::::K L:::::L E:::::::::::::::E V:::::V V:::::V E:::::::::::::::E R:::::::::::::RR | ||
# K:::::::::::K L:::::L E:::::::::::::::E V:::::V V:::::V E:::::::::::::::E R::::RRRRRR:::::R | ||
# K::::::K:::::K L:::::L E::::::EEEEEEEEEE V:::::V V:::::V E::::::EEEEEEEEEE R::::R R:::::R | ||
# K:::::K K:::::K L:::::L E:::::E V:::::V:::::V E:::::E R::::R R:::::R | ||
# KK::::::K K:::::KKK L:::::L LLLLLL E:::::E EEEEEE V:::::::::V E:::::E EEEEEE R::::R R:::::R | ||
# K:::::::K K::::::KLL:::::::LLLLLLLLL:::::LEE::::::EEEEEEEE:::::E V:::::::V EE::::::EEEEEEEE:::::ERR:::::R R:::::R | ||
# K:::::::K K:::::KL::::::::::::::::::::::LE::::::::::::::::::::E V:::::V E::::::::::::::::::::ER::::::R R:::::R | ||
# K:::::::K K:::::KL::::::::::::::::::::::LE::::::::::::::::::::E V:::V E::::::::::::::::::::ER::::::R R:::::R | ||
# KKKKKKKKK KKKKKKKLLLLLLLLLLLLLLLLLLLLLLLLEEEEEEEEEEEEEEEEEEEEEE VVV EEEEEEEEEEEEEEEEEEEEEERRRRRRRR RRRRRRR | ||
|
||
|
||
# LOAD builder info | ||
ifndef VERSION | ||
SHELL := /bin/bash | ||
VERSION := $(shell git describe --always --long --dirty --tag) | ||
endif | ||
ldflags := -X 'main.appVersion=${VERSION}' | ||
|
||
GOCMD=go | ||
GORUN=$(GOCMD) run -ldflags="$(ldflags)" | ||
GOBUILD=$(GOCMD) build -ldflags="$(ldflags)" | ||
|
||
|
||
############################ | ||
### DEMO APP ### | ||
############################ | ||
.PHONY: demo-getAccount demo-transfer demo-createAsset | ||
demo.%: DEMO=$* | ||
demo.%: | ||
$(GORUN) ./cmd/demo/$(DEMO) |
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,77 @@ | ||
package demo | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/klever-io/klever-go-sdk/core/account" | ||
"github.com/klever-io/klever-go-sdk/core/wallet" | ||
"github.com/klever-io/klever-go-sdk/provider" | ||
"github.com/klever-io/klever-go-sdk/provider/network" | ||
"github.com/klever-io/klever-go-sdk/provider/utils" | ||
) | ||
|
||
func InitWallets() ( | ||
accounts []account.Account, | ||
wallets []wallet.Wallet, | ||
kc provider.KleverChain, | ||
err error, | ||
) { | ||
|
||
wallets = make([]wallet.Wallet, 0) | ||
|
||
net := network.NewNetworkConfig(network.TestNet) | ||
httpClient := utils.NewHttpClient(10 * time.Second) | ||
kc, err = provider.NewKleverChain(net, httpClient) | ||
if err != nil { | ||
return | ||
} | ||
|
||
// load account from pemfile | ||
files, err := GetWallets(".", "*.pem") | ||
if err != nil { | ||
return | ||
} | ||
for _, f := range files { | ||
var w wallet.Wallet | ||
w, err = wallet.NewWalletFromPEM(f) | ||
if err != nil { | ||
return | ||
} | ||
wallets = append(wallets, w) | ||
|
||
var acc account.Account | ||
acc, err = w.GetAccount() | ||
if err != nil { | ||
return | ||
} | ||
err = acc.Sync(kc) | ||
|
||
accounts = append(accounts, acc) | ||
} | ||
|
||
return | ||
} | ||
|
||
func GetWallets(root, pattern string) ([]string, error) { | ||
var matches []string | ||
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() { | ||
return nil | ||
} | ||
if matched, err := filepath.Match(pattern, filepath.Base(path)); err != nil { | ||
return err | ||
} else if matched { | ||
matches = append(matches, path) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return matches, nil | ||
} |
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,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/klever-io/klever-go-sdk/cmd/demo" | ||
"github.com/klever-io/klever-go-sdk/models" | ||
) | ||
|
||
func main() { | ||
|
||
accounts, wallets, kc, err := demo.InitWallets() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
base := accounts[0].NewBaseTX() | ||
tx, err := kc.CreateKDA( | ||
base, | ||
models.KDAData_Fungible, | ||
&models.KDAOptions{ | ||
Name: "KleverTest", | ||
Ticker: "TST", | ||
Precision: 4, | ||
MaxSupply: 1000, | ||
InitialSupply: 10, | ||
AddRolesMint: []string{accounts[0].Address().Bech32(), accounts[1].Address().Bech32()}, | ||
Properties: models.PropertiesInfo{ | ||
CanMint: true, CanBurn: true, | ||
}, | ||
URIs: map[string]string{"explorer": "testnet.kleverscan.org"}, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = tx.Sign(wallets[0]) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
hash, err := tx.Broadcast(kc) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println("TxHash: ", hash) | ||
} |
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,33 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/klever-io/klever-go-sdk/cmd/demo" | ||
) | ||
|
||
func main() { | ||
|
||
accounts, wallets, kc, err := demo.InitWallets() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
base := accounts[0].NewBaseTX() | ||
tx, err := kc.Send(base, accounts[1].Address().Bech32(), 1, "") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = tx.Sign(wallets[0]) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
hash, err := tx.Broadcast(kc) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println("TxHash: ", hash) | ||
} |
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
Oops, something went wrong.