Documentation ¶
Index ¶
- Constants
- Variables
- func GetInputs(api *API, seed Trytes, start, end int, threshold int64, security int) ([]AddressInfo, Balances, error)
- func GetUsedAddress(api *API, seed Trytes, security int) (Address, []Address, error)
- func IsValidSig(expectedAddress Address, signatureFragments []Trytes, bundleHash Trytes) bool
- func IsValidTrit(t int8) error
- func IsValidTryte(t rune) error
- func SendTrytes(api *API, depth int64, trytes []Transaction, mwm int64, pow PowFunc) error
- type API
- func (api *API) AddNeighbors(uris []string) (*AddNeighborsResponse, error)
- func (api *API) AttachToMesh(att *AttachToMeshRequest) (*AttachToMeshResponse, error)
- func (api *API) Balances(adr []Address) (Balances, error)
- func (api *API) BroadcastTransactions(trytes []Transaction) error
- func (api *API) FindTransactions(ft *FindTransactionsRequest) (*FindTransactionsResponse, error)
- func (api *API) GetBalances(adr []Address, threshold int64) (*GetBalancesResponse, error)
- func (api *API) GetInclusionStates(tx []Trytes, tips []Trytes) (*GetInclusionStatesResponse, error)
- func (api *API) GetLatestInclusion(hash []Trytes) ([]bool, error)
- func (api *API) GetNeighbors() (*GetNeighborsResponse, error)
- func (api *API) GetNodeInfo() (*GetNodeInfoResponse, error)
- func (api *API) GetPeerAddresses() (*GetPeerAddressesResponse, error)
- func (api *API) GetTips() (*GetTipsResponse, error)
- func (api *API) GetTransactionsToApprove(depth int64) (*GetTransactionsToApproveResponse, error)
- func (api *API) GetTrytes(hashes []Trytes) (*GetTrytesResponse, error)
- func (api *API) InterruptAttachingToMesh() error
- func (api *API) RemoveNeighbors(uris []string) (*RemoveNeighborsResponse, error)
- func (api *API) StoreTransactions(trytes []Transaction) error
- type AddNeighborsRequest
- type AddNeighborsResponse
- type Address
- type AddressInfo
- type AttachToMeshRequest
- type AttachToMeshResponse
- type Balance
- type Balances
- type BroadcastTransactionsRequest
- type Bundle
- type Curl
- type ErrorResponse
- type FindTransactionsRequest
- type FindTransactionsResponse
- type GetBalancesRequest
- type GetBalancesResponse
- type GetInclusionStatesRequest
- type GetInclusionStatesResponse
- type GetNeighborsRequest
- type GetNeighborsResponse
- type GetNodeInfoRequest
- type GetNodeInfoResponse
- type GetPeerAddressesRawResponse
- type GetPeerAddressesRequest
- type GetPeerAddressesResponse
- type GetTipsRequest
- type GetTipsResponse
- type GetTransactionsToApproveRequest
- type GetTransactionsToApproveResponse
- type GetTrytesRequest
- type GetTrytesResponse
- type InterruptAttachingToMeshRequest
- type Neighbor
- type PeerAddress
- type PowFunc
- type RemoveNeighborsRequest
- type RemoveNeighborsResponse
- type StoreTransactionsRequest
- type Transaction
- type Transfer
- type Trits
- type Trytes
- func Digests(key Trytes) (Trytes, error)
- func NewKey(seed Trytes, index, securityLevel int) Trytes
- func NewSeed() Trytes
- func PowC(trytes Trytes, mwm int) (Trytes, error)
- func PowGo(trytes Trytes, mwm int) (Trytes, error)
- func PowSSE(trytes Trytes, mwm int) (Trytes, error)
- func Sign(normalizedBundleFragment []int8, keyFragment Trytes) Trytes
- func ToTrytes(t string) (Trytes, error)
Constants ¶
const ( TryteAlphabet = "9ABCDEFGHIJKLMNOPQRSTUVWXYZ" MinTryteValue = -13 MaxTryteValue = 13 SignatureSize = 6561 HashSize = 243 MinWeightMagnitude = 18 //must be 18. Depth = 3 )
Various constants for gadk.
const ( Ki = 1000 Mi = 1000000 Gi = 1000000000 Ti = 1000000000000 Pi = 1000000000000000 )
Units for adk token.
const ( SignatureMessageFragmentTrinaryOffset = 0 SignatureMessageFragmentTrinarySize = 6561 AddressTrinaryOffset = SignatureMessageFragmentTrinaryOffset + SignatureMessageFragmentTrinarySize AddressTrinarySize = 243 ValueTrinaryOffset = AddressTrinaryOffset + AddressTrinarySize ValueTrinarySize = 81 TagTrinaryOffset = ValueTrinaryOffset + ValueTrinarySize TagTrinarySize = 81 TimestampTrinaryOffset = TagTrinaryOffset + TagTrinarySize TimestampTrinarySize = 27 CurrentIndexTrinaryOffset = TimestampTrinaryOffset + TimestampTrinarySize CurrentIndexTrinarySize = 27 LastIndexTrinaryOffset = CurrentIndexTrinaryOffset + CurrentIndexTrinarySize LastIndexTrinarySize = 27 BundleTrinaryOffset = LastIndexTrinaryOffset + LastIndexTrinarySize BundleTrinarySize = 243 TrunkTransactionTrinaryOffset = BundleTrinaryOffset + BundleTrinarySize TrunkTransactionTrinarySize = 243 BranchTransactionTrinaryOffset = TrunkTransactionTrinaryOffset + TrunkTransactionTrinarySize BranchTransactionTrinarySize = 243 NonceTrinaryOffset = BranchTransactionTrinaryOffset + BranchTransactionTrinarySize NonceTrinarySize = 243 )
Trinary sizes and offsets of a transaction
Variables ¶
var ( //EmptyHash represents empty hash. EmptyHash Trytes = "999999999999999999999999999999999999999999999999999999999999999999999999999999999" //EmptyAddress represents empty address. EmptyAddress Address = "999999999999999999999999999999999999999999999999999999999999999999999999999999999" )
var ( ErrSeedTritsLength = errors.New("seed trit slice should be HashSize entries long") ErrKeyTritsLength = errors.New("key trit slice should be a multiple of HashSize*27 entries long") )
errors used in sign.
var ( ErrInvalidAddressTrytes = errors.New("addresses without checksum are 81 trytes in length") ErrInvalidAddressTrits = errors.New("addresses without checksum are 243 trits in length") )
Error types for address.
var ( ErrInvalidTransactionType = errors.New("invalid transaction type") ErrInvalidTransactionHash = errors.New("invalid transaction hash") ErrInvalidTransaction = errors.New("malformed transaction") )
errors for tx.
var ( //PowProcs is number of concurrencies. //default is NumCPU()-1. PowProcs int )
Functions ¶
func GetInputs ¶
func GetInputs(api *API, seed Trytes, start, end int, threshold int64, security int) ([]AddressInfo, Balances, error)
GetInputs gets all possible inputs of a seed and returns them with the total balance. end must be under start+500.
func GetUsedAddress ¶
GetUsedAddress generates a new address which is not found in the Mesh. and returns its new address and used addresses.
func IsValidSig ¶
IsValidSig validates signatureFragment.
func SendTrytes ¶
SendTrytes does attachToMesh and finally, it broadcasts the transactions.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is for calling APIs.
func NewAPI ¶
NewAPI takes an (optional) endpoint and optional http.Client and returns an API struct. If an empty endpoint is supplied, then "http://localhost:14265" is used.
func (*API) AddNeighbors ¶
func (api *API) AddNeighbors(uris []string) (*AddNeighborsResponse, error)
AddNeighbors calls AddNeighbors API.
func (*API) AttachToMesh ¶
func (api *API) AttachToMesh(att *AttachToMeshRequest) (*AttachToMeshResponse, error)
AttachToMesh calls AttachToMesh API.
func (*API) BroadcastTransactions ¶
func (api *API) BroadcastTransactions(trytes []Transaction) error
BroadcastTransactions calls BroadcastTransactions API.
func (*API) FindTransactions ¶
func (api *API) FindTransactions(ft *FindTransactionsRequest) (*FindTransactionsResponse, error)
FindTransactions calls FindTransactions API.
func (*API) GetBalances ¶
func (api *API) GetBalances(adr []Address, threshold int64) (*GetBalancesResponse, error)
GetBalances calls GetBalances API.
func (*API) GetInclusionStates ¶
func (api *API) GetInclusionStates(tx []Trytes, tips []Trytes) (*GetInclusionStatesResponse, error)
GetInclusionStates calls GetInclusionStates API.
func (*API) GetLatestInclusion ¶
GetLatestInclusion takes the most recent solid milestone as returned by getNodeInfo and uses it to get the inclusion states of a list of transaction hashes
func (*API) GetNeighbors ¶
func (api *API) GetNeighbors() (*GetNeighborsResponse, error)
GetNeighbors calls GetNeighbors API.
func (*API) GetNodeInfo ¶
func (api *API) GetNodeInfo() (*GetNodeInfoResponse, error)
GetNodeInfo calls GetNodeInfo API.
func (*API) GetPeerAddresses ¶
func (api *API) GetPeerAddresses() (*GetPeerAddressesResponse, error)
GetPeerAddresses calls GetPeerAddresses API.
func (*API) GetTips ¶
func (api *API) GetTips() (*GetTipsResponse, error)
GetTips calls GetTips API.
func (*API) GetTransactionsToApprove ¶
func (api *API) GetTransactionsToApprove(depth int64) (*GetTransactionsToApproveResponse, error)
GetTransactionsToApprove calls GetTransactionsToApprove API.
func (*API) GetTrytes ¶
func (api *API) GetTrytes(hashes []Trytes) (*GetTrytesResponse, error)
GetTrytes calls GetTrytes API.
func (*API) InterruptAttachingToMesh ¶
InterruptAttachingToMesh calls InterruptAttachingToMesh API.
func (*API) RemoveNeighbors ¶
func (api *API) RemoveNeighbors(uris []string) (*RemoveNeighborsResponse, error)
RemoveNeighbors calls RemoveNeighbors API.
func (*API) StoreTransactions ¶
func (api *API) StoreTransactions(trytes []Transaction) error
StoreTransactions calls StoreTransactions API.
type AddNeighborsRequest ¶
type AddNeighborsRequest struct { Command string `json:"command"` // URIS is an array of strings in the form of "udp://identifier:port" // where identifier can be either an IP address or a domain name. URIS []string `json:"uris"` }
AddNeighborsRequest is for AddNeighbors API request.
type AddNeighborsResponse ¶
type AddNeighborsResponse struct { Duration int64 `json:"duration"` AddedNeighbors int64 `json:"addedNeighbors"` }
AddNeighborsResponse is for AddNeighbors API response.
type Address ¶
type Address Trytes
Address represents address without checksum for adk. Don't use type cast, use ToAddress instead to check the validity.
func NewAddress ¶
NewAddress generates a new address from seed without checksum.
func NewAddresses ¶
NewAddresses generates new count addresses from seed without checksum.
func (Address) WithChecksum ¶
WithChecksum returns Address+checksum. This panics if len(address)<81
type AddressInfo ¶
AddressInfo includes address and its infomation. for using signing.
func (*AddressInfo) Address ¶
func (a *AddressInfo) Address() (Address, error)
Address makes Address from address infos.
type AttachToMeshRequest ¶
type AttachToMeshRequest struct { Command string `json:"command"` TrunkTransaction Trytes `json:"trunkTransaction"` BranchTransaction Trytes `json:"branchTransaction"` MinWeightMagnitude int64 `json:"minWeightMagnitude"` Trytes []Transaction `json:"trytes"` }
AttachToMeshRequest is for AttachToMesh API request.
type AttachToMeshResponse ¶
type AttachToMeshResponse struct { Duration int64 `json:"duration"` Trytes []Transaction `json:"trytes"` }
AttachToMeshResponse is for AttachToMesh API response.
type BroadcastTransactionsRequest ¶
type BroadcastTransactionsRequest struct { Command string `json:"command"` Trytes []Transaction `json:"trytes"` }
BroadcastTransactionsRequest is for BroadcastTransactions API request.
type Bundle ¶
type Bundle []Transaction
Bundle is transactions are bundled (or grouped) together during the creation of a transfer.
func PrepareTransfers ¶
func PrepareTransfers(api *API, seed Trytes, trs []Transfer, inputs []AddressInfo, remainder Address, security int) (Bundle, error)
PrepareTransfers gets an array of transfer objects as input, and then prepare the transfer by generating the correct bundle, as well as choosing and signing the inputs if necessary (if it's a value transfer).
func Send ¶
Send sends token. if you need to pow locally, you must specifiy pow func. otherwirse this calls AttachToMesh API.
func (*Bundle) Add ¶
Add adds one bundle to bundle slice tempolary. For now elements which are not specified are filled with trits 0.
func (Bundle) Categorize ¶
Categorize Categorizes a list of transfers into sent and received. It is important to note that zero value transfers (which for example, is being used for storing addresses in the Mesh), are seen as received in this function.
type Curl ¶
type Curl struct {
// contains filtered or unexported fields
}
Curl is a sponge function with an internal state of size StateSize. b = r + c, b = StateSize, r = HashSize, c = StateSize - HashSize
type ErrorResponse ¶
ErrorResponse is for occuring exception while calling API.
type FindTransactionsRequest ¶
type FindTransactionsRequest struct { Command string `json:"command"` Bundles []Trytes `json:"bundles,omitempty"` Addresses []Address `json:"addresses,omitempty"` Tags []Trytes `json:"tags,omitempty"` Approvees []Trytes `json:"approvees,omitempty"` }
FindTransactionsRequest is for FindTransactions API request.
type FindTransactionsResponse ¶
type FindTransactionsResponse struct { Duration int64 `json:"duration"` Hashes []Trytes `json:"hashes"` }
FindTransactionsResponse is for FindTransaction API response.
type GetBalancesRequest ¶
type GetBalancesRequest struct { Command string `json:"command"` Addresses []Address `json:"addresses"` Threshold int64 `json:"threshold"` }
GetBalancesRequest is for GetBalances API request.
type GetBalancesResponse ¶
type GetBalancesResponse struct { Duration int64 Balances []int64 Milestone Trytes MilestoneIndex int64 }
GetBalancesResponse is for GetBalances API response.
type GetInclusionStatesRequest ¶
type GetInclusionStatesRequest struct { Command string `json:"command"` Transactions []Trytes `json:"transactions"` Tips []Trytes `json:"tips"` }
GetInclusionStatesRequest is for GetInclusionStates API request.
type GetInclusionStatesResponse ¶
type GetInclusionStatesResponse struct { Duration int64 `json:"duration"` States []bool `json:"states"` }
GetInclusionStatesResponse is for GetInclusionStates API response.
type GetNeighborsRequest ¶
type GetNeighborsRequest struct {
Command string `json:"command"`
}
GetNeighborsRequest is for GetNeighbors API request.
type GetNeighborsResponse ¶
GetNeighborsResponse is for GetNeighbors API response.
type GetNodeInfoRequest ¶
type GetNodeInfoRequest struct {
Command string `json:"command"`
}
GetNodeInfoRequest is for GetNodeInfo API request.
type GetNodeInfoResponse ¶
type GetNodeInfoResponse struct { AppName string `json:"appName"` AppVersion string `json:"appVersion"` Duration int64 `json:"duration"` JREAvailableProcessors int64 `json:"jreAvailableProcessors"` JREFreeMemory int64 `json:"jreFreeMemory"` JREMaxMemory int64 `json:"jreMaxMemory"` JRETotalMemory int64 `json:"jreTotalMemory"` LatestMilestone Trytes `json:"latestMilestone"` LatestMilestoneIndex int64 `json:"latestMilestoneIndex"` LatestSolidSubmeshMilestone Trytes `json:"latestSolidSubmeshMilestone"` LatestSolidSubmeshMilestoneIndex int64 `json:"latestSolidSubmeshMilestoneIndex"` Neighbors int64 `json:"neighbors"` PacketQueueSize int64 `json:"packetQueueSize"` Time int64 `json:"time"` Tips int64 `json:"tips"` TransactionsToRequest int64 `json:"transactionsToRequest"` }
GetNodeInfoResponse is for GetNode APi response.
type GetPeerAddressesRawResponse ¶
type GetPeerAddressesRawResponse struct { Duration int64 `json:"duration"` Peers []string `json:"peerlist"` }
GetPeerAddressesRawResponse is for raw GetPeerAddresses API response.
type GetPeerAddressesRequest ¶
type GetPeerAddressesRequest struct {
Command string `json:"command"`
}
GetPeerAddressesRequest is for GetPeerAddresses API request.
type GetPeerAddressesResponse ¶
type GetPeerAddressesResponse struct { Duration int64 `json:"duration"` Peers []PeerAddress `json:"peerlist"` }
GetPeerAddressesResponse is for GetPeerAddresses API response.
type GetTipsRequest ¶
type GetTipsRequest struct {
Command string `json:"command"`
}
GetTipsRequest is for GetTipsRequest API request.
type GetTipsResponse ¶
GetTipsResponse is for GetTips API response.
type GetTransactionsToApproveRequest ¶
type GetTransactionsToApproveRequest struct { Command string `json:"command"` Depth int64 `json:"depth"` }
GetTransactionsToApproveRequest is for GetTransactionsToApprove API request.
type GetTransactionsToApproveResponse ¶
type GetTransactionsToApproveResponse struct { Duration int64 `json:"duration"` TrunkTransaction Trytes `json:"trunkTransaction"` BranchTransaction Trytes `json:"branchTransaction"` }
GetTransactionsToApproveResponse is for GetTransactionsToApprove API response.
type GetTrytesRequest ¶
GetTrytesRequest is for GetTrytes API request.
type GetTrytesResponse ¶
type GetTrytesResponse struct { Duration int64 `json:"duration"` Trytes []Transaction `json:"trytes"` }
GetTrytesResponse is for GetTrytes API response.
type InterruptAttachingToMeshRequest ¶
type InterruptAttachingToMeshRequest struct {
Command string `json:"command"`
}
InterruptAttachingToMeshRequest is for InterruptAttachingToMesh API request.
type Neighbor ¶
type Neighbor struct { Address Address `json:"address"` NumberOfAllTransactions int64 `json:"numberOfAllTransactions"` NumberOfInvalidTransactions int64 `json:"numberOfInvalidTransactions"` NumberOfNewTransactions int64 `json:"numberOfNewTransactions"` }
Neighbor is a part of response of GetNeighbors API.
type PeerAddress ¶
type RemoveNeighborsRequest ¶
type RemoveNeighborsRequest struct { Command string `json:"command"` // URIS is an array of strings in the form of "udp://identifier:port" // where identifier can be either an IP address or a domain name. URIS []string `json:"uris"` }
RemoveNeighborsRequest is for RemoveNeighbors API request.
type RemoveNeighborsResponse ¶
type RemoveNeighborsResponse struct { Duration int64 `json:"duration"` RemovedNeighbors int64 `json:"removedNeighbors"` }
RemoveNeighborsResponse is for RemoveNeighbors API response.
type StoreTransactionsRequest ¶
type StoreTransactionsRequest struct { Command string `json:"command"` Trytes []Transaction `json:"trytes"` }
StoreTransactionsRequest is for StoreTransactions API request.
type Transaction ¶
type Transaction struct { SignatureMessageFragment Trytes Address Address Value int64 `json:",string"` Tag Trytes Timestamp time.Time CurrentIndex int64 `json:",string"` LastIndex int64 `json:",string"` Bundle Trytes TrunkTransaction Trytes BranchTransaction Trytes Nonce Trytes }
Transaction is transaction structure for adk.
func NewTransaction ¶
func NewTransaction(trytes Trytes) (*Transaction, error)
NewTransaction makes tx from trits.
func (*Transaction) HasValidNonce ¶
func (t *Transaction) HasValidNonce() bool
HasValidNonce checks t's hash has valid MinWeightMagnitude.
func (*Transaction) HasValidNonceMWM ¶
func (t *Transaction) HasValidNonceMWM(mwm int) bool
HasValidNonceMWM checks t's hash has valid MinWeightMagnitude.
func (*Transaction) Hash ¶
func (t *Transaction) Hash() Trytes
Hash returns the hash of the transaction.
func (*Transaction) MarshalJSON ¶
func (t *Transaction) MarshalJSON() ([]byte, error)
MarshalJSON makes trytes ([]byte) from a transaction.
func (*Transaction) Trytes ¶
func (t *Transaction) Trytes() Trytes
Trytes converts the transaction to Trytes.
func (*Transaction) UnmarshalJSON ¶
func (t *Transaction) UnmarshalJSON(b []byte) error
UnmarshalJSON makes transaction struct from json.
type Trits ¶
type Trits []int8
Trits is a slice of int8. You should not use cast, use ToTrits instead to ensure the validity.
type Trytes ¶
type Trytes string
Trytes is a string of trytes. You should not use cast, use ToTrytes instead to ensure the validity.
func NewKey ¶
NewKey takes a seed encoded as Trits, an index and a security level to derive a private key.
func Sign ¶
Sign calculates signature from bundle hash and key by hashing x 13-normalizedBundleFragment[i] for each segments in keyTrits.