cardano

package
v3.0.0-...-e8b7a4c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2023 License: GPL-3.0 Imports: 27 Imported by: 0

README

run cardano node

https://developers.cardano.org/docs/get-started/installing-cardano-node/#overview

Graphql

https://github.com/input-output-hk/cardano-graphql

minting native tokenclear

https://docs.cardano.org/native-tokens/getting-started

deploy step

1 chainId
mainnet: 1645027868239
testnet: 1645027868240

2 url
mainnet: https://graphql-api.mainnet.dandelion.link/
testnet: https://graphql-api.testnet.dandelion.link/

3 update protocol.json file in ./txDb/config/protocol.json
cardano-cli query protocol-parameters \
--testnet-magic 1097911063 \
--out-file protocol.json

4 update NetWork fiels in tokens/cardano/cardanoCmd.go
testnet(1.35.2): --testnet-magic 1097911063
testnet(1.35.3): --testnet-magic 1
mainnet:	 --mainnet

5 get mpc publickKey and write a json file with publicKey to build a payment address
cardano-cli address build --payment-verification-key-file mpc.vkey --out-file mpc.addr --testnet-magic 1097911063

mpc.vkey:
{
    "type": "PaymentVerificationKeyShelley_ed25519",
    "description": "Payment Verification Key",
    "cborHex": "5820[mpc publicKey]"
}

6 mint native token
	need register metadata to repo: https://github.com/cardano-foundation/cardano-token-registry

	6.1 create policy.script(cp script file to ./txDb/policy)

	touch policy/policy.script && echo "{" > policy/policy.script 
	echo "  \"keyHash\": \"$(cardano-cli address key-hash --payment-verification-key-file mpc.vkey)\"," >> policy/policy.script 
	echo "  \"type\": \"sig\"" >> policy/policy.script 
	echo "}" >> policy/policy.script

	cat policy/policy.script
	res: 
	{
  		"keyHash": "b930621762bcb49f2735540974d5703d55729582eb31b9036c04ad24",
  		"type": "sig"
	}

	6.2 create policyId(update policyId field in ./tokens/cardano/cardanoCmd.gon)

	cardano-cli transaction policyid --script-file ./policy/policy.script 
	res: 8c7d04a9146bff45aadc19d3f3e4cdb8a989ff35182989dbfb93f5b4

	6.3 create assetNameId

	echo -n "tokenName" | xxd -ps
	res: 746f6b656e4e616d65

7 set config contract
	7.1 routerAddress is mpc address
	7.2 tokenAddress is policyId.assetName if token not ADA
	    tokenAddress is lovelace if token is ADA

Documentation

Index

Constants

View Source
const (
	CardanoMainNet = "https://cardano-mainnet.blockfrost.io/api/v0"
	CardanoTestNet = "https://cardano-testnet.blockfrost.io/api/v0"
	CardanoPreProd = "https://cardano-preprod.blockfrost.io/api/v0"
	CardanoPreview = "https://cardano-preview.blockfrost.io/api/v0"
	IPFSNet        = "https://ipfs.blockfrost.io/api/v0"
)
View Source
const (
	MetadataKey       = "123"
	SwapInMetadataKey = "223"
)
View Source
const (
	AdaAsset = "lovelace"
)

Variables

View Source
var (
	FixAdaAmount     = big.NewInt(1500000)
	DefaultAdaAmount = big.NewInt(2000000)
	QueryTransaction = "" /* 259-byte string literal not displayed */
	QueryOutputs     = "{utxos(where: { address: { _eq: \"%s\"}}) {txHash index tokens {asset {policyId assetName} quantity} value}}"

	QueryTIPAndProtocolParams = "" /* 193-byte string literal not displayed */

	TransactionChaining         = &TransactionChainingMap{InputKey: UtxoKey{}, AssetsMap: make(map[string]string)}
	TransactionChainingKeyCache = &TransactionChainingKey{SpentUtxoMap: make(map[UtxoKey]bool), SpentUtxoListGropByTxHash: make(map[string]*[]UtxoKey)}
)

