cardano

package
v3.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: GPL-3.0 Imports: 23 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 (
	NetWork       = "--mainnet" // for testnet, use "--testnet-magic 1"
	MPCPolicyId   = "f73d0275b986a17537f0dfa94060313f922ac1d7a81aec677fa3bdbe"
	RawPath       = "txDb/raw/"
	AdaAsset      = "lovelace"
	RawSuffix     = ".raw"
	WitnessPath   = "txDb/witness/"
	WitnessSuffix = ".witness"
	WitnessType   = "TxWitness AlonzoEra"
	SignedPath    = "txDb/signed/"
	SignedSuffix  = ".signed"
)
View Source
const (
	MetadataKey = "123"
)

Variables

View Source
var (
	FixAdaAmount                = big.NewInt(1500000)
	DefaultAdaAmount            = big.NewInt(2000000)
	AddressInfoCmd              = "cardano-cli address info --address %s"
	AssembleCmd                 = "cardano-cli transaction assemble --tx-body-file %s --witness-file %s --out-file %s"
	SubmitCmd                   = "cardano-cli transaction submit --tx-file %s " + NetWork
	BuildRawTxWithoutMintCmd    = "cardano-cli  transaction  build-raw  --fee  %s%s%s  --out-file  %s"
	BuildRawTxWithMintCmd       = "cardano-cli  transaction  build-raw  --fee  %s%s%s%s  --out-file  %s  --mint-script-file  txDb/policy/policy.script"
	CalcMinFeeCmd               = "cardano-cli transaction calculate-min-fee --tx-body-file %s --tx-in-count %d --tx-out-count %d --witness-count 1 --protocol-params-file txDb/config/protocol.json " + NetWork
	CalcTxIdCmd                 = "cardano-cli transaction txid --tx-body-file %s"
	QueryTipCmd                 = "cardano-cli query tip " + NetWork
	QueryTransaction            = "" /* 259-byte string literal not displayed */
	QueryOutputs                = "{utxos(where: { address: { _eq: \"%s\"}}) {txHash index tokens {asset {policyId assetName} quantity} value}}"
	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 CalcMinFee

func CalcMinFee(rawTransaction *RawTransaction) (string, error)

func CalcTxId

func CalcTxId(txPath string) (string, error)

func ClearTransactionChainingKeyCache

func ClearTransactionChainingKeyCache(txhash string)

func CreateRawTx

func CreateRawTx(rawTransaction *RawTransaction, mpcAddr string) error

func ExecCmd

func ExecCmd(cmdStr, space string) (string, error)

func GetLatestBlockNumber

func GetLatestBlockNumber() (uint64, error)

func GetStubChainID

func GetStubChainID(network string) *big.Int

GetStubChainID get stub chainID

func GetUtxosByAddress

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

func StringToPrivateKey

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

func SupportsChainID

func SupportsChainID(chainID *big.Int) bool

SupportsChainID supports chainID

func VerifyMPCPubKey

func VerifyMPCPubKey(mpcAddress, mpcPubkey string) error

VerifyMPCPubKey verify mpc address and public key is matching

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 Bridge

type Bridge struct {
	*base.NonceSetterBase
	RPCClientTimeout int
}

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) 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) CreateWitness

func (b *Bridge) CreateWitness(witnessPath, mpcPublicKey string, sig []byte) 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) GetPoolNonce

func (b *Bridge) GetPoolNonce(address, _height string) (uint64, error)

GetPoolNonce impl NonceSetter interface

func (*Bridge) GetSeq

func (b *Bridge) GetSeq(args *tokens.BuildTxArgs) (nonceptr *uint64, err error)

GetSeq returns account tx sequence

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) 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) 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) QueryUtxoOnChain

func (b *Bridge) QueryUtxoOnChain(address 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(txInputs []UtxoKey, txIndex uint64, assetsMap AssetsMap, txPath, witnessPath, signedPath, txHash, mpcPubkey, privKey string) (*SignedTransaction, string, error)

SignTransactionWithPrivateKey sign tx with ECDSA private key

func (*Bridge) SignTx

func (b *Bridge) SignTx(rawTxPath, witnessPath, signedPath string) error

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)
}

BridgeInterface btc bridge interface

var BridgeInstance BridgeInterface

BridgeInstance btc bridge instance

type Input added in v3.6.2

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 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 RawTransaction

type RawTransaction struct {
	Fee     string               `json:"fee"`
	TxIns   []UtxoKey            `json:"txIns"`
	TxOuts  map[string]AssetsMap `json:"txOuts"`
	Mint    AssetsMap            `json:"mint"`
	TxIndex uint64               `json:"txIndex"`
	OutFile string               `json:"outFile"`
}

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"`
}

type Tip

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

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