id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
300 | iotaledger/iota.go | merkle/merkle.go | MerkleRoot | func MerkleRoot(hash Trits, siblings Trits, siblingsNumber uint64, leafIndex uint64, spongeFunc ...sponge.SpongeFunction) (Trits, error) {
h := sponge.GetSpongeFunc(spongeFunc, curl.NewCurlP27)
var j uint64 = 1
var err error
for i := uint64(0); i < siblingsNumber; i++ {
siblingsIdx := i * HashTrinarySize
if (leafIndex & j) != 0 {
// if index is a right node, absorb a sibling (left) then the hash
err = h.Absorb(siblings[siblingsIdx : siblingsIdx+HashTrinarySize])
err = h.Absorb(hash)
} else {
// if index is a left node, absorb the hash then a sibling (right)
err = h.Absorb(hash)
err = h.Absorb(siblings[siblingsIdx : siblingsIdx+HashTrinarySize])
}
hash, err = h.Squeeze(HashTrinarySize)
h.Reset()
j <<= 1
}
return hash, err
} | go | func MerkleRoot(hash Trits, siblings Trits, siblingsNumber uint64, leafIndex uint64, spongeFunc ...sponge.SpongeFunction) (Trits, error) {
h := sponge.GetSpongeFunc(spongeFunc, curl.NewCurlP27)
var j uint64 = 1
var err error
for i := uint64(0); i < siblingsNumber; i++ {
siblingsIdx := i * HashTrinarySize
if (leafIndex & j) != 0 {
// if index is a right node, absorb a sibling (left) then the hash
err = h.Absorb(siblings[siblingsIdx : siblingsIdx+HashTrinarySize])
err = h.Absorb(hash)
} else {
// if index is a left node, absorb the hash then a sibling (right)
err = h.Absorb(hash)
err = h.Absorb(siblings[siblingsIdx : siblingsIdx+HashTrinarySize])
}
hash, err = h.Squeeze(HashTrinarySize)
h.Reset()
j <<= 1
}
return hash, err
} | [
"func",
"MerkleRoot",
"(",
"hash",
"Trits",
",",
"siblings",
"Trits",
",",
"siblingsNumber",
"uint64",
",",
"leafIndex",
"uint64",
",",
"spongeFunc",
"...",
"sponge",
".",
"SpongeFunction",
")",
"(",
"Trits",
",",
"error",
")",
"{",
"h",
":=",
"sponge",
".",
"GetSpongeFunc",
"(",
"spongeFunc",
",",
"curl",
".",
"NewCurlP27",
")",
"\n\n",
"var",
"j",
"uint64",
"=",
"1",
"\n",
"var",
"err",
"error",
"\n\n",
"for",
"i",
":=",
"uint64",
"(",
"0",
")",
";",
"i",
"<",
"siblingsNumber",
";",
"i",
"++",
"{",
"siblingsIdx",
":=",
"i",
"*",
"HashTrinarySize",
"\n\n",
"if",
"(",
"leafIndex",
"&",
"j",
")",
"!=",
"0",
"{",
"// if index is a right node, absorb a sibling (left) then the hash",
"err",
"=",
"h",
".",
"Absorb",
"(",
"siblings",
"[",
"siblingsIdx",
":",
"siblingsIdx",
"+",
"HashTrinarySize",
"]",
")",
"\n",
"err",
"=",
"h",
".",
"Absorb",
"(",
"hash",
")",
"\n",
"}",
"else",
"{",
"// if index is a left node, absorb the hash then a sibling (right)",
"err",
"=",
"h",
".",
"Absorb",
"(",
"hash",
")",
"\n",
"err",
"=",
"h",
".",
"Absorb",
"(",
"siblings",
"[",
"siblingsIdx",
":",
"siblingsIdx",
"+",
"HashTrinarySize",
"]",
")",
"\n",
"}",
"\n\n",
"hash",
",",
"err",
"=",
"h",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"h",
".",
"Reset",
"(",
")",
"\n\n",
"j",
"<<=",
"1",
"\n",
"}",
"\n",
"return",
"hash",
",",
"err",
"\n",
"}"
] | // MerkleRoot generates a merkle root from a hash and his siblings,
// hash is the hash
// siblings is the hash siblings
// siblingsNumber is the number of siblings
// leafIndex is the node index of the hash
// spongeFunc is the optional sponge function to use | [
"MerkleRoot",
"generates",
"a",
"merkle",
"root",
"from",
"a",
"hash",
"and",
"his",
"siblings",
"hash",
"is",
"the",
"hash",
"siblings",
"is",
"the",
"hash",
"siblings",
"siblingsNumber",
"is",
"the",
"number",
"of",
"siblings",
"leafIndex",
"is",
"the",
"node",
"index",
"of",
"the",
"hash",
"spongeFunc",
"is",
"the",
"optional",
"sponge",
"function",
"to",
"use"
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/merkle/merkle.go#L233-L258 |
301 | iotaledger/iota.go | pow/pow_go.go | DoPoW | func DoPoW(trunkTx Trytes, branchTx Trytes, trytes []Trytes, mwm uint64, pow ProofOfWorkFunc) ([]Trytes, error) {
txs, err := AsTransactionObjects(trytes, nil)
if err != nil {
return nil, err
}
var prev Trytes
for i := 0; i < len(txs); i++ {
switch {
case i == 0:
txs[i].TrunkTransaction = trunkTx
txs[i].BranchTransaction = branchTx
default:
txs[i].TrunkTransaction = prev
txs[i].BranchTransaction = trunkTx
}
txs[i].AttachmentTimestamp = time.Now().UnixNano() / 1000000
txs[i].AttachmentTimestampLowerBound = LowerBoundAttachmentTimestamp
txs[i].AttachmentTimestampUpperBound = UpperBoundAttachmentTimestamp
var err error
txs[i].Nonce, err = pow(MustTransactionToTrytes(&txs[i]), int(mwm))
if err != nil {
return nil, err
}
// set new transaction hash
txs[i].Hash = TransactionHash(&txs[i])
prev = txs[i].Hash
}
powedTxTrytes := MustTransactionsToTrytes(txs)
for left, right := 0, len(powedTxTrytes)-1; left < right; left, right = left+1, right-1 {
powedTxTrytes[left], powedTxTrytes[right] = powedTxTrytes[right], powedTxTrytes[left]
}
return powedTxTrytes, nil
} | go | func DoPoW(trunkTx Trytes, branchTx Trytes, trytes []Trytes, mwm uint64, pow ProofOfWorkFunc) ([]Trytes, error) {
txs, err := AsTransactionObjects(trytes, nil)
if err != nil {
return nil, err
}
var prev Trytes
for i := 0; i < len(txs); i++ {
switch {
case i == 0:
txs[i].TrunkTransaction = trunkTx
txs[i].BranchTransaction = branchTx
default:
txs[i].TrunkTransaction = prev
txs[i].BranchTransaction = trunkTx
}
txs[i].AttachmentTimestamp = time.Now().UnixNano() / 1000000
txs[i].AttachmentTimestampLowerBound = LowerBoundAttachmentTimestamp
txs[i].AttachmentTimestampUpperBound = UpperBoundAttachmentTimestamp
var err error
txs[i].Nonce, err = pow(MustTransactionToTrytes(&txs[i]), int(mwm))
if err != nil {
return nil, err
}
// set new transaction hash
txs[i].Hash = TransactionHash(&txs[i])
prev = txs[i].Hash
}
powedTxTrytes := MustTransactionsToTrytes(txs)
for left, right := 0, len(powedTxTrytes)-1; left < right; left, right = left+1, right-1 {
powedTxTrytes[left], powedTxTrytes[right] = powedTxTrytes[right], powedTxTrytes[left]
}
return powedTxTrytes, nil
} | [
"func",
"DoPoW",
"(",
"trunkTx",
"Trytes",
",",
"branchTx",
"Trytes",
",",
"trytes",
"[",
"]",
"Trytes",
",",
"mwm",
"uint64",
",",
"pow",
"ProofOfWorkFunc",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"txs",
",",
"err",
":=",
"AsTransactionObjects",
"(",
"trytes",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"prev",
"Trytes",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"txs",
")",
";",
"i",
"++",
"{",
"switch",
"{",
"case",
"i",
"==",
"0",
":",
"txs",
"[",
"i",
"]",
".",
"TrunkTransaction",
"=",
"trunkTx",
"\n",
"txs",
"[",
"i",
"]",
".",
"BranchTransaction",
"=",
"branchTx",
"\n",
"default",
":",
"txs",
"[",
"i",
"]",
".",
"TrunkTransaction",
"=",
"prev",
"\n",
"txs",
"[",
"i",
"]",
".",
"BranchTransaction",
"=",
"trunkTx",
"\n",
"}",
"\n\n",
"txs",
"[",
"i",
"]",
".",
"AttachmentTimestamp",
"=",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"/",
"1000000",
"\n",
"txs",
"[",
"i",
"]",
".",
"AttachmentTimestampLowerBound",
"=",
"LowerBoundAttachmentTimestamp",
"\n",
"txs",
"[",
"i",
"]",
".",
"AttachmentTimestampUpperBound",
"=",
"UpperBoundAttachmentTimestamp",
"\n\n",
"var",
"err",
"error",
"\n",
"txs",
"[",
"i",
"]",
".",
"Nonce",
",",
"err",
"=",
"pow",
"(",
"MustTransactionToTrytes",
"(",
"&",
"txs",
"[",
"i",
"]",
")",
",",
"int",
"(",
"mwm",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// set new transaction hash",
"txs",
"[",
"i",
"]",
".",
"Hash",
"=",
"TransactionHash",
"(",
"&",
"txs",
"[",
"i",
"]",
")",
"\n",
"prev",
"=",
"txs",
"[",
"i",
"]",
".",
"Hash",
"\n",
"}",
"\n",
"powedTxTrytes",
":=",
"MustTransactionsToTrytes",
"(",
"txs",
")",
"\n",
"for",
"left",
",",
"right",
":=",
"0",
",",
"len",
"(",
"powedTxTrytes",
")",
"-",
"1",
";",
"left",
"<",
"right",
";",
"left",
",",
"right",
"=",
"left",
"+",
"1",
",",
"right",
"-",
"1",
"{",
"powedTxTrytes",
"[",
"left",
"]",
",",
"powedTxTrytes",
"[",
"right",
"]",
"=",
"powedTxTrytes",
"[",
"right",
"]",
",",
"powedTxTrytes",
"[",
"left",
"]",
"\n",
"}",
"\n",
"return",
"powedTxTrytes",
",",
"nil",
"\n",
"}"
] | // DoPoW computes the nonce field for each transaction so that the last MWM-length trits of the
// transaction hash are all zeroes. Starting from the 0 index transaction, the transactions get chained to
// each other through the trunk transaction hash field. The last transaction in the bundle approves
// the given branch and trunk transactions. This function also initializes the attachment timestamp fields.
// This function expects the passed in transaction trytes from highest to lowest index, meaning the transaction
// with current index 0 at the last position. | [
"DoPoW",
"computes",
"the",
"nonce",
"field",
"for",
"each",
"transaction",
"so",
"that",
"the",
"last",
"MWM",
"-",
"length",
"trits",
"of",
"the",
"transaction",
"hash",
"are",
"all",
"zeroes",
".",
"Starting",
"from",
"the",
"0",
"index",
"transaction",
"the",
"transactions",
"get",
"chained",
"to",
"each",
"other",
"through",
"the",
"trunk",
"transaction",
"hash",
"field",
".",
"The",
"last",
"transaction",
"in",
"the",
"bundle",
"approves",
"the",
"given",
"branch",
"and",
"trunk",
"transactions",
".",
"This",
"function",
"also",
"initializes",
"the",
"attachment",
"timestamp",
"fields",
".",
"This",
"function",
"expects",
"the",
"passed",
"in",
"transaction",
"trytes",
"from",
"highest",
"to",
"lowest",
"index",
"meaning",
"the",
"transaction",
"with",
"current",
"index",
"0",
"at",
"the",
"last",
"position",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_go.go#L47-L83 |
302 | iotaledger/iota.go | pow/pow_go.go | GetProofOfWorkImpl | func GetProofOfWorkImpl(name string) (ProofOfWorkFunc, error) {
if p, exist := proofOfWorkFuncs[name]; exist {
return p, nil
}
return nil, errors.Wrapf(ErrUnknownProofOfWorkFunc, "%s", name)
} | go | func GetProofOfWorkImpl(name string) (ProofOfWorkFunc, error) {
if p, exist := proofOfWorkFuncs[name]; exist {
return p, nil
}
return nil, errors.Wrapf(ErrUnknownProofOfWorkFunc, "%s", name)
} | [
"func",
"GetProofOfWorkImpl",
"(",
"name",
"string",
")",
"(",
"ProofOfWorkFunc",
",",
"error",
")",
"{",
"if",
"p",
",",
"exist",
":=",
"proofOfWorkFuncs",
"[",
"name",
"]",
";",
"exist",
"{",
"return",
"p",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"ErrUnknownProofOfWorkFunc",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] | // GetProofOfWorkImpl returns the specified Proof-of-Work implementation given a name. | [
"GetProofOfWorkImpl",
"returns",
"the",
"specified",
"Proof",
"-",
"of",
"-",
"Work",
"implementation",
"given",
"a",
"name",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_go.go#L102-L108 |
303 | iotaledger/iota.go | pow/pow_go.go | GetProofOfWorkImplementations | func GetProofOfWorkImplementations() []string {
powFuncNames := make([]string, len(proofOfWorkFuncs))
i := 0
for k := range proofOfWorkFuncs {
powFuncNames[i] = k
i++
}
return powFuncNames
} | go | func GetProofOfWorkImplementations() []string {
powFuncNames := make([]string, len(proofOfWorkFuncs))
i := 0
for k := range proofOfWorkFuncs {
powFuncNames[i] = k
i++
}
return powFuncNames
} | [
"func",
"GetProofOfWorkImplementations",
"(",
")",
"[",
"]",
"string",
"{",
"powFuncNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"proofOfWorkFuncs",
")",
")",
"\n\n",
"i",
":=",
"0",
"\n",
"for",
"k",
":=",
"range",
"proofOfWorkFuncs",
"{",
"powFuncNames",
"[",
"i",
"]",
"=",
"k",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"return",
"powFuncNames",
"\n",
"}"
] | // GetProofOfWorkImplementations returns an array with the names of all available Proof-of-Work implementations. | [
"GetProofOfWorkImplementations",
"returns",
"an",
"array",
"with",
"the",
"names",
"of",
"all",
"available",
"Proof",
"-",
"of",
"-",
"Work",
"implementations",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_go.go#L111-L121 |
304 | iotaledger/iota.go | pow/pow_go.go | GoProofOfWork | func GoProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
return goProofOfWork(trytes, mwm, nil, parallelism...)
} | go | func GoProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
return goProofOfWork(trytes, mwm, nil, parallelism...)
} | [
"func",
"GoProofOfWork",
"(",
"trytes",
"Trytes",
",",
"mwm",
"int",
",",
"parallelism",
"...",
"int",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"return",
"goProofOfWork",
"(",
"trytes",
",",
"mwm",
",",
"nil",
",",
"parallelism",
"...",
")",
"\n",
"}"
] | // GoProofOfWork does Proof-of-Work on the given trytes using only Go code. | [
"GoProofOfWork",
"does",
"Proof",
"-",
"of",
"-",
"Work",
"on",
"the",
"given",
"trytes",
"using",
"only",
"Go",
"code",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_go.go#L139-L141 |
305 | iotaledger/iota.go | pow/pow_go.go | Loop | func Loop(lmid *[curl.StateSize]uint64, hmid *[curl.StateSize]uint64, m int, cancelled *bool, checkFun CheckFunc, loopCnt int) (nonce Trits, rate int64, foundIndex int) {
var lcpy, hcpy [curl.StateSize]uint64
var i int64
for i = 0; !*cancelled; i++ {
copy(lcpy[:], lmid[:])
copy(hcpy[:], hmid[:])
transform64(&lcpy, &hcpy, loopCnt)
if n := checkFun(&lcpy, &hcpy, m); n >= 0 {
nonce := seri(lmid, hmid, uint(n))
return nonce, i * 64, n
}
incr(lmid, hmid)
}
return nil, i * 64, -1
} | go | func Loop(lmid *[curl.StateSize]uint64, hmid *[curl.StateSize]uint64, m int, cancelled *bool, checkFun CheckFunc, loopCnt int) (nonce Trits, rate int64, foundIndex int) {
var lcpy, hcpy [curl.StateSize]uint64
var i int64
for i = 0; !*cancelled; i++ {
copy(lcpy[:], lmid[:])
copy(hcpy[:], hmid[:])
transform64(&lcpy, &hcpy, loopCnt)
if n := checkFun(&lcpy, &hcpy, m); n >= 0 {
nonce := seri(lmid, hmid, uint(n))
return nonce, i * 64, n
}
incr(lmid, hmid)
}
return nil, i * 64, -1
} | [
"func",
"Loop",
"(",
"lmid",
"*",
"[",
"curl",
".",
"StateSize",
"]",
"uint64",
",",
"hmid",
"*",
"[",
"curl",
".",
"StateSize",
"]",
"uint64",
",",
"m",
"int",
",",
"cancelled",
"*",
"bool",
",",
"checkFun",
"CheckFunc",
",",
"loopCnt",
"int",
")",
"(",
"nonce",
"Trits",
",",
"rate",
"int64",
",",
"foundIndex",
"int",
")",
"{",
"var",
"lcpy",
",",
"hcpy",
"[",
"curl",
".",
"StateSize",
"]",
"uint64",
"\n",
"var",
"i",
"int64",
"\n\n",
"for",
"i",
"=",
"0",
";",
"!",
"*",
"cancelled",
";",
"i",
"++",
"{",
"copy",
"(",
"lcpy",
"[",
":",
"]",
",",
"lmid",
"[",
":",
"]",
")",
"\n",
"copy",
"(",
"hcpy",
"[",
":",
"]",
",",
"hmid",
"[",
":",
"]",
")",
"\n",
"transform64",
"(",
"&",
"lcpy",
",",
"&",
"hcpy",
",",
"loopCnt",
")",
"\n\n",
"if",
"n",
":=",
"checkFun",
"(",
"&",
"lcpy",
",",
"&",
"hcpy",
",",
"m",
")",
";",
"n",
">=",
"0",
"{",
"nonce",
":=",
"seri",
"(",
"lmid",
",",
"hmid",
",",
"uint",
"(",
"n",
")",
")",
"\n",
"return",
"nonce",
",",
"i",
"*",
"64",
",",
"n",
"\n",
"}",
"\n",
"incr",
"(",
"lmid",
",",
"hmid",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"i",
"*",
"64",
",",
"-",
"1",
"\n",
"}"
] | // Loop increments and transforms until checkFun is true. | [
"Loop",
"increments",
"and",
"transforms",
"until",
"checkFun",
"is",
"true",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_go.go#L298-L314 |
306 | iotaledger/iota.go | pow/pow_go.go | goProofOfWork | func goProofOfWork(trytes Trytes, mwm int, optRate chan int64, parallelism ...int) (Trytes, error) {
if trytes == "" {
return "", ErrInvalidTrytesForProofOfWork
}
// if any goroutine finds a nonce, then the cancel flag is set to true
// and thereby all other ongoing Proof-of-Work tasks will halt.
cancelled := false
tr := MustTrytesToTrits(trytes)
c := curl.NewCurlP81().(*curl.Curl)
c.Absorb(tr[:(TransactionTrinarySize - HashTrinarySize)])
copy(c.State, tr[TransactionTrinarySize-HashTrinarySize:])
numGoroutines := proofOfWorkParallelism(parallelism...)
var result Trytes
var rate chan int64
if optRate != nil {
rate = make(chan int64, numGoroutines)
}
exit := make(chan struct{})
nonceChan := make(chan Trytes)
for i := 0; i < numGoroutines; i++ {
go func(i int) {
lmid, hmid := Para(c.State)
lmid[nonceOffset] = PearlDiverMidStateLow0
hmid[nonceOffset] = PearlDiverMidStateHigh0
lmid[nonceOffset+1] = PearlDiverMidStateLow1
hmid[nonceOffset+1] = PearlDiverMidStateHigh1
lmid[nonceOffset+2] = PearlDiverMidStateLow2
hmid[nonceOffset+2] = PearlDiverMidStateHigh2
lmid[nonceOffset+3] = PearlDiverMidStateLow3
hmid[nonceOffset+3] = PearlDiverMidStateHigh3
incrN(i, lmid, hmid)
nonce, r, _ := Loop(lmid, hmid, mwm, &cancelled, check, int(c.Rounds))
if rate != nil {
rate <- int64(math.Abs(float64(r)))
}
if r >= 0 && len(nonce) > 0 {
select {
case <-exit:
case nonceChan <- MustTritsToTrytes(nonce):
cancelled = true
}
}
}(i)
}
if rate != nil {
var rateSum int64
for i := 0; i < numGoroutines; i++ {
rateSum += <-rate
}
optRate <- rateSum
}
result = <-nonceChan
close(exit)
cancelled = true
return result, nil
} | go | func goProofOfWork(trytes Trytes, mwm int, optRate chan int64, parallelism ...int) (Trytes, error) {
if trytes == "" {
return "", ErrInvalidTrytesForProofOfWork
}
// if any goroutine finds a nonce, then the cancel flag is set to true
// and thereby all other ongoing Proof-of-Work tasks will halt.
cancelled := false
tr := MustTrytesToTrits(trytes)
c := curl.NewCurlP81().(*curl.Curl)
c.Absorb(tr[:(TransactionTrinarySize - HashTrinarySize)])
copy(c.State, tr[TransactionTrinarySize-HashTrinarySize:])
numGoroutines := proofOfWorkParallelism(parallelism...)
var result Trytes
var rate chan int64
if optRate != nil {
rate = make(chan int64, numGoroutines)
}
exit := make(chan struct{})
nonceChan := make(chan Trytes)
for i := 0; i < numGoroutines; i++ {
go func(i int) {
lmid, hmid := Para(c.State)
lmid[nonceOffset] = PearlDiverMidStateLow0
hmid[nonceOffset] = PearlDiverMidStateHigh0
lmid[nonceOffset+1] = PearlDiverMidStateLow1
hmid[nonceOffset+1] = PearlDiverMidStateHigh1
lmid[nonceOffset+2] = PearlDiverMidStateLow2
hmid[nonceOffset+2] = PearlDiverMidStateHigh2
lmid[nonceOffset+3] = PearlDiverMidStateLow3
hmid[nonceOffset+3] = PearlDiverMidStateHigh3
incrN(i, lmid, hmid)
nonce, r, _ := Loop(lmid, hmid, mwm, &cancelled, check, int(c.Rounds))
if rate != nil {
rate <- int64(math.Abs(float64(r)))
}
if r >= 0 && len(nonce) > 0 {
select {
case <-exit:
case nonceChan <- MustTritsToTrytes(nonce):
cancelled = true
}
}
}(i)
}
if rate != nil {
var rateSum int64
for i := 0; i < numGoroutines; i++ {
rateSum += <-rate
}
optRate <- rateSum
}
result = <-nonceChan
close(exit)
cancelled = true
return result, nil
} | [
"func",
"goProofOfWork",
"(",
"trytes",
"Trytes",
",",
"mwm",
"int",
",",
"optRate",
"chan",
"int64",
",",
"parallelism",
"...",
"int",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"if",
"trytes",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"ErrInvalidTrytesForProofOfWork",
"\n",
"}",
"\n\n",
"// if any goroutine finds a nonce, then the cancel flag is set to true",
"// and thereby all other ongoing Proof-of-Work tasks will halt.",
"cancelled",
":=",
"false",
"\n\n",
"tr",
":=",
"MustTrytesToTrits",
"(",
"trytes",
")",
"\n\n",
"c",
":=",
"curl",
".",
"NewCurlP81",
"(",
")",
".",
"(",
"*",
"curl",
".",
"Curl",
")",
"\n",
"c",
".",
"Absorb",
"(",
"tr",
"[",
":",
"(",
"TransactionTrinarySize",
"-",
"HashTrinarySize",
")",
"]",
")",
"\n",
"copy",
"(",
"c",
".",
"State",
",",
"tr",
"[",
"TransactionTrinarySize",
"-",
"HashTrinarySize",
":",
"]",
")",
"\n\n",
"numGoroutines",
":=",
"proofOfWorkParallelism",
"(",
"parallelism",
"...",
")",
"\n",
"var",
"result",
"Trytes",
"\n",
"var",
"rate",
"chan",
"int64",
"\n",
"if",
"optRate",
"!=",
"nil",
"{",
"rate",
"=",
"make",
"(",
"chan",
"int64",
",",
"numGoroutines",
")",
"\n",
"}",
"\n",
"exit",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"nonceChan",
":=",
"make",
"(",
"chan",
"Trytes",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"numGoroutines",
";",
"i",
"++",
"{",
"go",
"func",
"(",
"i",
"int",
")",
"{",
"lmid",
",",
"hmid",
":=",
"Para",
"(",
"c",
".",
"State",
")",
"\n",
"lmid",
"[",
"nonceOffset",
"]",
"=",
"PearlDiverMidStateLow0",
"\n",
"hmid",
"[",
"nonceOffset",
"]",
"=",
"PearlDiverMidStateHigh0",
"\n",
"lmid",
"[",
"nonceOffset",
"+",
"1",
"]",
"=",
"PearlDiverMidStateLow1",
"\n",
"hmid",
"[",
"nonceOffset",
"+",
"1",
"]",
"=",
"PearlDiverMidStateHigh1",
"\n",
"lmid",
"[",
"nonceOffset",
"+",
"2",
"]",
"=",
"PearlDiverMidStateLow2",
"\n",
"hmid",
"[",
"nonceOffset",
"+",
"2",
"]",
"=",
"PearlDiverMidStateHigh2",
"\n",
"lmid",
"[",
"nonceOffset",
"+",
"3",
"]",
"=",
"PearlDiverMidStateLow3",
"\n",
"hmid",
"[",
"nonceOffset",
"+",
"3",
"]",
"=",
"PearlDiverMidStateHigh3",
"\n\n",
"incrN",
"(",
"i",
",",
"lmid",
",",
"hmid",
")",
"\n",
"nonce",
",",
"r",
",",
"_",
":=",
"Loop",
"(",
"lmid",
",",
"hmid",
",",
"mwm",
",",
"&",
"cancelled",
",",
"check",
",",
"int",
"(",
"c",
".",
"Rounds",
")",
")",
"\n\n",
"if",
"rate",
"!=",
"nil",
"{",
"rate",
"<-",
"int64",
"(",
"math",
".",
"Abs",
"(",
"float64",
"(",
"r",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"r",
">=",
"0",
"&&",
"len",
"(",
"nonce",
")",
">",
"0",
"{",
"select",
"{",
"case",
"<-",
"exit",
":",
"case",
"nonceChan",
"<-",
"MustTritsToTrytes",
"(",
"nonce",
")",
":",
"cancelled",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
"i",
")",
"\n",
"}",
"\n\n",
"if",
"rate",
"!=",
"nil",
"{",
"var",
"rateSum",
"int64",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"numGoroutines",
";",
"i",
"++",
"{",
"rateSum",
"+=",
"<-",
"rate",
"\n",
"}",
"\n",
"optRate",
"<-",
"rateSum",
"\n",
"}",
"\n\n",
"result",
"=",
"<-",
"nonceChan",
"\n",
"close",
"(",
"exit",
")",
"\n",
"cancelled",
"=",
"true",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // implementation of Proof-of-Work in Go | [
"implementation",
"of",
"Proof",
"-",
"of",
"-",
"Work",
"in",
"Go"
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_go.go#L317-L381 |
307 | iotaledger/iota.go | account/deposit/deposit.go | AsMagnetLink | func (dc *CDA) AsMagnetLink() (string, error) {
var expectedAmount uint64
if dc.ExpectedAmount != nil {
expectedAmount = *dc.ExpectedAmount
}
checksum, err := dc.Checksum()
if err != nil {
return "", err
}
var multiUse int
if dc.MultiUse {
multiUse = 1
}
return fmt.Sprintf(MagnetLinkFormat,
dc.Address[:consts.HashTrytesSize],
checksum[consts.HashTrytesSize-consts.AddressChecksumTrytesSize:consts.HashTrytesSize],
MagnetLinkTimeoutField, dc.TimeoutAt.Unix(),
MagnetLinkMultiUseField, multiUse,
MagnetLinkExpectedAmountField, expectedAmount), nil
} | go | func (dc *CDA) AsMagnetLink() (string, error) {
var expectedAmount uint64
if dc.ExpectedAmount != nil {
expectedAmount = *dc.ExpectedAmount
}
checksum, err := dc.Checksum()
if err != nil {
return "", err
}
var multiUse int
if dc.MultiUse {
multiUse = 1
}
return fmt.Sprintf(MagnetLinkFormat,
dc.Address[:consts.HashTrytesSize],
checksum[consts.HashTrytesSize-consts.AddressChecksumTrytesSize:consts.HashTrytesSize],
MagnetLinkTimeoutField, dc.TimeoutAt.Unix(),
MagnetLinkMultiUseField, multiUse,
MagnetLinkExpectedAmountField, expectedAmount), nil
} | [
"func",
"(",
"dc",
"*",
"CDA",
")",
"AsMagnetLink",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"expectedAmount",
"uint64",
"\n",
"if",
"dc",
".",
"ExpectedAmount",
"!=",
"nil",
"{",
"expectedAmount",
"=",
"*",
"dc",
".",
"ExpectedAmount",
"\n",
"}",
"\n",
"checksum",
",",
"err",
":=",
"dc",
".",
"Checksum",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"var",
"multiUse",
"int",
"\n",
"if",
"dc",
".",
"MultiUse",
"{",
"multiUse",
"=",
"1",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"MagnetLinkFormat",
",",
"dc",
".",
"Address",
"[",
":",
"consts",
".",
"HashTrytesSize",
"]",
",",
"checksum",
"[",
"consts",
".",
"HashTrytesSize",
"-",
"consts",
".",
"AddressChecksumTrytesSize",
":",
"consts",
".",
"HashTrytesSize",
"]",
",",
"MagnetLinkTimeoutField",
",",
"dc",
".",
"TimeoutAt",
".",
"Unix",
"(",
")",
",",
"MagnetLinkMultiUseField",
",",
"multiUse",
",",
"MagnetLinkExpectedAmountField",
",",
"expectedAmount",
")",
",",
"nil",
"\n",
"}"
] | // AsMagnetLink converts the conditions into a magnet link URL. | [
"AsMagnetLink",
"converts",
"the",
"conditions",
"into",
"a",
"magnet",
"link",
"URL",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/deposit/deposit.go#L36-L56 |
308 | iotaledger/iota.go | account/deposit/deposit.go | AsTransfer | func (dc *CDA) AsTransfer() bundle.Transfer {
return bundle.Transfer{
Address: dc.Address,
Value: func() uint64 {
if dc.ExpectedAmount == nil {
return 0
}
return *dc.ExpectedAmount
}(),
}
} | go | func (dc *CDA) AsTransfer() bundle.Transfer {
return bundle.Transfer{
Address: dc.Address,
Value: func() uint64 {
if dc.ExpectedAmount == nil {
return 0
}
return *dc.ExpectedAmount
}(),
}
} | [
"func",
"(",
"dc",
"*",
"CDA",
")",
"AsTransfer",
"(",
")",
"bundle",
".",
"Transfer",
"{",
"return",
"bundle",
".",
"Transfer",
"{",
"Address",
":",
"dc",
".",
"Address",
",",
"Value",
":",
"func",
"(",
")",
"uint64",
"{",
"if",
"dc",
".",
"ExpectedAmount",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"*",
"dc",
".",
"ExpectedAmount",
"\n",
"}",
"(",
")",
",",
"}",
"\n",
"}"
] | // AsTransfer converts the conditional deposit address into a transfer object. | [
"AsTransfer",
"converts",
"the",
"conditional",
"deposit",
"address",
"into",
"a",
"transfer",
"object",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/deposit/deposit.go#L59-L69 |
309 | iotaledger/iota.go | account/deposit/deposit.go | Checksum | func (dc *CDA) Checksum() (Trytes, error) {
// checksum formula:
// Checksum = CurlHash(
// CurlHash(address_trits)[:134] +
// PadTrits27(timeout_value_trits) +
// MultiUse(0/1) +
// PadTrits81(amount_value_trits)
// )
if err := ValidateConditions(&dc.Conditions); err != nil {
return "", err
}
addrTrits, err := TrytesToTrits(dc.Address[:consts.HashTrytesSize])
if err != nil {
return "", err
}
c := curl.NewCurlP81()
if err := c.Absorb(addrTrits); err != nil {
return "", err
}
addrChecksumTrits, err := c.Squeeze(consts.HashTrinarySize)
if err != nil {
return "", err
}
timeoutAtTrits := PadTrits(IntToTrits(dc.TimeoutAt.Unix()), 27)
var expectedAmountTrits Trits
if dc.ExpectedAmount != nil {
expectedAmountTrits = PadTrits(IntToTrits(int64(*dc.ExpectedAmount)), 81)
} else {
expectedAmountTrits = PadTrits(expectedAmountTrits, 81)
}
var multiUse int8
if dc.MultiUse {
multiUse = 1
}
input := make(Trits, 0)
input = append(input, addrChecksumTrits[:134]...)
input = append(input, timeoutAtTrits...)
input = append(input, multiUse)
input = append(input, expectedAmountTrits...)
c.Reset()
if err := c.Absorb(input); err != nil {
return "", err
}
checksumTrits, err := c.Squeeze(consts.HashTrinarySize)
if err != nil {
return "", err
}
return TritsToTrytes(checksumTrits)
} | go | func (dc *CDA) Checksum() (Trytes, error) {
// checksum formula:
// Checksum = CurlHash(
// CurlHash(address_trits)[:134] +
// PadTrits27(timeout_value_trits) +
// MultiUse(0/1) +
// PadTrits81(amount_value_trits)
// )
if err := ValidateConditions(&dc.Conditions); err != nil {
return "", err
}
addrTrits, err := TrytesToTrits(dc.Address[:consts.HashTrytesSize])
if err != nil {
return "", err
}
c := curl.NewCurlP81()
if err := c.Absorb(addrTrits); err != nil {
return "", err
}
addrChecksumTrits, err := c.Squeeze(consts.HashTrinarySize)
if err != nil {
return "", err
}
timeoutAtTrits := PadTrits(IntToTrits(dc.TimeoutAt.Unix()), 27)
var expectedAmountTrits Trits
if dc.ExpectedAmount != nil {
expectedAmountTrits = PadTrits(IntToTrits(int64(*dc.ExpectedAmount)), 81)
} else {
expectedAmountTrits = PadTrits(expectedAmountTrits, 81)
}
var multiUse int8
if dc.MultiUse {
multiUse = 1
}
input := make(Trits, 0)
input = append(input, addrChecksumTrits[:134]...)
input = append(input, timeoutAtTrits...)
input = append(input, multiUse)
input = append(input, expectedAmountTrits...)
c.Reset()
if err := c.Absorb(input); err != nil {
return "", err
}
checksumTrits, err := c.Squeeze(consts.HashTrinarySize)
if err != nil {
return "", err
}
return TritsToTrytes(checksumTrits)
} | [
"func",
"(",
"dc",
"*",
"CDA",
")",
"Checksum",
"(",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"// checksum formula:",
"// Checksum = CurlHash(",
"// \tCurlHash(address_trits)[:134] +",
"// \tPadTrits27(timeout_value_trits) +",
"// \tMultiUse(0/1) +",
"// \tPadTrits81(amount_value_trits)",
"// )",
"if",
"err",
":=",
"ValidateConditions",
"(",
"&",
"dc",
".",
"Conditions",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"addrTrits",
",",
"err",
":=",
"TrytesToTrits",
"(",
"dc",
".",
"Address",
"[",
":",
"consts",
".",
"HashTrytesSize",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"c",
":=",
"curl",
".",
"NewCurlP81",
"(",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"Absorb",
"(",
"addrTrits",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"addrChecksumTrits",
",",
"err",
":=",
"c",
".",
"Squeeze",
"(",
"consts",
".",
"HashTrinarySize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"timeoutAtTrits",
":=",
"PadTrits",
"(",
"IntToTrits",
"(",
"dc",
".",
"TimeoutAt",
".",
"Unix",
"(",
")",
")",
",",
"27",
")",
"\n",
"var",
"expectedAmountTrits",
"Trits",
"\n",
"if",
"dc",
".",
"ExpectedAmount",
"!=",
"nil",
"{",
"expectedAmountTrits",
"=",
"PadTrits",
"(",
"IntToTrits",
"(",
"int64",
"(",
"*",
"dc",
".",
"ExpectedAmount",
")",
")",
",",
"81",
")",
"\n",
"}",
"else",
"{",
"expectedAmountTrits",
"=",
"PadTrits",
"(",
"expectedAmountTrits",
",",
"81",
")",
"\n",
"}",
"\n",
"var",
"multiUse",
"int8",
"\n",
"if",
"dc",
".",
"MultiUse",
"{",
"multiUse",
"=",
"1",
"\n",
"}",
"\n",
"input",
":=",
"make",
"(",
"Trits",
",",
"0",
")",
"\n",
"input",
"=",
"append",
"(",
"input",
",",
"addrChecksumTrits",
"[",
":",
"134",
"]",
"...",
")",
"\n",
"input",
"=",
"append",
"(",
"input",
",",
"timeoutAtTrits",
"...",
")",
"\n",
"input",
"=",
"append",
"(",
"input",
",",
"multiUse",
")",
"\n",
"input",
"=",
"append",
"(",
"input",
",",
"expectedAmountTrits",
"...",
")",
"\n",
"c",
".",
"Reset",
"(",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"Absorb",
"(",
"input",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"checksumTrits",
",",
"err",
":=",
"c",
".",
"Squeeze",
"(",
"consts",
".",
"HashTrinarySize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"TritsToTrytes",
"(",
"checksumTrits",
")",
"\n",
"}"
] | // Checksum returns the checksum of the the CDA. | [
"Checksum",
"returns",
"the",
"checksum",
"of",
"the",
"the",
"CDA",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/deposit/deposit.go#L72-L120 |
310 | iotaledger/iota.go | account/deposit/deposit.go | ParseMagnetLink | func ParseMagnetLink(cdaMagnetLink string) (*CDA, error) {
link, err := url.Parse(cdaMagnetLink)
if err != nil {
return nil, err
}
query := link.Query()
cda := &CDA{}
if len(link.Host) != consts.AddressWithChecksumTrytesSize {
return nil, errors.Wrap(ErrAddressInvalid, "host/address part of magnet-link must be 90 trytes long")
}
addrWithChecksum, err := checksum.AddChecksum(link.Host[:consts.HashTrytesSize], true, consts.AddressChecksumTrytesSize)
if err != nil {
return nil, err
}
cda.Address = addrWithChecksum
expiresSeconds, err := strconv.ParseInt(query.Get(MagnetLinkTimeoutField), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "invalid expire timestamp")
}
expire := time.Unix(expiresSeconds, 0).UTC()
cda.TimeoutAt = &expire
cda.MultiUse = query.Get(MagnetLinkMultiUseField) == "1"
expectedAmount, err := strconv.ParseUint(query.Get(MagnetLinkExpectedAmountField), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "invalid expected amount")
}
cda.ExpectedAmount = &expectedAmount
computedChecksum, err := cda.Checksum()
if err != nil {
return nil, err
}
magnetLinkChecksum := link.Host[consts.HashTrytesSize:]
if computedChecksum[consts.HashTrytesSize-consts.AddressChecksumTrytesSize:consts.HashTrytesSize] != magnetLinkChecksum {
return nil, ErrMagnetLinkChecksumInvalid
}
if err := ValidateConditions(&cda.Conditions); err != nil {
return nil, err
}
return cda, nil
} | go | func ParseMagnetLink(cdaMagnetLink string) (*CDA, error) {
link, err := url.Parse(cdaMagnetLink)
if err != nil {
return nil, err
}
query := link.Query()
cda := &CDA{}
if len(link.Host) != consts.AddressWithChecksumTrytesSize {
return nil, errors.Wrap(ErrAddressInvalid, "host/address part of magnet-link must be 90 trytes long")
}
addrWithChecksum, err := checksum.AddChecksum(link.Host[:consts.HashTrytesSize], true, consts.AddressChecksumTrytesSize)
if err != nil {
return nil, err
}
cda.Address = addrWithChecksum
expiresSeconds, err := strconv.ParseInt(query.Get(MagnetLinkTimeoutField), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "invalid expire timestamp")
}
expire := time.Unix(expiresSeconds, 0).UTC()
cda.TimeoutAt = &expire
cda.MultiUse = query.Get(MagnetLinkMultiUseField) == "1"
expectedAmount, err := strconv.ParseUint(query.Get(MagnetLinkExpectedAmountField), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "invalid expected amount")
}
cda.ExpectedAmount = &expectedAmount
computedChecksum, err := cda.Checksum()
if err != nil {
return nil, err
}
magnetLinkChecksum := link.Host[consts.HashTrytesSize:]
if computedChecksum[consts.HashTrytesSize-consts.AddressChecksumTrytesSize:consts.HashTrytesSize] != magnetLinkChecksum {
return nil, ErrMagnetLinkChecksumInvalid
}
if err := ValidateConditions(&cda.Conditions); err != nil {
return nil, err
}
return cda, nil
} | [
"func",
"ParseMagnetLink",
"(",
"cdaMagnetLink",
"string",
")",
"(",
"*",
"CDA",
",",
"error",
")",
"{",
"link",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"cdaMagnetLink",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"query",
":=",
"link",
".",
"Query",
"(",
")",
"\n",
"cda",
":=",
"&",
"CDA",
"{",
"}",
"\n",
"if",
"len",
"(",
"link",
".",
"Host",
")",
"!=",
"consts",
".",
"AddressWithChecksumTrytesSize",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"ErrAddressInvalid",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"addrWithChecksum",
",",
"err",
":=",
"checksum",
".",
"AddChecksum",
"(",
"link",
".",
"Host",
"[",
":",
"consts",
".",
"HashTrytesSize",
"]",
",",
"true",
",",
"consts",
".",
"AddressChecksumTrytesSize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cda",
".",
"Address",
"=",
"addrWithChecksum",
"\n",
"expiresSeconds",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"query",
".",
"Get",
"(",
"MagnetLinkTimeoutField",
")",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"expire",
":=",
"time",
".",
"Unix",
"(",
"expiresSeconds",
",",
"0",
")",
".",
"UTC",
"(",
")",
"\n",
"cda",
".",
"TimeoutAt",
"=",
"&",
"expire",
"\n",
"cda",
".",
"MultiUse",
"=",
"query",
".",
"Get",
"(",
"MagnetLinkMultiUseField",
")",
"==",
"\"",
"\"",
"\n",
"expectedAmount",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"query",
".",
"Get",
"(",
"MagnetLinkExpectedAmountField",
")",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cda",
".",
"ExpectedAmount",
"=",
"&",
"expectedAmount",
"\n\n",
"computedChecksum",
",",
"err",
":=",
"cda",
".",
"Checksum",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"magnetLinkChecksum",
":=",
"link",
".",
"Host",
"[",
"consts",
".",
"HashTrytesSize",
":",
"]",
"\n",
"if",
"computedChecksum",
"[",
"consts",
".",
"HashTrytesSize",
"-",
"consts",
".",
"AddressChecksumTrytesSize",
":",
"consts",
".",
"HashTrytesSize",
"]",
"!=",
"magnetLinkChecksum",
"{",
"return",
"nil",
",",
"ErrMagnetLinkChecksumInvalid",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ValidateConditions",
"(",
"&",
"cda",
".",
"Conditions",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"cda",
",",
"nil",
"\n",
"}"
] | // ParseMagnetLink parses the given magnet link URL. | [
"ParseMagnetLink",
"parses",
"the",
"given",
"magnet",
"link",
"URL",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/deposit/deposit.go#L123-L163 |
311 | iotaledger/iota.go | account/deposit/deposit.go | ValidateConditions | func ValidateConditions(conds *Conditions) error {
if conds.ExpectedAmount != nil {
if *conds.ExpectedAmount > 0 && conds.MultiUse {
return errors.Wrap(ErrInvalidDepositAddressOptions, "expected amount and multi use are mutually exclusive")
}
}
return nil
} | go | func ValidateConditions(conds *Conditions) error {
if conds.ExpectedAmount != nil {
if *conds.ExpectedAmount > 0 && conds.MultiUse {
return errors.Wrap(ErrInvalidDepositAddressOptions, "expected amount and multi use are mutually exclusive")
}
}
return nil
} | [
"func",
"ValidateConditions",
"(",
"conds",
"*",
"Conditions",
")",
"error",
"{",
"if",
"conds",
".",
"ExpectedAmount",
"!=",
"nil",
"{",
"if",
"*",
"conds",
".",
"ExpectedAmount",
">",
"0",
"&&",
"conds",
".",
"MultiUse",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"ErrInvalidDepositAddressOptions",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ValidateConditions validates the deposit conditions. | [
"ValidateConditions",
"validates",
"the",
"deposit",
"conditions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/deposit/deposit.go#L182-L189 |
312 | iotaledger/iota.go | guards/guards.go | IsAttachedTrytes | func IsAttachedTrytes(trytes Trytes) bool {
return IsTrytesOfExactLength(trytes, TransactionTrytesSize) && !IsEmptyTrytes(trytes[(TransactionTrytesSize)-3*HashTrytesSize:])
} | go | func IsAttachedTrytes(trytes Trytes) bool {
return IsTrytesOfExactLength(trytes, TransactionTrytesSize) && !IsEmptyTrytes(trytes[(TransactionTrytesSize)-3*HashTrytesSize:])
} | [
"func",
"IsAttachedTrytes",
"(",
"trytes",
"Trytes",
")",
"bool",
"{",
"return",
"IsTrytesOfExactLength",
"(",
"trytes",
",",
"TransactionTrytesSize",
")",
"&&",
"!",
"IsEmptyTrytes",
"(",
"trytes",
"[",
"(",
"TransactionTrytesSize",
")",
"-",
"3",
"*",
"HashTrytesSize",
":",
"]",
")",
"\n",
"}"
] | // IsAttachedTrytes checks if input is valid attached transaction trytes.
// For attached transactions the last 243 trytes are non-zero. | [
"IsAttachedTrytes",
"checks",
"if",
"input",
"is",
"valid",
"attached",
"transaction",
"trytes",
".",
"For",
"attached",
"transactions",
"the",
"last",
"243",
"trytes",
"are",
"non",
"-",
"zero",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/guards/guards.go#L114-L116 |
313 | iotaledger/iota.go | pow/pow_sse.go | SSEProofOfWork | func SSEProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
return sseProofOfwork(trytes, mwm, nil, parallelism...)
} | go | func SSEProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
return sseProofOfwork(trytes, mwm, nil, parallelism...)
} | [
"func",
"SSEProofOfWork",
"(",
"trytes",
"Trytes",
",",
"mwm",
"int",
",",
"parallelism",
"...",
"int",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"return",
"sseProofOfwork",
"(",
"trytes",
",",
"mwm",
",",
"nil",
",",
"parallelism",
"...",
")",
"\n",
"}"
] | // SSEProofOfWork does proof of work on the given trytes using SSE2 instructions. | [
"SSEProofOfWork",
"does",
"proof",
"of",
"work",
"on",
"the",
"given",
"trytes",
"using",
"SSE2",
"instructions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_sse.go#L263-L265 |
314 | iotaledger/iota.go | account/event/listener/callback_listener.go | NewCallbackEventListener | func NewCallbackEventListener(em event.EventMachine) *CallbackEventListener {
return &CallbackEventListener{em: em, ids: []uint64{}}
} | go | func NewCallbackEventListener(em event.EventMachine) *CallbackEventListener {
return &CallbackEventListener{em: em, ids: []uint64{}}
} | [
"func",
"NewCallbackEventListener",
"(",
"em",
"event",
".",
"EventMachine",
")",
"*",
"CallbackEventListener",
"{",
"return",
"&",
"CallbackEventListener",
"{",
"em",
":",
"em",
",",
"ids",
":",
"[",
"]",
"uint64",
"{",
"}",
"}",
"\n",
"}"
] | // NewCallbackEventListener creates a new CallbackEventListener using the given EventMachine. | [
"NewCallbackEventListener",
"creates",
"a",
"new",
"CallbackEventListener",
"using",
"the",
"given",
"EventMachine",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/callback_listener.go#L19-L21 |
315 | iotaledger/iota.go | account/event/listener/callback_listener.go | RegPromotions | func (el *CallbackEventListener) RegPromotions(f PromotionReattachmentEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(*promoter.PromotionReattachmentEvent))
}, promoter.EventPromotion))
} | go | func (el *CallbackEventListener) RegPromotions(f PromotionReattachmentEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(*promoter.PromotionReattachmentEvent))
}, promoter.EventPromotion))
} | [
"func",
"(",
"el",
"*",
"CallbackEventListener",
")",
"RegPromotions",
"(",
"f",
"PromotionReattachmentEventCallback",
")",
"{",
"el",
".",
"ids",
"=",
"append",
"(",
"el",
".",
"ids",
",",
"el",
".",
"em",
".",
"RegisterListener",
"(",
"func",
"(",
"data",
"interface",
"{",
"}",
")",
"{",
"f",
"(",
"data",
".",
"(",
"*",
"promoter",
".",
"PromotionReattachmentEvent",
")",
")",
"\n",
"}",
",",
"promoter",
".",
"EventPromotion",
")",
")",
"\n",
"}"
] | // RegPromotions registers the given callback to execute on promotions. | [
"RegPromotions",
"registers",
"the",
"given",
"callback",
"to",
"execute",
"on",
"promotions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/callback_listener.go#L42-L46 |
316 | iotaledger/iota.go | account/event/listener/callback_listener.go | RegReattachments | func (el *CallbackEventListener) RegReattachments(f PromotionReattachmentEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(*promoter.PromotionReattachmentEvent))
}, promoter.EventReattachment))
} | go | func (el *CallbackEventListener) RegReattachments(f PromotionReattachmentEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(*promoter.PromotionReattachmentEvent))
}, promoter.EventReattachment))
} | [
"func",
"(",
"el",
"*",
"CallbackEventListener",
")",
"RegReattachments",
"(",
"f",
"PromotionReattachmentEventCallback",
")",
"{",
"el",
".",
"ids",
"=",
"append",
"(",
"el",
".",
"ids",
",",
"el",
".",
"em",
".",
"RegisterListener",
"(",
"func",
"(",
"data",
"interface",
"{",
"}",
")",
"{",
"f",
"(",
"data",
".",
"(",
"*",
"promoter",
".",
"PromotionReattachmentEvent",
")",
")",
"\n",
"}",
",",
"promoter",
".",
"EventReattachment",
")",
")",
"\n",
"}"
] | // RegReattachments registers the given callback to execute on reattachments. | [
"RegReattachments",
"registers",
"the",
"given",
"callback",
"to",
"execute",
"on",
"reattachments",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/callback_listener.go#L49-L53 |
317 | iotaledger/iota.go | account/event/listener/callback_listener.go | RegSentTransfers | func (el *CallbackEventListener) RegSentTransfers(f BundleEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(bundle.Bundle))
}, event.EventSentTransfer))
} | go | func (el *CallbackEventListener) RegSentTransfers(f BundleEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(bundle.Bundle))
}, event.EventSentTransfer))
} | [
"func",
"(",
"el",
"*",
"CallbackEventListener",
")",
"RegSentTransfers",
"(",
"f",
"BundleEventCallback",
")",
"{",
"el",
".",
"ids",
"=",
"append",
"(",
"el",
".",
"ids",
",",
"el",
".",
"em",
".",
"RegisterListener",
"(",
"func",
"(",
"data",
"interface",
"{",
"}",
")",
"{",
"f",
"(",
"data",
".",
"(",
"bundle",
".",
"Bundle",
")",
")",
"\n",
"}",
",",
"event",
".",
"EventSentTransfer",
")",
")",
"\n",
"}"
] | // RegSentTransfers registers the given callback to execute when a transfer is sent off. | [
"RegSentTransfers",
"registers",
"the",
"given",
"callback",
"to",
"execute",
"when",
"a",
"transfer",
"is",
"sent",
"off",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/callback_listener.go#L56-L60 |
318 | iotaledger/iota.go | account/event/listener/callback_listener.go | RegConfirmedTransfers | func (el *CallbackEventListener) RegConfirmedTransfers(f BundleEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(bundle.Bundle))
}, poller.EventTransferConfirmed))
} | go | func (el *CallbackEventListener) RegConfirmedTransfers(f BundleEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(bundle.Bundle))
}, poller.EventTransferConfirmed))
} | [
"func",
"(",
"el",
"*",
"CallbackEventListener",
")",
"RegConfirmedTransfers",
"(",
"f",
"BundleEventCallback",
")",
"{",
"el",
".",
"ids",
"=",
"append",
"(",
"el",
".",
"ids",
",",
"el",
".",
"em",
".",
"RegisterListener",
"(",
"func",
"(",
"data",
"interface",
"{",
"}",
")",
"{",
"f",
"(",
"data",
".",
"(",
"bundle",
".",
"Bundle",
")",
")",
"\n",
"}",
",",
"poller",
".",
"EventTransferConfirmed",
")",
")",
"\n",
"}"
] | // RegConfirmedTransfers registers the given callback to execute when a transfer got confirmed. | [
"RegConfirmedTransfers",
"registers",
"the",
"given",
"callback",
"to",
"execute",
"when",
"a",
"transfer",
"got",
"confirmed",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/callback_listener.go#L63-L67 |
319 | iotaledger/iota.go | account/event/listener/callback_listener.go | RegReceivingDeposits | func (el *CallbackEventListener) RegReceivingDeposits(f BundleEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(bundle.Bundle))
}, poller.EventReceivingDeposit))
} | go | func (el *CallbackEventListener) RegReceivingDeposits(f BundleEventCallback) {
el.ids = append(el.ids, el.em.RegisterListener(func(data interface{}) {
f(data.(bundle.Bundle))
}, poller.EventReceivingDeposit))
} | [
"func",
"(",
"el",
"*",
"CallbackEventListener",
")",
"RegReceivingDeposits",
"(",
"f",
"BundleEventCallback",
")",
"{",
"el",
".",
"ids",
"=",
"append",
"(",
"el",
".",
"ids",
",",
"el",
".",
"em",
".",
"RegisterListener",
"(",
"func",
"(",
"data",
"interface",
"{",
"}",
")",
"{",
"f",
"(",
"data",
".",
"(",
"bundle",
".",
"Bundle",
")",
")",
"\n",
"}",
",",
"poller",
".",
"EventReceivingDeposit",
")",
")",
"\n",
"}"
] | // RegReceivingDeposits registers the given callback to execute when a new deposit is being received. | [
"RegReceivingDeposits",
"registers",
"the",
"given",
"callback",
"to",
"execute",
"when",
"a",
"new",
"deposit",
"is",
"being",
"received",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/event/listener/callback_listener.go#L70-L74 |
320 | iotaledger/iota.go | api/wrappers.go | BroadcastBundle | func (api *API) BroadcastBundle(tailTxHash Hash) ([]Trytes, error) {
if err := Validate(ValidateTransactionHashes(tailTxHash)); err != nil {
return nil, err
}
bndl, err := api.GetBundle(tailTxHash)
if err != nil {
return nil, err
}
trytes := transaction.MustFinalTransactionTrytes(bndl)
return api.BroadcastTransactions(trytes...)
} | go | func (api *API) BroadcastBundle(tailTxHash Hash) ([]Trytes, error) {
if err := Validate(ValidateTransactionHashes(tailTxHash)); err != nil {
return nil, err
}
bndl, err := api.GetBundle(tailTxHash)
if err != nil {
return nil, err
}
trytes := transaction.MustFinalTransactionTrytes(bndl)
return api.BroadcastTransactions(trytes...)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"BroadcastBundle",
"(",
"tailTxHash",
"Hash",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateTransactionHashes",
"(",
"tailTxHash",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"bndl",
",",
"err",
":=",
"api",
".",
"GetBundle",
"(",
"tailTxHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"trytes",
":=",
"transaction",
".",
"MustFinalTransactionTrytes",
"(",
"bndl",
")",
"\n",
"return",
"api",
".",
"BroadcastTransactions",
"(",
"trytes",
"...",
")",
"\n",
"}"
] | // BroadcastBundle re-broadcasts all transactions in a bundle given the tail transaction hash.
// It might be useful when transactions did not properly propagate, particularly in the case of large bundles. | [
"BroadcastBundle",
"re",
"-",
"broadcasts",
"all",
"transactions",
"in",
"a",
"bundle",
"given",
"the",
"tail",
"transaction",
"hash",
".",
"It",
"might",
"be",
"useful",
"when",
"transactions",
"did",
"not",
"properly",
"propagate",
"particularly",
"in",
"the",
"case",
"of",
"large",
"bundles",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L29-L40 |
321 | iotaledger/iota.go | api/wrappers.go | GetBundle | func (api *API) GetBundle(tailTxHash Hash) (bundle.Bundle, error) {
if err := Validate(ValidateTransactionHashes(tailTxHash)); err != nil {
return nil, err
}
var err error
bndl := bundle.Bundle{}
bndl, err = api.TraverseBundle(tailTxHash, bndl)
if err != nil {
return nil, err
}
if err := bundle.ValidBundle(bndl); err != nil {
return nil, err
}
return bndl, err
} | go | func (api *API) GetBundle(tailTxHash Hash) (bundle.Bundle, error) {
if err := Validate(ValidateTransactionHashes(tailTxHash)); err != nil {
return nil, err
}
var err error
bndl := bundle.Bundle{}
bndl, err = api.TraverseBundle(tailTxHash, bndl)
if err != nil {
return nil, err
}
if err := bundle.ValidBundle(bndl); err != nil {
return nil, err
}
return bndl, err
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetBundle",
"(",
"tailTxHash",
"Hash",
")",
"(",
"bundle",
".",
"Bundle",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateTransactionHashes",
"(",
"tailTxHash",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"bndl",
":=",
"bundle",
".",
"Bundle",
"{",
"}",
"\n",
"bndl",
",",
"err",
"=",
"api",
".",
"TraverseBundle",
"(",
"tailTxHash",
",",
"bndl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"bundle",
".",
"ValidBundle",
"(",
"bndl",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"bndl",
",",
"err",
"\n",
"}"
] | // GetBundle fetches and validates the bundle given a tail transaction hash by calling TraverseBundle
// and traversing through trunk transactions. | [
"GetBundle",
"fetches",
"and",
"validates",
"the",
"bundle",
"given",
"a",
"tail",
"transaction",
"hash",
"by",
"calling",
"TraverseBundle",
"and",
"traversing",
"through",
"trunk",
"transactions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L150-L164 |
322 | iotaledger/iota.go | api/wrappers.go | GetBundlesFromAddresses | func (api *API) GetBundlesFromAddresses(addresses Hashes, inclusionState ...bool) (bundle.Bundles, error) {
txs, err := api.FindTransactionObjects(FindTransactionsQuery{Addresses: addresses})
if err != nil {
return nil, err
}
if len(txs) == 0 {
return bundle.Bundles{}, nil
}
// misuse as a set
bundleHashesSet := map[Hash]struct{}{}
for i := range txs {
bundleHashesSet[txs[i].Bundle] = struct{}{}
}
bundleHashes := make(Hashes, len(bundleHashesSet))
i := 0
for hash := range bundleHashesSet {
bundleHashes[i] = hash
i++
}
allTxs, err := api.FindTransactionObjects(FindTransactionsQuery{Bundles: bundleHashes})
if err != nil {
return nil, err
}
bundles := bundle.GroupTransactionsIntoBundles(allTxs)
sort.Sort(bundle.BundlesByTimestamp(bundles))
if len(inclusionState) > 0 && inclusionState[0] {
// get tail tx hashes
hashes := make(Hashes, len(bundles))
for i := range bundles {
hashes[i] = bundles[i][0].Hash
}
states, err := api.GetLatestInclusion(hashes)
if err != nil {
return nil, err
}
// set confirmed property on each tx
// since bundles are atomic, each tx in the bundle
// as the same 'confirmed' state
for i := range bundles {
bndl := &bundles[i]
for j := range *bndl {
tx := &(*bndl)[j]
tx.Persistence = &states[i]
}
}
}
return bundles, err
} | go | func (api *API) GetBundlesFromAddresses(addresses Hashes, inclusionState ...bool) (bundle.Bundles, error) {
txs, err := api.FindTransactionObjects(FindTransactionsQuery{Addresses: addresses})
if err != nil {
return nil, err
}
if len(txs) == 0 {
return bundle.Bundles{}, nil
}
// misuse as a set
bundleHashesSet := map[Hash]struct{}{}
for i := range txs {
bundleHashesSet[txs[i].Bundle] = struct{}{}
}
bundleHashes := make(Hashes, len(bundleHashesSet))
i := 0
for hash := range bundleHashesSet {
bundleHashes[i] = hash
i++
}
allTxs, err := api.FindTransactionObjects(FindTransactionsQuery{Bundles: bundleHashes})
if err != nil {
return nil, err
}
bundles := bundle.GroupTransactionsIntoBundles(allTxs)
sort.Sort(bundle.BundlesByTimestamp(bundles))
if len(inclusionState) > 0 && inclusionState[0] {
// get tail tx hashes
hashes := make(Hashes, len(bundles))
for i := range bundles {
hashes[i] = bundles[i][0].Hash
}
states, err := api.GetLatestInclusion(hashes)
if err != nil {
return nil, err
}
// set confirmed property on each tx
// since bundles are atomic, each tx in the bundle
// as the same 'confirmed' state
for i := range bundles {
bndl := &bundles[i]
for j := range *bndl {
tx := &(*bndl)[j]
tx.Persistence = &states[i]
}
}
}
return bundles, err
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetBundlesFromAddresses",
"(",
"addresses",
"Hashes",
",",
"inclusionState",
"...",
"bool",
")",
"(",
"bundle",
".",
"Bundles",
",",
"error",
")",
"{",
"txs",
",",
"err",
":=",
"api",
".",
"FindTransactionObjects",
"(",
"FindTransactionsQuery",
"{",
"Addresses",
":",
"addresses",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"txs",
")",
"==",
"0",
"{",
"return",
"bundle",
".",
"Bundles",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"// misuse as a set",
"bundleHashesSet",
":=",
"map",
"[",
"Hash",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n",
"for",
"i",
":=",
"range",
"txs",
"{",
"bundleHashesSet",
"[",
"txs",
"[",
"i",
"]",
".",
"Bundle",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n\n",
"bundleHashes",
":=",
"make",
"(",
"Hashes",
",",
"len",
"(",
"bundleHashesSet",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"hash",
":=",
"range",
"bundleHashesSet",
"{",
"bundleHashes",
"[",
"i",
"]",
"=",
"hash",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"allTxs",
",",
"err",
":=",
"api",
".",
"FindTransactionObjects",
"(",
"FindTransactionsQuery",
"{",
"Bundles",
":",
"bundleHashes",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"bundles",
":=",
"bundle",
".",
"GroupTransactionsIntoBundles",
"(",
"allTxs",
")",
"\n",
"sort",
".",
"Sort",
"(",
"bundle",
".",
"BundlesByTimestamp",
"(",
"bundles",
")",
")",
"\n\n",
"if",
"len",
"(",
"inclusionState",
")",
">",
"0",
"&&",
"inclusionState",
"[",
"0",
"]",
"{",
"// get tail tx hashes",
"hashes",
":=",
"make",
"(",
"Hashes",
",",
"len",
"(",
"bundles",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"bundles",
"{",
"hashes",
"[",
"i",
"]",
"=",
"bundles",
"[",
"i",
"]",
"[",
"0",
"]",
".",
"Hash",
"\n",
"}",
"\n\n",
"states",
",",
"err",
":=",
"api",
".",
"GetLatestInclusion",
"(",
"hashes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// set confirmed property on each tx",
"// since bundles are atomic, each tx in the bundle",
"// as the same 'confirmed' state",
"for",
"i",
":=",
"range",
"bundles",
"{",
"bndl",
":=",
"&",
"bundles",
"[",
"i",
"]",
"\n",
"for",
"j",
":=",
"range",
"*",
"bndl",
"{",
"tx",
":=",
"&",
"(",
"*",
"bndl",
")",
"[",
"j",
"]",
"\n",
"tx",
".",
"Persistence",
"=",
"&",
"states",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"bundles",
",",
"err",
"\n",
"}"
] | // GetBundlesFromAddresses fetches all bundles from the given addresses and optionally sets
// the confirmed property on each transaction using GetLatestInclusion.
// This function does not validate the bundles. | [
"GetBundlesFromAddresses",
"fetches",
"all",
"bundles",
"from",
"the",
"given",
"addresses",
"and",
"optionally",
"sets",
"the",
"confirmed",
"property",
"on",
"each",
"transaction",
"using",
"GetLatestInclusion",
".",
"This",
"function",
"does",
"not",
"validate",
"the",
"bundles",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L169-L224 |
323 | iotaledger/iota.go | api/wrappers.go | IsAddressUsed | func (api *API) IsAddressUsed(address Hash) (bool, error) {
var err1, err2 error
var states []bool
var txs Hashes
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
defer wg.Done()
states, err1 = api.WereAddressesSpentFrom(address)
}()
go func() {
defer wg.Done()
txs, err2 = api.FindTransactions(FindTransactionsQuery{Addresses: Hashes{address}})
}()
wg.Wait()
if err := firstNonNilErr(err1, err2); err != nil {
return false, err
}
if states[0] || len(txs) > 0 {
return true, nil
}
return false, nil
} | go | func (api *API) IsAddressUsed(address Hash) (bool, error) {
var err1, err2 error
var states []bool
var txs Hashes
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
defer wg.Done()
states, err1 = api.WereAddressesSpentFrom(address)
}()
go func() {
defer wg.Done()
txs, err2 = api.FindTransactions(FindTransactionsQuery{Addresses: Hashes{address}})
}()
wg.Wait()
if err := firstNonNilErr(err1, err2); err != nil {
return false, err
}
if states[0] || len(txs) > 0 {
return true, nil
}
return false, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"IsAddressUsed",
"(",
"address",
"Hash",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"err1",
",",
"err2",
"error",
"\n",
"var",
"states",
"[",
"]",
"bool",
"\n",
"var",
"txs",
"Hashes",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"wg",
".",
"Add",
"(",
"2",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"states",
",",
"err1",
"=",
"api",
".",
"WereAddressesSpentFrom",
"(",
"address",
")",
"\n",
"}",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"txs",
",",
"err2",
"=",
"api",
".",
"FindTransactions",
"(",
"FindTransactionsQuery",
"{",
"Addresses",
":",
"Hashes",
"{",
"address",
"}",
"}",
")",
"\n",
"}",
"(",
")",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n\n",
"if",
"err",
":=",
"firstNonNilErr",
"(",
"err1",
",",
"err2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"states",
"[",
"0",
"]",
"||",
"len",
"(",
"txs",
")",
">",
"0",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // IsAddressUsed checks whether an address is used via FindTransactions and WereAddressesSpentFrom. | [
"IsAddressUsed",
"checks",
"whether",
"an",
"address",
"is",
"used",
"via",
"FindTransactions",
"and",
"WereAddressesSpentFrom",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L274-L298 |
324 | iotaledger/iota.go | api/wrappers.go | getUntilFirstUnusedAddress | func getUntilFirstUnusedAddress(
isAddressUsed isAddressUsedFunc,
seed Trytes, index uint64, security SecurityLevel,
returnAll bool,
) (Hashes, error) {
addresses := Hashes{}
for ; ; index++ {
nextAddress, err := address.GenerateAddress(seed, index, security, true)
if err != nil {
return nil, err
}
if returnAll {
addresses = append(addresses, nextAddress)
}
used, err := isAddressUsed(nextAddress)
if err != nil {
return nil, err
}
if used {
continue
}
if !returnAll {
addresses = append(addresses, nextAddress)
}
return addresses, nil
}
} | go | func getUntilFirstUnusedAddress(
isAddressUsed isAddressUsedFunc,
seed Trytes, index uint64, security SecurityLevel,
returnAll bool,
) (Hashes, error) {
addresses := Hashes{}
for ; ; index++ {
nextAddress, err := address.GenerateAddress(seed, index, security, true)
if err != nil {
return nil, err
}
if returnAll {
addresses = append(addresses, nextAddress)
}
used, err := isAddressUsed(nextAddress)
if err != nil {
return nil, err
}
if used {
continue
}
if !returnAll {
addresses = append(addresses, nextAddress)
}
return addresses, nil
}
} | [
"func",
"getUntilFirstUnusedAddress",
"(",
"isAddressUsed",
"isAddressUsedFunc",
",",
"seed",
"Trytes",
",",
"index",
"uint64",
",",
"security",
"SecurityLevel",
",",
"returnAll",
"bool",
",",
")",
"(",
"Hashes",
",",
"error",
")",
"{",
"addresses",
":=",
"Hashes",
"{",
"}",
"\n\n",
"for",
";",
";",
"index",
"++",
"{",
"nextAddress",
",",
"err",
":=",
"address",
".",
"GenerateAddress",
"(",
"seed",
",",
"index",
",",
"security",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"returnAll",
"{",
"addresses",
"=",
"append",
"(",
"addresses",
",",
"nextAddress",
")",
"\n",
"}",
"\n\n",
"used",
",",
"err",
":=",
"isAddressUsed",
"(",
"nextAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"used",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"!",
"returnAll",
"{",
"addresses",
"=",
"append",
"(",
"addresses",
",",
"nextAddress",
")",
"\n",
"}",
"\n\n",
"return",
"addresses",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // computes after a best effort method the first unused addresses | [
"computes",
"after",
"a",
"best",
"effort",
"method",
"the",
"first",
"unused",
"addresses"
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L303-L335 |
325 | iotaledger/iota.go | api/wrappers.go | GetTransactionObjects | func (api *API) GetTransactionObjects(hashes ...Hash) (transaction.Transactions, error) {
if err := Validate(ValidateTransactionHashes(hashes...)); err != nil {
return nil, err
}
trytes, err := api.GetTrytes(hashes...)
if err != nil {
return nil, err
}
return transaction.AsTransactionObjects(trytes, hashes)
} | go | func (api *API) GetTransactionObjects(hashes ...Hash) (transaction.Transactions, error) {
if err := Validate(ValidateTransactionHashes(hashes...)); err != nil {
return nil, err
}
trytes, err := api.GetTrytes(hashes...)
if err != nil {
return nil, err
}
return transaction.AsTransactionObjects(trytes, hashes)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetTransactionObjects",
"(",
"hashes",
"...",
"Hash",
")",
"(",
"transaction",
".",
"Transactions",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateTransactionHashes",
"(",
"hashes",
"...",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"trytes",
",",
"err",
":=",
"api",
".",
"GetTrytes",
"(",
"hashes",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"transaction",
".",
"AsTransactionObjects",
"(",
"trytes",
",",
"hashes",
")",
"\n",
"}"
] | // GetTransactionObjects fetches transaction objects given an array of transaction hashes. | [
"GetTransactionObjects",
"fetches",
"transaction",
"objects",
"given",
"an",
"array",
"of",
"transaction",
"hashes",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L338-L347 |
326 | iotaledger/iota.go | api/wrappers.go | FindTransactionObjects | func (api *API) FindTransactionObjects(query FindTransactionsQuery) (transaction.Transactions, error) {
txHashes, err := api.FindTransactions(query)
if err != nil {
return nil, err
}
if len(txHashes) == 0 {
return transaction.Transactions{}, nil
}
return api.GetTransactionObjects(txHashes...)
} | go | func (api *API) FindTransactionObjects(query FindTransactionsQuery) (transaction.Transactions, error) {
txHashes, err := api.FindTransactions(query)
if err != nil {
return nil, err
}
if len(txHashes) == 0 {
return transaction.Transactions{}, nil
}
return api.GetTransactionObjects(txHashes...)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"FindTransactionObjects",
"(",
"query",
"FindTransactionsQuery",
")",
"(",
"transaction",
".",
"Transactions",
",",
"error",
")",
"{",
"txHashes",
",",
"err",
":=",
"api",
".",
"FindTransactions",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"txHashes",
")",
"==",
"0",
"{",
"return",
"transaction",
".",
"Transactions",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"api",
".",
"GetTransactionObjects",
"(",
"txHashes",
"...",
")",
"\n",
"}"
] | // FindTransactionObjects searches for transactions given a query object with addresses, tags and approvees fields.
// Multiple query fields are supported and FindTransactionObjects returns the intersection of results. | [
"FindTransactionObjects",
"searches",
"for",
"transactions",
"given",
"a",
"query",
"object",
"with",
"addresses",
"tags",
"and",
"approvees",
"fields",
".",
"Multiple",
"query",
"fields",
"are",
"supported",
"and",
"FindTransactionObjects",
"returns",
"the",
"intersection",
"of",
"results",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L351-L360 |
327 | iotaledger/iota.go | api/wrappers.go | GetInputs | func (api *API) GetInputs(seed Trytes, options GetInputsOptions) (*Inputs, error) {
options = getInputDefaultOptions(options)
if err := Validate(
ValidateSeed(seed), ValidateSecurityLevel(options.Security),
ValidateStartEndOptions(options.Start, options.End),
); err != nil {
return nil, err
}
opts := options.ToGetNewAddressOptions()
addresses, err := api.GetNewAddress(seed, opts)
if err != nil {
return nil, err
}
balances, err := api.GetBalances(addresses, 100)
if err != nil {
return nil, err
}
inputs := api.GetInputObjects(addresses, balances.Balances, opts.Index, opts.Security)
// threshold is an api hard cap for needed inputs to fulfil the threshold value
if options.Threshold != nil {
threshold := *options.Threshold
if threshold > inputs.TotalBalance {
return nil, ErrInsufficientBalance
}
thresholdInputs := Inputs{}
for i := range inputs.Inputs {
if thresholdInputs.TotalBalance >= threshold {
break
}
input := inputs.Inputs[i]
thresholdInputs.Inputs = append(thresholdInputs.Inputs, input)
thresholdInputs.TotalBalance += input.Balance
}
inputs = thresholdInputs
}
return &inputs, nil
} | go | func (api *API) GetInputs(seed Trytes, options GetInputsOptions) (*Inputs, error) {
options = getInputDefaultOptions(options)
if err := Validate(
ValidateSeed(seed), ValidateSecurityLevel(options.Security),
ValidateStartEndOptions(options.Start, options.End),
); err != nil {
return nil, err
}
opts := options.ToGetNewAddressOptions()
addresses, err := api.GetNewAddress(seed, opts)
if err != nil {
return nil, err
}
balances, err := api.GetBalances(addresses, 100)
if err != nil {
return nil, err
}
inputs := api.GetInputObjects(addresses, balances.Balances, opts.Index, opts.Security)
// threshold is an api hard cap for needed inputs to fulfil the threshold value
if options.Threshold != nil {
threshold := *options.Threshold
if threshold > inputs.TotalBalance {
return nil, ErrInsufficientBalance
}
thresholdInputs := Inputs{}
for i := range inputs.Inputs {
if thresholdInputs.TotalBalance >= threshold {
break
}
input := inputs.Inputs[i]
thresholdInputs.Inputs = append(thresholdInputs.Inputs, input)
thresholdInputs.TotalBalance += input.Balance
}
inputs = thresholdInputs
}
return &inputs, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetInputs",
"(",
"seed",
"Trytes",
",",
"options",
"GetInputsOptions",
")",
"(",
"*",
"Inputs",
",",
"error",
")",
"{",
"options",
"=",
"getInputDefaultOptions",
"(",
"options",
")",
"\n",
"if",
"err",
":=",
"Validate",
"(",
"ValidateSeed",
"(",
"seed",
")",
",",
"ValidateSecurityLevel",
"(",
"options",
".",
"Security",
")",
",",
"ValidateStartEndOptions",
"(",
"options",
".",
"Start",
",",
"options",
".",
"End",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"opts",
":=",
"options",
".",
"ToGetNewAddressOptions",
"(",
")",
"\n",
"addresses",
",",
"err",
":=",
"api",
".",
"GetNewAddress",
"(",
"seed",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"balances",
",",
"err",
":=",
"api",
".",
"GetBalances",
"(",
"addresses",
",",
"100",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"inputs",
":=",
"api",
".",
"GetInputObjects",
"(",
"addresses",
",",
"balances",
".",
"Balances",
",",
"opts",
".",
"Index",
",",
"opts",
".",
"Security",
")",
"\n\n",
"// threshold is an api hard cap for needed inputs to fulfil the threshold value",
"if",
"options",
".",
"Threshold",
"!=",
"nil",
"{",
"threshold",
":=",
"*",
"options",
".",
"Threshold",
"\n\n",
"if",
"threshold",
">",
"inputs",
".",
"TotalBalance",
"{",
"return",
"nil",
",",
"ErrInsufficientBalance",
"\n",
"}",
"\n\n",
"thresholdInputs",
":=",
"Inputs",
"{",
"}",
"\n",
"for",
"i",
":=",
"range",
"inputs",
".",
"Inputs",
"{",
"if",
"thresholdInputs",
".",
"TotalBalance",
">=",
"threshold",
"{",
"break",
"\n",
"}",
"\n",
"input",
":=",
"inputs",
".",
"Inputs",
"[",
"i",
"]",
"\n",
"thresholdInputs",
".",
"Inputs",
"=",
"append",
"(",
"thresholdInputs",
".",
"Inputs",
",",
"input",
")",
"\n",
"thresholdInputs",
".",
"TotalBalance",
"+=",
"input",
".",
"Balance",
"\n",
"}",
"\n",
"inputs",
"=",
"thresholdInputs",
"\n",
"}",
"\n\n",
"return",
"&",
"inputs",
",",
"nil",
"\n",
"}"
] | // GetInputs creates and returns an Inputs object by generating addresses and fetching their latest balance. | [
"GetInputs",
"creates",
"and",
"returns",
"an",
"Inputs",
"object",
"by",
"generating",
"addresses",
"and",
"fetching",
"their",
"latest",
"balance",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L363-L405 |
328 | iotaledger/iota.go | api/wrappers.go | GetInputObjects | func (api *API) GetInputObjects(addresses Hashes, balances []uint64, start uint64, secLvl SecurityLevel) Inputs {
addrs := []Input{}
var totalBalance uint64
for i := range addresses {
value := balances[i]
if value <= 0 {
continue
}
addrs = append(addrs, Input{
Address: addresses[i], Security: secLvl,
Balance: value, KeyIndex: start + uint64(i)},
)
totalBalance += value
}
return Inputs{Inputs: addrs, TotalBalance: totalBalance}
} | go | func (api *API) GetInputObjects(addresses Hashes, balances []uint64, start uint64, secLvl SecurityLevel) Inputs {
addrs := []Input{}
var totalBalance uint64
for i := range addresses {
value := balances[i]
if value <= 0 {
continue
}
addrs = append(addrs, Input{
Address: addresses[i], Security: secLvl,
Balance: value, KeyIndex: start + uint64(i)},
)
totalBalance += value
}
return Inputs{Inputs: addrs, TotalBalance: totalBalance}
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetInputObjects",
"(",
"addresses",
"Hashes",
",",
"balances",
"[",
"]",
"uint64",
",",
"start",
"uint64",
",",
"secLvl",
"SecurityLevel",
")",
"Inputs",
"{",
"addrs",
":=",
"[",
"]",
"Input",
"{",
"}",
"\n",
"var",
"totalBalance",
"uint64",
"\n",
"for",
"i",
":=",
"range",
"addresses",
"{",
"value",
":=",
"balances",
"[",
"i",
"]",
"\n",
"if",
"value",
"<=",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"addrs",
"=",
"append",
"(",
"addrs",
",",
"Input",
"{",
"Address",
":",
"addresses",
"[",
"i",
"]",
",",
"Security",
":",
"secLvl",
",",
"Balance",
":",
"value",
",",
"KeyIndex",
":",
"start",
"+",
"uint64",
"(",
"i",
")",
"}",
",",
")",
"\n",
"totalBalance",
"+=",
"value",
"\n",
"}",
"\n",
"return",
"Inputs",
"{",
"Inputs",
":",
"addrs",
",",
"TotalBalance",
":",
"totalBalance",
"}",
"\n",
"}"
] | // GetInputObjects creates an Input object using the given addresses, balances, start index and security level. | [
"GetInputObjects",
"creates",
"an",
"Input",
"object",
"using",
"the",
"given",
"addresses",
"balances",
"start",
"index",
"and",
"security",
"level",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L408-L423 |
329 | iotaledger/iota.go | api/wrappers.go | GetTransfers | func (api *API) GetTransfers(seed Trytes, options GetTransfersOptions) (bundle.Bundles, error) {
options = getTransfersDefaultOptions(options)
if err := Validate(
ValidateSeed(seed), ValidateSecurityLevel(options.Security),
ValidateStartEndOptions(options.Start, options.End),
); err != nil {
return nil, err
}
addresses, err := api.GetNewAddress(seed, options.ToGetNewAddressOptions())
if err != nil {
return nil, err
}
return api.GetBundlesFromAddresses(addresses, options.InclusionStates)
} | go | func (api *API) GetTransfers(seed Trytes, options GetTransfersOptions) (bundle.Bundles, error) {
options = getTransfersDefaultOptions(options)
if err := Validate(
ValidateSeed(seed), ValidateSecurityLevel(options.Security),
ValidateStartEndOptions(options.Start, options.End),
); err != nil {
return nil, err
}
addresses, err := api.GetNewAddress(seed, options.ToGetNewAddressOptions())
if err != nil {
return nil, err
}
return api.GetBundlesFromAddresses(addresses, options.InclusionStates)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetTransfers",
"(",
"seed",
"Trytes",
",",
"options",
"GetTransfersOptions",
")",
"(",
"bundle",
".",
"Bundles",
",",
"error",
")",
"{",
"options",
"=",
"getTransfersDefaultOptions",
"(",
"options",
")",
"\n",
"if",
"err",
":=",
"Validate",
"(",
"ValidateSeed",
"(",
"seed",
")",
",",
"ValidateSecurityLevel",
"(",
"options",
".",
"Security",
")",
",",
"ValidateStartEndOptions",
"(",
"options",
".",
"Start",
",",
"options",
".",
"End",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"addresses",
",",
"err",
":=",
"api",
".",
"GetNewAddress",
"(",
"seed",
",",
"options",
".",
"ToGetNewAddressOptions",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"api",
".",
"GetBundlesFromAddresses",
"(",
"addresses",
",",
"options",
".",
"InclusionStates",
")",
"\n",
"}"
] | // GetTransfers returns bundles which operated on the given address range specified by the supplied options. | [
"GetTransfers",
"returns",
"bundles",
"which",
"operated",
"on",
"the",
"given",
"address",
"range",
"specified",
"by",
"the",
"supplied",
"options",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L426-L439 |
330 | iotaledger/iota.go | api/wrappers.go | IsPromotable | func (api *API) IsPromotable(tailTxHash Hash) (bool, error) {
var err1, err2 error
var isConsistent bool
var trytes []Trytes
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
defer wg.Done()
isConsistent, _, err1 = api.CheckConsistency(tailTxHash)
}()
go func() {
defer wg.Done()
trytes, err2 = api.GetTrytes(tailTxHash)
}()
wg.Wait()
if err := firstNonNilErr(err1, err2); err != nil {
return false, err
}
tx, err := transaction.AsTransactionObject(trytes[0])
if err != nil {
return false, err
}
return isConsistent && isAboveMaxDepth(tx.AttachmentTimestamp), nil
} | go | func (api *API) IsPromotable(tailTxHash Hash) (bool, error) {
var err1, err2 error
var isConsistent bool
var trytes []Trytes
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
defer wg.Done()
isConsistent, _, err1 = api.CheckConsistency(tailTxHash)
}()
go func() {
defer wg.Done()
trytes, err2 = api.GetTrytes(tailTxHash)
}()
wg.Wait()
if err := firstNonNilErr(err1, err2); err != nil {
return false, err
}
tx, err := transaction.AsTransactionObject(trytes[0])
if err != nil {
return false, err
}
return isConsistent && isAboveMaxDepth(tx.AttachmentTimestamp), nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"IsPromotable",
"(",
"tailTxHash",
"Hash",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"err1",
",",
"err2",
"error",
"\n",
"var",
"isConsistent",
"bool",
"\n",
"var",
"trytes",
"[",
"]",
"Trytes",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"wg",
".",
"Add",
"(",
"2",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"isConsistent",
",",
"_",
",",
"err1",
"=",
"api",
".",
"CheckConsistency",
"(",
"tailTxHash",
")",
"\n",
"}",
"(",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"trytes",
",",
"err2",
"=",
"api",
".",
"GetTrytes",
"(",
"tailTxHash",
")",
"\n",
"}",
"(",
")",
"\n\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"if",
"err",
":=",
"firstNonNilErr",
"(",
"err1",
",",
"err2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"tx",
",",
"err",
":=",
"transaction",
".",
"AsTransactionObject",
"(",
"trytes",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"isConsistent",
"&&",
"isAboveMaxDepth",
"(",
"tx",
".",
"AttachmentTimestamp",
")",
",",
"nil",
"\n",
"}"
] | // IsPromotable checks if a transaction is promotable by calling the checkConsistency IRI API command and
// verifying that attachmentTimestamp is above a lower bound. Lower bound is calculated based on the number of milestones issued
// since transaction attachment. | [
"IsPromotable",
"checks",
"if",
"a",
"transaction",
"is",
"promotable",
"by",
"calling",
"the",
"checkConsistency",
"IRI",
"API",
"command",
"and",
"verifying",
"that",
"attachmentTimestamp",
"is",
"above",
"a",
"lower",
"bound",
".",
"Lower",
"bound",
"is",
"calculated",
"based",
"on",
"the",
"number",
"of",
"milestones",
"issued",
"since",
"transaction",
"attachment",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L444-L471 |
331 | iotaledger/iota.go | api/wrappers.go | isAboveMaxDepth | func isAboveMaxDepth(attachmentTimestamp int64) bool {
nowMilli := time.Now().UnixNano() / int64(time.Millisecond)
return attachmentTimestamp < nowMilli && nowMilli-attachmentTimestamp < maxDepth*milestoneInterval*oneWayDelay
} | go | func isAboveMaxDepth(attachmentTimestamp int64) bool {
nowMilli := time.Now().UnixNano() / int64(time.Millisecond)
return attachmentTimestamp < nowMilli && nowMilli-attachmentTimestamp < maxDepth*milestoneInterval*oneWayDelay
} | [
"func",
"isAboveMaxDepth",
"(",
"attachmentTimestamp",
"int64",
")",
"bool",
"{",
"nowMilli",
":=",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"/",
"int64",
"(",
"time",
".",
"Millisecond",
")",
"\n",
"return",
"attachmentTimestamp",
"<",
"nowMilli",
"&&",
"nowMilli",
"-",
"attachmentTimestamp",
"<",
"maxDepth",
"*",
"milestoneInterval",
"*",
"oneWayDelay",
"\n",
"}"
] | // checks whether by the given timestamp the transaction is to deep to be promoted | [
"checks",
"whether",
"by",
"the",
"given",
"timestamp",
"the",
"transaction",
"is",
"to",
"deep",
"to",
"be",
"promoted"
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L478-L481 |
332 | iotaledger/iota.go | api/wrappers.go | SendTransfer | func (api *API) SendTransfer(seed Trytes, depth uint64, mwm uint64, transfers bundle.Transfers, options *SendTransfersOptions) (bundle.Bundle, error) {
if err := Validate(ValidateSeed(seed), ValidateTransfers(transfers...)); err != nil {
return nil, err
}
var opts PrepareTransfersOptions
refs := Hashes{}
if options == nil {
opts = getPrepareTransfersDefaultOptions(PrepareTransfersOptions{})
} else {
opts = getPrepareTransfersDefaultOptions(options.PrepareTransfersOptions)
if options.Reference != nil {
refs = append(refs, *options.Reference)
}
}
trytes, err := api.PrepareTransfers(seed, transfers, opts)
if err != nil {
return nil, err
}
return api.SendTrytes(trytes, depth, mwm, refs...)
} | go | func (api *API) SendTransfer(seed Trytes, depth uint64, mwm uint64, transfers bundle.Transfers, options *SendTransfersOptions) (bundle.Bundle, error) {
if err := Validate(ValidateSeed(seed), ValidateTransfers(transfers...)); err != nil {
return nil, err
}
var opts PrepareTransfersOptions
refs := Hashes{}
if options == nil {
opts = getPrepareTransfersDefaultOptions(PrepareTransfersOptions{})
} else {
opts = getPrepareTransfersDefaultOptions(options.PrepareTransfersOptions)
if options.Reference != nil {
refs = append(refs, *options.Reference)
}
}
trytes, err := api.PrepareTransfers(seed, transfers, opts)
if err != nil {
return nil, err
}
return api.SendTrytes(trytes, depth, mwm, refs...)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"SendTransfer",
"(",
"seed",
"Trytes",
",",
"depth",
"uint64",
",",
"mwm",
"uint64",
",",
"transfers",
"bundle",
".",
"Transfers",
",",
"options",
"*",
"SendTransfersOptions",
")",
"(",
"bundle",
".",
"Bundle",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateSeed",
"(",
"seed",
")",
",",
"ValidateTransfers",
"(",
"transfers",
"...",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"opts",
"PrepareTransfersOptions",
"\n",
"refs",
":=",
"Hashes",
"{",
"}",
"\n",
"if",
"options",
"==",
"nil",
"{",
"opts",
"=",
"getPrepareTransfersDefaultOptions",
"(",
"PrepareTransfersOptions",
"{",
"}",
")",
"\n",
"}",
"else",
"{",
"opts",
"=",
"getPrepareTransfersDefaultOptions",
"(",
"options",
".",
"PrepareTransfersOptions",
")",
"\n",
"if",
"options",
".",
"Reference",
"!=",
"nil",
"{",
"refs",
"=",
"append",
"(",
"refs",
",",
"*",
"options",
".",
"Reference",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"trytes",
",",
"err",
":=",
"api",
".",
"PrepareTransfers",
"(",
"seed",
",",
"transfers",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"api",
".",
"SendTrytes",
"(",
"trytes",
",",
"depth",
",",
"mwm",
",",
"refs",
"...",
")",
"\n",
"}"
] | // SendTransfer calls PrepareTransfers and then sends off the bundle via SendTrytes. | [
"SendTransfer",
"calls",
"PrepareTransfers",
"and",
"then",
"sends",
"off",
"the",
"bundle",
"via",
"SendTrytes",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L684-L705 |
333 | iotaledger/iota.go | api/wrappers.go | ReplayBundle | func (api *API) ReplayBundle(tailTxHash Hash, depth uint64, mwm uint64, reference ...Hash) (bundle.Bundle, error) {
if err := Validate(ValidateTransactionHashes(tailTxHash)); err != nil {
return nil, err
}
bndl, err := api.GetBundle(tailTxHash)
if err != nil {
return nil, err
}
trytes := transaction.MustFinalTransactionTrytes(bndl)
return api.SendTrytes(trytes, depth, mwm, reference...)
} | go | func (api *API) ReplayBundle(tailTxHash Hash, depth uint64, mwm uint64, reference ...Hash) (bundle.Bundle, error) {
if err := Validate(ValidateTransactionHashes(tailTxHash)); err != nil {
return nil, err
}
bndl, err := api.GetBundle(tailTxHash)
if err != nil {
return nil, err
}
trytes := transaction.MustFinalTransactionTrytes(bndl)
return api.SendTrytes(trytes, depth, mwm, reference...)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"ReplayBundle",
"(",
"tailTxHash",
"Hash",
",",
"depth",
"uint64",
",",
"mwm",
"uint64",
",",
"reference",
"...",
"Hash",
")",
"(",
"bundle",
".",
"Bundle",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateTransactionHashes",
"(",
"tailTxHash",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"bndl",
",",
"err",
":=",
"api",
".",
"GetBundle",
"(",
"tailTxHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"trytes",
":=",
"transaction",
".",
"MustFinalTransactionTrytes",
"(",
"bndl",
")",
"\n",
"return",
"api",
".",
"SendTrytes",
"(",
"trytes",
",",
"depth",
",",
"mwm",
",",
"reference",
"...",
")",
"\n",
"}"
] | // ReplayBundle reattaches a transfer to the Tangle by selecting tips & performing the Proof-of-Work again.
// Reattachments are useful in case original transactions are pending and can be done securely
// as many times as needed. | [
"ReplayBundle",
"reattaches",
"a",
"transfer",
"to",
"the",
"Tangle",
"by",
"selecting",
"tips",
"&",
"performing",
"the",
"Proof",
"-",
"of",
"-",
"Work",
"again",
".",
"Reattachments",
"are",
"useful",
"in",
"case",
"original",
"transactions",
"are",
"pending",
"and",
"can",
"be",
"done",
"securely",
"as",
"many",
"times",
"as",
"needed",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L766-L776 |
334 | iotaledger/iota.go | api/wrappers.go | SendTrytes | func (api *API) SendTrytes(trytes []Trytes, depth uint64, mwm uint64, reference ...Hash) (bundle.Bundle, error) {
if err := Validate(ValidateTransactionTrytes(trytes...)); err != nil {
return nil, err
}
tips, err := api.GetTransactionsToApprove(depth, reference...)
if err != nil {
return nil, err
}
trytes, err = api.AttachToTangle(tips.TrunkTransaction, tips.BranchTransaction, mwm, trytes)
if err != nil {
return nil, err
}
trytes, err = api.StoreAndBroadcast(trytes)
if err != nil {
return nil, err
}
return transaction.AsTransactionObjects(trytes, nil)
} | go | func (api *API) SendTrytes(trytes []Trytes, depth uint64, mwm uint64, reference ...Hash) (bundle.Bundle, error) {
if err := Validate(ValidateTransactionTrytes(trytes...)); err != nil {
return nil, err
}
tips, err := api.GetTransactionsToApprove(depth, reference...)
if err != nil {
return nil, err
}
trytes, err = api.AttachToTangle(tips.TrunkTransaction, tips.BranchTransaction, mwm, trytes)
if err != nil {
return nil, err
}
trytes, err = api.StoreAndBroadcast(trytes)
if err != nil {
return nil, err
}
return transaction.AsTransactionObjects(trytes, nil)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"SendTrytes",
"(",
"trytes",
"[",
"]",
"Trytes",
",",
"depth",
"uint64",
",",
"mwm",
"uint64",
",",
"reference",
"...",
"Hash",
")",
"(",
"bundle",
".",
"Bundle",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateTransactionTrytes",
"(",
"trytes",
"...",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tips",
",",
"err",
":=",
"api",
".",
"GetTransactionsToApprove",
"(",
"depth",
",",
"reference",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"trytes",
",",
"err",
"=",
"api",
".",
"AttachToTangle",
"(",
"tips",
".",
"TrunkTransaction",
",",
"tips",
".",
"BranchTransaction",
",",
"mwm",
",",
"trytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"trytes",
",",
"err",
"=",
"api",
".",
"StoreAndBroadcast",
"(",
"trytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"transaction",
".",
"AsTransactionObjects",
"(",
"trytes",
",",
"nil",
")",
"\n",
"}"
] | // SendTrytes performs Proof-of-Work, stores and then broadcasts the given transactions and returns them. | [
"SendTrytes",
"performs",
"Proof",
"-",
"of",
"-",
"Work",
"stores",
"and",
"then",
"broadcasts",
"the",
"given",
"transactions",
"and",
"returns",
"them",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L779-L796 |
335 | iotaledger/iota.go | api/wrappers.go | StoreAndBroadcast | func (api *API) StoreAndBroadcast(trytes []Trytes) ([]Trytes, error) {
if err := Validate(ValidateAttachedTransactionTrytes(trytes...)); err != nil {
return nil, err
}
trytes, err := api.StoreTransactions(trytes...)
if err != nil {
return nil, err
}
return api.BroadcastTransactions(trytes...)
} | go | func (api *API) StoreAndBroadcast(trytes []Trytes) ([]Trytes, error) {
if err := Validate(ValidateAttachedTransactionTrytes(trytes...)); err != nil {
return nil, err
}
trytes, err := api.StoreTransactions(trytes...)
if err != nil {
return nil, err
}
return api.BroadcastTransactions(trytes...)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"StoreAndBroadcast",
"(",
"trytes",
"[",
"]",
"Trytes",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateAttachedTransactionTrytes",
"(",
"trytes",
"...",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"trytes",
",",
"err",
":=",
"api",
".",
"StoreTransactions",
"(",
"trytes",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"api",
".",
"BroadcastTransactions",
"(",
"trytes",
"...",
")",
"\n",
"}"
] | // StoreAndBroadcast first stores and the broadcasts the given transactions. | [
"StoreAndBroadcast",
"first",
"stores",
"and",
"the",
"broadcasts",
"the",
"given",
"transactions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L799-L808 |
336 | iotaledger/iota.go | api/wrappers.go | TraverseBundle | func (api *API) TraverseBundle(trunkTxHash Hash, bndl bundle.Bundle) (bundle.Bundle, error) {
if err := Validate(ValidateTransactionHashes(trunkTxHash)); err != nil {
return nil, err
}
tailTrytes, err := api.GetTrytes(trunkTxHash)
if err != nil {
return nil, err
}
tx, err := transaction.AsTransactionObject(tailTrytes[0], trunkTxHash)
if err != nil {
return nil, err
}
// tail tx ?
if len(bndl) == 0 {
if !transaction.IsTailTransaction(tx) {
return nil, ErrInvalidTailTransaction
}
}
bndl = append(bndl, *tx)
if tx.CurrentIndex == tx.LastIndex {
return bndl, nil
}
return api.TraverseBundle(tx.TrunkTransaction, bndl)
} | go | func (api *API) TraverseBundle(trunkTxHash Hash, bndl bundle.Bundle) (bundle.Bundle, error) {
if err := Validate(ValidateTransactionHashes(trunkTxHash)); err != nil {
return nil, err
}
tailTrytes, err := api.GetTrytes(trunkTxHash)
if err != nil {
return nil, err
}
tx, err := transaction.AsTransactionObject(tailTrytes[0], trunkTxHash)
if err != nil {
return nil, err
}
// tail tx ?
if len(bndl) == 0 {
if !transaction.IsTailTransaction(tx) {
return nil, ErrInvalidTailTransaction
}
}
bndl = append(bndl, *tx)
if tx.CurrentIndex == tx.LastIndex {
return bndl, nil
}
return api.TraverseBundle(tx.TrunkTransaction, bndl)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"TraverseBundle",
"(",
"trunkTxHash",
"Hash",
",",
"bndl",
"bundle",
".",
"Bundle",
")",
"(",
"bundle",
".",
"Bundle",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateTransactionHashes",
"(",
"trunkTxHash",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tailTrytes",
",",
"err",
":=",
"api",
".",
"GetTrytes",
"(",
"trunkTxHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tx",
",",
"err",
":=",
"transaction",
".",
"AsTransactionObject",
"(",
"tailTrytes",
"[",
"0",
"]",
",",
"trunkTxHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// tail tx ?",
"if",
"len",
"(",
"bndl",
")",
"==",
"0",
"{",
"if",
"!",
"transaction",
".",
"IsTailTransaction",
"(",
"tx",
")",
"{",
"return",
"nil",
",",
"ErrInvalidTailTransaction",
"\n",
"}",
"\n",
"}",
"\n",
"bndl",
"=",
"append",
"(",
"bndl",
",",
"*",
"tx",
")",
"\n",
"if",
"tx",
".",
"CurrentIndex",
"==",
"tx",
".",
"LastIndex",
"{",
"return",
"bndl",
",",
"nil",
"\n",
"}",
"\n",
"return",
"api",
".",
"TraverseBundle",
"(",
"tx",
".",
"TrunkTransaction",
",",
"bndl",
")",
"\n",
"}"
] | // TraverseBundle fetches the bundle of a given tail transaction by traversing through the trunk transactions.
// It does not validate the bundle. | [
"TraverseBundle",
"fetches",
"the",
"bundle",
"of",
"a",
"given",
"tail",
"transaction",
"by",
"traversing",
"through",
"the",
"trunk",
"transactions",
".",
"It",
"does",
"not",
"validate",
"the",
"bundle",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/wrappers.go#L812-L835 |
337 | iotaledger/iota.go | kerl/sha3/xor_generic.go | xorInGeneric | func xorInGeneric(d *state, buf []byte) {
n := len(buf) / 8
for i := 0; i < n; i++ {
a := binary.LittleEndian.Uint64(buf)
d.a[i] ^= a
buf = buf[8:]
}
} | go | func xorInGeneric(d *state, buf []byte) {
n := len(buf) / 8
for i := 0; i < n; i++ {
a := binary.LittleEndian.Uint64(buf)
d.a[i] ^= a
buf = buf[8:]
}
} | [
"func",
"xorInGeneric",
"(",
"d",
"*",
"state",
",",
"buf",
"[",
"]",
"byte",
")",
"{",
"n",
":=",
"len",
"(",
"buf",
")",
"/",
"8",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"a",
":=",
"binary",
".",
"LittleEndian",
".",
"Uint64",
"(",
"buf",
")",
"\n",
"d",
".",
"a",
"[",
"i",
"]",
"^=",
"a",
"\n",
"buf",
"=",
"buf",
"[",
"8",
":",
"]",
"\n",
"}",
"\n",
"}"
] | // xorInGeneric xors the bytes in buf into the state; it
// makes no non-portable assumptions about memory layout
// or alignment. | [
"xorInGeneric",
"xors",
"the",
"bytes",
"in",
"buf",
"into",
"the",
"state",
";",
"it",
"makes",
"no",
"non",
"-",
"portable",
"assumptions",
"about",
"memory",
"layout",
"or",
"alignment",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/xor_generic.go#L12-L20 |
338 | iotaledger/iota.go | kerl/sha3/xor_generic.go | copyOutGeneric | func copyOutGeneric(d *state, b []byte) {
for i := 0; len(b) >= 8; i++ {
binary.LittleEndian.PutUint64(b, d.a[i])
b = b[8:]
}
} | go | func copyOutGeneric(d *state, b []byte) {
for i := 0; len(b) >= 8; i++ {
binary.LittleEndian.PutUint64(b, d.a[i])
b = b[8:]
}
} | [
"func",
"copyOutGeneric",
"(",
"d",
"*",
"state",
",",
"b",
"[",
"]",
"byte",
")",
"{",
"for",
"i",
":=",
"0",
";",
"len",
"(",
"b",
")",
">=",
"8",
";",
"i",
"++",
"{",
"binary",
".",
"LittleEndian",
".",
"PutUint64",
"(",
"b",
",",
"d",
".",
"a",
"[",
"i",
"]",
")",
"\n",
"b",
"=",
"b",
"[",
"8",
":",
"]",
"\n",
"}",
"\n",
"}"
] | // copyOutGeneric copies ulint64s to a byte buffer. | [
"copyOutGeneric",
"copies",
"ulint64s",
"to",
"a",
"byte",
"buffer",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/xor_generic.go#L23-L28 |
339 | iotaledger/iota.go | kerl/sha3/sha3.go | Reset | func (d *state) Reset() {
// Zero the permutation's state.
for i := range d.a {
d.a[i] = 0
}
d.state = spongeAbsorbing
d.buf = d.storage[:0]
} | go | func (d *state) Reset() {
// Zero the permutation's state.
for i := range d.a {
d.a[i] = 0
}
d.state = spongeAbsorbing
d.buf = d.storage[:0]
} | [
"func",
"(",
"d",
"*",
"state",
")",
"Reset",
"(",
")",
"{",
"// Zero the permutation's state.",
"for",
"i",
":=",
"range",
"d",
".",
"a",
"{",
"d",
".",
"a",
"[",
"i",
"]",
"=",
"0",
"\n",
"}",
"\n",
"d",
".",
"state",
"=",
"spongeAbsorbing",
"\n",
"d",
".",
"buf",
"=",
"d",
".",
"storage",
"[",
":",
"0",
"]",
"\n",
"}"
] | // Reset clears the internal state by zeroing the sponge state and
// the byte buffer, and setting Sponge.state to absorbing. | [
"Reset",
"clears",
"the",
"internal",
"state",
"by",
"zeroing",
"the",
"sponge",
"state",
"and",
"the",
"byte",
"buffer",
"and",
"setting",
"Sponge",
".",
"state",
"to",
"absorbing",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/sha3.go#L61-L68 |
340 | iotaledger/iota.go | kerl/sha3/sha3.go | permute | func (d *state) permute() {
switch d.state {
case spongeAbsorbing:
// If we're absorbing, we need to xor the input into the state
// before applying the permutation.
xorIn(d, d.buf)
d.buf = d.storage[:0]
keccakF1600(&d.a)
case spongeSqueezing:
// If we're squeezing, we need to apply the permutatin before
// copying more output.
keccakF1600(&d.a)
d.buf = d.storage[:d.rate]
copyOut(d, d.buf)
}
} | go | func (d *state) permute() {
switch d.state {
case spongeAbsorbing:
// If we're absorbing, we need to xor the input into the state
// before applying the permutation.
xorIn(d, d.buf)
d.buf = d.storage[:0]
keccakF1600(&d.a)
case spongeSqueezing:
// If we're squeezing, we need to apply the permutatin before
// copying more output.
keccakF1600(&d.a)
d.buf = d.storage[:d.rate]
copyOut(d, d.buf)
}
} | [
"func",
"(",
"d",
"*",
"state",
")",
"permute",
"(",
")",
"{",
"switch",
"d",
".",
"state",
"{",
"case",
"spongeAbsorbing",
":",
"// If we're absorbing, we need to xor the input into the state",
"// before applying the permutation.",
"xorIn",
"(",
"d",
",",
"d",
".",
"buf",
")",
"\n",
"d",
".",
"buf",
"=",
"d",
".",
"storage",
"[",
":",
"0",
"]",
"\n",
"keccakF1600",
"(",
"&",
"d",
".",
"a",
")",
"\n",
"case",
"spongeSqueezing",
":",
"// If we're squeezing, we need to apply the permutatin before",
"// copying more output.",
"keccakF1600",
"(",
"&",
"d",
".",
"a",
")",
"\n",
"d",
".",
"buf",
"=",
"d",
".",
"storage",
"[",
":",
"d",
".",
"rate",
"]",
"\n",
"copyOut",
"(",
"d",
",",
"d",
".",
"buf",
")",
"\n",
"}",
"\n",
"}"
] | // permute applies the KeccakF-1600 permutation. It handles
// any input-output buffering. | [
"permute",
"applies",
"the",
"KeccakF",
"-",
"1600",
"permutation",
".",
"It",
"handles",
"any",
"input",
"-",
"output",
"buffering",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/sha3.go#L83-L98 |
341 | iotaledger/iota.go | kerl/sha3/sha3.go | padAndPermute | func (d *state) padAndPermute(dsbyte byte) {
if d.buf == nil {
d.buf = d.storage[:0]
}
// Pad with this instance's domain-separator bits. We know that there's
// at least one byte of space in d.buf because, if it were full,
// permute would have been called to empty it. dsbyte also contains the
// first one bit for the padding. See the comment in the state struct.
d.buf = append(d.buf, dsbyte)
zerosStart := len(d.buf)
d.buf = d.storage[:d.rate]
for i := zerosStart; i < d.rate; i++ {
d.buf[i] = 0
}
// This adds the final one bit for the padding. Because of the way that
// bits are numbered from the LSB upwards, the final bit is the MSB of
// the last byte.
d.buf[d.rate-1] ^= 0x80
// Apply the permutation
d.permute()
d.state = spongeSqueezing
d.buf = d.storage[:d.rate]
copyOut(d, d.buf)
} | go | func (d *state) padAndPermute(dsbyte byte) {
if d.buf == nil {
d.buf = d.storage[:0]
}
// Pad with this instance's domain-separator bits. We know that there's
// at least one byte of space in d.buf because, if it were full,
// permute would have been called to empty it. dsbyte also contains the
// first one bit for the padding. See the comment in the state struct.
d.buf = append(d.buf, dsbyte)
zerosStart := len(d.buf)
d.buf = d.storage[:d.rate]
for i := zerosStart; i < d.rate; i++ {
d.buf[i] = 0
}
// This adds the final one bit for the padding. Because of the way that
// bits are numbered from the LSB upwards, the final bit is the MSB of
// the last byte.
d.buf[d.rate-1] ^= 0x80
// Apply the permutation
d.permute()
d.state = spongeSqueezing
d.buf = d.storage[:d.rate]
copyOut(d, d.buf)
} | [
"func",
"(",
"d",
"*",
"state",
")",
"padAndPermute",
"(",
"dsbyte",
"byte",
")",
"{",
"if",
"d",
".",
"buf",
"==",
"nil",
"{",
"d",
".",
"buf",
"=",
"d",
".",
"storage",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"// Pad with this instance's domain-separator bits. We know that there's",
"// at least one byte of space in d.buf because, if it were full,",
"// permute would have been called to empty it. dsbyte also contains the",
"// first one bit for the padding. See the comment in the state struct.",
"d",
".",
"buf",
"=",
"append",
"(",
"d",
".",
"buf",
",",
"dsbyte",
")",
"\n",
"zerosStart",
":=",
"len",
"(",
"d",
".",
"buf",
")",
"\n",
"d",
".",
"buf",
"=",
"d",
".",
"storage",
"[",
":",
"d",
".",
"rate",
"]",
"\n",
"for",
"i",
":=",
"zerosStart",
";",
"i",
"<",
"d",
".",
"rate",
";",
"i",
"++",
"{",
"d",
".",
"buf",
"[",
"i",
"]",
"=",
"0",
"\n",
"}",
"\n",
"// This adds the final one bit for the padding. Because of the way that",
"// bits are numbered from the LSB upwards, the final bit is the MSB of",
"// the last byte.",
"d",
".",
"buf",
"[",
"d",
".",
"rate",
"-",
"1",
"]",
"^=",
"0x80",
"\n",
"// Apply the permutation",
"d",
".",
"permute",
"(",
")",
"\n",
"d",
".",
"state",
"=",
"spongeSqueezing",
"\n",
"d",
".",
"buf",
"=",
"d",
".",
"storage",
"[",
":",
"d",
".",
"rate",
"]",
"\n",
"copyOut",
"(",
"d",
",",
"d",
".",
"buf",
")",
"\n",
"}"
] | // pads appends the domain separation bits in dsbyte, applies
// the multi-bitrate 10..1 padding rule, and permutes the state. | [
"pads",
"appends",
"the",
"domain",
"separation",
"bits",
"in",
"dsbyte",
"applies",
"the",
"multi",
"-",
"bitrate",
"10",
"..",
"1",
"padding",
"rule",
"and",
"permutes",
"the",
"state",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/sha3.go#L102-L125 |
342 | iotaledger/iota.go | kerl/sha3/sha3.go | Write | func (d *state) Write(p []byte) (written int, err error) {
if d.state != spongeAbsorbing {
panic("sha3: write to sponge after read")
}
if d.buf == nil {
d.buf = d.storage[:0]
}
written = len(p)
for len(p) > 0 {
if len(d.buf) == 0 && len(p) >= d.rate {
// The fast path; absorb a full "rate" bytes of input and apply the permutation.
xorIn(d, p[:d.rate])
p = p[d.rate:]
keccakF1600(&d.a)
} else {
// The slow path; buffer the input until we can fill the sponge, and then xor it in.
todo := d.rate - len(d.buf)
if todo > len(p) {
todo = len(p)
}
d.buf = append(d.buf, p[:todo]...)
p = p[todo:]
// If the sponge is full, apply the permutation.
if len(d.buf) == d.rate {
d.permute()
}
}
}
return
} | go | func (d *state) Write(p []byte) (written int, err error) {
if d.state != spongeAbsorbing {
panic("sha3: write to sponge after read")
}
if d.buf == nil {
d.buf = d.storage[:0]
}
written = len(p)
for len(p) > 0 {
if len(d.buf) == 0 && len(p) >= d.rate {
// The fast path; absorb a full "rate" bytes of input and apply the permutation.
xorIn(d, p[:d.rate])
p = p[d.rate:]
keccakF1600(&d.a)
} else {
// The slow path; buffer the input until we can fill the sponge, and then xor it in.
todo := d.rate - len(d.buf)
if todo > len(p) {
todo = len(p)
}
d.buf = append(d.buf, p[:todo]...)
p = p[todo:]
// If the sponge is full, apply the permutation.
if len(d.buf) == d.rate {
d.permute()
}
}
}
return
} | [
"func",
"(",
"d",
"*",
"state",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"written",
"int",
",",
"err",
"error",
")",
"{",
"if",
"d",
".",
"state",
"!=",
"spongeAbsorbing",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"d",
".",
"buf",
"==",
"nil",
"{",
"d",
".",
"buf",
"=",
"d",
".",
"storage",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"written",
"=",
"len",
"(",
"p",
")",
"\n\n",
"for",
"len",
"(",
"p",
")",
">",
"0",
"{",
"if",
"len",
"(",
"d",
".",
"buf",
")",
"==",
"0",
"&&",
"len",
"(",
"p",
")",
">=",
"d",
".",
"rate",
"{",
"// The fast path; absorb a full \"rate\" bytes of input and apply the permutation.",
"xorIn",
"(",
"d",
",",
"p",
"[",
":",
"d",
".",
"rate",
"]",
")",
"\n",
"p",
"=",
"p",
"[",
"d",
".",
"rate",
":",
"]",
"\n",
"keccakF1600",
"(",
"&",
"d",
".",
"a",
")",
"\n",
"}",
"else",
"{",
"// The slow path; buffer the input until we can fill the sponge, and then xor it in.",
"todo",
":=",
"d",
".",
"rate",
"-",
"len",
"(",
"d",
".",
"buf",
")",
"\n",
"if",
"todo",
">",
"len",
"(",
"p",
")",
"{",
"todo",
"=",
"len",
"(",
"p",
")",
"\n",
"}",
"\n",
"d",
".",
"buf",
"=",
"append",
"(",
"d",
".",
"buf",
",",
"p",
"[",
":",
"todo",
"]",
"...",
")",
"\n",
"p",
"=",
"p",
"[",
"todo",
":",
"]",
"\n\n",
"// If the sponge is full, apply the permutation.",
"if",
"len",
"(",
"d",
".",
"buf",
")",
"==",
"d",
".",
"rate",
"{",
"d",
".",
"permute",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Write absorbs more data into the hash's state. It produces an error
// if more data is written to the ShakeHash after writing | [
"Write",
"absorbs",
"more",
"data",
"into",
"the",
"hash",
"s",
"state",
".",
"It",
"produces",
"an",
"error",
"if",
"more",
"data",
"is",
"written",
"to",
"the",
"ShakeHash",
"after",
"writing"
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/sha3.go#L129-L161 |
343 | iotaledger/iota.go | kerl/sha3/sha3.go | Sum | func (d *state) Sum(in []byte) []byte {
// Make a copy of the original hash so that caller can keep writing
// and summing.
dup := d.clone()
hash := make([]byte, dup.outputLen)
dup.Read(hash)
return append(in, hash...)
} | go | func (d *state) Sum(in []byte) []byte {
// Make a copy of the original hash so that caller can keep writing
// and summing.
dup := d.clone()
hash := make([]byte, dup.outputLen)
dup.Read(hash)
return append(in, hash...)
} | [
"func",
"(",
"d",
"*",
"state",
")",
"Sum",
"(",
"in",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"// Make a copy of the original hash so that caller can keep writing",
"// and summing.",
"dup",
":=",
"d",
".",
"clone",
"(",
")",
"\n",
"hash",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"dup",
".",
"outputLen",
")",
"\n",
"dup",
".",
"Read",
"(",
"hash",
")",
"\n",
"return",
"append",
"(",
"in",
",",
"hash",
"...",
")",
"\n",
"}"
] | // Sum applies padding to the hash state and then squeezes out the desired
// number of output bytes. | [
"Sum",
"applies",
"padding",
"to",
"the",
"hash",
"state",
"and",
"then",
"squeezes",
"out",
"the",
"desired",
"number",
"of",
"output",
"bytes",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/sha3.go#L189-L196 |
344 | iotaledger/iota.go | kerl/sha3/shake.go | NewShake128 | func NewShake128() ShakeHash {
if h := newShake128Asm(); h != nil {
return h
}
return &state{rate: 168, dsbyte: 0x1f}
} | go | func NewShake128() ShakeHash {
if h := newShake128Asm(); h != nil {
return h
}
return &state{rate: 168, dsbyte: 0x1f}
} | [
"func",
"NewShake128",
"(",
")",
"ShakeHash",
"{",
"if",
"h",
":=",
"newShake128Asm",
"(",
")",
";",
"h",
"!=",
"nil",
"{",
"return",
"h",
"\n",
"}",
"\n",
"return",
"&",
"state",
"{",
"rate",
":",
"168",
",",
"dsbyte",
":",
"0x1f",
"}",
"\n",
"}"
] | // NewShake128 creates a new SHAKE128 variable-output-length ShakeHash.
// Its generic security strength is 128 bits against all attacks if at
// least 32 bytes of its output are used. | [
"NewShake128",
"creates",
"a",
"new",
"SHAKE128",
"variable",
"-",
"output",
"-",
"length",
"ShakeHash",
".",
"Its",
"generic",
"security",
"strength",
"is",
"128",
"bits",
"against",
"all",
"attacks",
"if",
"at",
"least",
"32",
"bytes",
"of",
"its",
"output",
"are",
"used",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/shake.go#L41-L46 |
345 | iotaledger/iota.go | kerl/sha3/shake.go | NewShake256 | func NewShake256() ShakeHash {
if h := newShake256Asm(); h != nil {
return h
}
return &state{rate: 136, dsbyte: 0x1f}
} | go | func NewShake256() ShakeHash {
if h := newShake256Asm(); h != nil {
return h
}
return &state{rate: 136, dsbyte: 0x1f}
} | [
"func",
"NewShake256",
"(",
")",
"ShakeHash",
"{",
"if",
"h",
":=",
"newShake256Asm",
"(",
")",
";",
"h",
"!=",
"nil",
"{",
"return",
"h",
"\n",
"}",
"\n",
"return",
"&",
"state",
"{",
"rate",
":",
"136",
",",
"dsbyte",
":",
"0x1f",
"}",
"\n",
"}"
] | // NewShake256 creates a new SHAKE256 variable-output-length ShakeHash.
// Its generic security strength is 256 bits against all attacks if
// at least 64 bytes of its output are used. | [
"NewShake256",
"creates",
"a",
"new",
"SHAKE256",
"variable",
"-",
"output",
"-",
"length",
"ShakeHash",
".",
"Its",
"generic",
"security",
"strength",
"is",
"256",
"bits",
"against",
"all",
"attacks",
"if",
"at",
"least",
"64",
"bytes",
"of",
"its",
"output",
"are",
"used",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/shake.go#L51-L56 |
346 | iotaledger/iota.go | kerl/sha3/shake.go | ShakeSum128 | func ShakeSum128(hash, data []byte) {
h := NewShake128()
h.Write(data)
h.Read(hash)
} | go | func ShakeSum128(hash, data []byte) {
h := NewShake128()
h.Write(data)
h.Read(hash)
} | [
"func",
"ShakeSum128",
"(",
"hash",
",",
"data",
"[",
"]",
"byte",
")",
"{",
"h",
":=",
"NewShake128",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"data",
")",
"\n",
"h",
".",
"Read",
"(",
"hash",
")",
"\n",
"}"
] | // ShakeSum128 writes an arbitrary-length digest of data into hash. | [
"ShakeSum128",
"writes",
"an",
"arbitrary",
"-",
"length",
"digest",
"of",
"data",
"into",
"hash",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/shake.go#L59-L63 |
347 | iotaledger/iota.go | kerl/sha3/shake.go | ShakeSum256 | func ShakeSum256(hash, data []byte) {
h := NewShake256()
h.Write(data)
h.Read(hash)
} | go | func ShakeSum256(hash, data []byte) {
h := NewShake256()
h.Write(data)
h.Read(hash)
} | [
"func",
"ShakeSum256",
"(",
"hash",
",",
"data",
"[",
"]",
"byte",
")",
"{",
"h",
":=",
"NewShake256",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"data",
")",
"\n",
"h",
".",
"Read",
"(",
"hash",
")",
"\n",
"}"
] | // ShakeSum256 writes an arbitrary-length digest of data into hash. | [
"ShakeSum256",
"writes",
"an",
"arbitrary",
"-",
"length",
"digest",
"of",
"data",
"into",
"hash",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/kerl/sha3/shake.go#L66-L70 |
348 | iotaledger/iota.go | signing/utils/sponge.go | GetSpongeFunc | func GetSpongeFunc(spongeFunc []SpongeFunction, defaultSpongeFuncCreator ...SpongeFunctionCreator) SpongeFunction {
if len(spongeFunc) > 0 {
return spongeFunc[0]
}
if len(defaultSpongeFuncCreator) > 0 {
return defaultSpongeFuncCreator[0]()
}
panic("No sponge function given")
} | go | func GetSpongeFunc(spongeFunc []SpongeFunction, defaultSpongeFuncCreator ...SpongeFunctionCreator) SpongeFunction {
if len(spongeFunc) > 0 {
return spongeFunc[0]
}
if len(defaultSpongeFuncCreator) > 0 {
return defaultSpongeFuncCreator[0]()
}
panic("No sponge function given")
} | [
"func",
"GetSpongeFunc",
"(",
"spongeFunc",
"[",
"]",
"SpongeFunction",
",",
"defaultSpongeFuncCreator",
"...",
"SpongeFunctionCreator",
")",
"SpongeFunction",
"{",
"if",
"len",
"(",
"spongeFunc",
")",
">",
"0",
"{",
"return",
"spongeFunc",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"defaultSpongeFuncCreator",
")",
">",
"0",
"{",
"return",
"defaultSpongeFuncCreator",
"[",
"0",
"]",
"(",
")",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // GetSpongeFunc checks if a hash function was given, otherwise uses defaultSpongeFuncCreator. Panics if none given. | [
"GetSpongeFunc",
"checks",
"if",
"a",
"hash",
"function",
"was",
"given",
"otherwise",
"uses",
"defaultSpongeFuncCreator",
".",
"Panics",
"if",
"none",
"given",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/signing/utils/sponge.go#L24-L32 |
349 | iotaledger/iota.go | checksum/checksum.go | AddChecksum | func AddChecksum(input Trytes, isAddress bool, checksumLength uint64) (Trytes, error) {
if isAddress && len(input) != HashTrytesSize {
if len(input) == AddressWithChecksumTrytesSize {
return input, nil
}
return "", ErrInvalidAddress
}
if checksumLength < MinChecksumTrytesSize ||
(isAddress && checksumLength != AddressChecksumTrytesSize) {
return "", ErrInvalidChecksum
}
inputCopy := input
for len(inputCopy)%HashTrytesSize != 0 {
inputCopy += "9"
}
inputTrits := MustTrytesToTrits(inputCopy)
k := kerl.NewKerl()
if err := k.Absorb(inputTrits); err != nil {
return "", err
}
checksumTrits, err := k.Squeeze(HashTrinarySize)
if err != nil {
return "", err
}
input += MustTritsToTrytes(checksumTrits[HashTrinarySize-checksumLength*3 : HashTrinarySize])
return input, nil
} | go | func AddChecksum(input Trytes, isAddress bool, checksumLength uint64) (Trytes, error) {
if isAddress && len(input) != HashTrytesSize {
if len(input) == AddressWithChecksumTrytesSize {
return input, nil
}
return "", ErrInvalidAddress
}
if checksumLength < MinChecksumTrytesSize ||
(isAddress && checksumLength != AddressChecksumTrytesSize) {
return "", ErrInvalidChecksum
}
inputCopy := input
for len(inputCopy)%HashTrytesSize != 0 {
inputCopy += "9"
}
inputTrits := MustTrytesToTrits(inputCopy)
k := kerl.NewKerl()
if err := k.Absorb(inputTrits); err != nil {
return "", err
}
checksumTrits, err := k.Squeeze(HashTrinarySize)
if err != nil {
return "", err
}
input += MustTritsToTrytes(checksumTrits[HashTrinarySize-checksumLength*3 : HashTrinarySize])
return input, nil
} | [
"func",
"AddChecksum",
"(",
"input",
"Trytes",
",",
"isAddress",
"bool",
",",
"checksumLength",
"uint64",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"if",
"isAddress",
"&&",
"len",
"(",
"input",
")",
"!=",
"HashTrytesSize",
"{",
"if",
"len",
"(",
"input",
")",
"==",
"AddressWithChecksumTrytesSize",
"{",
"return",
"input",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"ErrInvalidAddress",
"\n",
"}",
"\n\n",
"if",
"checksumLength",
"<",
"MinChecksumTrytesSize",
"||",
"(",
"isAddress",
"&&",
"checksumLength",
"!=",
"AddressChecksumTrytesSize",
")",
"{",
"return",
"\"",
"\"",
",",
"ErrInvalidChecksum",
"\n",
"}",
"\n\n",
"inputCopy",
":=",
"input",
"\n\n",
"for",
"len",
"(",
"inputCopy",
")",
"%",
"HashTrytesSize",
"!=",
"0",
"{",
"inputCopy",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"inputTrits",
":=",
"MustTrytesToTrits",
"(",
"inputCopy",
")",
"\n",
"k",
":=",
"kerl",
".",
"NewKerl",
"(",
")",
"\n",
"if",
"err",
":=",
"k",
".",
"Absorb",
"(",
"inputTrits",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"checksumTrits",
",",
"err",
":=",
"k",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"input",
"+=",
"MustTritsToTrytes",
"(",
"checksumTrits",
"[",
"HashTrinarySize",
"-",
"checksumLength",
"*",
"3",
":",
"HashTrinarySize",
"]",
")",
"\n",
"return",
"input",
",",
"nil",
"\n",
"}"
] | // AddChecksum computes the checksum and returns the given trytes with the appended checksum.
// If isAddress is true, then the input trytes must be of length HashTrytesSize.
// Specified checksum length must be at least MinChecksumTrytesSize long or it must be
// AddressChecksumTrytesSize if isAddress is true. | [
"AddChecksum",
"computes",
"the",
"checksum",
"and",
"returns",
"the",
"given",
"trytes",
"with",
"the",
"appended",
"checksum",
".",
"If",
"isAddress",
"is",
"true",
"then",
"the",
"input",
"trytes",
"must",
"be",
"of",
"length",
"HashTrytesSize",
".",
"Specified",
"checksum",
"length",
"must",
"be",
"at",
"least",
"MinChecksumTrytesSize",
"long",
"or",
"it",
"must",
"be",
"AddressChecksumTrytesSize",
"if",
"isAddress",
"is",
"true",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/checksum/checksum.go#L15-L45 |
350 | iotaledger/iota.go | checksum/checksum.go | AddChecksums | func AddChecksums(inputs []Trytes, isAddress bool, checksumLength uint64) ([]Trytes, error) {
withChecksums := make([]Trytes, len(inputs))
for i, s := range inputs {
t, err := AddChecksum(s, isAddress, checksumLength)
if err != nil {
return nil, err
}
withChecksums[i] = t
}
return withChecksums, nil
} | go | func AddChecksums(inputs []Trytes, isAddress bool, checksumLength uint64) ([]Trytes, error) {
withChecksums := make([]Trytes, len(inputs))
for i, s := range inputs {
t, err := AddChecksum(s, isAddress, checksumLength)
if err != nil {
return nil, err
}
withChecksums[i] = t
}
return withChecksums, nil
} | [
"func",
"AddChecksums",
"(",
"inputs",
"[",
"]",
"Trytes",
",",
"isAddress",
"bool",
",",
"checksumLength",
"uint64",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"withChecksums",
":=",
"make",
"(",
"[",
"]",
"Trytes",
",",
"len",
"(",
"inputs",
")",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"inputs",
"{",
"t",
",",
"err",
":=",
"AddChecksum",
"(",
"s",
",",
"isAddress",
",",
"checksumLength",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"withChecksums",
"[",
"i",
"]",
"=",
"t",
"\n",
"}",
"\n",
"return",
"withChecksums",
",",
"nil",
"\n",
"}"
] | // AddChecksums is a wrapper function around AddChecksum for multiple trytes strings. | [
"AddChecksums",
"is",
"a",
"wrapper",
"function",
"around",
"AddChecksum",
"for",
"multiple",
"trytes",
"strings",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/checksum/checksum.go#L48-L58 |
351 | iotaledger/iota.go | checksum/checksum.go | RemoveChecksum | func RemoveChecksum(input Trytes) (Trytes, error) {
if !guards.IsTrytesOfExactLength(input, HashTrytesSize) &&
!guards.IsTrytesOfExactLength(input, AddressWithChecksumTrytesSize) {
return "", ErrInvalidAddress
}
return input[:HashTrytesSize], nil
} | go | func RemoveChecksum(input Trytes) (Trytes, error) {
if !guards.IsTrytesOfExactLength(input, HashTrytesSize) &&
!guards.IsTrytesOfExactLength(input, AddressWithChecksumTrytesSize) {
return "", ErrInvalidAddress
}
return input[:HashTrytesSize], nil
} | [
"func",
"RemoveChecksum",
"(",
"input",
"Trytes",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"if",
"!",
"guards",
".",
"IsTrytesOfExactLength",
"(",
"input",
",",
"HashTrytesSize",
")",
"&&",
"!",
"guards",
".",
"IsTrytesOfExactLength",
"(",
"input",
",",
"AddressWithChecksumTrytesSize",
")",
"{",
"return",
"\"",
"\"",
",",
"ErrInvalidAddress",
"\n",
"}",
"\n",
"return",
"input",
"[",
":",
"HashTrytesSize",
"]",
",",
"nil",
"\n",
"}"
] | // RemoveChecksum removes the checksum from the given trytes.
// The input trytes must be of length HashTrytesSize or AddressWithChecksumTrytesSize. | [
"RemoveChecksum",
"removes",
"the",
"checksum",
"from",
"the",
"given",
"trytes",
".",
"The",
"input",
"trytes",
"must",
"be",
"of",
"length",
"HashTrytesSize",
"or",
"AddressWithChecksumTrytesSize",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/checksum/checksum.go#L62-L68 |
352 | iotaledger/iota.go | checksum/checksum.go | RemoveChecksums | func RemoveChecksums(inputs []Trytes) ([]Trytes, error) {
withoutChecksums := make([]Trytes, len(inputs))
for i, s := range inputs {
t, err := RemoveChecksum(s)
if err != nil {
return nil, err
}
withoutChecksums[i] = t
}
return withoutChecksums, nil
} | go | func RemoveChecksums(inputs []Trytes) ([]Trytes, error) {
withoutChecksums := make([]Trytes, len(inputs))
for i, s := range inputs {
t, err := RemoveChecksum(s)
if err != nil {
return nil, err
}
withoutChecksums[i] = t
}
return withoutChecksums, nil
} | [
"func",
"RemoveChecksums",
"(",
"inputs",
"[",
"]",
"Trytes",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"withoutChecksums",
":=",
"make",
"(",
"[",
"]",
"Trytes",
",",
"len",
"(",
"inputs",
")",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"inputs",
"{",
"t",
",",
"err",
":=",
"RemoveChecksum",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"withoutChecksums",
"[",
"i",
"]",
"=",
"t",
"\n",
"}",
"\n",
"return",
"withoutChecksums",
",",
"nil",
"\n",
"}"
] | // RemoveChecksums is a wrapper function around RemoveChecksum for multiple trytes strings. | [
"RemoveChecksums",
"is",
"a",
"wrapper",
"function",
"around",
"RemoveChecksum",
"for",
"multiple",
"trytes",
"strings",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/checksum/checksum.go#L71-L81 |
353 | iotaledger/iota.go | units/units.go | ConvertUnits | func ConvertUnits(val float64, from Unit, to Unit) float64 {
value := Unit(val)
// convert to I unit by multiplying with the current unit
value *= from
// convert to the target unit by dividing by it
if to == I {
return math.Round(float64(value))
}
value /= to
return float64(value)
} | go | func ConvertUnits(val float64, from Unit, to Unit) float64 {
value := Unit(val)
// convert to I unit by multiplying with the current unit
value *= from
// convert to the target unit by dividing by it
if to == I {
return math.Round(float64(value))
}
value /= to
return float64(value)
} | [
"func",
"ConvertUnits",
"(",
"val",
"float64",
",",
"from",
"Unit",
",",
"to",
"Unit",
")",
"float64",
"{",
"value",
":=",
"Unit",
"(",
"val",
")",
"\n",
"// convert to I unit by multiplying with the current unit",
"value",
"*=",
"from",
"\n",
"// convert to the target unit by dividing by it",
"if",
"to",
"==",
"I",
"{",
"return",
"math",
".",
"Round",
"(",
"float64",
"(",
"value",
")",
")",
"\n",
"}",
"\n",
"value",
"/=",
"to",
"\n",
"return",
"float64",
"(",
"value",
")",
"\n",
"}"
] | // ConvertUnits converts the given value in the base Unit to the given new Unit. | [
"ConvertUnits",
"converts",
"the",
"given",
"value",
"in",
"the",
"base",
"Unit",
"to",
"the",
"given",
"new",
"Unit",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/units/units.go#L28-L38 |
354 | iotaledger/iota.go | units/units.go | ConvertUnitsString | func ConvertUnitsString(val string, from Unit, to Unit) (float64, error) {
floatValue, err := strconv.ParseFloat(val, 64)
if err != nil {
return 0, err
}
return ConvertUnits(floatValue, from, to), nil
} | go | func ConvertUnitsString(val string, from Unit, to Unit) (float64, error) {
floatValue, err := strconv.ParseFloat(val, 64)
if err != nil {
return 0, err
}
return ConvertUnits(floatValue, from, to), nil
} | [
"func",
"ConvertUnitsString",
"(",
"val",
"string",
",",
"from",
"Unit",
",",
"to",
"Unit",
")",
"(",
"float64",
",",
"error",
")",
"{",
"floatValue",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"val",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"ConvertUnits",
"(",
"floatValue",
",",
"from",
",",
"to",
")",
",",
"nil",
"\n",
"}"
] | // ConvertUnitsString converts the given string value in the base Unit to the given new Unit. | [
"ConvertUnitsString",
"converts",
"the",
"given",
"string",
"value",
"in",
"the",
"base",
"Unit",
"to",
"the",
"given",
"new",
"Unit",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/units/units.go#L41-L47 |
355 | iotaledger/iota.go | account/account.go | Sum | func (recipients Recipients) Sum() uint64 {
var sum uint64
for _, target := range recipients {
sum += target.Value
}
return sum
} | go | func (recipients Recipients) Sum() uint64 {
var sum uint64
for _, target := range recipients {
sum += target.Value
}
return sum
} | [
"func",
"(",
"recipients",
"Recipients",
")",
"Sum",
"(",
")",
"uint64",
"{",
"var",
"sum",
"uint64",
"\n",
"for",
"_",
",",
"target",
":=",
"range",
"recipients",
"{",
"sum",
"+=",
"target",
".",
"Value",
"\n",
"}",
"\n",
"return",
"sum",
"\n",
"}"
] | // Sum returns the sum of all amounts. | [
"Sum",
"returns",
"the",
"sum",
"of",
"all",
"amounts",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/account.go#L52-L58 |
356 | iotaledger/iota.go | account/account.go | AsTransfers | func (recipients Recipients) AsTransfers() bundle.Transfers {
transfers := make(bundle.Transfers, len(recipients))
for i, recipient := range recipients {
transfers[i] = recipient
}
return transfers
} | go | func (recipients Recipients) AsTransfers() bundle.Transfers {
transfers := make(bundle.Transfers, len(recipients))
for i, recipient := range recipients {
transfers[i] = recipient
}
return transfers
} | [
"func",
"(",
"recipients",
"Recipients",
")",
"AsTransfers",
"(",
")",
"bundle",
".",
"Transfers",
"{",
"transfers",
":=",
"make",
"(",
"bundle",
".",
"Transfers",
",",
"len",
"(",
"recipients",
")",
")",
"\n",
"for",
"i",
",",
"recipient",
":=",
"range",
"recipients",
"{",
"transfers",
"[",
"i",
"]",
"=",
"recipient",
"\n",
"}",
"\n",
"return",
"transfers",
"\n",
"}"
] | // AsTransfers converts the recipients to transfers. | [
"AsTransfers",
"converts",
"the",
"recipients",
"to",
"transfers",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/account.go#L61-L67 |
357 | iotaledger/iota.go | account/settings.go | DefaultAddrGen | func DefaultAddrGen(provider SeedProvider, withCache bool) AddrGenFunc {
var cacheMu sync.Mutex
var cache map[uint64]map[consts.SecurityLevel]trinary.Hash
if withCache {
cache = map[uint64]map[consts.SecurityLevel]trinary.Hash{}
}
read := func(index uint64, secLvl consts.SecurityLevel, addChecksum bool) trinary.Hash {
cacheMu.Lock()
defer cacheMu.Unlock()
m, hasEntry := cache[index]
if !hasEntry {
return ""
}
cachedAddr, hasAddr := m[secLvl]
if !hasAddr {
return ""
}
if addChecksum {
return cachedAddr
}
return cachedAddr[:consts.HashTrytesSize]
}
write := func(index uint64, secLvl consts.SecurityLevel, addr trinary.Hash) {
cacheMu.Lock()
defer cacheMu.Unlock()
m, hasEntry := cache[index]
if !hasEntry {
m = map[consts.SecurityLevel]trinary.Hash{}
m[secLvl] = addr
cache[index] = m
return
}
m[secLvl] = addr
}
generate := func(index uint64, secLvl consts.SecurityLevel) (trinary.Hash, error) {
seed, err := provider.Seed()
if err != nil {
return "", err
}
addr, err := address.GenerateAddress(seed, index, secLvl, true)
return addr, err
}
if !withCache {
return func(index uint64, secLvl consts.SecurityLevel, addChecksum bool) (trinary.Hash, error) {
addr, err := generate(index, secLvl)
if err != nil {
return "", err
}
if addChecksum {
return addr, nil
}
return addr[:consts.HashTrytesSize], nil
}
}
return func(index uint64, secLvl consts.SecurityLevel, addChecksum bool) (trinary.Hash, error) {
if hash := read(index, secLvl, addChecksum); hash != "" {
return hash, nil
}
addr, err := generate(index, secLvl)
if err != nil {
return "", err
}
write(index, secLvl, addr)
if addChecksum {
return addr, nil
}
return addr[:consts.HashTrytesSize], nil
}
} | go | func DefaultAddrGen(provider SeedProvider, withCache bool) AddrGenFunc {
var cacheMu sync.Mutex
var cache map[uint64]map[consts.SecurityLevel]trinary.Hash
if withCache {
cache = map[uint64]map[consts.SecurityLevel]trinary.Hash{}
}
read := func(index uint64, secLvl consts.SecurityLevel, addChecksum bool) trinary.Hash {
cacheMu.Lock()
defer cacheMu.Unlock()
m, hasEntry := cache[index]
if !hasEntry {
return ""
}
cachedAddr, hasAddr := m[secLvl]
if !hasAddr {
return ""
}
if addChecksum {
return cachedAddr
}
return cachedAddr[:consts.HashTrytesSize]
}
write := func(index uint64, secLvl consts.SecurityLevel, addr trinary.Hash) {
cacheMu.Lock()
defer cacheMu.Unlock()
m, hasEntry := cache[index]
if !hasEntry {
m = map[consts.SecurityLevel]trinary.Hash{}
m[secLvl] = addr
cache[index] = m
return
}
m[secLvl] = addr
}
generate := func(index uint64, secLvl consts.SecurityLevel) (trinary.Hash, error) {
seed, err := provider.Seed()
if err != nil {
return "", err
}
addr, err := address.GenerateAddress(seed, index, secLvl, true)
return addr, err
}
if !withCache {
return func(index uint64, secLvl consts.SecurityLevel, addChecksum bool) (trinary.Hash, error) {
addr, err := generate(index, secLvl)
if err != nil {
return "", err
}
if addChecksum {
return addr, nil
}
return addr[:consts.HashTrytesSize], nil
}
}
return func(index uint64, secLvl consts.SecurityLevel, addChecksum bool) (trinary.Hash, error) {
if hash := read(index, secLvl, addChecksum); hash != "" {
return hash, nil
}
addr, err := generate(index, secLvl)
if err != nil {
return "", err
}
write(index, secLvl, addr)
if addChecksum {
return addr, nil
}
return addr[:consts.HashTrytesSize], nil
}
} | [
"func",
"DefaultAddrGen",
"(",
"provider",
"SeedProvider",
",",
"withCache",
"bool",
")",
"AddrGenFunc",
"{",
"var",
"cacheMu",
"sync",
".",
"Mutex",
"\n",
"var",
"cache",
"map",
"[",
"uint64",
"]",
"map",
"[",
"consts",
".",
"SecurityLevel",
"]",
"trinary",
".",
"Hash",
"\n\n",
"if",
"withCache",
"{",
"cache",
"=",
"map",
"[",
"uint64",
"]",
"map",
"[",
"consts",
".",
"SecurityLevel",
"]",
"trinary",
".",
"Hash",
"{",
"}",
"\n",
"}",
"\n\n",
"read",
":=",
"func",
"(",
"index",
"uint64",
",",
"secLvl",
"consts",
".",
"SecurityLevel",
",",
"addChecksum",
"bool",
")",
"trinary",
".",
"Hash",
"{",
"cacheMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cacheMu",
".",
"Unlock",
"(",
")",
"\n",
"m",
",",
"hasEntry",
":=",
"cache",
"[",
"index",
"]",
"\n",
"if",
"!",
"hasEntry",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"cachedAddr",
",",
"hasAddr",
":=",
"m",
"[",
"secLvl",
"]",
"\n",
"if",
"!",
"hasAddr",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"addChecksum",
"{",
"return",
"cachedAddr",
"\n",
"}",
"\n",
"return",
"cachedAddr",
"[",
":",
"consts",
".",
"HashTrytesSize",
"]",
"\n",
"}",
"\n\n",
"write",
":=",
"func",
"(",
"index",
"uint64",
",",
"secLvl",
"consts",
".",
"SecurityLevel",
",",
"addr",
"trinary",
".",
"Hash",
")",
"{",
"cacheMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cacheMu",
".",
"Unlock",
"(",
")",
"\n",
"m",
",",
"hasEntry",
":=",
"cache",
"[",
"index",
"]",
"\n",
"if",
"!",
"hasEntry",
"{",
"m",
"=",
"map",
"[",
"consts",
".",
"SecurityLevel",
"]",
"trinary",
".",
"Hash",
"{",
"}",
"\n",
"m",
"[",
"secLvl",
"]",
"=",
"addr",
"\n",
"cache",
"[",
"index",
"]",
"=",
"m",
"\n",
"return",
"\n",
"}",
"\n",
"m",
"[",
"secLvl",
"]",
"=",
"addr",
"\n",
"}",
"\n\n",
"generate",
":=",
"func",
"(",
"index",
"uint64",
",",
"secLvl",
"consts",
".",
"SecurityLevel",
")",
"(",
"trinary",
".",
"Hash",
",",
"error",
")",
"{",
"seed",
",",
"err",
":=",
"provider",
".",
"Seed",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"addr",
",",
"err",
":=",
"address",
".",
"GenerateAddress",
"(",
"seed",
",",
"index",
",",
"secLvl",
",",
"true",
")",
"\n",
"return",
"addr",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"withCache",
"{",
"return",
"func",
"(",
"index",
"uint64",
",",
"secLvl",
"consts",
".",
"SecurityLevel",
",",
"addChecksum",
"bool",
")",
"(",
"trinary",
".",
"Hash",
",",
"error",
")",
"{",
"addr",
",",
"err",
":=",
"generate",
"(",
"index",
",",
"secLvl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"addChecksum",
"{",
"return",
"addr",
",",
"nil",
"\n",
"}",
"\n",
"return",
"addr",
"[",
":",
"consts",
".",
"HashTrytesSize",
"]",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"func",
"(",
"index",
"uint64",
",",
"secLvl",
"consts",
".",
"SecurityLevel",
",",
"addChecksum",
"bool",
")",
"(",
"trinary",
".",
"Hash",
",",
"error",
")",
"{",
"if",
"hash",
":=",
"read",
"(",
"index",
",",
"secLvl",
",",
"addChecksum",
")",
";",
"hash",
"!=",
"\"",
"\"",
"{",
"return",
"hash",
",",
"nil",
"\n",
"}",
"\n\n",
"addr",
",",
"err",
":=",
"generate",
"(",
"index",
",",
"secLvl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"write",
"(",
"index",
",",
"secLvl",
",",
"addr",
")",
"\n",
"if",
"addChecksum",
"{",
"return",
"addr",
",",
"nil",
"\n",
"}",
"\n",
"return",
"addr",
"[",
":",
"consts",
".",
"HashTrytesSize",
"]",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // DefaultAddrGen is the default address generation function used by the account, if non is specified.
// withCache creates a function which caches the computed addresses by the index and security level for subsequent calls. | [
"DefaultAddrGen",
"is",
"the",
"default",
"address",
"generation",
"function",
"used",
"by",
"the",
"account",
"if",
"non",
"is",
"specified",
".",
"withCache",
"creates",
"a",
"function",
"which",
"caches",
"the",
"computed",
"addresses",
"by",
"the",
"index",
"and",
"security",
"level",
"for",
"subsequent",
"calls",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/settings.go#L32-L109 |
358 | iotaledger/iota.go | account/settings.go | DefaultPrepareTransfers | func DefaultPrepareTransfers(a *api.API, provider SeedProvider) PrepareTransfersFunc {
return func(transfers bundle.Transfers, options api.PrepareTransfersOptions) ([]trinary.Trytes, error) {
seed, err := provider.Seed()
if err != nil {
return nil, err
}
return a.PrepareTransfers(seed, transfers, options)
}
} | go | func DefaultPrepareTransfers(a *api.API, provider SeedProvider) PrepareTransfersFunc {
return func(transfers bundle.Transfers, options api.PrepareTransfersOptions) ([]trinary.Trytes, error) {
seed, err := provider.Seed()
if err != nil {
return nil, err
}
return a.PrepareTransfers(seed, transfers, options)
}
} | [
"func",
"DefaultPrepareTransfers",
"(",
"a",
"*",
"api",
".",
"API",
",",
"provider",
"SeedProvider",
")",
"PrepareTransfersFunc",
"{",
"return",
"func",
"(",
"transfers",
"bundle",
".",
"Transfers",
",",
"options",
"api",
".",
"PrepareTransfersOptions",
")",
"(",
"[",
"]",
"trinary",
".",
"Trytes",
",",
"error",
")",
"{",
"seed",
",",
"err",
":=",
"provider",
".",
"Seed",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"a",
".",
"PrepareTransfers",
"(",
"seed",
",",
"transfers",
",",
"options",
")",
"\n",
"}",
"\n",
"}"
] | // DefaultPrepareTransfers is the default prepare transfers function used by the account, if non is specified. | [
"DefaultPrepareTransfers",
"is",
"the",
"default",
"prepare",
"transfers",
"function",
"used",
"by",
"the",
"account",
"if",
"non",
"is",
"specified",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/settings.go#L112-L120 |
359 | iotaledger/iota.go | api/types.go | ToGetNewAddressOptions | func (gio GetInputsOptions) ToGetNewAddressOptions() GetNewAddressOptions {
if gio.End != nil {
total := *gio.End - gio.Start
return GetNewAddressOptions{
Index: gio.Start, Total: &total, Security: gio.Security, ReturnAll: true,
}
}
return GetNewAddressOptions{
Index: gio.Start, Security: gio.Security, ReturnAll: true,
}
} | go | func (gio GetInputsOptions) ToGetNewAddressOptions() GetNewAddressOptions {
if gio.End != nil {
total := *gio.End - gio.Start
return GetNewAddressOptions{
Index: gio.Start, Total: &total, Security: gio.Security, ReturnAll: true,
}
}
return GetNewAddressOptions{
Index: gio.Start, Security: gio.Security, ReturnAll: true,
}
} | [
"func",
"(",
"gio",
"GetInputsOptions",
")",
"ToGetNewAddressOptions",
"(",
")",
"GetNewAddressOptions",
"{",
"if",
"gio",
".",
"End",
"!=",
"nil",
"{",
"total",
":=",
"*",
"gio",
".",
"End",
"-",
"gio",
".",
"Start",
"\n",
"return",
"GetNewAddressOptions",
"{",
"Index",
":",
"gio",
".",
"Start",
",",
"Total",
":",
"&",
"total",
",",
"Security",
":",
"gio",
".",
"Security",
",",
"ReturnAll",
":",
"true",
",",
"}",
"\n",
"}",
"\n",
"return",
"GetNewAddressOptions",
"{",
"Index",
":",
"gio",
".",
"Start",
",",
"Security",
":",
"gio",
".",
"Security",
",",
"ReturnAll",
":",
"true",
",",
"}",
"\n",
"}"
] | // ToGetNewAddressOptions converts GetInputsOptions to GetNewAddressOptions. | [
"ToGetNewAddressOptions",
"converts",
"GetInputsOptions",
"to",
"GetNewAddressOptions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/types.go#L127-L137 |
360 | iotaledger/iota.go | api/types.go | ToGetNewAddressOptions | func (gto GetTransfersOptions) ToGetNewAddressOptions() GetNewAddressOptions {
opts := GetNewAddressOptions{}
opts.Index = gto.Start
opts.Security = gto.Security
opts.ReturnAll = true
if gto.End != nil {
total := *gto.End - gto.Start
opts.Total = &total
}
return opts
} | go | func (gto GetTransfersOptions) ToGetNewAddressOptions() GetNewAddressOptions {
opts := GetNewAddressOptions{}
opts.Index = gto.Start
opts.Security = gto.Security
opts.ReturnAll = true
if gto.End != nil {
total := *gto.End - gto.Start
opts.Total = &total
}
return opts
} | [
"func",
"(",
"gto",
"GetTransfersOptions",
")",
"ToGetNewAddressOptions",
"(",
")",
"GetNewAddressOptions",
"{",
"opts",
":=",
"GetNewAddressOptions",
"{",
"}",
"\n",
"opts",
".",
"Index",
"=",
"gto",
".",
"Start",
"\n",
"opts",
".",
"Security",
"=",
"gto",
".",
"Security",
"\n",
"opts",
".",
"ReturnAll",
"=",
"true",
"\n",
"if",
"gto",
".",
"End",
"!=",
"nil",
"{",
"total",
":=",
"*",
"gto",
".",
"End",
"-",
"gto",
".",
"Start",
"\n",
"opts",
".",
"Total",
"=",
"&",
"total",
"\n",
"}",
"\n",
"return",
"opts",
"\n",
"}"
] | // ToGetNewAddressOptions converts GetTransfersOptions to GetNewAddressOptions. | [
"ToGetNewAddressOptions",
"converts",
"GetTransfersOptions",
"to",
"GetNewAddressOptions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/types.go#L165-L175 |
361 | iotaledger/iota.go | api/iricalls.go | AddNeighbors | func (api *API) AddNeighbors(uris ...string) (int64, error) {
if err := Validate(ValidateURIs(uris...), ValidateNonEmptyStrings(ErrInvalidURI, uris...)); err != nil {
return 0, err
}
cmd := &AddNeighborsCommand{Command: Command{AddNeighborsCmd}, URIs: uris}
rsp := &AddNeighborsResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return 0, err
}
return rsp.AddedNeighbors, nil
} | go | func (api *API) AddNeighbors(uris ...string) (int64, error) {
if err := Validate(ValidateURIs(uris...), ValidateNonEmptyStrings(ErrInvalidURI, uris...)); err != nil {
return 0, err
}
cmd := &AddNeighborsCommand{Command: Command{AddNeighborsCmd}, URIs: uris}
rsp := &AddNeighborsResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return 0, err
}
return rsp.AddedNeighbors, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"AddNeighbors",
"(",
"uris",
"...",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateURIs",
"(",
"uris",
"...",
")",
",",
"ValidateNonEmptyStrings",
"(",
"ErrInvalidURI",
",",
"uris",
"...",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"cmd",
":=",
"&",
"AddNeighborsCommand",
"{",
"Command",
":",
"Command",
"{",
"AddNeighborsCmd",
"}",
",",
"URIs",
":",
"uris",
"}",
"\n",
"rsp",
":=",
"&",
"AddNeighborsResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"rsp",
".",
"AddedNeighbors",
",",
"nil",
"\n",
"}"
] | // AddNeighbors adds a list of neighbors to the connected IRI node.
// Assumes addNeighbors command is available on the node.
// AddNeighbors has only a temporary effect until the node relaunches. | [
"AddNeighbors",
"adds",
"a",
"list",
"of",
"neighbors",
"to",
"the",
"connected",
"IRI",
"node",
".",
"Assumes",
"addNeighbors",
"command",
"is",
"available",
"on",
"the",
"node",
".",
"AddNeighbors",
"has",
"only",
"a",
"temporary",
"effect",
"until",
"the",
"node",
"relaunches",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L16-L26 |
362 | iotaledger/iota.go | api/iricalls.go | BroadcastTransactions | func (api *API) BroadcastTransactions(trytes ...Trytes) ([]Trytes, error) {
if err := Validate(ValidateAttachedTransactionTrytes(trytes...)); err != nil {
return nil, err
}
cmd := &BroadcastTransactionsCommand{Trytes: trytes, Command: Command{BroadcastTransactionsCmd}}
if err := api.provider.Send(cmd, nil); err != nil {
return nil, err
}
return trytes, nil
} | go | func (api *API) BroadcastTransactions(trytes ...Trytes) ([]Trytes, error) {
if err := Validate(ValidateAttachedTransactionTrytes(trytes...)); err != nil {
return nil, err
}
cmd := &BroadcastTransactionsCommand{Trytes: trytes, Command: Command{BroadcastTransactionsCmd}}
if err := api.provider.Send(cmd, nil); err != nil {
return nil, err
}
return trytes, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"BroadcastTransactions",
"(",
"trytes",
"...",
"Trytes",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateAttachedTransactionTrytes",
"(",
"trytes",
"...",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cmd",
":=",
"&",
"BroadcastTransactionsCommand",
"{",
"Trytes",
":",
"trytes",
",",
"Command",
":",
"Command",
"{",
"BroadcastTransactionsCmd",
"}",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"trytes",
",",
"nil",
"\n",
"}"
] | // BroadcastTransactions broadcasts a list of attached transaction trytes to the network.
// Tip-selection and Proof-of-Work must be done first by calling
// GetTransactionsToApprove and AttachToTangle or an equivalent attach method.
//
// You may use this method to increase odds of effective transaction propagation.
//
// Persist the transaction trytes in local storage before calling this command for first time, to ensure
// that reattachment is possible, until your bundle has been included. | [
"BroadcastTransactions",
"broadcasts",
"a",
"list",
"of",
"attached",
"transaction",
"trytes",
"to",
"the",
"network",
".",
"Tip",
"-",
"selection",
"and",
"Proof",
"-",
"of",
"-",
"Work",
"must",
"be",
"done",
"first",
"by",
"calling",
"GetTransactionsToApprove",
"and",
"AttachToTangle",
"or",
"an",
"equivalent",
"attach",
"method",
".",
"You",
"may",
"use",
"this",
"method",
"to",
"increase",
"odds",
"of",
"effective",
"transaction",
"propagation",
".",
"Persist",
"the",
"transaction",
"trytes",
"in",
"local",
"storage",
"before",
"calling",
"this",
"command",
"for",
"first",
"time",
"to",
"ensure",
"that",
"reattachment",
"is",
"possible",
"until",
"your",
"bundle",
"has",
"been",
"included",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L71-L80 |
363 | iotaledger/iota.go | api/iricalls.go | GetBalances | func (api *API) GetBalances(addresses Hashes, threshold uint64, tips ...Hash) (*Balances, error) {
if err := Validate(ValidateAddresses(false, addresses...)); err != nil {
return nil, err
}
if threshold > 100 {
return nil, ErrInvalidThreshold
}
cleanedAddrs, err := checksum.RemoveChecksums(addresses)
if err != nil {
return nil, err
}
cmd := &GetBalancesCommand{
Addresses: cleanedAddrs,
Threshold: threshold,
Command: Command{GetBalancesCmd},
Tips: tips,
}
rsp := &GetBalancesResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
balances := &Balances{
Balances: make([]uint64, len(rsp.Balances)),
Milestone: rsp.Milestone, MilestoneIndex: rsp.MilestoneIndex,
}
for i, s := range rsp.Balances {
num, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return nil, err
}
balances.Balances[i] = num
}
return balances, err
} | go | func (api *API) GetBalances(addresses Hashes, threshold uint64, tips ...Hash) (*Balances, error) {
if err := Validate(ValidateAddresses(false, addresses...)); err != nil {
return nil, err
}
if threshold > 100 {
return nil, ErrInvalidThreshold
}
cleanedAddrs, err := checksum.RemoveChecksums(addresses)
if err != nil {
return nil, err
}
cmd := &GetBalancesCommand{
Addresses: cleanedAddrs,
Threshold: threshold,
Command: Command{GetBalancesCmd},
Tips: tips,
}
rsp := &GetBalancesResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
balances := &Balances{
Balances: make([]uint64, len(rsp.Balances)),
Milestone: rsp.Milestone, MilestoneIndex: rsp.MilestoneIndex,
}
for i, s := range rsp.Balances {
num, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return nil, err
}
balances.Balances[i] = num
}
return balances, err
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetBalances",
"(",
"addresses",
"Hashes",
",",
"threshold",
"uint64",
",",
"tips",
"...",
"Hash",
")",
"(",
"*",
"Balances",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateAddresses",
"(",
"false",
",",
"addresses",
"...",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"threshold",
">",
"100",
"{",
"return",
"nil",
",",
"ErrInvalidThreshold",
"\n",
"}",
"\n\n",
"cleanedAddrs",
",",
"err",
":=",
"checksum",
".",
"RemoveChecksums",
"(",
"addresses",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"GetBalancesCommand",
"{",
"Addresses",
":",
"cleanedAddrs",
",",
"Threshold",
":",
"threshold",
",",
"Command",
":",
"Command",
"{",
"GetBalancesCmd",
"}",
",",
"Tips",
":",
"tips",
",",
"}",
"\n",
"rsp",
":=",
"&",
"GetBalancesResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"balances",
":=",
"&",
"Balances",
"{",
"Balances",
":",
"make",
"(",
"[",
"]",
"uint64",
",",
"len",
"(",
"rsp",
".",
"Balances",
")",
")",
",",
"Milestone",
":",
"rsp",
".",
"Milestone",
",",
"MilestoneIndex",
":",
"rsp",
".",
"MilestoneIndex",
",",
"}",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"rsp",
".",
"Balances",
"{",
"num",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"balances",
".",
"Balances",
"[",
"i",
"]",
"=",
"num",
"\n",
"}",
"\n",
"return",
"balances",
",",
"err",
"\n",
"}"
] | // GetBalances fetches confirmed balances of the given addresses at the latest solid milestone. | [
"GetBalances",
"fetches",
"confirmed",
"balances",
"of",
"the",
"given",
"addresses",
"at",
"the",
"latest",
"solid",
"milestone",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L162-L198 |
364 | iotaledger/iota.go | api/iricalls.go | GetInclusionStates | func (api *API) GetInclusionStates(txHashes Hashes, tips ...Hash) ([]bool, error) {
if err := Validate(
ValidateTransactionHashes(txHashes...),
ValidateNonEmptyStrings(ErrInvalidTransactionHash, txHashes...),
ValidateTransactionHashes(tips...),
ValidateNonEmptyStrings(ErrInvalidTransactionHash, tips...),
); err != nil {
return nil, err
}
cmd := &GetInclusionStatesCommand{Transactions: txHashes, Tips: tips, Command: Command{GetInclusionStatesCmd}}
rsp := &GetInclusionStatesResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
return rsp.States, nil
} | go | func (api *API) GetInclusionStates(txHashes Hashes, tips ...Hash) ([]bool, error) {
if err := Validate(
ValidateTransactionHashes(txHashes...),
ValidateNonEmptyStrings(ErrInvalidTransactionHash, txHashes...),
ValidateTransactionHashes(tips...),
ValidateNonEmptyStrings(ErrInvalidTransactionHash, tips...),
); err != nil {
return nil, err
}
cmd := &GetInclusionStatesCommand{Transactions: txHashes, Tips: tips, Command: Command{GetInclusionStatesCmd}}
rsp := &GetInclusionStatesResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
return rsp.States, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetInclusionStates",
"(",
"txHashes",
"Hashes",
",",
"tips",
"...",
"Hash",
")",
"(",
"[",
"]",
"bool",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateTransactionHashes",
"(",
"txHashes",
"...",
")",
",",
"ValidateNonEmptyStrings",
"(",
"ErrInvalidTransactionHash",
",",
"txHashes",
"...",
")",
",",
"ValidateTransactionHashes",
"(",
"tips",
"...",
")",
",",
"ValidateNonEmptyStrings",
"(",
"ErrInvalidTransactionHash",
",",
"tips",
"...",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"GetInclusionStatesCommand",
"{",
"Transactions",
":",
"txHashes",
",",
"Tips",
":",
"tips",
",",
"Command",
":",
"Command",
"{",
"GetInclusionStatesCmd",
"}",
"}",
"\n",
"rsp",
":=",
"&",
"GetInclusionStatesResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rsp",
".",
"States",
",",
"nil",
"\n",
"}"
] | // GetInclusionStates fetches inclusion states of a given list of transactions. | [
"GetInclusionStates",
"fetches",
"inclusion",
"states",
"of",
"a",
"given",
"list",
"of",
"transactions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L201-L217 |
365 | iotaledger/iota.go | api/iricalls.go | GetNeighbors | func (api *API) GetNeighbors() (Neighbors, error) {
cmd := &GetNeighborsCommand{Command: Command{GetNeighborsCmd}}
rsp := &GetNeighborsResponse{}
err := api.provider.Send(cmd, rsp)
if err != nil {
return nil, err
}
return rsp.Neighbors, nil
} | go | func (api *API) GetNeighbors() (Neighbors, error) {
cmd := &GetNeighborsCommand{Command: Command{GetNeighborsCmd}}
rsp := &GetNeighborsResponse{}
err := api.provider.Send(cmd, rsp)
if err != nil {
return nil, err
}
return rsp.Neighbors, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetNeighbors",
"(",
")",
"(",
"Neighbors",
",",
"error",
")",
"{",
"cmd",
":=",
"&",
"GetNeighborsCommand",
"{",
"Command",
":",
"Command",
"{",
"GetNeighborsCmd",
"}",
"}",
"\n",
"rsp",
":=",
"&",
"GetNeighborsResponse",
"{",
"}",
"\n",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"rsp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rsp",
".",
"Neighbors",
",",
"nil",
"\n",
"}"
] | // GetNeighbors returns the list of connected neighbors of the connected node. | [
"GetNeighbors",
"returns",
"the",
"list",
"of",
"connected",
"neighbors",
"of",
"the",
"connected",
"node",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L220-L228 |
366 | iotaledger/iota.go | api/iricalls.go | GetNodeInfo | func (api *API) GetNodeInfo() (*GetNodeInfoResponse, error) {
cmd := &GetNodeInfoCommand{Command: Command{GetNodeInfoCmd}}
rsp := &GetNodeInfoResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
return rsp, nil
} | go | func (api *API) GetNodeInfo() (*GetNodeInfoResponse, error) {
cmd := &GetNodeInfoCommand{Command: Command{GetNodeInfoCmd}}
rsp := &GetNodeInfoResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
return rsp, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetNodeInfo",
"(",
")",
"(",
"*",
"GetNodeInfoResponse",
",",
"error",
")",
"{",
"cmd",
":=",
"&",
"GetNodeInfoCommand",
"{",
"Command",
":",
"Command",
"{",
"GetNodeInfoCmd",
"}",
"}",
"\n",
"rsp",
":=",
"&",
"GetNodeInfoResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rsp",
",",
"nil",
"\n",
"}"
] | // GetNodeInfo returns information about the connected node. | [
"GetNodeInfo",
"returns",
"information",
"about",
"the",
"connected",
"node",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L231-L238 |
367 | iotaledger/iota.go | api/iricalls.go | GetTrytes | func (api *API) GetTrytes(hashes ...Hash) ([]Trytes, error) {
if err := Validate(
ValidateNonEmptyStrings(ErrInvalidTransactionHash, hashes...),
ValidateTransactionHashes(hashes...),
); err != nil {
return nil, err
}
cmd := &GetTrytesCommand{Hashes: hashes, Command: Command{GetTrytesCmd}}
rsp := &GetTrytesResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
return rsp.Trytes, nil
} | go | func (api *API) GetTrytes(hashes ...Hash) ([]Trytes, error) {
if err := Validate(
ValidateNonEmptyStrings(ErrInvalidTransactionHash, hashes...),
ValidateTransactionHashes(hashes...),
); err != nil {
return nil, err
}
cmd := &GetTrytesCommand{Hashes: hashes, Command: Command{GetTrytesCmd}}
rsp := &GetTrytesResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
return rsp.Trytes, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"GetTrytes",
"(",
"hashes",
"...",
"Hash",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateNonEmptyStrings",
"(",
"ErrInvalidTransactionHash",
",",
"hashes",
"...",
")",
",",
"ValidateTransactionHashes",
"(",
"hashes",
"...",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cmd",
":=",
"&",
"GetTrytesCommand",
"{",
"Hashes",
":",
"hashes",
",",
"Command",
":",
"Command",
"{",
"GetTrytesCmd",
"}",
"}",
"\n",
"rsp",
":=",
"&",
"GetTrytesResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rsp",
".",
"Trytes",
",",
"nil",
"\n",
"}"
] | // GetTrytes fetches the transaction trytes given a list of transaction hashes. | [
"GetTrytes",
"fetches",
"the",
"transaction",
"trytes",
"given",
"a",
"list",
"of",
"transaction",
"hashes",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L277-L290 |
368 | iotaledger/iota.go | api/iricalls.go | InterruptAttachToTangle | func (api *API) InterruptAttachToTangle() error {
cmd := &InterruptAttachToTangleCommand{Command: Command{InterruptAttachToTangleCmd}}
return api.provider.Send(cmd, nil)
} | go | func (api *API) InterruptAttachToTangle() error {
cmd := &InterruptAttachToTangleCommand{Command: Command{InterruptAttachToTangleCmd}}
return api.provider.Send(cmd, nil)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"InterruptAttachToTangle",
"(",
")",
"error",
"{",
"cmd",
":=",
"&",
"InterruptAttachToTangleCommand",
"{",
"Command",
":",
"Command",
"{",
"InterruptAttachToTangleCmd",
"}",
"}",
"\n",
"return",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"nil",
")",
"\n",
"}"
] | // InterruptAttachToTangle interrupts the currently ongoing Proof-of-Work on the connected node. | [
"InterruptAttachToTangle",
"interrupts",
"the",
"currently",
"ongoing",
"Proof",
"-",
"of",
"-",
"Work",
"on",
"the",
"connected",
"node",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L293-L296 |
369 | iotaledger/iota.go | api/iricalls.go | RemoveNeighbors | func (api *API) RemoveNeighbors(uris ...string) (int64, error) {
if err := Validate(
ValidateNonEmptyStrings(ErrInvalidURI, uris...),
ValidateURIs(uris...),
); err != nil {
return 0, err
}
cmd := &RemoveNeighborsCommand{Command: Command{RemoveNeighborsCmd}, URIs: uris}
rsp := &RemoveNeighborsResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return 0, err
}
return rsp.RemovedNeighbors, nil
} | go | func (api *API) RemoveNeighbors(uris ...string) (int64, error) {
if err := Validate(
ValidateNonEmptyStrings(ErrInvalidURI, uris...),
ValidateURIs(uris...),
); err != nil {
return 0, err
}
cmd := &RemoveNeighborsCommand{Command: Command{RemoveNeighborsCmd}, URIs: uris}
rsp := &RemoveNeighborsResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return 0, err
}
return rsp.RemovedNeighbors, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"RemoveNeighbors",
"(",
"uris",
"...",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateNonEmptyStrings",
"(",
"ErrInvalidURI",
",",
"uris",
"...",
")",
",",
"ValidateURIs",
"(",
"uris",
"...",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"cmd",
":=",
"&",
"RemoveNeighborsCommand",
"{",
"Command",
":",
"Command",
"{",
"RemoveNeighborsCmd",
"}",
",",
"URIs",
":",
"uris",
"}",
"\n",
"rsp",
":=",
"&",
"RemoveNeighborsResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"rsp",
".",
"RemovedNeighbors",
",",
"nil",
"\n",
"}"
] | // RemoveNeighbors removes a list of neighbors from the connected IRI node.
// This method has a temporary effect until the IRI node relaunches. | [
"RemoveNeighbors",
"removes",
"a",
"list",
"of",
"neighbors",
"from",
"the",
"connected",
"IRI",
"node",
".",
"This",
"method",
"has",
"a",
"temporary",
"effect",
"until",
"the",
"IRI",
"node",
"relaunches",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L300-L313 |
370 | iotaledger/iota.go | api/iricalls.go | StoreTransactions | func (api *API) StoreTransactions(trytes ...Trytes) ([]Trytes, error) {
if err := Validate(
ValidateNonEmptyStrings(ErrInvalidTrytes, trytes...),
ValidateAttachedTransactionTrytes(trytes...),
); err != nil {
return nil, err
}
cmd := &StoreTransactionsCommand{Trytes: trytes, Command: Command{StoreTransactionsCmd}}
if err := api.provider.Send(cmd, nil); err != nil {
return nil, err
}
return trytes, nil
} | go | func (api *API) StoreTransactions(trytes ...Trytes) ([]Trytes, error) {
if err := Validate(
ValidateNonEmptyStrings(ErrInvalidTrytes, trytes...),
ValidateAttachedTransactionTrytes(trytes...),
); err != nil {
return nil, err
}
cmd := &StoreTransactionsCommand{Trytes: trytes, Command: Command{StoreTransactionsCmd}}
if err := api.provider.Send(cmd, nil); err != nil {
return nil, err
}
return trytes, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"StoreTransactions",
"(",
"trytes",
"...",
"Trytes",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateNonEmptyStrings",
"(",
"ErrInvalidTrytes",
",",
"trytes",
"...",
")",
",",
"ValidateAttachedTransactionTrytes",
"(",
"trytes",
"...",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cmd",
":=",
"&",
"StoreTransactionsCommand",
"{",
"Trytes",
":",
"trytes",
",",
"Command",
":",
"Command",
"{",
"StoreTransactionsCmd",
"}",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"trytes",
",",
"nil",
"\n",
"}"
] | // StoreTransactions persists a list of attached transaction trytes in the store of the connected node.
// Tip-selection and Proof-of-Work must be done first by calling GetTransactionsToApprove and
// AttachToTangle or an equivalent attach method.
//
// Persist the transaction trytes in local storage before calling this command, to ensure
// reattachment is possible, until your bundle has been included.
//
// Any transactions stored with this command will eventually be erased as a result of a snapshot. | [
"StoreTransactions",
"persists",
"a",
"list",
"of",
"attached",
"transaction",
"trytes",
"in",
"the",
"store",
"of",
"the",
"connected",
"node",
".",
"Tip",
"-",
"selection",
"and",
"Proof",
"-",
"of",
"-",
"Work",
"must",
"be",
"done",
"first",
"by",
"calling",
"GetTransactionsToApprove",
"and",
"AttachToTangle",
"or",
"an",
"equivalent",
"attach",
"method",
".",
"Persist",
"the",
"transaction",
"trytes",
"in",
"local",
"storage",
"before",
"calling",
"this",
"command",
"to",
"ensure",
"reattachment",
"is",
"possible",
"until",
"your",
"bundle",
"has",
"been",
"included",
".",
"Any",
"transactions",
"stored",
"with",
"this",
"command",
"will",
"eventually",
"be",
"erased",
"as",
"a",
"result",
"of",
"a",
"snapshot",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L323-L335 |
371 | iotaledger/iota.go | api/iricalls.go | WereAddressesSpentFrom | func (api *API) WereAddressesSpentFrom(addresses ...Hash) ([]bool, error) {
if err := Validate(
ValidateAddresses(false, addresses...),
); err != nil {
return nil, err
}
cleanedAddrs, err := checksum.RemoveChecksums(addresses)
if err != nil {
return nil, err
}
cmd := &WereAddressesSpentFromCommand{Addresses: cleanedAddrs, Command: Command{WereAddressesSpentFromCmd}}
rsp := &WereAddressesSpentFromResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
return rsp.States, nil
} | go | func (api *API) WereAddressesSpentFrom(addresses ...Hash) ([]bool, error) {
if err := Validate(
ValidateAddresses(false, addresses...),
); err != nil {
return nil, err
}
cleanedAddrs, err := checksum.RemoveChecksums(addresses)
if err != nil {
return nil, err
}
cmd := &WereAddressesSpentFromCommand{Addresses: cleanedAddrs, Command: Command{WereAddressesSpentFromCmd}}
rsp := &WereAddressesSpentFromResponse{}
if err := api.provider.Send(cmd, rsp); err != nil {
return nil, err
}
return rsp.States, nil
} | [
"func",
"(",
"api",
"*",
"API",
")",
"WereAddressesSpentFrom",
"(",
"addresses",
"...",
"Hash",
")",
"(",
"[",
"]",
"bool",
",",
"error",
")",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateAddresses",
"(",
"false",
",",
"addresses",
"...",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cleanedAddrs",
",",
"err",
":=",
"checksum",
".",
"RemoveChecksums",
"(",
"addresses",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"WereAddressesSpentFromCommand",
"{",
"Addresses",
":",
"cleanedAddrs",
",",
"Command",
":",
"Command",
"{",
"WereAddressesSpentFromCmd",
"}",
"}",
"\n",
"rsp",
":=",
"&",
"WereAddressesSpentFromResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"api",
".",
"provider",
".",
"Send",
"(",
"cmd",
",",
"rsp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rsp",
".",
"States",
",",
"nil",
"\n",
"}"
] | // WereAddressesSpentFrom checks whether the given addresses were already spent. | [
"WereAddressesSpentFrom",
"checks",
"whether",
"the",
"given",
"addresses",
"were",
"already",
"spent",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/api/iricalls.go#L338-L356 |
372 | iotaledger/iota.go | curl/hamming/hamming.go | Hamming | func Hamming(c *curl.Curl, offset, end, security int) Trits {
lmid, hmid := pow.Para(c.State)
lmid[offset] = pow.PearlDiverMidStateLow0
hmid[offset] = pow.PearlDiverMidStateHigh0
lmid[offset+1] = pow.PearlDiverMidStateLow1
hmid[offset+1] = pow.PearlDiverMidStateHigh1
lmid[offset+2] = pow.PearlDiverMidStateLow2
hmid[offset+2] = pow.PearlDiverMidStateHigh2
lmid[offset+3] = pow.PearlDiverMidStateLow3
hmid[offset+3] = pow.PearlDiverMidStateHigh3
cancelled := false
nonce, _, foundIndex := pow.Loop(lmid, hmid, security, &cancelled, check, int(c.Rounds))
if foundIndex >= 0 {
copy(c.State[offset:], ptritsToTrits(lmid, hmid, uint64(foundIndex), len(c.State)-offset))
return nonce
}
return nil
} | go | func Hamming(c *curl.Curl, offset, end, security int) Trits {
lmid, hmid := pow.Para(c.State)
lmid[offset] = pow.PearlDiverMidStateLow0
hmid[offset] = pow.PearlDiverMidStateHigh0
lmid[offset+1] = pow.PearlDiverMidStateLow1
hmid[offset+1] = pow.PearlDiverMidStateHigh1
lmid[offset+2] = pow.PearlDiverMidStateLow2
hmid[offset+2] = pow.PearlDiverMidStateHigh2
lmid[offset+3] = pow.PearlDiverMidStateLow3
hmid[offset+3] = pow.PearlDiverMidStateHigh3
cancelled := false
nonce, _, foundIndex := pow.Loop(lmid, hmid, security, &cancelled, check, int(c.Rounds))
if foundIndex >= 0 {
copy(c.State[offset:], ptritsToTrits(lmid, hmid, uint64(foundIndex), len(c.State)-offset))
return nonce
}
return nil
} | [
"func",
"Hamming",
"(",
"c",
"*",
"curl",
".",
"Curl",
",",
"offset",
",",
"end",
",",
"security",
"int",
")",
"Trits",
"{",
"lmid",
",",
"hmid",
":=",
"pow",
".",
"Para",
"(",
"c",
".",
"State",
")",
"\n\n",
"lmid",
"[",
"offset",
"]",
"=",
"pow",
".",
"PearlDiverMidStateLow0",
"\n",
"hmid",
"[",
"offset",
"]",
"=",
"pow",
".",
"PearlDiverMidStateHigh0",
"\n",
"lmid",
"[",
"offset",
"+",
"1",
"]",
"=",
"pow",
".",
"PearlDiverMidStateLow1",
"\n",
"hmid",
"[",
"offset",
"+",
"1",
"]",
"=",
"pow",
".",
"PearlDiverMidStateHigh1",
"\n",
"lmid",
"[",
"offset",
"+",
"2",
"]",
"=",
"pow",
".",
"PearlDiverMidStateLow2",
"\n",
"hmid",
"[",
"offset",
"+",
"2",
"]",
"=",
"pow",
".",
"PearlDiverMidStateHigh2",
"\n",
"lmid",
"[",
"offset",
"+",
"3",
"]",
"=",
"pow",
".",
"PearlDiverMidStateLow3",
"\n",
"hmid",
"[",
"offset",
"+",
"3",
"]",
"=",
"pow",
".",
"PearlDiverMidStateHigh3",
"\n\n",
"cancelled",
":=",
"false",
"\n",
"nonce",
",",
"_",
",",
"foundIndex",
":=",
"pow",
".",
"Loop",
"(",
"lmid",
",",
"hmid",
",",
"security",
",",
"&",
"cancelled",
",",
"check",
",",
"int",
"(",
"c",
".",
"Rounds",
")",
")",
"\n",
"if",
"foundIndex",
">=",
"0",
"{",
"copy",
"(",
"c",
".",
"State",
"[",
"offset",
":",
"]",
",",
"ptritsToTrits",
"(",
"lmid",
",",
"hmid",
",",
"uint64",
"(",
"foundIndex",
")",
",",
"len",
"(",
"c",
".",
"State",
")",
"-",
"offset",
")",
")",
"\n",
"return",
"nonce",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Hamming calculates the hamming nonce. | [
"Hamming",
"calculates",
"the",
"hamming",
"nonce",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/hamming/hamming.go#L41-L60 |
373 | iotaledger/iota.go | converter/ascii.go | ASCIIToTrytes | func ASCIIToTrytes(s string) (Trytes, error) {
if !asciiRegex.MatchString(s) {
return "", ErrInvalidASCIIInput
}
trytesStr := ""
for _, c := range s {
trytesStr += string(TryteAlphabet[c%27])
trytesStr += string(TryteAlphabet[(c-c%27)/27])
}
return NewTrytes(trytesStr)
} | go | func ASCIIToTrytes(s string) (Trytes, error) {
if !asciiRegex.MatchString(s) {
return "", ErrInvalidASCIIInput
}
trytesStr := ""
for _, c := range s {
trytesStr += string(TryteAlphabet[c%27])
trytesStr += string(TryteAlphabet[(c-c%27)/27])
}
return NewTrytes(trytesStr)
} | [
"func",
"ASCIIToTrytes",
"(",
"s",
"string",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"if",
"!",
"asciiRegex",
".",
"MatchString",
"(",
"s",
")",
"{",
"return",
"\"",
"\"",
",",
"ErrInvalidASCIIInput",
"\n",
"}",
"\n\n",
"trytesStr",
":=",
"\"",
"\"",
"\n\n",
"for",
"_",
",",
"c",
":=",
"range",
"s",
"{",
"trytesStr",
"+=",
"string",
"(",
"TryteAlphabet",
"[",
"c",
"%",
"27",
"]",
")",
"\n",
"trytesStr",
"+=",
"string",
"(",
"TryteAlphabet",
"[",
"(",
"c",
"-",
"c",
"%",
"27",
")",
"/",
"27",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"NewTrytes",
"(",
"trytesStr",
")",
"\n",
"}"
] | // ASCIIToTrytes converts an ascii encoded string to trytes. | [
"ASCIIToTrytes",
"converts",
"an",
"ascii",
"encoded",
"string",
"to",
"trytes",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/converter/ascii.go#L14-L27 |
374 | iotaledger/iota.go | converter/ascii.go | TrytesToASCII | func TrytesToASCII(trytes Trytes) (string, error) {
if err := ValidTrytes(trytes); err != nil {
return "", err
}
if len(trytes)%2 != 0 {
return "", ErrInvalidOddLength
}
ascii := ""
for i := 0; i < len(trytes); i += 2 {
ascii += string(strings.IndexRune(TryteAlphabet, rune(trytes[i])) + (strings.IndexRune(TryteAlphabet, rune(trytes[i+1])) * 27))
}
return ascii, nil
} | go | func TrytesToASCII(trytes Trytes) (string, error) {
if err := ValidTrytes(trytes); err != nil {
return "", err
}
if len(trytes)%2 != 0 {
return "", ErrInvalidOddLength
}
ascii := ""
for i := 0; i < len(trytes); i += 2 {
ascii += string(strings.IndexRune(TryteAlphabet, rune(trytes[i])) + (strings.IndexRune(TryteAlphabet, rune(trytes[i+1])) * 27))
}
return ascii, nil
} | [
"func",
"TrytesToASCII",
"(",
"trytes",
"Trytes",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"err",
":=",
"ValidTrytes",
"(",
"trytes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"trytes",
")",
"%",
"2",
"!=",
"0",
"{",
"return",
"\"",
"\"",
",",
"ErrInvalidOddLength",
"\n",
"}",
"\n\n",
"ascii",
":=",
"\"",
"\"",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"trytes",
")",
";",
"i",
"+=",
"2",
"{",
"ascii",
"+=",
"string",
"(",
"strings",
".",
"IndexRune",
"(",
"TryteAlphabet",
",",
"rune",
"(",
"trytes",
"[",
"i",
"]",
")",
")",
"+",
"(",
"strings",
".",
"IndexRune",
"(",
"TryteAlphabet",
",",
"rune",
"(",
"trytes",
"[",
"i",
"+",
"1",
"]",
")",
")",
"*",
"27",
")",
")",
"\n",
"}",
"\n\n",
"return",
"ascii",
",",
"nil",
"\n",
"}"
] | // TrytesToASCII converts trytes of even length to an ascii string. | [
"TrytesToASCII",
"converts",
"trytes",
"of",
"even",
"length",
"to",
"an",
"ascii",
"string",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/converter/ascii.go#L30-L45 |
375 | iotaledger/iota.go | pow/pow_c.go | CProofOfWork | func CProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
return cProofOfWork(trytes, mwm, nil, parallelism...)
} | go | func CProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error) {
return cProofOfWork(trytes, mwm, nil, parallelism...)
} | [
"func",
"CProofOfWork",
"(",
"trytes",
"Trytes",
",",
"mwm",
"int",
",",
"parallelism",
"...",
"int",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"return",
"cProofOfWork",
"(",
"trytes",
",",
"mwm",
",",
"nil",
",",
"parallelism",
"...",
")",
"\n",
"}"
] | // PoWC does proof of work on the given trytes via native C code. | [
"PoWC",
"does",
"proof",
"of",
"work",
"on",
"the",
"given",
"trytes",
"via",
"native",
"C",
"code",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/pow/pow_c.go#L228-L230 |
376 | iotaledger/iota.go | signing/signing.go | Digests | func Digests(key Trits, spongeFunc ...SpongeFunction) (Trits, error) {
var err error
fragments := int(math.Floor(float64(len(key)) / KeyFragmentLength))
digests := make(Trits, fragments*HashTrinarySize)
buf := make(Trits, HashTrinarySize)
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
defer h.Reset()
// iterate through each key fragment
for i := 0; i < fragments; i++ {
keyFragment := key[i*KeyFragmentLength : (i+1)*KeyFragmentLength]
// each fragment consists of 27 segments
for j := 0; j < KeySegmentsPerFragment; j++ {
copy(buf, keyFragment[j*HashTrinarySize:(j+1)*HashTrinarySize])
// hash each segment 26 times
for k := 0; k < KeySegmentHashRounds; k++ {
h.Absorb(buf)
buf, err = h.Squeeze(HashTrinarySize)
if err != nil {
return nil, err
}
h.Reset()
}
copy(keyFragment[j*HashTrinarySize:], buf)
}
// hash the key fragment (which now consists of hashed segments)
if err := h.Absorb(keyFragment); err != nil {
return nil, err
}
buf, err := h.Squeeze(HashTrinarySize)
if err != nil {
return nil, err
}
copy(digests[i*HashTrinarySize:], buf)
h.Reset()
}
return digests, nil
} | go | func Digests(key Trits, spongeFunc ...SpongeFunction) (Trits, error) {
var err error
fragments := int(math.Floor(float64(len(key)) / KeyFragmentLength))
digests := make(Trits, fragments*HashTrinarySize)
buf := make(Trits, HashTrinarySize)
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
defer h.Reset()
// iterate through each key fragment
for i := 0; i < fragments; i++ {
keyFragment := key[i*KeyFragmentLength : (i+1)*KeyFragmentLength]
// each fragment consists of 27 segments
for j := 0; j < KeySegmentsPerFragment; j++ {
copy(buf, keyFragment[j*HashTrinarySize:(j+1)*HashTrinarySize])
// hash each segment 26 times
for k := 0; k < KeySegmentHashRounds; k++ {
h.Absorb(buf)
buf, err = h.Squeeze(HashTrinarySize)
if err != nil {
return nil, err
}
h.Reset()
}
copy(keyFragment[j*HashTrinarySize:], buf)
}
// hash the key fragment (which now consists of hashed segments)
if err := h.Absorb(keyFragment); err != nil {
return nil, err
}
buf, err := h.Squeeze(HashTrinarySize)
if err != nil {
return nil, err
}
copy(digests[i*HashTrinarySize:], buf)
h.Reset()
}
return digests, nil
} | [
"func",
"Digests",
"(",
"key",
"Trits",
",",
"spongeFunc",
"...",
"SpongeFunction",
")",
"(",
"Trits",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"fragments",
":=",
"int",
"(",
"math",
".",
"Floor",
"(",
"float64",
"(",
"len",
"(",
"key",
")",
")",
"/",
"KeyFragmentLength",
")",
")",
"\n",
"digests",
":=",
"make",
"(",
"Trits",
",",
"fragments",
"*",
"HashTrinarySize",
")",
"\n",
"buf",
":=",
"make",
"(",
"Trits",
",",
"HashTrinarySize",
")",
"\n\n",
"h",
":=",
"GetSpongeFunc",
"(",
"spongeFunc",
",",
"kerl",
".",
"NewKerl",
")",
"\n",
"defer",
"h",
".",
"Reset",
"(",
")",
"\n\n",
"// iterate through each key fragment",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"fragments",
";",
"i",
"++",
"{",
"keyFragment",
":=",
"key",
"[",
"i",
"*",
"KeyFragmentLength",
":",
"(",
"i",
"+",
"1",
")",
"*",
"KeyFragmentLength",
"]",
"\n\n",
"// each fragment consists of 27 segments",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"KeySegmentsPerFragment",
";",
"j",
"++",
"{",
"copy",
"(",
"buf",
",",
"keyFragment",
"[",
"j",
"*",
"HashTrinarySize",
":",
"(",
"j",
"+",
"1",
")",
"*",
"HashTrinarySize",
"]",
")",
"\n\n",
"// hash each segment 26 times",
"for",
"k",
":=",
"0",
";",
"k",
"<",
"KeySegmentHashRounds",
";",
"k",
"++",
"{",
"h",
".",
"Absorb",
"(",
"buf",
")",
"\n",
"buf",
",",
"err",
"=",
"h",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"h",
".",
"Reset",
"(",
")",
"\n",
"}",
"\n\n",
"copy",
"(",
"keyFragment",
"[",
"j",
"*",
"HashTrinarySize",
":",
"]",
",",
"buf",
")",
"\n",
"}",
"\n\n",
"// hash the key fragment (which now consists of hashed segments)",
"if",
"err",
":=",
"h",
".",
"Absorb",
"(",
"keyFragment",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
":=",
"h",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"copy",
"(",
"digests",
"[",
"i",
"*",
"HashTrinarySize",
":",
"]",
",",
"buf",
")",
"\n\n",
"h",
".",
"Reset",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"digests",
",",
"nil",
"\n",
"}"
] | // Digests hashes each segment of each key fragment 26 times and returns them.
// Optionally takes the SpongeFunction to use. Default is Kerl. | [
"Digests",
"hashes",
"each",
"segment",
"of",
"each",
"key",
"fragment",
"26",
"times",
"and",
"returns",
"them",
".",
"Optionally",
"takes",
"the",
"SpongeFunction",
"to",
"use",
".",
"Default",
"is",
"Kerl",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/signing/signing.go#L72-L118 |
377 | iotaledger/iota.go | signing/signing.go | Digest | func Digest(normalizedBundleHashFragment []int8, signatureFragment Trits, spongeFunc ...SpongeFunction) (Trits, error) {
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
defer h.Reset()
buf := make(Trits, HashTrinarySize)
sig := make(Trits, KeySegmentsPerFragment*HashTrinarySize)
for i := 0; i < KeySegmentsPerFragment; i++ {
copy(buf, signatureFragment[i*HashTrinarySize:(i+1)*HashTrinarySize])
for j := normalizedBundleHashFragment[i] + MaxTryteValue; j > 0; j-- {
err := h.Absorb(buf)
if err != nil {
return nil, err
}
buf, err = h.Squeeze(HashTrinarySize)
if err != nil {
return nil, err
}
h.Reset()
}
copy(sig[i*HashTrinarySize:(i+1)*HashTrinarySize], buf)
}
if err := h.Absorb(sig); err != nil {
return nil, err
}
return h.Squeeze(HashTrinarySize)
} | go | func Digest(normalizedBundleHashFragment []int8, signatureFragment Trits, spongeFunc ...SpongeFunction) (Trits, error) {
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
defer h.Reset()
buf := make(Trits, HashTrinarySize)
sig := make(Trits, KeySegmentsPerFragment*HashTrinarySize)
for i := 0; i < KeySegmentsPerFragment; i++ {
copy(buf, signatureFragment[i*HashTrinarySize:(i+1)*HashTrinarySize])
for j := normalizedBundleHashFragment[i] + MaxTryteValue; j > 0; j-- {
err := h.Absorb(buf)
if err != nil {
return nil, err
}
buf, err = h.Squeeze(HashTrinarySize)
if err != nil {
return nil, err
}
h.Reset()
}
copy(sig[i*HashTrinarySize:(i+1)*HashTrinarySize], buf)
}
if err := h.Absorb(sig); err != nil {
return nil, err
}
return h.Squeeze(HashTrinarySize)
} | [
"func",
"Digest",
"(",
"normalizedBundleHashFragment",
"[",
"]",
"int8",
",",
"signatureFragment",
"Trits",
",",
"spongeFunc",
"...",
"SpongeFunction",
")",
"(",
"Trits",
",",
"error",
")",
"{",
"h",
":=",
"GetSpongeFunc",
"(",
"spongeFunc",
",",
"kerl",
".",
"NewKerl",
")",
"\n",
"defer",
"h",
".",
"Reset",
"(",
")",
"\n\n",
"buf",
":=",
"make",
"(",
"Trits",
",",
"HashTrinarySize",
")",
"\n",
"sig",
":=",
"make",
"(",
"Trits",
",",
"KeySegmentsPerFragment",
"*",
"HashTrinarySize",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"KeySegmentsPerFragment",
";",
"i",
"++",
"{",
"copy",
"(",
"buf",
",",
"signatureFragment",
"[",
"i",
"*",
"HashTrinarySize",
":",
"(",
"i",
"+",
"1",
")",
"*",
"HashTrinarySize",
"]",
")",
"\n\n",
"for",
"j",
":=",
"normalizedBundleHashFragment",
"[",
"i",
"]",
"+",
"MaxTryteValue",
";",
"j",
">",
"0",
";",
"j",
"--",
"{",
"err",
":=",
"h",
".",
"Absorb",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"buf",
",",
"err",
"=",
"h",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"h",
".",
"Reset",
"(",
")",
"\n",
"}",
"\n\n",
"copy",
"(",
"sig",
"[",
"i",
"*",
"HashTrinarySize",
":",
"(",
"i",
"+",
"1",
")",
"*",
"HashTrinarySize",
"]",
",",
"buf",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"h",
".",
"Absorb",
"(",
"sig",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"h",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"}"
] | // Digest computes the digest derived from the signature fragment and normalized bundle hash.
// Optionally takes the SpongeFunction to use. Default is Kerl. | [
"Digest",
"computes",
"the",
"digest",
"derived",
"from",
"the",
"signature",
"fragment",
"and",
"normalized",
"bundle",
"hash",
".",
"Optionally",
"takes",
"the",
"SpongeFunction",
"to",
"use",
".",
"Default",
"is",
"Kerl",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/signing/signing.go#L199-L229 |
378 | iotaledger/iota.go | multisig/multisig.go | Key | func (m *Multisig) Key(seed Trytes, index uint64, security SecurityLevel, spongeFunc ...SpongeFunction) (Trytes, error) {
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
subseed, err := signing.Subseed(seed, index, h)
if err != nil {
return "", err
}
keyTrits, err := signing.Key(subseed, security, h)
if err != nil {
return "", err
}
return MustTritsToTrytes(keyTrits), nil
} | go | func (m *Multisig) Key(seed Trytes, index uint64, security SecurityLevel, spongeFunc ...SpongeFunction) (Trytes, error) {
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
subseed, err := signing.Subseed(seed, index, h)
if err != nil {
return "", err
}
keyTrits, err := signing.Key(subseed, security, h)
if err != nil {
return "", err
}
return MustTritsToTrytes(keyTrits), nil
} | [
"func",
"(",
"m",
"*",
"Multisig",
")",
"Key",
"(",
"seed",
"Trytes",
",",
"index",
"uint64",
",",
"security",
"SecurityLevel",
",",
"spongeFunc",
"...",
"SpongeFunction",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"h",
":=",
"GetSpongeFunc",
"(",
"spongeFunc",
",",
"kerl",
".",
"NewKerl",
")",
"\n\n",
"subseed",
",",
"err",
":=",
"signing",
".",
"Subseed",
"(",
"seed",
",",
"index",
",",
"h",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"keyTrits",
",",
"err",
":=",
"signing",
".",
"Key",
"(",
"subseed",
",",
"security",
",",
"h",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"MustTritsToTrytes",
"(",
"keyTrits",
")",
",",
"nil",
"\n",
"}"
] | // Key gets the key value of a seed. | [
"Key",
"gets",
"the",
"key",
"value",
"of",
"a",
"seed",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/multisig/multisig.go#L40-L54 |
379 | iotaledger/iota.go | multisig/multisig.go | ValidateAddress | func (m *Multisig) ValidateAddress(addr Trytes, digests []Trytes, spongeFunc ...SpongeFunction) (bool, error) {
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
for i := range digests {
digestTrits, err := TrytesToTrits(digests[i])
if err != nil {
return false, err
}
if err := h.Absorb(digestTrits); err != nil {
return false, err
}
}
addressTrits, err := h.Squeeze(HashTrinarySize)
if err != nil {
return false, err
}
return MustTritsToTrytes(addressTrits) == addr, nil
} | go | func (m *Multisig) ValidateAddress(addr Trytes, digests []Trytes, spongeFunc ...SpongeFunction) (bool, error) {
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
for i := range digests {
digestTrits, err := TrytesToTrits(digests[i])
if err != nil {
return false, err
}
if err := h.Absorb(digestTrits); err != nil {
return false, err
}
}
addressTrits, err := h.Squeeze(HashTrinarySize)
if err != nil {
return false, err
}
return MustTritsToTrytes(addressTrits) == addr, nil
} | [
"func",
"(",
"m",
"*",
"Multisig",
")",
"ValidateAddress",
"(",
"addr",
"Trytes",
",",
"digests",
"[",
"]",
"Trytes",
",",
"spongeFunc",
"...",
"SpongeFunction",
")",
"(",
"bool",
",",
"error",
")",
"{",
"h",
":=",
"GetSpongeFunc",
"(",
"spongeFunc",
",",
"kerl",
".",
"NewKerl",
")",
"\n\n",
"for",
"i",
":=",
"range",
"digests",
"{",
"digestTrits",
",",
"err",
":=",
"TrytesToTrits",
"(",
"digests",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"h",
".",
"Absorb",
"(",
"digestTrits",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"addressTrits",
",",
"err",
":=",
"h",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"return",
"MustTritsToTrytes",
"(",
"addressTrits",
")",
"==",
"addr",
",",
"nil",
"\n",
"}"
] | // ValidateAddress validates the given multisig address. | [
"ValidateAddress",
"validates",
"the",
"given",
"multisig",
"address",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/multisig/multisig.go#L79-L97 |
380 | iotaledger/iota.go | multisig/multisig.go | InitiateTransfer | func (m *Multisig) InitiateTransfer(input MultisigInput, transfers bundle.Transfers, remainderAddress *Trytes) (bundle.Bundle, error) {
if err := validateMultisigInput(input); err != nil {
return nil, err
}
if err := Validate(ValidateTransfers(transfers...)); err != nil {
return nil, err
}
if remainderAddress != nil {
if err := Validate(ValidateHashes(*remainderAddress)); err != nil {
return nil, err
}
}
for i := range transfers {
transfer := &transfers[i]
addr, err := checksum.RemoveChecksum(transfer.Address)
if err != nil {
return nil, err
}
transfer.Address = addr
transfer.Tag = bundle.PadTag(transfer.Tag)
}
if input.Balance > 0 {
return createBundle(input, transfers, remainderAddress)
}
balances, err := m.API.GetBalances(Hashes{input.Address}, 100)
if err != nil {
return nil, err
}
inputWithBalance := MultisigInput{
Balance: balances.Balances[0],
Address: input.Address,
SecuritySum: input.SecuritySum,
}
return createBundle(inputWithBalance, transfers, remainderAddress)
} | go | func (m *Multisig) InitiateTransfer(input MultisigInput, transfers bundle.Transfers, remainderAddress *Trytes) (bundle.Bundle, error) {
if err := validateMultisigInput(input); err != nil {
return nil, err
}
if err := Validate(ValidateTransfers(transfers...)); err != nil {
return nil, err
}
if remainderAddress != nil {
if err := Validate(ValidateHashes(*remainderAddress)); err != nil {
return nil, err
}
}
for i := range transfers {
transfer := &transfers[i]
addr, err := checksum.RemoveChecksum(transfer.Address)
if err != nil {
return nil, err
}
transfer.Address = addr
transfer.Tag = bundle.PadTag(transfer.Tag)
}
if input.Balance > 0 {
return createBundle(input, transfers, remainderAddress)
}
balances, err := m.API.GetBalances(Hashes{input.Address}, 100)
if err != nil {
return nil, err
}
inputWithBalance := MultisigInput{
Balance: balances.Balances[0],
Address: input.Address,
SecuritySum: input.SecuritySum,
}
return createBundle(inputWithBalance, transfers, remainderAddress)
} | [
"func",
"(",
"m",
"*",
"Multisig",
")",
"InitiateTransfer",
"(",
"input",
"MultisigInput",
",",
"transfers",
"bundle",
".",
"Transfers",
",",
"remainderAddress",
"*",
"Trytes",
")",
"(",
"bundle",
".",
"Bundle",
",",
"error",
")",
"{",
"if",
"err",
":=",
"validateMultisigInput",
"(",
"input",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"Validate",
"(",
"ValidateTransfers",
"(",
"transfers",
"...",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"remainderAddress",
"!=",
"nil",
"{",
"if",
"err",
":=",
"Validate",
"(",
"ValidateHashes",
"(",
"*",
"remainderAddress",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"transfers",
"{",
"transfer",
":=",
"&",
"transfers",
"[",
"i",
"]",
"\n",
"addr",
",",
"err",
":=",
"checksum",
".",
"RemoveChecksum",
"(",
"transfer",
".",
"Address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"transfer",
".",
"Address",
"=",
"addr",
"\n",
"transfer",
".",
"Tag",
"=",
"bundle",
".",
"PadTag",
"(",
"transfer",
".",
"Tag",
")",
"\n",
"}",
"\n\n",
"if",
"input",
".",
"Balance",
">",
"0",
"{",
"return",
"createBundle",
"(",
"input",
",",
"transfers",
",",
"remainderAddress",
")",
"\n",
"}",
"\n",
"balances",
",",
"err",
":=",
"m",
".",
"API",
".",
"GetBalances",
"(",
"Hashes",
"{",
"input",
".",
"Address",
"}",
",",
"100",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"inputWithBalance",
":=",
"MultisigInput",
"{",
"Balance",
":",
"balances",
".",
"Balances",
"[",
"0",
"]",
",",
"Address",
":",
"input",
".",
"Address",
",",
"SecuritySum",
":",
"input",
".",
"SecuritySum",
",",
"}",
"\n\n",
"return",
"createBundle",
"(",
"inputWithBalance",
",",
"transfers",
",",
"remainderAddress",
")",
"\n\n",
"}"
] | // InitiateTransfer prepares a transfer by generating the bundle with the corresponding cosigner transactions.
// Does not contain signatures. | [
"InitiateTransfer",
"prepares",
"a",
"transfer",
"by",
"generating",
"the",
"bundle",
"with",
"the",
"corresponding",
"cosigner",
"transactions",
".",
"Does",
"not",
"contain",
"signatures",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/multisig/multisig.go#L101-L140 |
381 | iotaledger/iota.go | multisig/multisig.go | AddSignature | func (m *Multisig) AddSignature(bndl bundle.Bundle, inputAddr Trytes, key Trytes) ([]Trytes, error) {
security := len(key) / SignatureMessageFragmentSizeInTrytes
keyTrits, err := TrytesToTrits(key)
if err != nil {
return nil, err
}
signedFrags := []Trytes{}
numSignedTxs := 0
for i := 0; i < len(bndl); i++ {
tx := &bndl[i]
if tx.Address != inputAddr {
continue
}
if !guards.IsEmptyTrytes(tx.SignatureMessageFragment) {
numSignedTxs++
continue
}
bundleHash := tx.Bundle
firstFrag := keyTrits[0:6561]
normalizedBundleHash := signing.NormalizedBundleHash(bundleHash)
normalizedBundleFrags := [][]int8{}
for k := 0; k < 3; k++ {
normalizedBundleFrags[k] = normalizedBundleHash[k*27 : (k+1)*27]
}
firstBundleFrag := normalizedBundleFrags[numSignedTxs%3]
firstSignedFrag, err := signing.SignatureFragment(firstBundleFrag, firstFrag)
if err != nil {
return nil, err
}
signedFrags = append(signedFrags, MustTritsToTrytes(firstSignedFrag))
for j := 1; j < security; j++ {
nextFrag := keyTrits[6561*j : (j+1)*6561]
nextBundleFrag := normalizedBundleFrags[(numSignedTxs+j)%3]
nextSignedFrag, err := signing.SignatureFragment(nextBundleFrag, nextFrag)
if err != nil {
return nil, err
}
signedFrags = append(signedFrags, MustTritsToTrytes(nextSignedFrag))
}
}
return signedFrags, nil
} | go | func (m *Multisig) AddSignature(bndl bundle.Bundle, inputAddr Trytes, key Trytes) ([]Trytes, error) {
security := len(key) / SignatureMessageFragmentSizeInTrytes
keyTrits, err := TrytesToTrits(key)
if err != nil {
return nil, err
}
signedFrags := []Trytes{}
numSignedTxs := 0
for i := 0; i < len(bndl); i++ {
tx := &bndl[i]
if tx.Address != inputAddr {
continue
}
if !guards.IsEmptyTrytes(tx.SignatureMessageFragment) {
numSignedTxs++
continue
}
bundleHash := tx.Bundle
firstFrag := keyTrits[0:6561]
normalizedBundleHash := signing.NormalizedBundleHash(bundleHash)
normalizedBundleFrags := [][]int8{}
for k := 0; k < 3; k++ {
normalizedBundleFrags[k] = normalizedBundleHash[k*27 : (k+1)*27]
}
firstBundleFrag := normalizedBundleFrags[numSignedTxs%3]
firstSignedFrag, err := signing.SignatureFragment(firstBundleFrag, firstFrag)
if err != nil {
return nil, err
}
signedFrags = append(signedFrags, MustTritsToTrytes(firstSignedFrag))
for j := 1; j < security; j++ {
nextFrag := keyTrits[6561*j : (j+1)*6561]
nextBundleFrag := normalizedBundleFrags[(numSignedTxs+j)%3]
nextSignedFrag, err := signing.SignatureFragment(nextBundleFrag, nextFrag)
if err != nil {
return nil, err
}
signedFrags = append(signedFrags, MustTritsToTrytes(nextSignedFrag))
}
}
return signedFrags, nil
} | [
"func",
"(",
"m",
"*",
"Multisig",
")",
"AddSignature",
"(",
"bndl",
"bundle",
".",
"Bundle",
",",
"inputAddr",
"Trytes",
",",
"key",
"Trytes",
")",
"(",
"[",
"]",
"Trytes",
",",
"error",
")",
"{",
"security",
":=",
"len",
"(",
"key",
")",
"/",
"SignatureMessageFragmentSizeInTrytes",
"\n",
"keyTrits",
",",
"err",
":=",
"TrytesToTrits",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"signedFrags",
":=",
"[",
"]",
"Trytes",
"{",
"}",
"\n\n",
"numSignedTxs",
":=",
"0",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"bndl",
")",
";",
"i",
"++",
"{",
"tx",
":=",
"&",
"bndl",
"[",
"i",
"]",
"\n",
"if",
"tx",
".",
"Address",
"!=",
"inputAddr",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"!",
"guards",
".",
"IsEmptyTrytes",
"(",
"tx",
".",
"SignatureMessageFragment",
")",
"{",
"numSignedTxs",
"++",
"\n",
"continue",
"\n",
"}",
"\n\n",
"bundleHash",
":=",
"tx",
".",
"Bundle",
"\n",
"firstFrag",
":=",
"keyTrits",
"[",
"0",
":",
"6561",
"]",
"\n",
"normalizedBundleHash",
":=",
"signing",
".",
"NormalizedBundleHash",
"(",
"bundleHash",
")",
"\n",
"normalizedBundleFrags",
":=",
"[",
"]",
"[",
"]",
"int8",
"{",
"}",
"\n\n",
"for",
"k",
":=",
"0",
";",
"k",
"<",
"3",
";",
"k",
"++",
"{",
"normalizedBundleFrags",
"[",
"k",
"]",
"=",
"normalizedBundleHash",
"[",
"k",
"*",
"27",
":",
"(",
"k",
"+",
"1",
")",
"*",
"27",
"]",
"\n",
"}",
"\n\n",
"firstBundleFrag",
":=",
"normalizedBundleFrags",
"[",
"numSignedTxs",
"%",
"3",
"]",
"\n",
"firstSignedFrag",
",",
"err",
":=",
"signing",
".",
"SignatureFragment",
"(",
"firstBundleFrag",
",",
"firstFrag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"signedFrags",
"=",
"append",
"(",
"signedFrags",
",",
"MustTritsToTrytes",
"(",
"firstSignedFrag",
")",
")",
"\n\n",
"for",
"j",
":=",
"1",
";",
"j",
"<",
"security",
";",
"j",
"++",
"{",
"nextFrag",
":=",
"keyTrits",
"[",
"6561",
"*",
"j",
":",
"(",
"j",
"+",
"1",
")",
"*",
"6561",
"]",
"\n",
"nextBundleFrag",
":=",
"normalizedBundleFrags",
"[",
"(",
"numSignedTxs",
"+",
"j",
")",
"%",
"3",
"]",
"\n",
"nextSignedFrag",
",",
"err",
":=",
"signing",
".",
"SignatureFragment",
"(",
"nextBundleFrag",
",",
"nextFrag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"signedFrags",
"=",
"append",
"(",
"signedFrags",
",",
"MustTritsToTrytes",
"(",
"nextSignedFrag",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"signedFrags",
",",
"nil",
"\n",
"}"
] | // AddSignature returns cosigner signatures for the transactions. | [
"AddSignature",
"returns",
"cosigner",
"signatures",
"for",
"the",
"transactions",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/multisig/multisig.go#L156-L207 |
382 | iotaledger/iota.go | curl/curl.go | NewCurl | func NewCurl(rounds ...CurlRounds) SpongeFunction {
curlRounds := NumberOfRounds
if len(rounds) > 0 {
curlRounds = rounds[0]
}
c := &Curl{
State: make(Trits, StateSize),
Rounds: curlRounds,
}
return c
} | go | func NewCurl(rounds ...CurlRounds) SpongeFunction {
curlRounds := NumberOfRounds
if len(rounds) > 0 {
curlRounds = rounds[0]
}
c := &Curl{
State: make(Trits, StateSize),
Rounds: curlRounds,
}
return c
} | [
"func",
"NewCurl",
"(",
"rounds",
"...",
"CurlRounds",
")",
"SpongeFunction",
"{",
"curlRounds",
":=",
"NumberOfRounds",
"\n\n",
"if",
"len",
"(",
"rounds",
")",
">",
"0",
"{",
"curlRounds",
"=",
"rounds",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"c",
":=",
"&",
"Curl",
"{",
"State",
":",
"make",
"(",
"Trits",
",",
"StateSize",
")",
",",
"Rounds",
":",
"curlRounds",
",",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // NewCurl initializes a new instance with an empty State. | [
"NewCurl",
"initializes",
"a",
"new",
"instance",
"with",
"an",
"empty",
"State",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/curl.go#L56-L68 |
383 | iotaledger/iota.go | curl/curl.go | Squeeze | func (c *Curl) Squeeze(length int) (Trits, error) {
if length%HashTrinarySize != 0 {
return nil, ErrInvalidSqueezeLength
}
out := make(Trits, length)
for i := 1; i <= length/HashTrinarySize; i++ {
copy(out[HashTrinarySize*(i-1):HashTrinarySize*i], c.State[:HashTrinarySize])
c.Transform()
}
return out, nil
} | go | func (c *Curl) Squeeze(length int) (Trits, error) {
if length%HashTrinarySize != 0 {
return nil, ErrInvalidSqueezeLength
}
out := make(Trits, length)
for i := 1; i <= length/HashTrinarySize; i++ {
copy(out[HashTrinarySize*(i-1):HashTrinarySize*i], c.State[:HashTrinarySize])
c.Transform()
}
return out, nil
} | [
"func",
"(",
"c",
"*",
"Curl",
")",
"Squeeze",
"(",
"length",
"int",
")",
"(",
"Trits",
",",
"error",
")",
"{",
"if",
"length",
"%",
"HashTrinarySize",
"!=",
"0",
"{",
"return",
"nil",
",",
"ErrInvalidSqueezeLength",
"\n",
"}",
"\n\n",
"out",
":=",
"make",
"(",
"Trits",
",",
"length",
")",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<=",
"length",
"/",
"HashTrinarySize",
";",
"i",
"++",
"{",
"copy",
"(",
"out",
"[",
"HashTrinarySize",
"*",
"(",
"i",
"-",
"1",
")",
":",
"HashTrinarySize",
"*",
"i",
"]",
",",
"c",
".",
"State",
"[",
":",
"HashTrinarySize",
"]",
")",
"\n",
"c",
".",
"Transform",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // Squeeze squeezes out trits of the given length. Length has to be a multiple of HashTrinarySize. | [
"Squeeze",
"squeezes",
"out",
"trits",
"of",
"the",
"given",
"length",
".",
"Length",
"has",
"to",
"be",
"a",
"multiple",
"of",
"HashTrinarySize",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/curl.go#L81-L93 |
384 | iotaledger/iota.go | curl/curl.go | Absorb | func (c *Curl) Absorb(in Trits) error {
var lenn int
for i := 0; i < len(in); i += lenn {
lenn = HashTrinarySize
if len(in)-i < HashTrinarySize {
lenn = len(in) - i
}
copy(c.State, in[i:i+lenn])
c.Transform()
}
return nil
} | go | func (c *Curl) Absorb(in Trits) error {
var lenn int
for i := 0; i < len(in); i += lenn {
lenn = HashTrinarySize
if len(in)-i < HashTrinarySize {
lenn = len(in) - i
}
copy(c.State, in[i:i+lenn])
c.Transform()
}
return nil
} | [
"func",
"(",
"c",
"*",
"Curl",
")",
"Absorb",
"(",
"in",
"Trits",
")",
"error",
"{",
"var",
"lenn",
"int",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"in",
")",
";",
"i",
"+=",
"lenn",
"{",
"lenn",
"=",
"HashTrinarySize",
"\n\n",
"if",
"len",
"(",
"in",
")",
"-",
"i",
"<",
"HashTrinarySize",
"{",
"lenn",
"=",
"len",
"(",
"in",
")",
"-",
"i",
"\n",
"}",
"\n\n",
"copy",
"(",
"c",
".",
"State",
",",
"in",
"[",
"i",
":",
"i",
"+",
"lenn",
"]",
")",
"\n",
"c",
".",
"Transform",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Absorb fills the internal State of the sponge with the given trits. | [
"Absorb",
"fills",
"the",
"internal",
"State",
"of",
"the",
"sponge",
"with",
"the",
"given",
"trits",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/curl.go#L121-L134 |
385 | iotaledger/iota.go | curl/curl.go | Transform | func (c *Curl) Transform() {
if transformC != nil {
transformC(c.State, int(c.Rounds))
return
}
var cpy [StateSize]int8
for r := c.Rounds; r > 0; r-- {
copy(cpy[:], c.State)
for i := 0; i < StateSize; i++ {
t1 := Indices[i]
t2 := Indices[i+1]
c.State[i] = TruthTable[cpy[t1]+(cpy[t2]<<2)+5]
}
}
} | go | func (c *Curl) Transform() {
if transformC != nil {
transformC(c.State, int(c.Rounds))
return
}
var cpy [StateSize]int8
for r := c.Rounds; r > 0; r-- {
copy(cpy[:], c.State)
for i := 0; i < StateSize; i++ {
t1 := Indices[i]
t2 := Indices[i+1]
c.State[i] = TruthTable[cpy[t1]+(cpy[t2]<<2)+5]
}
}
} | [
"func",
"(",
"c",
"*",
"Curl",
")",
"Transform",
"(",
")",
"{",
"if",
"transformC",
"!=",
"nil",
"{",
"transformC",
"(",
"c",
".",
"State",
",",
"int",
"(",
"c",
".",
"Rounds",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"var",
"cpy",
"[",
"StateSize",
"]",
"int8",
"\n\n",
"for",
"r",
":=",
"c",
".",
"Rounds",
";",
"r",
">",
"0",
";",
"r",
"--",
"{",
"copy",
"(",
"cpy",
"[",
":",
"]",
",",
"c",
".",
"State",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"StateSize",
";",
"i",
"++",
"{",
"t1",
":=",
"Indices",
"[",
"i",
"]",
"\n",
"t2",
":=",
"Indices",
"[",
"i",
"+",
"1",
"]",
"\n",
"c",
".",
"State",
"[",
"i",
"]",
"=",
"TruthTable",
"[",
"cpy",
"[",
"t1",
"]",
"+",
"(",
"cpy",
"[",
"t2",
"]",
"<<",
"2",
")",
"+",
"5",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Transform does Transform in sponge func. | [
"Transform",
"does",
"Transform",
"in",
"sponge",
"func",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/curl.go#L162-L178 |
386 | iotaledger/iota.go | curl/curl.go | HashTrits | func HashTrits(trits Trits, rounds ...CurlRounds) (Trits, error) {
c := NewCurl(rounds...)
c.Absorb(trits)
return c.Squeeze(HashTrinarySize)
} | go | func HashTrits(trits Trits, rounds ...CurlRounds) (Trits, error) {
c := NewCurl(rounds...)
c.Absorb(trits)
return c.Squeeze(HashTrinarySize)
} | [
"func",
"HashTrits",
"(",
"trits",
"Trits",
",",
"rounds",
"...",
"CurlRounds",
")",
"(",
"Trits",
",",
"error",
")",
"{",
"c",
":=",
"NewCurl",
"(",
"rounds",
"...",
")",
"\n",
"c",
".",
"Absorb",
"(",
"trits",
")",
"\n",
"return",
"c",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"}"
] | // HashTrits returns the hash of the given trits. | [
"HashTrits",
"returns",
"the",
"hash",
"of",
"the",
"given",
"trits",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/curl.go#L188-L192 |
387 | iotaledger/iota.go | curl/curl.go | HashTrytes | func HashTrytes(t Trytes, rounds ...CurlRounds) (Trytes, error) {
c := NewCurl(rounds...)
err := c.AbsorbTrytes(t)
if err != nil {
return "", err
}
return c.SqueezeTrytes(HashTrinarySize)
} | go | func HashTrytes(t Trytes, rounds ...CurlRounds) (Trytes, error) {
c := NewCurl(rounds...)
err := c.AbsorbTrytes(t)
if err != nil {
return "", err
}
return c.SqueezeTrytes(HashTrinarySize)
} | [
"func",
"HashTrytes",
"(",
"t",
"Trytes",
",",
"rounds",
"...",
"CurlRounds",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"c",
":=",
"NewCurl",
"(",
"rounds",
"...",
")",
"\n",
"err",
":=",
"c",
".",
"AbsorbTrytes",
"(",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"c",
".",
"SqueezeTrytes",
"(",
"HashTrinarySize",
")",
"\n",
"}"
] | // HashTrytes returns the hash of the given trytes. | [
"HashTrytes",
"returns",
"the",
"hash",
"of",
"the",
"given",
"trytes",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/curl.go#L195-L202 |
388 | iotaledger/iota.go | curl/curl.go | MustHashTrytes | func MustHashTrytes(t Trytes, rounds ...CurlRounds) Trytes {
trytes, err := HashTrytes(t, rounds...)
if err != nil {
panic(err)
}
return trytes
} | go | func MustHashTrytes(t Trytes, rounds ...CurlRounds) Trytes {
trytes, err := HashTrytes(t, rounds...)
if err != nil {
panic(err)
}
return trytes
} | [
"func",
"MustHashTrytes",
"(",
"t",
"Trytes",
",",
"rounds",
"...",
"CurlRounds",
")",
"Trytes",
"{",
"trytes",
",",
"err",
":=",
"HashTrytes",
"(",
"t",
",",
"rounds",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"trytes",
"\n",
"}"
] | // MustHashTrytes returns the hash of the given trytes.
// It panics if the given trytes are not valid. | [
"MustHashTrytes",
"returns",
"the",
"hash",
"of",
"the",
"given",
"trytes",
".",
"It",
"panics",
"if",
"the",
"given",
"trytes",
"are",
"not",
"valid",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/curl.go#L206-L212 |
389 | iotaledger/iota.go | curl/curl.go | Clone | func (c *Curl) Clone() SpongeFunction {
clone := NewCurl(c.Rounds).(*Curl)
copy(clone.State, c.State)
return clone
} | go | func (c *Curl) Clone() SpongeFunction {
clone := NewCurl(c.Rounds).(*Curl)
copy(clone.State, c.State)
return clone
} | [
"func",
"(",
"c",
"*",
"Curl",
")",
"Clone",
"(",
")",
"SpongeFunction",
"{",
"clone",
":=",
"NewCurl",
"(",
"c",
".",
"Rounds",
")",
".",
"(",
"*",
"Curl",
")",
"\n",
"copy",
"(",
"clone",
".",
"State",
",",
"c",
".",
"State",
")",
"\n",
"return",
"clone",
"\n",
"}"
] | // Clone returns a deep copy of the current Curl | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"the",
"current",
"Curl"
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/curl/curl.go#L215-L219 |
390 | iotaledger/iota.go | multisig/address.go | NewMultisigAddress | func NewMultisigAddress(digests Trytes, spongeFunc ...SpongeFunction) (*MultisigAddress, error) {
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
m := &MultisigAddress{h: h}
if len(digests) != 0 {
if err := m.Absorb(digests); err != nil {
return nil, err
}
}
return m, nil
} | go | func NewMultisigAddress(digests Trytes, spongeFunc ...SpongeFunction) (*MultisigAddress, error) {
h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
m := &MultisigAddress{h: h}
if len(digests) != 0 {
if err := m.Absorb(digests); err != nil {
return nil, err
}
}
return m, nil
} | [
"func",
"NewMultisigAddress",
"(",
"digests",
"Trytes",
",",
"spongeFunc",
"...",
"SpongeFunction",
")",
"(",
"*",
"MultisigAddress",
",",
"error",
")",
"{",
"h",
":=",
"GetSpongeFunc",
"(",
"spongeFunc",
",",
"kerl",
".",
"NewKerl",
")",
"\n\n",
"m",
":=",
"&",
"MultisigAddress",
"{",
"h",
":",
"h",
"}",
"\n",
"if",
"len",
"(",
"digests",
")",
"!=",
"0",
"{",
"if",
"err",
":=",
"m",
".",
"Absorb",
"(",
"digests",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] | // NewMultisigAddress creates a new multisig address object. | [
"NewMultisigAddress",
"creates",
"a",
"new",
"multisig",
"address",
"object",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/multisig/address.go#L11-L21 |
391 | iotaledger/iota.go | multisig/address.go | Absorb | func (m *MultisigAddress) Absorb(digests ...Trytes) error {
for i := range digests {
if err := m.h.Absorb(MustTrytesToTrits(digests[i])); err != nil {
return err
}
}
return nil
} | go | func (m *MultisigAddress) Absorb(digests ...Trytes) error {
for i := range digests {
if err := m.h.Absorb(MustTrytesToTrits(digests[i])); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"MultisigAddress",
")",
"Absorb",
"(",
"digests",
"...",
"Trytes",
")",
"error",
"{",
"for",
"i",
":=",
"range",
"digests",
"{",
"if",
"err",
":=",
"m",
".",
"h",
".",
"Absorb",
"(",
"MustTrytesToTrits",
"(",
"digests",
"[",
"i",
"]",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Absorb absorbs the given key digests. | [
"Absorb",
"absorbs",
"the",
"given",
"key",
"digests",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/multisig/address.go#L29-L36 |
392 | iotaledger/iota.go | multisig/address.go | Finalize | func (m *MultisigAddress) Finalize(digest *string) (Trytes, error) {
if digest != nil {
if err := m.Absorb(*digest); err != nil {
return "", err
}
}
addressTrits, err := m.h.Squeeze(HashTrinarySize)
if err != nil {
return "", err
}
return MustTritsToTrytes(addressTrits), nil
} | go | func (m *MultisigAddress) Finalize(digest *string) (Trytes, error) {
if digest != nil {
if err := m.Absorb(*digest); err != nil {
return "", err
}
}
addressTrits, err := m.h.Squeeze(HashTrinarySize)
if err != nil {
return "", err
}
return MustTritsToTrytes(addressTrits), nil
} | [
"func",
"(",
"m",
"*",
"MultisigAddress",
")",
"Finalize",
"(",
"digest",
"*",
"string",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"if",
"digest",
"!=",
"nil",
"{",
"if",
"err",
":=",
"m",
".",
"Absorb",
"(",
"*",
"digest",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"addressTrits",
",",
"err",
":=",
"m",
".",
"h",
".",
"Squeeze",
"(",
"HashTrinarySize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"MustTritsToTrytes",
"(",
"addressTrits",
")",
",",
"nil",
"\n",
"}"
] | // Finalize finalizes and returns the multisig address as trytes. | [
"Finalize",
"finalizes",
"and",
"returns",
"the",
"multisig",
"address",
"as",
"trytes",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/multisig/address.go#L39-L52 |
393 | iotaledger/iota.go | address/address.go | Checksum | func Checksum(address Hash) (Trytes, error) {
if len(address) < 81 {
return "", ErrInvalidAddress
}
addressWithChecksum, err := checksum.AddChecksum(address[:81], true, 9)
if err != nil {
return "", err
}
return addressWithChecksum[AddressWithChecksumTrytesSize-AddressChecksumTrytesSize : 90], nil
} | go | func Checksum(address Hash) (Trytes, error) {
if len(address) < 81 {
return "", ErrInvalidAddress
}
addressWithChecksum, err := checksum.AddChecksum(address[:81], true, 9)
if err != nil {
return "", err
}
return addressWithChecksum[AddressWithChecksumTrytesSize-AddressChecksumTrytesSize : 90], nil
} | [
"func",
"Checksum",
"(",
"address",
"Hash",
")",
"(",
"Trytes",
",",
"error",
")",
"{",
"if",
"len",
"(",
"address",
")",
"<",
"81",
"{",
"return",
"\"",
"\"",
",",
"ErrInvalidAddress",
"\n",
"}",
"\n\n",
"addressWithChecksum",
",",
"err",
":=",
"checksum",
".",
"AddChecksum",
"(",
"address",
"[",
":",
"81",
"]",
",",
"true",
",",
"9",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"addressWithChecksum",
"[",
"AddressWithChecksumTrytesSize",
"-",
"AddressChecksumTrytesSize",
":",
"90",
"]",
",",
"nil",
"\n",
"}"
] | // Checksum returns the checksum of the given address. | [
"Checksum",
"returns",
"the",
"checksum",
"of",
"the",
"given",
"address",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/address/address.go#L12-L22 |
394 | iotaledger/iota.go | address/address.go | ValidAddress | func ValidAddress(address Hash) error {
switch len(address) {
case 90:
if err := ValidChecksum(address[:81], address[81:]); err != nil {
return err
}
case 81:
default:
return ErrInvalidAddress
}
return ValidTrytes(address)
} | go | func ValidAddress(address Hash) error {
switch len(address) {
case 90:
if err := ValidChecksum(address[:81], address[81:]); err != nil {
return err
}
case 81:
default:
return ErrInvalidAddress
}
return ValidTrytes(address)
} | [
"func",
"ValidAddress",
"(",
"address",
"Hash",
")",
"error",
"{",
"switch",
"len",
"(",
"address",
")",
"{",
"case",
"90",
":",
"if",
"err",
":=",
"ValidChecksum",
"(",
"address",
"[",
":",
"81",
"]",
",",
"address",
"[",
"81",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"case",
"81",
":",
"default",
":",
"return",
"ErrInvalidAddress",
"\n",
"}",
"\n",
"return",
"ValidTrytes",
"(",
"address",
")",
"\n",
"}"
] | // ValidAddress checks whether the given address is valid. | [
"ValidAddress",
"checks",
"whether",
"the",
"given",
"address",
"is",
"valid",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/address/address.go#L25-L36 |
395 | iotaledger/iota.go | address/address.go | ValidChecksum | func ValidChecksum(address Hash, checksum Trytes) error {
actualChecksum, err := Checksum(address)
if err != nil {
return err
}
if checksum != actualChecksum {
return ErrInvalidChecksum
}
return nil
} | go | func ValidChecksum(address Hash, checksum Trytes) error {
actualChecksum, err := Checksum(address)
if err != nil {
return err
}
if checksum != actualChecksum {
return ErrInvalidChecksum
}
return nil
} | [
"func",
"ValidChecksum",
"(",
"address",
"Hash",
",",
"checksum",
"Trytes",
")",
"error",
"{",
"actualChecksum",
",",
"err",
":=",
"Checksum",
"(",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"checksum",
"!=",
"actualChecksum",
"{",
"return",
"ErrInvalidChecksum",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ValidChecksum checks whether the given checksum corresponds to the given address. | [
"ValidChecksum",
"checks",
"whether",
"the",
"given",
"checksum",
"corresponds",
"to",
"the",
"given",
"address",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/address/address.go#L39-L48 |
396 | iotaledger/iota.go | address/address.go | GenerateAddress | func GenerateAddress(seed Trytes, index uint64, secLvl SecurityLevel, addChecksum ...bool) (Hash, error) {
for len(seed)%81 != 0 {
seed += "9"
}
if secLvl == 0 {
secLvl = SecurityLevelMedium
}
subseed, err := Subseed(seed, index)
if err != nil {
return "", err
}
prvKey, err := Key(subseed, secLvl)
if err != nil {
return "", err
}
digests, err := Digests(prvKey)
if err != nil {
return "", err
}
addressTrits, err := Address(digests)
if err != nil {
return "", err
}
address := MustTritsToTrytes(addressTrits)
if len(addChecksum) > 0 && addChecksum[0] {
return checksum.AddChecksum(address, true, 9)
}
return address, nil
} | go | func GenerateAddress(seed Trytes, index uint64, secLvl SecurityLevel, addChecksum ...bool) (Hash, error) {
for len(seed)%81 != 0 {
seed += "9"
}
if secLvl == 0 {
secLvl = SecurityLevelMedium
}
subseed, err := Subseed(seed, index)
if err != nil {
return "", err
}
prvKey, err := Key(subseed, secLvl)
if err != nil {
return "", err
}
digests, err := Digests(prvKey)
if err != nil {
return "", err
}
addressTrits, err := Address(digests)
if err != nil {
return "", err
}
address := MustTritsToTrytes(addressTrits)
if len(addChecksum) > 0 && addChecksum[0] {
return checksum.AddChecksum(address, true, 9)
}
return address, nil
} | [
"func",
"GenerateAddress",
"(",
"seed",
"Trytes",
",",
"index",
"uint64",
",",
"secLvl",
"SecurityLevel",
",",
"addChecksum",
"...",
"bool",
")",
"(",
"Hash",
",",
"error",
")",
"{",
"for",
"len",
"(",
"seed",
")",
"%",
"81",
"!=",
"0",
"{",
"seed",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"secLvl",
"==",
"0",
"{",
"secLvl",
"=",
"SecurityLevelMedium",
"\n",
"}",
"\n\n",
"subseed",
",",
"err",
":=",
"Subseed",
"(",
"seed",
",",
"index",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"prvKey",
",",
"err",
":=",
"Key",
"(",
"subseed",
",",
"secLvl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"digests",
",",
"err",
":=",
"Digests",
"(",
"prvKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"addressTrits",
",",
"err",
":=",
"Address",
"(",
"digests",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"address",
":=",
"MustTritsToTrytes",
"(",
"addressTrits",
")",
"\n\n",
"if",
"len",
"(",
"addChecksum",
")",
">",
"0",
"&&",
"addChecksum",
"[",
"0",
"]",
"{",
"return",
"checksum",
".",
"AddChecksum",
"(",
"address",
",",
"true",
",",
"9",
")",
"\n",
"}",
"\n\n",
"return",
"address",
",",
"nil",
"\n",
"}"
] | // GenerateAddress generates an address deterministically, according to the given seed, index and security level. | [
"GenerateAddress",
"generates",
"an",
"address",
"deterministically",
"according",
"to",
"the",
"given",
"seed",
"index",
"and",
"security",
"level",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/address/address.go#L51-L87 |
397 | iotaledger/iota.go | address/address.go | GenerateAddresses | func GenerateAddresses(seed Trytes, start uint64, count uint64, secLvl SecurityLevel, addChecksum ...bool) (Hashes, error) {
addresses := make(Hashes, count)
var withChecksum bool
if len(addChecksum) > 0 && addChecksum[0] {
withChecksum = true
}
var err error
for i := 0; i < int(count); i++ {
addresses[i], err = GenerateAddress(seed, start+uint64(i), secLvl, withChecksum)
if err != nil {
return nil, err
}
}
return addresses, nil
} | go | func GenerateAddresses(seed Trytes, start uint64, count uint64, secLvl SecurityLevel, addChecksum ...bool) (Hashes, error) {
addresses := make(Hashes, count)
var withChecksum bool
if len(addChecksum) > 0 && addChecksum[0] {
withChecksum = true
}
var err error
for i := 0; i < int(count); i++ {
addresses[i], err = GenerateAddress(seed, start+uint64(i), secLvl, withChecksum)
if err != nil {
return nil, err
}
}
return addresses, nil
} | [
"func",
"GenerateAddresses",
"(",
"seed",
"Trytes",
",",
"start",
"uint64",
",",
"count",
"uint64",
",",
"secLvl",
"SecurityLevel",
",",
"addChecksum",
"...",
"bool",
")",
"(",
"Hashes",
",",
"error",
")",
"{",
"addresses",
":=",
"make",
"(",
"Hashes",
",",
"count",
")",
"\n\n",
"var",
"withChecksum",
"bool",
"\n",
"if",
"len",
"(",
"addChecksum",
")",
">",
"0",
"&&",
"addChecksum",
"[",
"0",
"]",
"{",
"withChecksum",
"=",
"true",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"int",
"(",
"count",
")",
";",
"i",
"++",
"{",
"addresses",
"[",
"i",
"]",
",",
"err",
"=",
"GenerateAddress",
"(",
"seed",
",",
"start",
"+",
"uint64",
"(",
"i",
")",
",",
"secLvl",
",",
"withChecksum",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"addresses",
",",
"nil",
"\n",
"}"
] | // GenerateAddresses generates N new addresses from the given seed, indices and security level. | [
"GenerateAddresses",
"generates",
"N",
"new",
"addresses",
"from",
"the",
"given",
"seed",
"indices",
"and",
"security",
"level",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/address/address.go#L90-L106 |
398 | iotaledger/iota.go | account/store/store.go | TrytesToPendingTransfer | func TrytesToPendingTransfer(trytes []Trytes) PendingTransfer {
essences := make([]Trytes, len(trytes))
for i := 0; i < len(trytes); i++ {
// if the transaction has a non empty signature message fragment, we store it in the store
storeSigMsgFrag := !guards.IsEmptyTrytes(trytes[i][:consts.AddressTrinaryOffset/3])
if storeSigMsgFrag {
essences[i] = trytes[i][:consts.BundleTrinaryOffset/3]
} else {
essences[i] = trytes[i][consts.AddressTrinaryOffset/3 : consts.BundleTrinaryOffset/3]
}
}
return PendingTransfer{Bundle: essences, Tails: Hashes{}}
} | go | func TrytesToPendingTransfer(trytes []Trytes) PendingTransfer {
essences := make([]Trytes, len(trytes))
for i := 0; i < len(trytes); i++ {
// if the transaction has a non empty signature message fragment, we store it in the store
storeSigMsgFrag := !guards.IsEmptyTrytes(trytes[i][:consts.AddressTrinaryOffset/3])
if storeSigMsgFrag {
essences[i] = trytes[i][:consts.BundleTrinaryOffset/3]
} else {
essences[i] = trytes[i][consts.AddressTrinaryOffset/3 : consts.BundleTrinaryOffset/3]
}
}
return PendingTransfer{Bundle: essences, Tails: Hashes{}}
} | [
"func",
"TrytesToPendingTransfer",
"(",
"trytes",
"[",
"]",
"Trytes",
")",
"PendingTransfer",
"{",
"essences",
":=",
"make",
"(",
"[",
"]",
"Trytes",
",",
"len",
"(",
"trytes",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"trytes",
")",
";",
"i",
"++",
"{",
"// if the transaction has a non empty signature message fragment, we store it in the store",
"storeSigMsgFrag",
":=",
"!",
"guards",
".",
"IsEmptyTrytes",
"(",
"trytes",
"[",
"i",
"]",
"[",
":",
"consts",
".",
"AddressTrinaryOffset",
"/",
"3",
"]",
")",
"\n",
"if",
"storeSigMsgFrag",
"{",
"essences",
"[",
"i",
"]",
"=",
"trytes",
"[",
"i",
"]",
"[",
":",
"consts",
".",
"BundleTrinaryOffset",
"/",
"3",
"]",
"\n",
"}",
"else",
"{",
"essences",
"[",
"i",
"]",
"=",
"trytes",
"[",
"i",
"]",
"[",
"consts",
".",
"AddressTrinaryOffset",
"/",
"3",
":",
"consts",
".",
"BundleTrinaryOffset",
"/",
"3",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"PendingTransfer",
"{",
"Bundle",
":",
"essences",
",",
"Tails",
":",
"Hashes",
"{",
"}",
"}",
"\n",
"}"
] | // TrytesToPendingTransfer converts the given trytes to its essence trits. | [
"TrytesToPendingTransfer",
"converts",
"the",
"given",
"trytes",
"to",
"its",
"essence",
"trits",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/account/store/store.go#L101-L113 |
399 | iotaledger/iota.go | bundle/bundle.go | TransfersToBundleEntries | func TransfersToBundleEntries(timestamp uint64, transfers ...Transfer) (BundleEntries, error) {
entries := BundleEntries{}
for i := range transfers {
transfer := &transfers[i]
msgLength := len(transfer.Message)
length := int(math.Ceil(float64(msgLength) / SignatureMessageFragmentSizeInTrytes))
if length == 0 {
length = 1
}
addr, err := checksum.RemoveChecksum(transfer.Address)
if err != nil {
return nil, err
}
transfer.Message = Pad(transfer.Message, length*SignatureMessageFragmentSizeInTrytes)
bndlEntry := BundleEntry{
Address: addr, Value: int64(transfer.Value),
Tag: transfer.Tag, Timestamp: timestamp,
Length: uint64(length),
SignatureMessageFragments: func() []Trytes {
splitFrags := make([]Trytes, int(length))
for i := 0; i < int(length); i++ {
splitFrags[i] = transfer.Message[i*SignatureMessageFragmentSizeInTrytes : (i+1)*SignatureMessageFragmentSizeInTrytes]
}
return splitFrags
}(),
}
entries = append(entries, bndlEntry)
}
return entries, nil
} | go | func TransfersToBundleEntries(timestamp uint64, transfers ...Transfer) (BundleEntries, error) {
entries := BundleEntries{}
for i := range transfers {
transfer := &transfers[i]
msgLength := len(transfer.Message)
length := int(math.Ceil(float64(msgLength) / SignatureMessageFragmentSizeInTrytes))
if length == 0 {
length = 1
}
addr, err := checksum.RemoveChecksum(transfer.Address)
if err != nil {
return nil, err
}
transfer.Message = Pad(transfer.Message, length*SignatureMessageFragmentSizeInTrytes)
bndlEntry := BundleEntry{
Address: addr, Value: int64(transfer.Value),
Tag: transfer.Tag, Timestamp: timestamp,
Length: uint64(length),
SignatureMessageFragments: func() []Trytes {
splitFrags := make([]Trytes, int(length))
for i := 0; i < int(length); i++ {
splitFrags[i] = transfer.Message[i*SignatureMessageFragmentSizeInTrytes : (i+1)*SignatureMessageFragmentSizeInTrytes]
}
return splitFrags
}(),
}
entries = append(entries, bndlEntry)
}
return entries, nil
} | [
"func",
"TransfersToBundleEntries",
"(",
"timestamp",
"uint64",
",",
"transfers",
"...",
"Transfer",
")",
"(",
"BundleEntries",
",",
"error",
")",
"{",
"entries",
":=",
"BundleEntries",
"{",
"}",
"\n",
"for",
"i",
":=",
"range",
"transfers",
"{",
"transfer",
":=",
"&",
"transfers",
"[",
"i",
"]",
"\n",
"msgLength",
":=",
"len",
"(",
"transfer",
".",
"Message",
")",
"\n",
"length",
":=",
"int",
"(",
"math",
".",
"Ceil",
"(",
"float64",
"(",
"msgLength",
")",
"/",
"SignatureMessageFragmentSizeInTrytes",
")",
")",
"\n",
"if",
"length",
"==",
"0",
"{",
"length",
"=",
"1",
"\n",
"}",
"\n",
"addr",
",",
"err",
":=",
"checksum",
".",
"RemoveChecksum",
"(",
"transfer",
".",
"Address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"transfer",
".",
"Message",
"=",
"Pad",
"(",
"transfer",
".",
"Message",
",",
"length",
"*",
"SignatureMessageFragmentSizeInTrytes",
")",
"\n\n",
"bndlEntry",
":=",
"BundleEntry",
"{",
"Address",
":",
"addr",
",",
"Value",
":",
"int64",
"(",
"transfer",
".",
"Value",
")",
",",
"Tag",
":",
"transfer",
".",
"Tag",
",",
"Timestamp",
":",
"timestamp",
",",
"Length",
":",
"uint64",
"(",
"length",
")",
",",
"SignatureMessageFragments",
":",
"func",
"(",
")",
"[",
"]",
"Trytes",
"{",
"splitFrags",
":=",
"make",
"(",
"[",
"]",
"Trytes",
",",
"int",
"(",
"length",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"int",
"(",
"length",
")",
";",
"i",
"++",
"{",
"splitFrags",
"[",
"i",
"]",
"=",
"transfer",
".",
"Message",
"[",
"i",
"*",
"SignatureMessageFragmentSizeInTrytes",
":",
"(",
"i",
"+",
"1",
")",
"*",
"SignatureMessageFragmentSizeInTrytes",
"]",
"\n",
"}",
"\n",
"return",
"splitFrags",
"\n",
"}",
"(",
")",
",",
"}",
"\n\n",
"entries",
"=",
"append",
"(",
"entries",
",",
"bndlEntry",
")",
"\n",
"}",
"\n\n",
"return",
"entries",
",",
"nil",
"\n",
"}"
] | // TransfersToBundleEntries translates transfers to bundle entries. | [
"TransfersToBundleEntries",
"translates",
"transfers",
"to",
"bundle",
"entries",
"."
] | 812d82f707314a82defbb5ef9d965fd2129dfa50 | https://github.com/iotaledger/iota.go/blob/812d82f707314a82defbb5ef9d965fd2129dfa50/bundle/bundle.go#L81-L114 |