Functions

func AddTransactionChainingKeyCache

func AddTransactionChainingKeyCache(txhash string, txIns *[]UtxoKey)

func ClearTransactionChainingKeyCache

func ClearTransactionChainingKeyCache(txhash string)

func GetStubChainID

func GetStubChainID(network string) *big.Int

GetStubChainID get stub chainID

func GetUtxosByAddress

func GetUtxosByAddress(url, address string) (*[]Output, error)

func NewNode

func NewNode(network cardanosdk.Network, networkUrl string, projectID string) cardanosdk.Node

NewNode returns a new instance of BlockfrostNode.

func StringToPrivateKey

func StringToPrivateKey(priv string) (*ed25519.PrivateKey, error)

func SupportsChainID

func SupportsChainID(chainID *big.Int) bool

SupportsChainID supports chainID

Types

type Asset

type Asset struct {
	PolicyId  string `json:"policyId"`
	AssetName string `json:"assetName"`
}

type AssetsMap

type AssetsMap map[string]string

type Block

type Block struct {
	EpochNo uint64 `json:"epochNo"`
	Number  uint64 `json:"number"`
	SlotNo  uint64 `json:"slotNo"`
}

type BlockfrostNode

type BlockfrostNode struct {
	// contains filtered or unexported fields
}

BlockfrostNode implements Node using the blockfrost API.

func (*BlockfrostNode) GetTransactionByHash

func (b *BlockfrostNode) GetTransactionByHash(txHash string) (*blockfrost.TransactionContent, error)

func (*BlockfrostNode) GetTransactionMetadataByHash

func (b *BlockfrostNode) GetTransactionMetadataByHash(txHash string) (*[]blockfrost.TransactionMetadata, error)

func (*BlockfrostNode) GetTransactionUtxoByHash

func (b *BlockfrostNode) GetTransactionUtxoByHash(txHash string) (*blockfrost.TransactionUTXOs, error)

func (*BlockfrostNode) Network

func (b *BlockfrostNode) Network() cardanosdk.Network

func (*BlockfrostNode) ProtocolParams

func (b *BlockfrostNode) ProtocolParams() (*cardanosdk.ProtocolParams, error)

func (*BlockfrostNode) SubmitTx

func (b *BlockfrostNode) SubmitTx(tx *cardanosdk.Tx) (*cardanosdk.Hash32, error)

func (*BlockfrostNode) Tip

func (b *BlockfrostNode) Tip() (*cardanosdk.NodeTip, error)

func (*BlockfrostNode) UTxOs

func (b *BlockfrostNode) UTxOs(addr cardanosdk.Address) ([]cardanosdk.UTxO, error)

type Bridge

type Bridge struct {
	*tokens.CrossChainBridgeBase
	*base.ReSwapableBridgeBase
	RpcClient      cardanosdk.Node
	FakePrikey     crypto.PrvKey
	ProtocolParams *cardanosdk.ProtocolParams
}

Bridge block bridge inherit from btc bridge

func NewCrossChainBridge

func NewCrossChainBridge() *Bridge

NewCrossChainBridge new bridge

func (*Bridge) AggregateTx

func (b *Bridge) AggregateTx() (txHash string, err error)

func (*Bridge) AppendSignature

func (b *Bridge) AppendSignature(tx *cardanosdk.Tx, pubKey crypto.PubKey, signature []byte)

func (*Bridge) BuildAggregateTx

func (b *Bridge) BuildAggregateTx(swapId string, utxos map[UtxoKey]AssetsMap) (*RawTransaction, error)

func (*Bridge) BuildRawTransaction

func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)

BuildRawTransaction build raw tx

func (*Bridge) BuildTx

