Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
siovanus committed Jun 23, 2020
1 parent bbd7eb1 commit a39bda6
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ build/
*.rej
vendor/*
*.iml
ontology-tool
wallet.dat
main
123 changes: 123 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (C) 2018 The ontology Authors
* This file is part of The ontology library.
*
* The ontology is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ontology is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with The ontology. If not, see <http://www.gnu.org/licenses/>.
*/

package common

import (
"encoding/hex"
"encoding/json"
"fmt"
"time"

log4 "github.com/alecthomas/log4go"
"github.com/ontio/ontology-crypto/keypair"
sdk "github.com/ontio/ontology-go-sdk"
scommon "github.com/ontio/ontology/common"
"github.com/ontio/ontology/common/password"
"github.com/ontio/ontology/consensus/vbft"
"github.com/ontio/ontology/consensus/vbft/config"
"github.com/ontio/ontology/core/types"
)

func GetAccountByPassword(sdk *sdk.OntologySdk, path string) (*sdk.Account, bool) {
wallet, err := sdk.OpenWallet(path)
if err != nil {
log4.Error("open wallet error:", err)
return nil, false
}
pwd, err := password.GetPassword()
if err != nil {
log4.Error("getPassword error:", err)
return nil, false
}
user, err := wallet.GetDefaultAccount(pwd)
if err != nil {
log4.Error("getDefaultAccount error:", err)
return nil, false
}
return user, true
}

func InvokeNativeContractWithMultiSign(
sdk *sdk.OntologySdk,
gasPrice,
gasLimit uint64,
pubKeys []keypair.PublicKey,
singers []*sdk.Account,
cversion byte,
contractAddress scommon.Address,
method string,
params []interface{},
) (scommon.Uint256, error) {
tx, err := sdk.Native.NewNativeInvokeTransaction(gasPrice, gasLimit, cversion, contractAddress, method, params)
if err != nil {
return scommon.UINT256_EMPTY, err
}
for _, singer := range singers {
err = sdk.MultiSignToTransaction(tx, uint16((5*len(pubKeys)+6)/7), pubKeys, singer)
if err != nil {
return scommon.UINT256_EMPTY, err
}
}
return sdk.SendTransaction(tx)
}

func WaitForBlock(sdk *sdk.OntologySdk) bool {
_, err := sdk.WaitForGenerateBlock(30*time.Second, 1)
if err != nil {
log4.Error("WaitForGenerateBlock error:", err)
return false
}
return true
}

func ConcatKey(args ...[]byte) []byte {
temp := []byte{}
for _, arg := range args {
temp = append(temp, arg...)
}
return temp
}

func InitVbftBlock(block *types.Block) (*vbft.Block, error) {
if block == nil {
return nil, fmt.Errorf("nil block in initVbftBlock")
}

blkInfo := &vconfig.VbftBlockInfo{}
if err := json.Unmarshal(block.Header.ConsensusPayload, blkInfo); err != nil {
return nil, fmt.Errorf("unmarshal blockInfo: %s", err)
}

return &vbft.Block{
Block: block,
Info: blkInfo,
}, nil
}

func GetAddressByHexString(hexString string) (scommon.Address, error) {
contractByte, err := hex.DecodeString(hexString)
if err != nil {
return scommon.Address{}, fmt.Errorf("hex.DecodeString failed %v", err)
}
contractAddress, err := scommon.AddressParseFromBytes(scommon.ToArrayReverse(contractByte))
if err != nil {
return scommon.Address{}, fmt.Errorf("common.AddressParseFromBytes failed %v", err)
}
return contractAddress, nil
}
6 changes: 3 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"JsonRpcAddress":"http://localhost:20336",
"JsonRpcAddress":"http://polaris1.ont.io:20336",
"WalletPath": "wallet.dat",
"PeerPublicKey": "02d500543eaa4110b8d5f8df4fabe31a8caabaa58cb8512baa8af15a303606efe4",
"InitPos":100000,
"GasPrice":0,
"InitPos":10000,
"GasPrice":500,
"GasLimit":20000
}
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/ontio/triones-node-tool

go 1.14

require (
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/alecthomas/log4go v0.0.0-20180109082532-d146e6b86faa
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/ontio/ontology v1.10.0
github.com/ontio/ontology-crypto v1.0.9
github.com/ontio/ontology-go-sdk v1.11.1
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect
)
Loading

0 comments on commit a39bda6

Please sign in to comment.