gitlab.com/jokerrs1/Sia@v1.3.2/node/api/scan.go (about)

     1  package api
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"errors"
     7  	"github.com/NebulousLabs/Sia/crypto"
     8  	"github.com/NebulousLabs/Sia/types"
     9  )
    10  
    11  // scanAmount scans a types.Currency from a string.
    12  func scanAmount(amount string) (types.Currency, bool) {
    13  	// use SetString manually to ensure that amount does not contain
    14  	// multiple values, which would confuse fmt.Scan
    15  	i, ok := new(big.Int).SetString(amount, 10)
    16  	if !ok {
    17  		return types.Currency{}, ok
    18  	}
    19  	return types.NewCurrency(i), true
    20  }
    21  
    22  // scanAddress scans a types.UnlockHash from a string.
    23  func scanAddress(addrStr string) (addr types.UnlockHash, err error) {
    24  	err = addr.LoadString(addrStr)
    25  	if err != nil {
    26  		return types.UnlockHash{}, err
    27  	}
    28  	return addr, nil
    29  }
    30  
    31  // scanHash scans a crypto.Hash from a string.
    32  func scanHash(s string) (h crypto.Hash, err error) {
    33  	err = h.LoadString(s)
    34  	if err != nil {
    35  		return crypto.Hash{}, err
    36  	}
    37  	return h, nil
    38  }
    39  
    40  // scanBool converts "true" and "false" strings to their respective
    41  // boolean value and returns an error if conversion is not possible.
    42  func scanBool(param string) (bool, error) {
    43  	if param == "true" {
    44  		return true, nil
    45  	} else if param == "false" || len(param) == 0 {
    46  		return false, nil
    47  	}
    48  	return false, errors.New("could not decode boolean: value was not true or false")
    49  }