func (b *Bridge) BuildTx(swapId, receiver, assetId string, amount *big.Int, utxos map[UtxoKey]AssetsMap) (*RawTransaction, error)

func (*Bridge) CreateRawTx

func (b *Bridge) CreateRawTx(rawTransaction *RawTransaction, mpcAddr string) (*cardanosdk.Tx, error)

func (*Bridge) CreateSwapoutRawTx

func (b *Bridge) CreateSwapoutRawTx(rawTransaction *RawTransaction, mpcAddr, bind, toChainId string) (*cardanosdk.Tx, error)

func (*Bridge) GetAssetPolicy

func (b *Bridge) GetAssetPolicy(name string) (crypto.XPrvKey, cardanosdk.NativeScript, cardanosdk.PolicyID)

func (*Bridge) GetCurrentThreshold

func (b *Bridge) GetCurrentThreshold() (*uint64, error)

func (*Bridge) GetLatestBlockNumber

func (b *Bridge) GetLatestBlockNumber() (num uint64, err error)

GetLatestBlockNumber gets latest block number

func (*Bridge) GetLatestBlockNumberOf

func (b *Bridge) GetLatestBlockNumberOf(url string) (num uint64, err error)

GetLatestBlockNumberOf gets latest block number from single api

func (*Bridge) GetTip

func (b *Bridge) GetTip() (tip *cardanosdk.NodeTip, err error)

func (*Bridge) GetTransaction

func (b *Bridge) GetTransaction(txHash string) (tx interface{}, err error)

GetTransaction impl

func (*Bridge) GetTransactionByHash

func (b *Bridge) GetTransactionByHash(txHash string) (*Transaction, error)

GetTransactionByHash call eth_getTransactionByHash

func (*Bridge) GetTransactionChainingMap

func (b *Bridge) GetTransactionChainingMap(assetName string, amount *big.Int) (map[UtxoKey]AssetsMap, error)

func (*Bridge) GetTransactionStatus

func (b *Bridge) GetTransactionStatus(txHash string) (status *tokens.TxStatus, err error)

GetTransactionStatus impl

func (*Bridge) GetUtxosByAddress

func (b *Bridge) GetUtxosByAddress(address string) (*[]Output, error)

GetTransactionByHash call eth_getTransactionByHash

func (*Bridge) InitAfterConfig

func (b *Bridge) InitAfterConfig()

InitAfterConfig init variables (ie. extra members) after loading config

func (*Bridge) InitRouterInfo

func (b *Bridge) InitRouterInfo(routerContract, routerVersion string) (err error)

InitRouterInfo init router info

func (*Bridge) IsValidAddress

func (b *Bridge) IsValidAddress(addr string) bool

IsValidAddress check address

func (*Bridge) MPCSignSwapTransaction

func (b *Bridge) MPCSignSwapTransaction(rawTx interface{}, args *tokens.BuildTxArgs, bind, toChainId string) (signTx interface{}, txHash string, err error)

func (*Bridge) MPCSignTransaction

func (b *Bridge) MPCSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signTx interface{}, txHash string, err error)

MPCSignTransaction mpc sign raw tx

func (*Bridge) PublicKeyToAddress

func (b *Bridge) PublicKeyToAddress(pubKeyHex string) (string, error)

PublicKeyToAddress impl

func (*Bridge) QueryUtxo

func (b *Bridge) QueryUtxo(address, assetName string, amount *big.Int) (map[UtxoKey]AssetsMap, error)

func (*Bridge) QueryUtxoByAPI

func (b *Bridge) QueryUtxoByAPI(address string) (map[UtxoKey]AssetsMap, error)

func (*Bridge) QueryUtxoByGQL

func (b *Bridge) QueryUtxoByGQL(address string) (map[UtxoKey]AssetsMap, error)

func (*Bridge) QueryUtxoOnChain

func (b *Bridge) QueryUtxoOnChain(address string) (map[UtxoKey]AssetsMap, error)

