tezos

package module
v0.0.0-...-c4e539a Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 6 Imported by: 0

README

tezos-sdk

Tezos SDK is used to interact with the Tezos blockchain, it contains various functions can be used to web3 wallet.

Installation

go get

To obtain the latest version, simply require the project using :

go get -u github.com/xiaohuasheng0x1/blockchains/coins/tezos

Usage

New address
addr, err := GetAddress("edpkucde3WUTR2s6KgDBwvR7NiezGyHNj1aGz6WrJg6SeZWHNjDA8N")
fmt.Println(addr)
Transfer
var amount int64 = 6000000
var fee int64 = 10000 // 0.010000 XTZ
var counter int64 = 339709
opt := NewCallOptions("BL74GqeaJ8tdFuBR2RhsGXET7MNonprQ49BBreZHE9yn9x85hJP", counter, false)
privateKey, err := types.ParsePrivateKey(p1)
require.NoError(t, err)
tx, err := NewJakartanetTransaction(n1, n3, amount, opt)
require.NoError(t, err)
err = BuildTransaction(tx, fee, privateKey.Public(), opt)
require.NoError(t, err)
rawTx, err := SignTransaction(tx, p1, opt)
require.NoError(t, err)
expected := "33b684e3912522308951aea7e274f0f97a920d9ea268de31c2ca842cba8edd5a6c00cb15c8cb2ebe15662ad5697e139eabf3e0f1aea6904efedd1480bd3fe0d403809bee0200008e1c63b65a34abf66f88b0314549ca3295004eb700cfce6d27ca0feac5877bd24a7080c52a6c89c3378f3d45642d9e6729386e8dc1bff7b4041e8e2255d01f8ab0634bba2823314406844c026dd9b9dd9d3f989708"
require.Equal(t, expected, hex.EncodeToString(rawTx))
New jakartanet delegation transaction
var to string = "tz1foXHgRzdYdaLgX6XhpZGxbBv42LZ6ubvE"
var fee int64 = 10000
var counter int64 = 331345
opt := NewCallOptions("BL7kQbhcCsMYB954n94XcSZmS1oTYcg8J7ut2wj6iZpL3fRBdM3", counter, false)
privateKey, err := types.ParsePrivateKey(p2)
tx, err := NewJakartanetDelegationTransaction(n2, to, opt)
err = BuildTransaction(tx, fee, privateKey.Public(), opt)
rawTx, err := SignTransaction(tx, p2, opt)
expected := "3548bdffd1ce6eb49efda7ebfaa9518a5868870fadf4fc0b45906412496c24376e00de6e07b12d524f72641623528d0de4da3a4cbce3904ed29c1480bd3fe0d403ff00dd2e214620a9ceaf0c38da92f9a56954f81e5ee006e44a704a0914a1c9b5adcc99fc5a238da3a1b7649a08fb5b89d66cc04c494a67fa9a40da6c1cf91ee652bf510dc6403cb654d6a0a849ed08b06a9280b9fd02"
New jakartanet undelegation transaction
var fee int64 = 10000 // 0.010000 XTZ
var counter int64 = 339708
opt := NewCallOptions("BL7kQbhcCsMYB954n94XcSZmS1oTYcg8J7ut2wj6iZpL3fRBdM3", counter, false)
privateKey, err := types.ParsePrivateKey(p2)
tx, err := NewJakartanetUnDelegationTransaction(n2, opt)
err = BuildTransaction(tx, fee, privateKey.Public(), opt)
rawTx, err := SignTransaction(tx, p2, opt)

License

Most packages or folder are MIT licensed, see package or folder for the respective license.

Documentation

Index

Constants

View Source
const GasSafetyMargin int64 = 100

Variables

View Source
var DefaultOptions = CallOptions{
	MaxFee: 1_000_000,
}

Functions

func AddTransferOpTransaction

func AddTransferOpTransaction(to string, amount int64, op *types.Op) (*types.Op, error)

func BuildTransaction

func BuildTransaction(op *types.Op, fee int64, key types.Key, opts *CallOptions) error

func CalculateMinFee

func CalculateMinFee(o types.Operation, gas int64, withHeader bool, p *types.Params) int64

CalculateMinFee returns the minimum fee at/above which bakers will accept this operation under default config settings.

func CompleteTransaction

func CompleteTransaction(o *types.Op, key types.Key, opts *CallOptions) error

CompleteTransaction ensures an operation is compatible with the current source account's on-chain state. Sets branch for TTL control, replay counters, and reveals the sender's pubkey if not published yet.

func GenerateKeyPair

func GenerateKeyPair() (string, string, error)

func GetAddress

func GetAddress(publicKey string) (string, error)

func GetAddressByPrivateKey

func GetAddressByPrivateKey(privateKey string) (string, error)

func GetAddressByPublicKey

func GetAddressByPublicKey(publicKey string) (string, error)

func InitOperationSourceBranch

func InitOperationSourceBranch(from string, op *types.Op, opts *CallOptions) error

func NewDelegationTransaction

func NewDelegationTransaction(from, to string, opts *CallOptions) (*types.Op, error)

func NewDelegationTransactionByOperation

func NewDelegationTransactionByOperation(from, to string, op *types.Op, opts *CallOptions) (*types.Op, error)

func NewJakartanetDelegationTransaction

func NewJakartanetDelegationTransaction(from, to string, opts *CallOptions) (*types.Op, error)

func NewJakartanetTransaction

func NewJakartanetTransaction(from, to string, amount int64, opts *CallOptions) (*types.Op, error)

func NewJakartanetUnDelegationTransaction

func NewJakartanetUnDelegationTransaction(from string, opts *CallOptions) (*types.Op, error)

func NewTransaction

func NewTransaction(from, to string, amount int64, opts *CallOptions) (*types.Op, error)

func NewTransactionByOperation

func NewTransactionByOperation(from, to string, amount int64, op *types.Op, opts *CallOptions) (*types.Op, error)

func NewUnDelegationTransaction

func NewUnDelegationTransaction(from string, opts *CallOptions) (*types.Op, error)

func NewUnDelegationTransactionByOperation

func NewUnDelegationTransactionByOperation(from string, op *types.Op, opts *CallOptions) (*types.Op, error)

func SignTransaction

func SignTransaction(op *types.Op, privateKey string, opts *CallOptions) ([]byte, error)

func ValidAddress

func ValidAddress(addr string) (bool, error)

Types

type CallOptions

type CallOptions struct {
	MaxFee       int64 // max acceptable fee, optional (default = 0)
	IgnoreLimits bool  // ignore simulated limits and use user-defined limits from op
	// custom options
	BlockHash  types.BlockHash
	Counter    int64 // number of times counters
	NeedReveal bool
}

func NewCallOptions

func NewCallOptions(blockHash string, counter int64, needReveal bool) *CallOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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