-
Notifications
You must be signed in to change notification settings - Fork 13
/
frombitcoin.go
54 lines (42 loc) · 1.14 KB
/
frombitcoin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package litecoin
import (
"crypto/sha256"
"github.com/bitmark-inc/bitmarkd/currency/bitcoin"
"github.com/bitmark-inc/bitmarkd/fault"
"github.com/bitmark-inc/bitmarkd/util"
)
// FromBitcoin - check the address and return its version
func FromBitcoin(address string) (string, error) {
version, addressBytes, err := bitcoin.ValidateAddress(address)
if err != nil {
return "", err
}
ltcVersion := vNull
switch version {
case bitcoin.Livenet:
ltcVersion = Livenet
case bitcoin.LivenetScript:
ltcVersion = LivenetScript
// case bitcoin.LivenetScript2:
// ltcVersion = LivenetScript2
case bitcoin.Testnet:
ltcVersion = Testnet
case bitcoin.TestnetScript:
ltcVersion = TestnetScript
default:
return "", fault.InvalidBitcoinAddress
}
ltc := append([]byte{byte(ltcVersion)}, addressBytes[:]...)
h := sha256.New()
h.Write(ltc)
d := h.Sum([]byte{})
h = sha256.New()
h.Write(d)
d = h.Sum([]byte{})
ltc = append(ltc, d[0:4]...)
return util.ToBase58(ltc), nil
}