func (*Bridge) QueryUtxoOnChainByAsset

func (b *Bridge) QueryUtxoOnChainByAsset(address string, asset string) (map[UtxoKey]AssetsMap, error)

func (*Bridge) RegisterSwap

func (b *Bridge) RegisterSwap(txHash string, args *tokens.RegisterArgs) ([]*tokens.SwapTxInfo, []error)

RegisterSwap api

func (*Bridge) SendTransaction

func (b *Bridge) SendTransaction(signedTx interface{}) (string, error)

SendTransaction send signed tx

func (*Bridge) SetTokenConfig

func (b *Bridge) SetTokenConfig(tokenAddr string, tokenCfg *tokens.TokenConfig)

SetTokenConfig set token config

func (*Bridge) SignAggregateTx

func (b *Bridge) SignAggregateTx(swapId string, rawTx interface{}) (string, error)

func (*Bridge) SignTransactionWithPrivateKey

func (b *Bridge) SignTransactionWithPrivateKey(tx *cardanosdk.Tx, rawTransaction *RawTransaction, args *tokens.BuildTxArgs, privKey string) (*SignedTransaction, string, error)

SignTransactionWithPrivateKey sign tx with ECDSA private key

func (*Bridge) VerifyAggregate

func (b *Bridge) VerifyAggregate(msgHash []string, args *tokens.BuildTxArgs) error

func (*Bridge) VerifyMPCPubKey

func (b *Bridge) VerifyMPCPubKey(mpcAddress, mpcPubkey string) error

VerifyMPCPubKey verify mpc address and public key is matching

func (*Bridge) VerifyMsgHash

func (b *Bridge) VerifyMsgHash(rawTx interface{}, msgHashes []string) (err error)

VerifyMsgHash verify msg hash

func (*Bridge) VerifyRawTransaction

func (b *Bridge) VerifyRawTransaction(raw *RawTransaction, args *tokens.BuildTxArgs) error

func (*Bridge) VerifyTokenConfig

func (b *Bridge) VerifyTokenConfig(tokenCfg *tokens.TokenConfig) error

VerifyTokenConfig verify token config

func (*Bridge) VerifyTransaction

func (b *Bridge) VerifyTransaction(txHash string, args *tokens.VerifyArgs) (*tokens.SwapTxInfo, error)

VerifyTransaction impl

type BridgeInterface

type BridgeInterface interface {
	tokens.IBridge

	QueryUtxoOnChain(address string) (map[UtxoKey]AssetsMap, error)
	BuildAggregateTx(swapId string, utxos map[UtxoKey]AssetsMap) (*RawTransaction, error)
	AggregateTx() (string, error)
	VerifyAggregate(msgHash []string, args *tokens.BuildTxArgs) error
}

BridgeInterface btc bridge interface

var BridgeInstance BridgeInterface

BridgeInstance btc bridge instance

type Epoch

type Epoch struct {
	Number         uint64         `json:"number"`
	ProtocolParams ProtocolParams `json:"protocolParams"`
}

type Input

type Input struct {
	Address string `json:"address"`
	Value   string `json:"value"`
}

type Metadata

type Metadata struct {
	Key   string        `json:"key"`
	Value MetadataValue `json:"value"`
}

type MetadataValue

type MetadataValue struct {
	Bind      string `json:"bind,omitempty"`
	ToChainId string `json:"toChainId,omitempty"`
}

type NodeTip

type NodeTip struct {
	Tip TipInfo `json:"tip"`
}

type Output

type Output struct {
	Address string  `json:"address"`
	Index   uint64  `json:"index"`
	Tokens  []Token `json:"tokens"`
	Value   string  `json:"value"`
	TxHash  string  `json:"txHash"`
}

type OutputsResult

type OutputsResult struct {
	Outputs []Output `json:"utxos"`
}

type ProtocolParams

