github.com/quantosnetwork/Quantos@v0.0.0-20220306172517-e20b28c5a29a/sdk/addresses.go (about)

     1  package sdk
     2  
     3  import (
     4  	"github.com/holiman/uint256"
     5  	"github.com/quantosnetwork/Quantos/sdk/config"
     6  	"github.com/quantosnetwork/Quantos/uint512"
     7  	"math/big"
     8  )
     9  
    10  type AddressSDK interface {
    11  	InitSDK(netID string)
    12  	GenerateMasterWalletAddress() (*uint512.Address, string)
    13  	VerifyAddress(in string, out bool)
    14  	IsZeroAddress(in string, out bool)
    15  	GenerateTXAddress(in InputData, out OutputData)
    16  	GenerateBlockAddress(in InputData, out OutputData)
    17  	GetZeroAddress() string
    18  	DeriveFromMaster(master *uint512.Address, derivationPath string) string
    19  }
    20  
    21  type InputData struct {
    22  	data interface{}
    23  }
    24  
    25  type OutputData struct {
    26  	data string
    27  }
    28  
    29  type addrFunctions struct{}
    30  
    31  func (a addrFunctions) IsZeroAddress(in string, out bool) {
    32  	//TODO implement me
    33  	panic("implement me")
    34  }
    35  
    36  func (a addrFunctions) GenerateTXAddress(in InputData, out OutputData) {
    37  	//TODO implement me
    38  	panic("implement me")
    39  }
    40  
    41  func (a addrFunctions) GenerateBlockAddress(in InputData, out OutputData) {
    42  	//TODO implement me
    43  	panic("implement me")
    44  }
    45  
    46  var CurrentNetworkID config.NetworkID
    47  
    48  func (a addrFunctions) GenerateMasterWalletAddress() (*uint512.Address, string) {
    49  
    50  	addr := &uint512.Address{}
    51  	am := addr.Raw.Create()
    52  	m := am.Master()
    53  	masterBig := new(big.Int).SetBytes(m)
    54  	out1, _ := uint256.FromBig(masterBig)
    55  	out := out1.String()
    56  
    57  	return am, out
    58  }
    59  
    60  func (a addrFunctions) DeriveFromMaster(master *uint512.Address, derivationPath string) string {
    61  	return master.Derive()
    62  }
    63  
    64  func (a addrFunctions) InitSDK(netID string) {
    65  	switch netID {
    66  	case "live":
    67  
    68  		CurrentNetworkID = config.LIVENET
    69  		return
    70  	case "test":
    71  		CurrentNetworkID = config.TESTNET
    72  		return
    73  	case "local":
    74  		CurrentNetworkID = config.LOCALNET
    75  		return
    76  	}
    77  	return
    78  }
    79  
    80  func initZeroAddress() {
    81  
    82  }
    83  
    84  func (a addrFunctions) VerifyAddress(in string, out bool) {
    85  
    86  }
    87  
    88  func (a addrFunctions) GetZeroAddress() string {
    89  	return config.ZEROADDRESS
    90  }
    91  
    92  func GetAddressSDK() AddressSDK {
    93  	var a addrFunctions
    94  	return a
    95  }