OSDN Git Service

rename (#465)
[bytom/vapor.git] / toolbar / federation / common / util.go
1 package common
2
3 import (
4         "encoding/hex"
5
6         log "github.com/sirupsen/logrus"
7
8         "github.com/bytom/vapor/consensus"
9         "github.com/bytom/vapor/consensus/segwit"
10         "github.com/bytom/vapor/wallet"
11 )
12
13 func ProgToAddress(prog []byte, netParams *consensus.Params) string {
14         hash, err := segwit.GetHashFromStandardProg(prog)
15         if err != nil {
16                 log.WithFields(log.Fields{"prog": hex.EncodeToString(prog), "err": err}).Warn("fail on GetHashFromStandardProg")
17                 return ""
18         }
19
20         if segwit.IsP2WPKHScript(prog) {
21                 return wallet.BuildP2PKHAddress(hash, netParams)
22         } else if segwit.IsP2WSHScript(prog) {
23                 return wallet.BuildP2SHAddress(hash, netParams)
24         }
25         return ""
26 }