type ProtocolParams struct {
	CoinsPerUtxoByte uint64 `json:"coinsPerUtxoByte"`
	KeyDeposit       uint64 `json:"keyDeposit"`
	MaxBlockBodySize uint64 `json:"maxBlockBodySize"`
	MaxBlockExMem    string `json:"maxBlockExMem"`
	MaxTxSize        uint64 `json:"maxTxSize"`
	MaxValSize       string `json:"maxValSize"`
	MinFeeA          uint64 `json:"minFeeA"`
	MinFeeB          uint64 `json:"minFeeB"`
	MinPoolCost      uint64 `json:"minPoolCost"`
	MinUTxOValue     uint64 `json:"minUTxOValue"`
}

type RawTransaction

type RawTransaction struct {
	// Fee string `json:"fee"`
	TxIns            []UtxoKey            `json:"txIns"`
	TxInsAssets      []AssetsMap          `json:"txInsAssets"`
	TxOuts           map[string]AssetsMap `json:"txOuts"`
	Mint             AssetsMap            `json:"mint"`
	TxIndex          uint64               `json:"txIndex"`
	SwapId           string               `json:"swapId"`
	KeyDeposit       uint64               `json:"keyDeposit"`
	CoinsPerUTXOWord uint64               `json:"coinsPerUTXOWord"`
	MinFeeA          uint64               `json:"minFeeA"`
	MinFeeB          uint64               `json:"minFeeB"`
	Slot             uint64               `json:"slot"`
}

func (*RawTransaction) ProtoMessage

func (*RawTransaction) ProtoMessage()

type SignedTransaction

type SignedTransaction struct {
	FilePath  string         `json:"filePath"`
	TxIns     []UtxoKey      `json:"txIns"`
	TxHash    string         `json:"txHash"`
	TxIndex   uint64         `json:"txIndex"`
	AssetsMap AssetsMap      `json:"assetsMap"`
	Tx        *cardanosdk.Tx `json:"-"`
}

type Tip

type Tip struct {
	Slot  uint64 `json:"slot"`
	Block uint64 `json:"block"`
	Epoch uint64 `json:"epoch"`
	Hash  string `json:"hash"`
}

type TipInfo

type TipInfo struct {
	BlockNumber uint64 `json:"number"`
	Epoch       Epoch  `json:"epoch"`
	SlotNo      uint64 `json:"slotNo"`
}

type TipResponse

type TipResponse struct {
	Cardano NodeTip `json:"cardano"`
}

func GetCardanoTip

func GetCardanoTip(url string) (*TipResponse, error)

type Token

type Token struct {
	Asset    Asset  `json:"asset"`
	Quantity string `json:"quantity"`
}

type Transaction

type Transaction struct {
	Block         Block      `json:"block"`
	Hash          string     `json:"hash"`
	Metadata      []Metadata `json:"metadata"`
	Inputs        []Input    `json:"inputs"`
	Outputs       []Output   `json:"outputs"`
	ValidContract bool       `json:"validContract"`
}

func GetTransactionByHash

func GetTransactionByHash(url, txHash string) (*Transaction, error)

type TransactionChainingKey

type TransactionChainingKey struct {
	SpentUtxoMap              map[UtxoKey]bool      `json:"SpentUtxoMap"`
	SpentUtxoListGropByTxHash map[string]*[]UtxoKey `json:"SpentUtxoListGropByTxHash"`
}

type TransactionChainingMap

type TransactionChainingMap struct {
	InputKey  UtxoKey   `json:"inputKey"`
	AssetsMap AssetsMap `json:"assetsMap"`
}

type TransactionResult

type TransactionResult struct {
	Transactions []Transaction `json:"transactions"`
}

type UtxoKey

type UtxoKey struct {
	TxHash  string `json:"txHash"`
	TxIndex uint64 `json:"txIndex"`
}

Directories

Path Synopsis
tools

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL