本文整理匯總了Golang中github.com/eris-ltd/eris-logger.WithField函數的典型用法代碼示例。如果您正苦於以下問題:Golang WithField函數的具體用法?Golang WithField怎麽用?Golang WithField使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WithField函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetAccountJob
func SetAccountJob(account *definitions.Account, do *definitions.Do) (string, error) {
var result string
var err error
// Preprocess
account.Address, _ = util.PreProcess(account.Address, do)
// Set the Account in the Package & Announce
do.Package.Account = account.Address
log.WithField("=>", do.Package.Account).Info("Setting Account")
// Set the public key from eris-keys
keys.DaemonAddr = do.Signer
log.WithField("from", keys.DaemonAddr).Info("Getting Public Key")
do.PublicKey, err = keys.Call("pub", map[string]string{"addr": do.Package.Account, "name": ""})
if _, ok := err.(keys.ErrConnectionRefused); ok {
keys.ExitConnectErr(err)
}
if err != nil {
return util.KeysErrorHandler(do, err)
}
// Set result and return
result = account.Address
return result, nil
}
示例2: assembleTypesWizard
func assembleTypesWizard(accountT *definitions.AccountType, tokenIze bool) error {
var err error
accountT.Number, err = common.GetIntResponse(AccountTypeIntro(accountT), accountT.Number, reader)
log.WithField("=>", accountT.Number).Debug("What the marmots heard")
if err != nil {
return err
}
if tokenIze && accountT.Number > 0 {
accountT.Tokens, err = common.GetIntResponse(AccountTypeTokens(accountT), accountT.Tokens, reader)
log.WithField("=>", accountT.Tokens).Debug("What the marmots heard")
if err != nil {
return err
}
}
if accountT.Perms["bond"] == 1 && accountT.Number > 0 {
accountT.ToBond, err = common.GetIntResponse(AccountTypeToBond(accountT), accountT.ToBond, reader)
log.WithField("=>", accountT.ToBond).Debug("What the marmots heard")
if err != nil {
return err
}
} else {
log.Info("Setting accountType.ToBond to 0")
log.WithField("=>", accountT.Name).Debug("No bond permissions")
accountT.ToBond = 0
}
return nil
}
示例3: CheckDefaultTypes
// ensures that the files which are included in this repository (`defaultTyps`) are also
// present in the user's .eris/chains/account_types directory.
//
// does not ensure that the contents of the files are the same so will not affect user
// defined settings around these files.
//
// does not check if the user has more account_types files in their .eris/chains/account_types
// directory either so users can safely add additional account_types beyond the marmot
// established defaults.
func CheckDefaultTypes(erisPath, myPath string) error {
// by default the dockerimage will move the default files to /default
// however if anyone installs by binary then these files will be located
// in the repo.
defaultTypsPath := filepath.Join("/defaults", myPath, "*.toml")
if _, err := os.Stat(filepath.Dir(defaultTypsPath)); os.IsNotExist(err) {
log.WithField("path", defaultTypsPath).Warn("Default types path does not exist. Trying GOPATH.")
defaultTypsPath = filepath.Join(ErisGo, version.NAME, myPath, "*.toml")
}
if _, err := os.Stat(filepath.Dir(defaultTypsPath)); os.IsNotExist(err) {
log.WithField("path", defaultTypsPath).Info("Default types path does not exist. Exiting.")
return fmt.Errorf("Could not locate default directory for %s", myPath)
}
// files in the default location which is /defaults in the docker image and $GOPATH/src/github.com/.../
// if binary install
defaultTyps, err := filepath.Glob(defaultTypsPath)
if err != nil {
return err
}
// these are files which are in ~/.eris/chains/XXXXX and imported to the data container
// by cli
haveTyps, err := AccountTypesNames(erisPath, true)
if err != nil {
return err
}
// fail fast if there are not files present in either imported or in default directory
if len(defaultTyps) == 0 && len(haveTyps) == 0 {
return fmt.Errorf("There are no default or custom types to use.")
}
for _, file := range defaultTyps {
f := filepath.Base(file)
itsThere := false
// check if present
for _, b := range haveTyps {
if f == b {
itsThere = true
}
}
if !itsThere {
log.WithFields(log.Fields{
"file": file,
"path": filepath.Join(erisPath, f),
}).Debug("Copying default file")
Copy(file, filepath.Join(erisPath, f))
}
}
return nil
}
示例4: replaceBlockVariable
func replaceBlockVariable(toReplace string, do *definitions.Do) (string, error) {
log.WithFields(log.Fields{
"chain": do.Chain,
"var": toReplace,
}).Debug("Correcting $block variable")
blockHeight, err := GetBlockHeight(do)
block := strconv.Itoa(blockHeight)
log.WithField("=>", block).Debug("Current height is")
if err != nil {
return "", err
}
if toReplace == "$block" {
log.WithField("=>", block).Debug("Replacement (=)")
return block, nil
}
catchEr := regexp.MustCompile("\\$block\\+(\\d*)")
if catchEr.MatchString(toReplace) {
height := catchEr.FindStringSubmatch(toReplace)[1]
h1, err := strconv.Atoi(height)
if err != nil {
return "", err
}
h2, err := strconv.Atoi(block)
if err != nil {
return "", err
}
height = strconv.Itoa(h1 + h2)
log.WithField("=>", height).Debug("Replacement (+)")
return height, nil
}
catchEr = regexp.MustCompile("\\$block\\-(\\d*)")
if catchEr.MatchString(toReplace) {
height := catchEr.FindStringSubmatch(toReplace)[1]
h1, err := strconv.Atoi(height)
if err != nil {
return "", err
}
h2, err := strconv.Atoi(block)
if err != nil {
return "", err
}
height = strconv.Itoa(h1 - h2)
log.WithField("=>", height).Debug("Replacement (-)")
return height, nil
}
log.WithField("=>", toReplace).Debug("Replacement (unknown)")
return toReplace, nil
}
示例5: MakeAccounts
func MakeAccounts(name, chainType string, accountTypes []*definitions.AccountType) ([]*definitions.Account, error) {
accounts := []*definitions.Account{}
for _, accountT := range accountTypes {
log.WithField("type", accountT.Name).Info("Making Account Type")
perms := &definitions.MintAccountPermissions{}
var err error
if chainType == "mint" {
perms, err = MintAccountPermissions(accountT.Perms, []string{}) // TODO: expose roles
if err != nil {
return nil, err
}
}
for i := 0; i < accountT.Number; i++ {
thisAct := &definitions.Account{}
thisAct.Name = fmt.Sprintf("%s_%s_%03d", name, accountT.Name, i)
thisAct.Name = strings.ToLower(thisAct.Name)
log.WithField("name", thisAct.Name).Debug("Making Account")
thisAct.Tokens = accountT.Tokens
thisAct.ToBond = accountT.ToBond
thisAct.PermissionsMap = accountT.Perms
thisAct.Validator = false
if thisAct.ToBond != 0 {
thisAct.Validator = true
}
if chainType == "mint" {
thisAct.MintPermissions = &definitions.MintAccountPermissions{}
thisAct.MintPermissions.MintBase = &definitions.MintBasePermissions{}
thisAct.MintPermissions.MintBase.MintPerms = perms.MintBase.MintPerms
thisAct.MintPermissions.MintBase.MintSetBit = perms.MintBase.MintSetBit
thisAct.MintPermissions.MintRoles = perms.MintRoles
log.WithField("perms", thisAct.MintPermissions.MintBase.MintPerms).Debug()
if err := makeKey("ed25519,ripemd160", thisAct); err != nil {
return nil, err
}
}
accounts = append(accounts, thisAct)
}
}
return accounts, nil
}
示例6: makeKey
func makeKey(keyType string, account *definitions.Account) error {
log.WithFields(log.Fields{
"path": keys.DaemonAddr,
"type": keyType,
}).Debug("Sending Call to eris-keys server")
var err error
log.WithField("endpoint", "gen").Debug()
account.Address, err = keys.Call("gen", map[string]string{"auth": "", "type": keyType, "name": account.Name}) // note, for now we use not password to lock/unlock keys
if _, ok := err.(keys.ErrConnectionRefused); ok {
return fmt.Errorf("Could not connect to eris-keys server. Start it with `eris services start keys`. Error: %v", err)
}
if err != nil {
return err
}
log.WithField("endpoint", "pub").Debug()
account.PubKey, err = keys.Call("pub", map[string]string{"addr": account.Address, "name": account.Name})
if _, ok := err.(keys.ErrConnectionRefused); ok {
return fmt.Errorf("Could not connect to eris-keys server. Start it with `eris services start keys`. Error: %v", err)
}
if err != nil {
return err
}
// log.WithField("endpoint", "to-mint").Debug()
// mint, err := keys.Call("to-mint", map[string]string{"addr": account.Address, "name": account.Name})
log.WithField("endpoint", "mint").Debug()
mint, err := keys.Call("mint", map[string]string{"addr": account.Address, "name": account.Name})
if _, ok := err.(keys.ErrConnectionRefused); ok {
return fmt.Errorf("Could not connect to eris-keys server. Start it with `eris services start keys`. Error: %v", err)
}
if err != nil {
return err
}
account.MintKey = &definitions.MintPrivValidator{}
err = json.Unmarshal([]byte(mint), account.MintKey)
if err != nil {
log.Error(string(mint))
log.Error(account.MintKey)
return err
}
account.MintKey.Address = account.Address
return nil
}
示例7: WriteConfigurationFile
func WriteConfigurationFile(chain_name, account_name, seeds string, single bool,
chainImageName string, useDataContainer bool, exportedPorts []string, containerEntrypoint string) error {
if account_name == "" {
account_name = "anonymous_marmot"
}
if chain_name == "" {
return fmt.Errorf("No chain name provided.")
}
var fileBytes []byte
var err error
if fileBytes, err = configuration.GetConfigurationFileBytes(chain_name,
account_name, seeds, chainImageName, useDataContainer,
convertExportPortsSliceToString(exportedPorts), containerEntrypoint); err != nil {
return err
}
var file string
if !single {
file = filepath.Join(ChainsPath, chain_name, account_name, "config.toml")
} else {
file = filepath.Join(ChainsPath, chain_name, "config.toml")
}
log.WithField("path", file).Debug("Saving File.")
if err := WriteFile(string(fileBytes), file); err != nil {
return err
}
return nil
}
示例8: SetValJob
func SetValJob(set *definitions.Set, do *definitions.Do) (string, error) {
var result string
set.Value, _ = util.PreProcess(set.Value, do)
log.WithField("=>", set.Value).Info("Setting Variable")
result = set.Value
return result, nil
}
示例9: makeWizard
func makeWizard(do *definitions.Do) error {
proceed, err := common.GetBoolResponse(ChainsMakeWelcome(), true, os.Stdin)
log.WithField("=>", proceed).Debug("What the marmots heard")
if err != nil {
return err
}
if !proceed {
log.Warn("The marmots will not proceed without your authorization. Exiting.")
return nil
}
prelims := make(map[string]bool)
for e, q := range ChainsMakePrelimQuestions() {
prelims[e], err = common.GetBoolResponse(q, false, os.Stdin)
log.WithField("=>", prelims[e]).Debug("What the marmots heard")
if err != nil {
return err
}
}
accountTypes, err := LoadAccountTypes()
if err != nil {
return err
}
for _, accountT := range accountTypes {
if err := assembleTypesWizard(accountT, prelims["tokens"]); err != nil {
return err
}
}
if prelims["dryrun"] {
// todo check if procede or return....
}
if prelims["manual"] {
var err error
accountTypes, err = addManualAccountType(accountTypes, 0)
if err != nil {
return err
}
}
return maker(do, "mint", accountTypes)
}
示例10: assembleTypesCSV
func assembleTypesCSV(accountT []*definitions.AccountType, do *definitions.Do) error {
clearDefaultNumbers(accountT)
csvfile, err := os.Open(do.CSV)
if err != nil {
return err
}
defer csvfile.Close()
reader := csv.NewReader(csvfile)
reader.TrimLeadingSpace = true
rawCSVdata, err := reader.ReadAll()
if err != nil {
return err
}
log.WithField("rawCSVdata", rawCSVdata).Debug("Data read.")
for _, record := range rawCSVdata {
act, num, tokens, toBond, perms := record[0], record[1], record[2], record[3], record[4:]
for _, thisActT := range accountT {
if thisActT.Name == act {
var err error
thisActT.Number, err = strconv.Atoi(num)
if err != nil {
return err
}
thisActT.Tokens, err = strconv.Atoi(tokens)
if err != nil {
return err
}
thisActT.ToBond, err = strconv.Atoi(toBond)
if err != nil {
return err
}
permsPrime := make(map[string]int)
for i := 0; i < len(perms); i++ {
p, err := strconv.Atoi(perms[i+1])
if err != nil {
return err
}
permsPrime[perms[i]] = p
i++
}
thisActT.Perms = permsPrime
log.WithFields(log.Fields{
"name": thisActT.Name,
"number": thisActT.Number,
"tokens": thisActT.Tokens,
"toBond": thisActT.ToBond,
"perms": thisActT.Perms,
}).Debug("Setting Account Type Number")
}
}
}
return nil
}
示例11: PermissionJob
func PermissionJob(perm *definitions.Permission, do *definitions.Do) (string, error) {
// Process Variables
perm.Source, _ = util.PreProcess(perm.Source, do)
perm.Action, _ = util.PreProcess(perm.Action, do)
perm.PermissionFlag, _ = util.PreProcess(perm.PermissionFlag, do)
perm.Value, _ = util.PreProcess(perm.Value, do)
perm.Target, _ = util.PreProcess(perm.Target, do)
perm.Role, _ = util.PreProcess(perm.Role, do)
// Set defaults
perm.Source = useDefault(perm.Source, do.Package.Account)
log.Debug("Target: ", perm.Target)
log.Debug("Marmots Deny: ", perm.Role)
log.Debug("Action: ", perm.Action)
// Populate the transaction appropriately
var args []string
switch perm.Action {
case "set_global":
args = []string{perm.PermissionFlag, perm.Value}
case "set_base":
args = []string{perm.Target, perm.PermissionFlag, perm.Value}
case "unset_base":
args = []string{perm.Target, perm.PermissionFlag}
case "add_role", "rm_role":
args = []string{perm.Target, perm.Role}
}
// Don't use pubKey if account override
var oldKey string
if perm.Source != do.Package.Account {
oldKey = do.PublicKey
do.PublicKey = ""
}
// Formulate tx
arg := fmt.Sprintf("%s:%s", args[0], args[1])
log.WithField(perm.Action, arg).Info("Setting Permissions")
erisNodeClient := client.NewErisNodeClient(do.Chain)
erisKeyClient := keys.NewErisKeyClient(do.Signer)
tx, err := core.Permissions(erisNodeClient, erisKeyClient, do.PublicKey, perm.Source, perm.Nonce, perm.Action, args)
if err != nil {
return util.MintChainErrorHandler(do, err)
}
log.Debug("What are the args returned in transaction: ", tx.PermArgs)
// Don't use pubKey if account override
if perm.Source != do.Package.Account {
do.PublicKey = oldKey
}
// Sign, broadcast, display
return txFinalize(do, tx, perm.Wait)
}
示例12: ReadAndDecodeContractReturn
func ReadAndDecodeContractReturn(abiLocation, funcName string, resultRaw []byte, do *definitions.Do) ([]*definitions.Variable, error) {
abiSpecBytes, err := readAbi(do.ABIPath, abiLocation)
if err != nil {
return nil, err
}
log.WithField("=>", abiSpecBytes).Debug("ABI Specification (Decode)")
// Unpack the result
return ebi.Unpacker(abiSpecBytes, funcName, resultRaw)
}
示例13: QueryValsJob
func QueryValsJob(query *definitions.QueryVals, do *definitions.Do) (string, error) {
var result string
// Preprocess variables
query.Field, _ = util.PreProcess(query.Field, do)
// Peform query
log.WithField("=>", query.Field).Info("Querying Vals")
result, err := util.ValidatorsInfo(query.Field, do)
if err != nil {
return "", err
}
if result != "" {
log.WithField("=>", result).Warn("Return Value")
} else {
log.Debug("No return.")
}
return result, nil
}
示例14: ReadTxSignAndBroadcast
// This is a closer function which is called by most of the tx_run functions
func ReadTxSignAndBroadcast(result *core.TxResult, err error) error {
// if there's an error just return.
if err != nil {
return err
}
// if there is nothing to unpack then just return.
if result == nil {
return nil
}
// Unpack and display for the user.
addr := fmt.Sprintf("%X", result.Address)
hash := fmt.Sprintf("%X", result.Hash)
blkHash := fmt.Sprintf("%X", result.BlockHash)
ret := fmt.Sprintf("%X", result.Return)
if result.Address != nil {
log.WithField("addr", addr).Warn()
log.WithField("txHash", hash).Info()
} else {
log.WithField("=>", hash).Warn("Transaction Hash")
log.WithField("=>", blkHash).Debug("Block Hash")
if len(result.Return) != 0 {
if ret != "" {
log.WithField("=>", ret).Warn("Return Value")
} else {
log.Debug("No return.")
}
log.WithField("=>", result.Exception).Debug("Exception")
}
}
return nil
}
示例15: ReadAbiFormulateCall
func ReadAbiFormulateCall(abiLocation string, funcName string, args []string, do *definitions.Do) ([]byte, error) {
abiSpecBytes, err := readAbi(do.ABIPath, abiLocation)
if err != nil {
return []byte{}, err
}
log.WithField("=>", string(abiSpecBytes)).Debug("ABI Specification (Formulate)")
log.WithFields(log.Fields{
"function": funcName,
"arguments": fmt.Sprintf("%v", args),
}).Debug("Packing Call via ABI")
return ebi.Packer(abiSpecBytes, funcName, args...)
}