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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
hyperledger/burrow | util/slice/slice.go | DeepFlatten | func DeepFlatten(slice []interface{}, depth int) []interface{} {
if depth == 0 {
return slice
}
returnSlice := []interface{}{}
for _, element := range slice {
if s, ok := element.([]interface{}); ok {
returnSlice = append(returnSlice, DeepFlatten(s, depth-1)...)
} else {
returnSlice = append(returnSlice, element)
}
}
return returnSlice
} | go | func DeepFlatten(slice []interface{}, depth int) []interface{} {
if depth == 0 {
return slice
}
returnSlice := []interface{}{}
for _, element := range slice {
if s, ok := element.([]interface{}); ok {
returnSlice = append(returnSlice, DeepFlatten(s, depth-1)...)
} else {
returnSlice = append(returnSlice, element)
}
}
return returnSlice
} | [
"func",
"DeepFlatten",
"(",
"slice",
"[",
"]",
"interface",
"{",
"}",
",",
"depth",
"int",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"if",
"depth",
"==",
"0",
"{",
"return",
"slice",
"\n",
"}",
"\n",
"returnSlice",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n\n",
"for",
"_",
",",
"element",
":=",
"range",
"slice",
"{",
"if",
"s",
",",
"ok",
":=",
"element",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"returnSlice",
"=",
"append",
"(",
"returnSlice",
",",
"DeepFlatten",
"(",
"s",
",",
"depth",
"-",
"1",
")",
"...",
")",
"\n",
"}",
"else",
"{",
"returnSlice",
"=",
"append",
"(",
"returnSlice",
",",
"element",
")",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"return",
"returnSlice",
"\n",
"}"
] | // Recursively flattens a list by splicing any sub-lists into their parent until
// depth is reached. If a negative number is passed for depth then it continues
// until no elements of the returned list are lists | [
"Recursively",
"flattens",
"a",
"list",
"by",
"splicing",
"any",
"sub",
"-",
"lists",
"into",
"their",
"parent",
"until",
"depth",
"is",
"reached",
".",
"If",
"a",
"negative",
"number",
"is",
"passed",
"for",
"depth",
"then",
"it",
"continues",
"until",
"no",
"elements",
"of",
"the",
"returned",
"list",
"are",
"lists"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/util/slice/slice.go#L90-L106 | train |
hyperledger/burrow | execution/transactor.go | BroadcastTxAsync | func (trans *Transactor) BroadcastTxAsync(ctx context.Context, txEnv *txs.Envelope) (*txs.Receipt, error) {
return trans.CheckTxSync(ctx, txEnv)
} | go | func (trans *Transactor) BroadcastTxAsync(ctx context.Context, txEnv *txs.Envelope) (*txs.Receipt, error) {
return trans.CheckTxSync(ctx, txEnv)
} | [
"func",
"(",
"trans",
"*",
"Transactor",
")",
"BroadcastTxAsync",
"(",
"ctx",
"context",
".",
"Context",
",",
"txEnv",
"*",
"txs",
".",
"Envelope",
")",
"(",
"*",
"txs",
".",
"Receipt",
",",
"error",
")",
"{",
"return",
"trans",
".",
"CheckTxSync",
"(",
"ctx",
",",
"txEnv",
")",
"\n",
"}"
] | // Broadcast a transaction without waiting for confirmation - will attempt to sign server-side and set sequence numbers
// if no signatures are provided | [
"Broadcast",
"a",
"transaction",
"without",
"waiting",
"for",
"confirmation",
"-",
"will",
"attempt",
"to",
"sign",
"server",
"-",
"side",
"and",
"set",
"sequence",
"numbers",
"if",
"no",
"signatures",
"are",
"provided"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/transactor.go#L117-L119 | train |
hyperledger/burrow | execution/exec/stream_event.go | Consume | func (ba *BlockAccumulator) Consume(ev *StreamEvent) *BlockExecution {
switch {
case ev.BeginBlock != nil:
ba.block = &BlockExecution{
Height: ev.BeginBlock.Height,
Header: ev.BeginBlock.Header,
}
case ev.BeginTx != nil, ev.Envelope != nil, ev.Event != nil, ev.EndTx != nil:
txe := ba.stack.Consume(ev)
if txe != nil {
ba.block.TxExecutions = append(ba.block.TxExecutions, txe)
}
case ev.EndBlock != nil:
return ba.block
}
return nil
} | go | func (ba *BlockAccumulator) Consume(ev *StreamEvent) *BlockExecution {
switch {
case ev.BeginBlock != nil:
ba.block = &BlockExecution{
Height: ev.BeginBlock.Height,
Header: ev.BeginBlock.Header,
}
case ev.BeginTx != nil, ev.Envelope != nil, ev.Event != nil, ev.EndTx != nil:
txe := ba.stack.Consume(ev)
if txe != nil {
ba.block.TxExecutions = append(ba.block.TxExecutions, txe)
}
case ev.EndBlock != nil:
return ba.block
}
return nil
} | [
"func",
"(",
"ba",
"*",
"BlockAccumulator",
")",
"Consume",
"(",
"ev",
"*",
"StreamEvent",
")",
"*",
"BlockExecution",
"{",
"switch",
"{",
"case",
"ev",
".",
"BeginBlock",
"!=",
"nil",
":",
"ba",
".",
"block",
"=",
"&",
"BlockExecution",
"{",
"Height",
":",
"ev",
".",
"BeginBlock",
".",
"Height",
",",
"Header",
":",
"ev",
".",
"BeginBlock",
".",
"Header",
",",
"}",
"\n",
"case",
"ev",
".",
"BeginTx",
"!=",
"nil",
",",
"ev",
".",
"Envelope",
"!=",
"nil",
",",
"ev",
".",
"Event",
"!=",
"nil",
",",
"ev",
".",
"EndTx",
"!=",
"nil",
":",
"txe",
":=",
"ba",
".",
"stack",
".",
"Consume",
"(",
"ev",
")",
"\n",
"if",
"txe",
"!=",
"nil",
"{",
"ba",
".",
"block",
".",
"TxExecutions",
"=",
"append",
"(",
"ba",
".",
"block",
".",
"TxExecutions",
",",
"txe",
")",
"\n",
"}",
"\n",
"case",
"ev",
".",
"EndBlock",
"!=",
"nil",
":",
"return",
"ba",
".",
"block",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Consume will add the StreamEvent passed to the block accumulator and if the block complete is complete return the
// BlockExecution, otherwise will return nil | [
"Consume",
"will",
"add",
"the",
"StreamEvent",
"passed",
"to",
"the",
"block",
"accumulator",
"and",
"if",
"the",
"block",
"complete",
"is",
"complete",
"return",
"the",
"BlockExecution",
"otherwise",
"will",
"return",
"nil"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/exec/stream_event.go#L43-L59 | train |
hyperledger/burrow | execution/exec/stream_event.go | Consume | func (stack *TxStack) Consume(ev *StreamEvent) *TxExecution {
switch {
case ev.BeginTx != nil:
stack.Push(initTx(ev.BeginTx))
case ev.Envelope != nil:
txe := stack.Peek()
txe.Envelope = ev.Envelope
txe.Receipt = txe.Envelope.Tx.GenerateReceipt()
case ev.Event != nil:
txe := stack.Peek()
txe.Events = append(txe.Events, ev.Event)
case ev.EndTx != nil:
txe := stack.Pop()
if len(*stack) == 0 {
// This terminates the outermost transaction
return txe
}
// If there is a parent tx on the stack add this tx as child
parent := stack.Peek()
parent.TxExecutions = append(parent.TxExecutions, txe)
}
return nil
} | go | func (stack *TxStack) Consume(ev *StreamEvent) *TxExecution {
switch {
case ev.BeginTx != nil:
stack.Push(initTx(ev.BeginTx))
case ev.Envelope != nil:
txe := stack.Peek()
txe.Envelope = ev.Envelope
txe.Receipt = txe.Envelope.Tx.GenerateReceipt()
case ev.Event != nil:
txe := stack.Peek()
txe.Events = append(txe.Events, ev.Event)
case ev.EndTx != nil:
txe := stack.Pop()
if len(*stack) == 0 {
// This terminates the outermost transaction
return txe
}
// If there is a parent tx on the stack add this tx as child
parent := stack.Peek()
parent.TxExecutions = append(parent.TxExecutions, txe)
}
return nil
} | [
"func",
"(",
"stack",
"*",
"TxStack",
")",
"Consume",
"(",
"ev",
"*",
"StreamEvent",
")",
"*",
"TxExecution",
"{",
"switch",
"{",
"case",
"ev",
".",
"BeginTx",
"!=",
"nil",
":",
"stack",
".",
"Push",
"(",
"initTx",
"(",
"ev",
".",
"BeginTx",
")",
")",
"\n",
"case",
"ev",
".",
"Envelope",
"!=",
"nil",
":",
"txe",
":=",
"stack",
".",
"Peek",
"(",
")",
"\n",
"txe",
".",
"Envelope",
"=",
"ev",
".",
"Envelope",
"\n",
"txe",
".",
"Receipt",
"=",
"txe",
".",
"Envelope",
".",
"Tx",
".",
"GenerateReceipt",
"(",
")",
"\n",
"case",
"ev",
".",
"Event",
"!=",
"nil",
":",
"txe",
":=",
"stack",
".",
"Peek",
"(",
")",
"\n",
"txe",
".",
"Events",
"=",
"append",
"(",
"txe",
".",
"Events",
",",
"ev",
".",
"Event",
")",
"\n",
"case",
"ev",
".",
"EndTx",
"!=",
"nil",
":",
"txe",
":=",
"stack",
".",
"Pop",
"(",
")",
"\n",
"if",
"len",
"(",
"*",
"stack",
")",
"==",
"0",
"{",
"// This terminates the outermost transaction",
"return",
"txe",
"\n",
"}",
"\n",
"// If there is a parent tx on the stack add this tx as child",
"parent",
":=",
"stack",
".",
"Peek",
"(",
")",
"\n",
"parent",
".",
"TxExecutions",
"=",
"append",
"(",
"parent",
".",
"TxExecutions",
",",
"txe",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Consume will add the StreamEvent to the transaction stack and if that completes a single outermost transaction
// returns the TxExecution otherwise will return nil | [
"Consume",
"will",
"add",
"the",
"StreamEvent",
"to",
"the",
"transaction",
"stack",
"and",
"if",
"that",
"completes",
"a",
"single",
"outermost",
"transaction",
"returns",
"the",
"TxExecution",
"otherwise",
"will",
"return",
"nil"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/exec/stream_event.go#L82-L104 | train |
hyperledger/burrow | acm/validator/validators.go | Diff | func Diff(before, after IterableReader) (*Set, error) {
diff := NewSet()
err := after.IterateValidators(func(id crypto.Addressable, powerAfter *big.Int) error {
powerBefore, err := before.Power(id.GetAddress())
if err != nil {
return err
}
// Exclude any powers from before that much after
if powerBefore.Cmp(powerAfter) != 0 {
diff.ChangePower(id.GetPublicKey(), powerAfter)
}
return nil
})
if err != nil {
return nil, err
}
// Make sure to zero any validators in before but not in after
err = before.IterateValidators(func(id crypto.Addressable, powerBefore *big.Int) error {
powerAfter, err := after.Power(id.GetAddress())
if err != nil {
return err
}
// If there is a difference value then add to diff
if powerAfter.Cmp(powerBefore) != 0 {
diff.ChangePower(id.GetPublicKey(), powerAfter)
}
return nil
})
if err != nil {
return nil, err
}
return diff, nil
} | go | func Diff(before, after IterableReader) (*Set, error) {
diff := NewSet()
err := after.IterateValidators(func(id crypto.Addressable, powerAfter *big.Int) error {
powerBefore, err := before.Power(id.GetAddress())
if err != nil {
return err
}
// Exclude any powers from before that much after
if powerBefore.Cmp(powerAfter) != 0 {
diff.ChangePower(id.GetPublicKey(), powerAfter)
}
return nil
})
if err != nil {
return nil, err
}
// Make sure to zero any validators in before but not in after
err = before.IterateValidators(func(id crypto.Addressable, powerBefore *big.Int) error {
powerAfter, err := after.Power(id.GetAddress())
if err != nil {
return err
}
// If there is a difference value then add to diff
if powerAfter.Cmp(powerBefore) != 0 {
diff.ChangePower(id.GetPublicKey(), powerAfter)
}
return nil
})
if err != nil {
return nil, err
}
return diff, nil
} | [
"func",
"Diff",
"(",
"before",
",",
"after",
"IterableReader",
")",
"(",
"*",
"Set",
",",
"error",
")",
"{",
"diff",
":=",
"NewSet",
"(",
")",
"\n",
"err",
":=",
"after",
".",
"IterateValidators",
"(",
"func",
"(",
"id",
"crypto",
".",
"Addressable",
",",
"powerAfter",
"*",
"big",
".",
"Int",
")",
"error",
"{",
"powerBefore",
",",
"err",
":=",
"before",
".",
"Power",
"(",
"id",
".",
"GetAddress",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Exclude any powers from before that much after",
"if",
"powerBefore",
".",
"Cmp",
"(",
"powerAfter",
")",
"!=",
"0",
"{",
"diff",
".",
"ChangePower",
"(",
"id",
".",
"GetPublicKey",
"(",
")",
",",
"powerAfter",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Make sure to zero any validators in before but not in after",
"err",
"=",
"before",
".",
"IterateValidators",
"(",
"func",
"(",
"id",
"crypto",
".",
"Addressable",
",",
"powerBefore",
"*",
"big",
".",
"Int",
")",
"error",
"{",
"powerAfter",
",",
"err",
":=",
"after",
".",
"Power",
"(",
"id",
".",
"GetAddress",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// If there is a difference value then add to diff",
"if",
"powerAfter",
".",
"Cmp",
"(",
"powerBefore",
")",
"!=",
"0",
"{",
"diff",
".",
"ChangePower",
"(",
"id",
".",
"GetPublicKey",
"(",
")",
",",
"powerAfter",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"diff",
",",
"nil",
"\n",
"}"
] | // Returns the asymmetric difference, diff, between two Sets such that applying diff to before results in after | [
"Returns",
"the",
"asymmetric",
"difference",
"diff",
"between",
"two",
"Sets",
"such",
"that",
"applying",
"diff",
"to",
"before",
"results",
"in",
"after"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/validator/validators.go#L65-L97 | train |
hyperledger/burrow | acm/validator/validators.go | Add | func Add(vs ReaderWriter, vsOther Iterable) error {
return vsOther.IterateValidators(func(id crypto.Addressable, power *big.Int) error {
return AddPower(vs, id.GetPublicKey(), power)
})
} | go | func Add(vs ReaderWriter, vsOther Iterable) error {
return vsOther.IterateValidators(func(id crypto.Addressable, power *big.Int) error {
return AddPower(vs, id.GetPublicKey(), power)
})
} | [
"func",
"Add",
"(",
"vs",
"ReaderWriter",
",",
"vsOther",
"Iterable",
")",
"error",
"{",
"return",
"vsOther",
".",
"IterateValidators",
"(",
"func",
"(",
"id",
"crypto",
".",
"Addressable",
",",
"power",
"*",
"big",
".",
"Int",
")",
"error",
"{",
"return",
"AddPower",
"(",
"vs",
",",
"id",
".",
"GetPublicKey",
"(",
")",
",",
"power",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Adds vsOther to vs | [
"Adds",
"vsOther",
"to",
"vs"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/validator/validators.go#L113-L117 | train |
hyperledger/burrow | acm/validator/validators.go | Subtract | func Subtract(vs ReaderWriter, vsOther Iterable) error {
return vsOther.IterateValidators(func(id crypto.Addressable, power *big.Int) error {
return SubtractPower(vs, id.GetPublicKey(), power)
})
} | go | func Subtract(vs ReaderWriter, vsOther Iterable) error {
return vsOther.IterateValidators(func(id crypto.Addressable, power *big.Int) error {
return SubtractPower(vs, id.GetPublicKey(), power)
})
} | [
"func",
"Subtract",
"(",
"vs",
"ReaderWriter",
",",
"vsOther",
"Iterable",
")",
"error",
"{",
"return",
"vsOther",
".",
"IterateValidators",
"(",
"func",
"(",
"id",
"crypto",
".",
"Addressable",
",",
"power",
"*",
"big",
".",
"Int",
")",
"error",
"{",
"return",
"SubtractPower",
"(",
"vs",
",",
"id",
".",
"GetPublicKey",
"(",
")",
",",
"power",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Subtracts vsOther from vs | [
"Subtracts",
"vsOther",
"from",
"vs"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/validator/validators.go#L120-L124 | train |
hyperledger/burrow | event/query/reflect_tagged.go | ReflectTags | func ReflectTags(value interface{}, fieldNames ...string) (*ReflectTagged, error) {
rv := reflect.ValueOf(value)
if rv.IsNil() {
return &ReflectTagged{}, nil
}
if rv.Kind() != reflect.Ptr {
return nil, fmt.Errorf("ReflectStructTags needs a pointer to a struct but %v is not a pointer",
rv.Interface())
}
if rv.Elem().Kind() != reflect.Struct {
return nil, fmt.Errorf("ReflectStructTags needs a pointer to a struct but %v does not point to a struct",
rv.Interface())
}
ty := rv.Elem().Type()
// Try our global cache on types
if rt, ok := cache.get(ty, fieldNames); ok {
rt.rv = rv
return rt, nil
}
numField := ty.NumField()
if len(fieldNames) > 0 {
if len(fieldNames) > numField {
return nil, fmt.Errorf("ReflectTags asked to tag %v fields but %v only has %v fields",
len(fieldNames), rv.Interface(), numField)
}
numField = len(fieldNames)
}
rt := &ReflectTagged{
rv: rv,
ks: make(map[string]struct{}, numField),
keys: make([]string, 0, numField),
}
if len(fieldNames) > 0 {
for _, fieldName := range fieldNames {
field, ok := ty.FieldByName(fieldName)
if !ok {
return nil, fmt.Errorf("ReflectTags asked to tag field named %s by no such field on %v",
fieldName, rv.Interface())
}
ok = rt.registerField(field)
if !ok {
return nil, fmt.Errorf("field %s of %v is not exported so cannot act as tag", fieldName,
rv.Interface())
}
}
} else {
for i := 0; i < numField; i++ {
rt.registerField(ty.Field(i))
}
}
// Cache the registration
cache.put(ty, rt, fieldNames)
return rt, nil
} | go | func ReflectTags(value interface{}, fieldNames ...string) (*ReflectTagged, error) {
rv := reflect.ValueOf(value)
if rv.IsNil() {
return &ReflectTagged{}, nil
}
if rv.Kind() != reflect.Ptr {
return nil, fmt.Errorf("ReflectStructTags needs a pointer to a struct but %v is not a pointer",
rv.Interface())
}
if rv.Elem().Kind() != reflect.Struct {
return nil, fmt.Errorf("ReflectStructTags needs a pointer to a struct but %v does not point to a struct",
rv.Interface())
}
ty := rv.Elem().Type()
// Try our global cache on types
if rt, ok := cache.get(ty, fieldNames); ok {
rt.rv = rv
return rt, nil
}
numField := ty.NumField()
if len(fieldNames) > 0 {
if len(fieldNames) > numField {
return nil, fmt.Errorf("ReflectTags asked to tag %v fields but %v only has %v fields",
len(fieldNames), rv.Interface(), numField)
}
numField = len(fieldNames)
}
rt := &ReflectTagged{
rv: rv,
ks: make(map[string]struct{}, numField),
keys: make([]string, 0, numField),
}
if len(fieldNames) > 0 {
for _, fieldName := range fieldNames {
field, ok := ty.FieldByName(fieldName)
if !ok {
return nil, fmt.Errorf("ReflectTags asked to tag field named %s by no such field on %v",
fieldName, rv.Interface())
}
ok = rt.registerField(field)
if !ok {
return nil, fmt.Errorf("field %s of %v is not exported so cannot act as tag", fieldName,
rv.Interface())
}
}
} else {
for i := 0; i < numField; i++ {
rt.registerField(ty.Field(i))
}
}
// Cache the registration
cache.put(ty, rt, fieldNames)
return rt, nil
} | [
"func",
"ReflectTags",
"(",
"value",
"interface",
"{",
"}",
",",
"fieldNames",
"...",
"string",
")",
"(",
"*",
"ReflectTagged",
",",
"error",
")",
"{",
"rv",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"if",
"rv",
".",
"IsNil",
"(",
")",
"{",
"return",
"&",
"ReflectTagged",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"if",
"rv",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rv",
".",
"Interface",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"rv",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Struct",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rv",
".",
"Interface",
"(",
")",
")",
"\n",
"}",
"\n",
"ty",
":=",
"rv",
".",
"Elem",
"(",
")",
".",
"Type",
"(",
")",
"\n",
"// Try our global cache on types",
"if",
"rt",
",",
"ok",
":=",
"cache",
".",
"get",
"(",
"ty",
",",
"fieldNames",
")",
";",
"ok",
"{",
"rt",
".",
"rv",
"=",
"rv",
"\n",
"return",
"rt",
",",
"nil",
"\n",
"}",
"\n\n",
"numField",
":=",
"ty",
".",
"NumField",
"(",
")",
"\n",
"if",
"len",
"(",
"fieldNames",
")",
">",
"0",
"{",
"if",
"len",
"(",
"fieldNames",
")",
">",
"numField",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"fieldNames",
")",
",",
"rv",
".",
"Interface",
"(",
")",
",",
"numField",
")",
"\n",
"}",
"\n",
"numField",
"=",
"len",
"(",
"fieldNames",
")",
"\n",
"}",
"\n",
"rt",
":=",
"&",
"ReflectTagged",
"{",
"rv",
":",
"rv",
",",
"ks",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
",",
"numField",
")",
",",
"keys",
":",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"numField",
")",
",",
"}",
"\n",
"if",
"len",
"(",
"fieldNames",
")",
">",
"0",
"{",
"for",
"_",
",",
"fieldName",
":=",
"range",
"fieldNames",
"{",
"field",
",",
"ok",
":=",
"ty",
".",
"FieldByName",
"(",
"fieldName",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fieldName",
",",
"rv",
".",
"Interface",
"(",
")",
")",
"\n",
"}",
"\n",
"ok",
"=",
"rt",
".",
"registerField",
"(",
"field",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fieldName",
",",
"rv",
".",
"Interface",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"numField",
";",
"i",
"++",
"{",
"rt",
".",
"registerField",
"(",
"ty",
".",
"Field",
"(",
"i",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Cache the registration",
"cache",
".",
"put",
"(",
"ty",
",",
"rt",
",",
"fieldNames",
")",
"\n",
"return",
"rt",
",",
"nil",
"\n",
"}"
] | // ReflectTags provides a query.Tagged on a structs exported fields using query.StringFromValue to derive the string
// values associated with each field. If passed explicit field names will only only provide those fields as tags,
// otherwise all exported fields are provided. | [
"ReflectTags",
"provides",
"a",
"query",
".",
"Tagged",
"on",
"a",
"structs",
"exported",
"fields",
"using",
"query",
".",
"StringFromValue",
"to",
"derive",
"the",
"string",
"values",
"associated",
"with",
"each",
"field",
".",
"If",
"passed",
"explicit",
"field",
"names",
"will",
"only",
"only",
"provide",
"those",
"fields",
"as",
"tags",
"otherwise",
"all",
"exported",
"fields",
"are",
"provided",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/query/reflect_tagged.go#L29-L83 | train |
hyperledger/burrow | acm/acmstate/memory_state.go | NewMemoryState | func NewMemoryState() *MemoryState {
return &MemoryState{
Accounts: make(map[crypto.Address]*acm.Account),
Storage: make(map[crypto.Address]map[binary.Word256]binary.Word256),
}
} | go | func NewMemoryState() *MemoryState {
return &MemoryState{
Accounts: make(map[crypto.Address]*acm.Account),
Storage: make(map[crypto.Address]map[binary.Word256]binary.Word256),
}
} | [
"func",
"NewMemoryState",
"(",
")",
"*",
"MemoryState",
"{",
"return",
"&",
"MemoryState",
"{",
"Accounts",
":",
"make",
"(",
"map",
"[",
"crypto",
".",
"Address",
"]",
"*",
"acm",
".",
"Account",
")",
",",
"Storage",
":",
"make",
"(",
"map",
"[",
"crypto",
".",
"Address",
"]",
"map",
"[",
"binary",
".",
"Word256",
"]",
"binary",
".",
"Word256",
")",
",",
"}",
"\n",
"}"
] | // Get an in-memory state IterableReader | [
"Get",
"an",
"in",
"-",
"memory",
"state",
"IterableReader"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/acm/acmstate/memory_state.go#L19-L24 | train |
hyperledger/burrow | logging/structure/structure.go | ValuesAndContext | func ValuesAndContext(keyvals []interface{},
keys ...interface{}) (map[string]interface{}, []interface{}) {
vals := make(map[string]interface{}, len(keys))
context := make([]interface{}, len(keyvals))
copy(context, keyvals)
deletions := 0
// We can't really do better than a linear scan of both lists here. N is small
// so screw the asymptotics.
// Guard against odd-length list
for i := 0; i < 2*(len(keyvals)/2); i += 2 {
for k := 0; k < len(keys); k++ {
if keyvals[i] == keys[k] {
// Pull the matching key-value pair into vals to return
vals[StringifyKey(keys[k])] = keyvals[i+1]
// Delete the key once it's found
keys = DeleteAt(keys, k)
// And remove the key-value pair from context
context = Delete(context, i-deletions, 2)
// Keep a track of how much we've shrunk the context to offset next
// deletion
deletions += 2
break
}
}
}
return vals, context
} | go | func ValuesAndContext(keyvals []interface{},
keys ...interface{}) (map[string]interface{}, []interface{}) {
vals := make(map[string]interface{}, len(keys))
context := make([]interface{}, len(keyvals))
copy(context, keyvals)
deletions := 0
// We can't really do better than a linear scan of both lists here. N is small
// so screw the asymptotics.
// Guard against odd-length list
for i := 0; i < 2*(len(keyvals)/2); i += 2 {
for k := 0; k < len(keys); k++ {
if keyvals[i] == keys[k] {
// Pull the matching key-value pair into vals to return
vals[StringifyKey(keys[k])] = keyvals[i+1]
// Delete the key once it's found
keys = DeleteAt(keys, k)
// And remove the key-value pair from context
context = Delete(context, i-deletions, 2)
// Keep a track of how much we've shrunk the context to offset next
// deletion
deletions += 2
break
}
}
}
return vals, context
} | [
"func",
"ValuesAndContext",
"(",
"keyvals",
"[",
"]",
"interface",
"{",
"}",
",",
"keys",
"...",
"interface",
"{",
"}",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"vals",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"keys",
")",
")",
"\n",
"context",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"keyvals",
")",
")",
"\n",
"copy",
"(",
"context",
",",
"keyvals",
")",
"\n",
"deletions",
":=",
"0",
"\n",
"// We can't really do better than a linear scan of both lists here. N is small",
"// so screw the asymptotics.",
"// Guard against odd-length list",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"2",
"*",
"(",
"len",
"(",
"keyvals",
")",
"/",
"2",
")",
";",
"i",
"+=",
"2",
"{",
"for",
"k",
":=",
"0",
";",
"k",
"<",
"len",
"(",
"keys",
")",
";",
"k",
"++",
"{",
"if",
"keyvals",
"[",
"i",
"]",
"==",
"keys",
"[",
"k",
"]",
"{",
"// Pull the matching key-value pair into vals to return",
"vals",
"[",
"StringifyKey",
"(",
"keys",
"[",
"k",
"]",
")",
"]",
"=",
"keyvals",
"[",
"i",
"+",
"1",
"]",
"\n",
"// Delete the key once it's found",
"keys",
"=",
"DeleteAt",
"(",
"keys",
",",
"k",
")",
"\n",
"// And remove the key-value pair from context",
"context",
"=",
"Delete",
"(",
"context",
",",
"i",
"-",
"deletions",
",",
"2",
")",
"\n",
"// Keep a track of how much we've shrunk the context to offset next",
"// deletion",
"deletions",
"+=",
"2",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"vals",
",",
"context",
"\n",
"}"
] | // Pull the specified values from a structured log line into a map.
// Assumes keys are single-valued.
// Returns a map of the key-values from the requested keys and
// the unmatched remainder keyvals as context as a slice of key-values. | [
"Pull",
"the",
"specified",
"values",
"from",
"a",
"structured",
"log",
"line",
"into",
"a",
"map",
".",
"Assumes",
"keys",
"are",
"single",
"-",
"valued",
".",
"Returns",
"a",
"map",
"of",
"the",
"key",
"-",
"values",
"from",
"the",
"requested",
"keys",
"and",
"the",
"unmatched",
"remainder",
"keyvals",
"as",
"context",
"as",
"a",
"slice",
"of",
"key",
"-",
"values",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/structure/structure.go#L65-L92 | train |
hyperledger/burrow | logging/structure/structure.go | KeyValuesMap | func KeyValuesMap(keyvals []interface{}) map[string]interface{} {
length := len(keyvals) / 2
vals := make(map[string]interface{}, length)
for i := 0; i < 2*length; i += 2 {
vals[StringifyKey(keyvals[i])] = keyvals[i+1]
}
return vals
} | go | func KeyValuesMap(keyvals []interface{}) map[string]interface{} {
length := len(keyvals) / 2
vals := make(map[string]interface{}, length)
for i := 0; i < 2*length; i += 2 {
vals[StringifyKey(keyvals[i])] = keyvals[i+1]
}
return vals
} | [
"func",
"KeyValuesMap",
"(",
"keyvals",
"[",
"]",
"interface",
"{",
"}",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"length",
":=",
"len",
"(",
"keyvals",
")",
"/",
"2",
"\n",
"vals",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"length",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"2",
"*",
"length",
";",
"i",
"+=",
"2",
"{",
"vals",
"[",
"StringifyKey",
"(",
"keyvals",
"[",
"i",
"]",
")",
"]",
"=",
"keyvals",
"[",
"i",
"+",
"1",
"]",
"\n",
"}",
"\n",
"return",
"vals",
"\n",
"}"
] | // Returns keyvals as a map from keys to vals | [
"Returns",
"keyvals",
"as",
"a",
"map",
"from",
"keys",
"to",
"vals"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/structure/structure.go#L95-L102 | train |
hyperledger/burrow | logging/structure/structure.go | DropKeys | func DropKeys(keyvals []interface{}, dropKeyValPredicate func(key, value interface{}) bool) []interface{} {
keyvalsDropped := make([]interface{}, 0, len(keyvals))
for i := 0; i < 2*(len(keyvals)/2); i += 2 {
if !dropKeyValPredicate(keyvals[i], keyvals[i+1]) {
keyvalsDropped = append(keyvalsDropped, keyvals[i], keyvals[i+1])
}
}
return keyvalsDropped
} | go | func DropKeys(keyvals []interface{}, dropKeyValPredicate func(key, value interface{}) bool) []interface{} {
keyvalsDropped := make([]interface{}, 0, len(keyvals))
for i := 0; i < 2*(len(keyvals)/2); i += 2 {
if !dropKeyValPredicate(keyvals[i], keyvals[i+1]) {
keyvalsDropped = append(keyvalsDropped, keyvals[i], keyvals[i+1])
}
}
return keyvalsDropped
} | [
"func",
"DropKeys",
"(",
"keyvals",
"[",
"]",
"interface",
"{",
"}",
",",
"dropKeyValPredicate",
"func",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"bool",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"keyvalsDropped",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
",",
"len",
"(",
"keyvals",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"2",
"*",
"(",
"len",
"(",
"keyvals",
")",
"/",
"2",
")",
";",
"i",
"+=",
"2",
"{",
"if",
"!",
"dropKeyValPredicate",
"(",
"keyvals",
"[",
"i",
"]",
",",
"keyvals",
"[",
"i",
"+",
"1",
"]",
")",
"{",
"keyvalsDropped",
"=",
"append",
"(",
"keyvalsDropped",
",",
"keyvals",
"[",
"i",
"]",
",",
"keyvals",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"keyvalsDropped",
"\n",
"}"
] | // Drops all key value pairs where dropKeyValPredicate is true | [
"Drops",
"all",
"key",
"value",
"pairs",
"where",
"dropKeyValPredicate",
"is",
"true"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/structure/structure.go#L127-L135 | train |
hyperledger/burrow | logging/structure/structure.go | Vectorise | func Vectorise(keyvals []interface{}, vectorKeys ...string) []interface{} {
// We rely on working against a single backing array, so we use a capacity that is the maximum possible size of the
// slice after vectorising (in the case there are no duplicate keys and this is a no-op)
outputKeyvals := make([]interface{}, 0, len(keyvals))
// Track the location and vector status of the values in the output
valueIndices := make(map[string]*vectorValueindex, len(vectorKeys))
elided := 0
for i := 0; i < 2*(len(keyvals)/2); i += 2 {
key := keyvals[i]
val := keyvals[i+1]
// Only attempt to vectorise string keys
if k, ok := key.(string); ok {
if valueIndices[k] == nil {
// Record that this key has been seen once
valueIndices[k] = &vectorValueindex{
valueIndex: i + 1 - elided,
}
// Copy the key-value to output with the single value
outputKeyvals = append(outputKeyvals, key, val)
} else {
// We have seen this key before
vi := valueIndices[k]
if !vi.vector {
// This must be the only second occurrence of the key so now vectorise the value
outputKeyvals[vi.valueIndex] = Vector([]interface{}{outputKeyvals[vi.valueIndex]})
vi.vector = true
}
// Grow the vector value
outputKeyvals[vi.valueIndex] = append(outputKeyvals[vi.valueIndex].(Vector), val)
// We are now running two more elements behind the input keyvals because we have absorbed this key-value pair
elided += 2
}
} else {
// Just copy the key-value to the output for non-string keys
outputKeyvals = append(outputKeyvals, key, val)
}
}
return outputKeyvals
} | go | func Vectorise(keyvals []interface{}, vectorKeys ...string) []interface{} {
// We rely on working against a single backing array, so we use a capacity that is the maximum possible size of the
// slice after vectorising (in the case there are no duplicate keys and this is a no-op)
outputKeyvals := make([]interface{}, 0, len(keyvals))
// Track the location and vector status of the values in the output
valueIndices := make(map[string]*vectorValueindex, len(vectorKeys))
elided := 0
for i := 0; i < 2*(len(keyvals)/2); i += 2 {
key := keyvals[i]
val := keyvals[i+1]
// Only attempt to vectorise string keys
if k, ok := key.(string); ok {
if valueIndices[k] == nil {
// Record that this key has been seen once
valueIndices[k] = &vectorValueindex{
valueIndex: i + 1 - elided,
}
// Copy the key-value to output with the single value
outputKeyvals = append(outputKeyvals, key, val)
} else {
// We have seen this key before
vi := valueIndices[k]
if !vi.vector {
// This must be the only second occurrence of the key so now vectorise the value
outputKeyvals[vi.valueIndex] = Vector([]interface{}{outputKeyvals[vi.valueIndex]})
vi.vector = true
}
// Grow the vector value
outputKeyvals[vi.valueIndex] = append(outputKeyvals[vi.valueIndex].(Vector), val)
// We are now running two more elements behind the input keyvals because we have absorbed this key-value pair
elided += 2
}
} else {
// Just copy the key-value to the output for non-string keys
outputKeyvals = append(outputKeyvals, key, val)
}
}
return outputKeyvals
} | [
"func",
"Vectorise",
"(",
"keyvals",
"[",
"]",
"interface",
"{",
"}",
",",
"vectorKeys",
"...",
"string",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"// We rely on working against a single backing array, so we use a capacity that is the maximum possible size of the",
"// slice after vectorising (in the case there are no duplicate keys and this is a no-op)",
"outputKeyvals",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
",",
"len",
"(",
"keyvals",
")",
")",
"\n",
"// Track the location and vector status of the values in the output",
"valueIndices",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"vectorValueindex",
",",
"len",
"(",
"vectorKeys",
")",
")",
"\n",
"elided",
":=",
"0",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"2",
"*",
"(",
"len",
"(",
"keyvals",
")",
"/",
"2",
")",
";",
"i",
"+=",
"2",
"{",
"key",
":=",
"keyvals",
"[",
"i",
"]",
"\n",
"val",
":=",
"keyvals",
"[",
"i",
"+",
"1",
"]",
"\n\n",
"// Only attempt to vectorise string keys",
"if",
"k",
",",
"ok",
":=",
"key",
".",
"(",
"string",
")",
";",
"ok",
"{",
"if",
"valueIndices",
"[",
"k",
"]",
"==",
"nil",
"{",
"// Record that this key has been seen once",
"valueIndices",
"[",
"k",
"]",
"=",
"&",
"vectorValueindex",
"{",
"valueIndex",
":",
"i",
"+",
"1",
"-",
"elided",
",",
"}",
"\n",
"// Copy the key-value to output with the single value",
"outputKeyvals",
"=",
"append",
"(",
"outputKeyvals",
",",
"key",
",",
"val",
")",
"\n",
"}",
"else",
"{",
"// We have seen this key before",
"vi",
":=",
"valueIndices",
"[",
"k",
"]",
"\n",
"if",
"!",
"vi",
".",
"vector",
"{",
"// This must be the only second occurrence of the key so now vectorise the value",
"outputKeyvals",
"[",
"vi",
".",
"valueIndex",
"]",
"=",
"Vector",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"outputKeyvals",
"[",
"vi",
".",
"valueIndex",
"]",
"}",
")",
"\n",
"vi",
".",
"vector",
"=",
"true",
"\n",
"}",
"\n",
"// Grow the vector value",
"outputKeyvals",
"[",
"vi",
".",
"valueIndex",
"]",
"=",
"append",
"(",
"outputKeyvals",
"[",
"vi",
".",
"valueIndex",
"]",
".",
"(",
"Vector",
")",
",",
"val",
")",
"\n",
"// We are now running two more elements behind the input keyvals because we have absorbed this key-value pair",
"elided",
"+=",
"2",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Just copy the key-value to the output for non-string keys",
"outputKeyvals",
"=",
"append",
"(",
"outputKeyvals",
",",
"key",
",",
"val",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"outputKeyvals",
"\n",
"}"
] | // 'Vectorises' values associated with repeated string keys member by collapsing many values into a single vector value.
// The result is a copy of keyvals where the first occurrence of each matching key and its first value are replaced by
// that key and all of its values in a single slice. | [
"Vectorises",
"values",
"associated",
"with",
"repeated",
"string",
"keys",
"member",
"by",
"collapsing",
"many",
"values",
"into",
"a",
"single",
"vector",
"value",
".",
"The",
"result",
"is",
"a",
"copy",
"of",
"keyvals",
"where",
"the",
"first",
"occurrence",
"of",
"each",
"matching",
"key",
"and",
"its",
"first",
"value",
"are",
"replaced",
"by",
"that",
"key",
"and",
"all",
"of",
"its",
"values",
"in",
"a",
"single",
"slice",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/structure/structure.go#L167-L206 | train |
hyperledger/burrow | logging/structure/structure.go | Value | func Value(keyvals []interface{}, key interface{}) interface{} {
for i := 0; i < 2*(len(keyvals)/2); i += 2 {
if keyvals[i] == key {
return keyvals[i+1]
}
}
return nil
} | go | func Value(keyvals []interface{}, key interface{}) interface{} {
for i := 0; i < 2*(len(keyvals)/2); i += 2 {
if keyvals[i] == key {
return keyvals[i+1]
}
}
return nil
} | [
"func",
"Value",
"(",
"keyvals",
"[",
"]",
"interface",
"{",
"}",
",",
"key",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"2",
"*",
"(",
"len",
"(",
"keyvals",
")",
"/",
"2",
")",
";",
"i",
"+=",
"2",
"{",
"if",
"keyvals",
"[",
"i",
"]",
"==",
"key",
"{",
"return",
"keyvals",
"[",
"i",
"+",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Return a single value corresponding to key in keyvals | [
"Return",
"a",
"single",
"value",
"corresponding",
"to",
"key",
"in",
"keyvals"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/structure/structure.go#L209-L216 | train |
hyperledger/burrow | logging/structure/structure.go | StringifyKey | func StringifyKey(key interface{}) string {
switch key {
// For named keys we want to handle explicitly
default:
// Stringify keys
switch k := key.(type) {
case string:
return k
case fmt.Stringer:
return k.String()
default:
return fmt.Sprintf("%v", key)
}
}
} | go | func StringifyKey(key interface{}) string {
switch key {
// For named keys we want to handle explicitly
default:
// Stringify keys
switch k := key.(type) {
case string:
return k
case fmt.Stringer:
return k.String()
default:
return fmt.Sprintf("%v", key)
}
}
} | [
"func",
"StringifyKey",
"(",
"key",
"interface",
"{",
"}",
")",
"string",
"{",
"switch",
"key",
"{",
"// For named keys we want to handle explicitly",
"default",
":",
"// Stringify keys",
"switch",
"k",
":=",
"key",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"k",
"\n",
"case",
"fmt",
".",
"Stringer",
":",
"return",
"k",
".",
"String",
"(",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Provides a canonical way to stringify keys | [
"Provides",
"a",
"canonical",
"way",
"to",
"stringify",
"keys"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/structure/structure.go#L254-L269 | train |
hyperledger/burrow | logging/structure/structure.go | Signal | func Signal(keyvals []interface{}) string {
last := len(keyvals) - 1
if last > 0 && keyvals[last-1] == SignalKey {
signal, ok := keyvals[last].(string)
if ok {
return signal
}
}
return ""
} | go | func Signal(keyvals []interface{}) string {
last := len(keyvals) - 1
if last > 0 && keyvals[last-1] == SignalKey {
signal, ok := keyvals[last].(string)
if ok {
return signal
}
}
return ""
} | [
"func",
"Signal",
"(",
"keyvals",
"[",
"]",
"interface",
"{",
"}",
")",
"string",
"{",
"last",
":=",
"len",
"(",
"keyvals",
")",
"-",
"1",
"\n",
"if",
"last",
">",
"0",
"&&",
"keyvals",
"[",
"last",
"-",
"1",
"]",
"==",
"SignalKey",
"{",
"signal",
",",
"ok",
":=",
"keyvals",
"[",
"last",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"ok",
"{",
"return",
"signal",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // Tried to interpret the logline as a signal by matching the last key-value pair as a signal,
// returns empty string if no match. The idea with signals is that the should be transmitted to a root logger
// as a single key-value pair so we avoid the need to do a linear probe over every log line in order to detect a signal. | [
"Tried",
"to",
"interpret",
"the",
"logline",
"as",
"a",
"signal",
"by",
"matching",
"the",
"last",
"key",
"-",
"value",
"pair",
"as",
"a",
"signal",
"returns",
"empty",
"string",
"if",
"no",
"match",
".",
"The",
"idea",
"with",
"signals",
"is",
"that",
"the",
"should",
"be",
"transmitted",
"to",
"a",
"root",
"logger",
"as",
"a",
"single",
"key",
"-",
"value",
"pair",
"so",
"we",
"avoid",
"the",
"need",
"to",
"do",
"a",
"linear",
"probe",
"over",
"every",
"log",
"line",
"in",
"order",
"to",
"detect",
"a",
"signal",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/structure/structure.go#L284-L293 | train |
hyperledger/burrow | execution/exec/block_execution.go | StreamEvents | func (be *BlockExecution) StreamEvents() StreamEvents {
var ses StreamEvents
ses = append(ses, &StreamEvent{
BeginBlock: &BeginBlock{
Height: be.Height,
Header: be.Header,
},
})
for _, txe := range be.TxExecutions {
ses = append(ses, txe.StreamEvents()...)
}
return append(ses, &StreamEvent{
EndBlock: &EndBlock{
Height: be.Height,
},
})
} | go | func (be *BlockExecution) StreamEvents() StreamEvents {
var ses StreamEvents
ses = append(ses, &StreamEvent{
BeginBlock: &BeginBlock{
Height: be.Height,
Header: be.Header,
},
})
for _, txe := range be.TxExecutions {
ses = append(ses, txe.StreamEvents()...)
}
return append(ses, &StreamEvent{
EndBlock: &EndBlock{
Height: be.Height,
},
})
} | [
"func",
"(",
"be",
"*",
"BlockExecution",
")",
"StreamEvents",
"(",
")",
"StreamEvents",
"{",
"var",
"ses",
"StreamEvents",
"\n",
"ses",
"=",
"append",
"(",
"ses",
",",
"&",
"StreamEvent",
"{",
"BeginBlock",
":",
"&",
"BeginBlock",
"{",
"Height",
":",
"be",
".",
"Height",
",",
"Header",
":",
"be",
".",
"Header",
",",
"}",
",",
"}",
")",
"\n",
"for",
"_",
",",
"txe",
":=",
"range",
"be",
".",
"TxExecutions",
"{",
"ses",
"=",
"append",
"(",
"ses",
",",
"txe",
".",
"StreamEvents",
"(",
")",
"...",
")",
"\n",
"}",
"\n",
"return",
"append",
"(",
"ses",
",",
"&",
"StreamEvent",
"{",
"EndBlock",
":",
"&",
"EndBlock",
"{",
"Height",
":",
"be",
".",
"Height",
",",
"}",
",",
"}",
")",
"\n",
"}"
] | // Write out TxExecutions parenthetically | [
"Write",
"out",
"TxExecutions",
"parenthetically"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/exec/block_execution.go#L23-L39 | train |
hyperledger/burrow | storage/kvcache.go | WriteTo | func (kvc *KVCache) WriteTo(writer KVWriter) {
kvc.Lock()
defer kvc.Unlock()
for k, vi := range kvc.cache {
kb := []byte(k)
if vi.deleted {
writer.Delete(kb)
} else {
writer.Set(kb, vi.value)
}
}
} | go | func (kvc *KVCache) WriteTo(writer KVWriter) {
kvc.Lock()
defer kvc.Unlock()
for k, vi := range kvc.cache {
kb := []byte(k)
if vi.deleted {
writer.Delete(kb)
} else {
writer.Set(kb, vi.value)
}
}
} | [
"func",
"(",
"kvc",
"*",
"KVCache",
")",
"WriteTo",
"(",
"writer",
"KVWriter",
")",
"{",
"kvc",
".",
"Lock",
"(",
")",
"\n",
"defer",
"kvc",
".",
"Unlock",
"(",
")",
"\n",
"for",
"k",
",",
"vi",
":=",
"range",
"kvc",
".",
"cache",
"{",
"kb",
":=",
"[",
"]",
"byte",
"(",
"k",
")",
"\n",
"if",
"vi",
".",
"deleted",
"{",
"writer",
".",
"Delete",
"(",
"kb",
")",
"\n",
"}",
"else",
"{",
"writer",
".",
"Set",
"(",
"kb",
",",
"vi",
".",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Writes contents of cache to backend without flushing the cache | [
"Writes",
"contents",
"of",
"cache",
"to",
"backend",
"without",
"flushing",
"the",
"cache"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/storage/kvcache.go#L109-L120 | train |
hyperledger/burrow | event/emitter.go | NewEmitter | func NewEmitter() *Emitter {
pubsubServer := pubsub.NewServer(pubsub.BufferCapacity(DefaultEventBufferCapacity))
pubsubServer.BaseService = *common.NewBaseService(nil, "Emitter", pubsubServer)
pubsubServer.Start()
return &Emitter{
pubsubServer: pubsubServer,
}
} | go | func NewEmitter() *Emitter {
pubsubServer := pubsub.NewServer(pubsub.BufferCapacity(DefaultEventBufferCapacity))
pubsubServer.BaseService = *common.NewBaseService(nil, "Emitter", pubsubServer)
pubsubServer.Start()
return &Emitter{
pubsubServer: pubsubServer,
}
} | [
"func",
"NewEmitter",
"(",
")",
"*",
"Emitter",
"{",
"pubsubServer",
":=",
"pubsub",
".",
"NewServer",
"(",
"pubsub",
".",
"BufferCapacity",
"(",
"DefaultEventBufferCapacity",
")",
")",
"\n",
"pubsubServer",
".",
"BaseService",
"=",
"*",
"common",
".",
"NewBaseService",
"(",
"nil",
",",
"\"",
"\"",
",",
"pubsubServer",
")",
"\n",
"pubsubServer",
".",
"Start",
"(",
")",
"\n",
"return",
"&",
"Emitter",
"{",
"pubsubServer",
":",
"pubsubServer",
",",
"}",
"\n",
"}"
] | // NewEmitter initializes an emitter struct with a pubsubServer | [
"NewEmitter",
"initializes",
"an",
"emitter",
"struct",
"with",
"a",
"pubsubServer"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/emitter.go#L42-L49 | train |
hyperledger/burrow | event/emitter.go | SetLogger | func (em *Emitter) SetLogger(logger *logging.Logger) {
em.logger = logger.With(structure.ComponentKey, "Events")
} | go | func (em *Emitter) SetLogger(logger *logging.Logger) {
em.logger = logger.With(structure.ComponentKey, "Events")
} | [
"func",
"(",
"em",
"*",
"Emitter",
")",
"SetLogger",
"(",
"logger",
"*",
"logging",
".",
"Logger",
")",
"{",
"em",
".",
"logger",
"=",
"logger",
".",
"With",
"(",
"structure",
".",
"ComponentKey",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // SetLogger attaches a log handler to this emitter | [
"SetLogger",
"attaches",
"a",
"log",
"handler",
"to",
"this",
"emitter"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/emitter.go#L52-L54 | train |
hyperledger/burrow | event/emitter.go | Shutdown | func (em *Emitter) Shutdown(ctx context.Context) error {
return em.pubsubServer.Stop()
} | go | func (em *Emitter) Shutdown(ctx context.Context) error {
return em.pubsubServer.Stop()
} | [
"func",
"(",
"em",
"*",
"Emitter",
")",
"Shutdown",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"return",
"em",
".",
"pubsubServer",
".",
"Stop",
"(",
")",
"\n",
"}"
] | // Shutdown stops the pubsubServer | [
"Shutdown",
"stops",
"the",
"pubsubServer"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/emitter.go#L57-L59 | train |
hyperledger/burrow | event/emitter.go | Publish | func (em *Emitter) Publish(ctx context.Context, message interface{}, tags query.Tagged) error {
if em == nil || em.pubsubServer == nil {
return nil
}
return em.pubsubServer.PublishWithTags(ctx, message, tags)
} | go | func (em *Emitter) Publish(ctx context.Context, message interface{}, tags query.Tagged) error {
if em == nil || em.pubsubServer == nil {
return nil
}
return em.pubsubServer.PublishWithTags(ctx, message, tags)
} | [
"func",
"(",
"em",
"*",
"Emitter",
")",
"Publish",
"(",
"ctx",
"context",
".",
"Context",
",",
"message",
"interface",
"{",
"}",
",",
"tags",
"query",
".",
"Tagged",
")",
"error",
"{",
"if",
"em",
"==",
"nil",
"||",
"em",
".",
"pubsubServer",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"em",
".",
"pubsubServer",
".",
"PublishWithTags",
"(",
"ctx",
",",
"message",
",",
"tags",
")",
"\n",
"}"
] | // Publish tells the emitter to publish with the given message and tags | [
"Publish",
"tells",
"the",
"emitter",
"to",
"publish",
"with",
"the",
"given",
"message",
"and",
"tags"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/emitter.go#L62-L67 | train |
hyperledger/burrow | event/emitter.go | Subscribe | func (em *Emitter) Subscribe(ctx context.Context, subscriber string, queryable query.Queryable, bufferSize int) (<-chan interface{}, error) {
qry, err := queryable.Query()
if err != nil {
return nil, err
}
return em.pubsubServer.Subscribe(ctx, subscriber, qry, bufferSize)
} | go | func (em *Emitter) Subscribe(ctx context.Context, subscriber string, queryable query.Queryable, bufferSize int) (<-chan interface{}, error) {
qry, err := queryable.Query()
if err != nil {
return nil, err
}
return em.pubsubServer.Subscribe(ctx, subscriber, qry, bufferSize)
} | [
"func",
"(",
"em",
"*",
"Emitter",
")",
"Subscribe",
"(",
"ctx",
"context",
".",
"Context",
",",
"subscriber",
"string",
",",
"queryable",
"query",
".",
"Queryable",
",",
"bufferSize",
"int",
")",
"(",
"<-",
"chan",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"qry",
",",
"err",
":=",
"queryable",
".",
"Query",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"em",
".",
"pubsubServer",
".",
"Subscribe",
"(",
"ctx",
",",
"subscriber",
",",
"qry",
",",
"bufferSize",
")",
"\n",
"}"
] | // Subscribe tells the emitter to listen for messages on the given query | [
"Subscribe",
"tells",
"the",
"emitter",
"to",
"listen",
"for",
"messages",
"on",
"the",
"given",
"query"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/emitter.go#L70-L76 | train |
hyperledger/burrow | event/emitter.go | Unsubscribe | func (em *Emitter) Unsubscribe(ctx context.Context, subscriber string, queryable query.Queryable) error {
pubsubQuery, err := queryable.Query()
if err != nil {
return nil
}
return em.pubsubServer.Unsubscribe(ctx, subscriber, pubsubQuery)
} | go | func (em *Emitter) Unsubscribe(ctx context.Context, subscriber string, queryable query.Queryable) error {
pubsubQuery, err := queryable.Query()
if err != nil {
return nil
}
return em.pubsubServer.Unsubscribe(ctx, subscriber, pubsubQuery)
} | [
"func",
"(",
"em",
"*",
"Emitter",
")",
"Unsubscribe",
"(",
"ctx",
"context",
".",
"Context",
",",
"subscriber",
"string",
",",
"queryable",
"query",
".",
"Queryable",
")",
"error",
"{",
"pubsubQuery",
",",
"err",
":=",
"queryable",
".",
"Query",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"em",
".",
"pubsubServer",
".",
"Unsubscribe",
"(",
"ctx",
",",
"subscriber",
",",
"pubsubQuery",
")",
"\n",
"}"
] | // Unsubscribe tells the emitter to stop listening for said messages | [
"Unsubscribe",
"tells",
"the",
"emitter",
"to",
"stop",
"listening",
"for",
"said",
"messages"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/emitter.go#L79-L85 | train |
hyperledger/burrow | event/emitter.go | UnsubscribeAll | func (em *Emitter) UnsubscribeAll(ctx context.Context, subscriber string) error {
return em.pubsubServer.UnsubscribeAll(ctx, subscriber)
} | go | func (em *Emitter) UnsubscribeAll(ctx context.Context, subscriber string) error {
return em.pubsubServer.UnsubscribeAll(ctx, subscriber)
} | [
"func",
"(",
"em",
"*",
"Emitter",
")",
"UnsubscribeAll",
"(",
"ctx",
"context",
".",
"Context",
",",
"subscriber",
"string",
")",
"error",
"{",
"return",
"em",
".",
"pubsubServer",
".",
"UnsubscribeAll",
"(",
"ctx",
",",
"subscriber",
")",
"\n",
"}"
] | // UnsubscribeAll just stop listening for all messages | [
"UnsubscribeAll",
"just",
"stop",
"listening",
"for",
"all",
"messages"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/event/emitter.go#L88-L90 | train |
hyperledger/burrow | logging/loggers/capture_logger.go | SetPassthrough | func (cl *CaptureLogger) SetPassthrough(passthrough bool) {
cl.Lock()
defer cl.Unlock()
cl.passthrough = passthrough
} | go | func (cl *CaptureLogger) SetPassthrough(passthrough bool) {
cl.Lock()
defer cl.Unlock()
cl.passthrough = passthrough
} | [
"func",
"(",
"cl",
"*",
"CaptureLogger",
")",
"SetPassthrough",
"(",
"passthrough",
"bool",
")",
"{",
"cl",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cl",
".",
"Unlock",
"(",
")",
"\n",
"cl",
".",
"passthrough",
"=",
"passthrough",
"\n",
"}"
] | // Sets whether the CaptureLogger is forwarding log lines sent to it through
// to its output logger. Concurrently safe. | [
"Sets",
"whether",
"the",
"CaptureLogger",
"is",
"forwarding",
"log",
"lines",
"sent",
"to",
"it",
"through",
"to",
"its",
"output",
"logger",
".",
"Concurrently",
"safe",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/loggers/capture_logger.go#L58-L62 | train |
hyperledger/burrow | logging/loggers/capture_logger.go | Passthrough | func (cl *CaptureLogger) Passthrough() bool {
cl.RLock()
defer cl.RUnlock()
return cl.passthrough
} | go | func (cl *CaptureLogger) Passthrough() bool {
cl.RLock()
defer cl.RUnlock()
return cl.passthrough
} | [
"func",
"(",
"cl",
"*",
"CaptureLogger",
")",
"Passthrough",
"(",
")",
"bool",
"{",
"cl",
".",
"RLock",
"(",
")",
"\n",
"defer",
"cl",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"cl",
".",
"passthrough",
"\n",
"}"
] | // Gets whether the CaptureLogger is forwarding log lines sent to through to its
// OutputLogger. Concurrently Safe. | [
"Gets",
"whether",
"the",
"CaptureLogger",
"is",
"forwarding",
"log",
"lines",
"sent",
"to",
"through",
"to",
"its",
"OutputLogger",
".",
"Concurrently",
"Safe",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/loggers/capture_logger.go#L66-L70 | train |
hyperledger/burrow | util/logging/cmd/main.go | main | func main() {
loggingConfig := &LoggingConfig{
RootSink: Sink().
AddSinks(
// Log everything to Stderr
Sink().SetOutput(StderrOutput()),
Sink().SetTransform(FilterTransform(ExcludeWhenAllMatch,
"module", "p2p",
"captured_logging_source", "tendermint_log15")).
AddSinks(
Sink().SetOutput(StdoutOutput()),
),
),
}
fmt.Println(loggingConfig.RootTOMLString())
} | go | func main() {
loggingConfig := &LoggingConfig{
RootSink: Sink().
AddSinks(
// Log everything to Stderr
Sink().SetOutput(StderrOutput()),
Sink().SetTransform(FilterTransform(ExcludeWhenAllMatch,
"module", "p2p",
"captured_logging_source", "tendermint_log15")).
AddSinks(
Sink().SetOutput(StdoutOutput()),
),
),
}
fmt.Println(loggingConfig.RootTOMLString())
} | [
"func",
"main",
"(",
")",
"{",
"loggingConfig",
":=",
"&",
"LoggingConfig",
"{",
"RootSink",
":",
"Sink",
"(",
")",
".",
"AddSinks",
"(",
"// Log everything to Stderr",
"Sink",
"(",
")",
".",
"SetOutput",
"(",
"StderrOutput",
"(",
")",
")",
",",
"Sink",
"(",
")",
".",
"SetTransform",
"(",
"FilterTransform",
"(",
"ExcludeWhenAllMatch",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
".",
"AddSinks",
"(",
"Sink",
"(",
")",
".",
"SetOutput",
"(",
"StdoutOutput",
"(",
")",
")",
",",
")",
",",
")",
",",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"loggingConfig",
".",
"RootTOMLString",
"(",
")",
")",
"\n",
"}"
] | // Dump an example logging configuration | [
"Dump",
"an",
"example",
"logging",
"configuration"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/util/logging/cmd/main.go#L24-L39 | train |
hyperledger/burrow | logging/logger.go | NewLogger | func NewLogger(outputLogger log.Logger) *Logger {
// We will never halt the progress of a log emitter. If log output takes too
// long will start dropping log lines by using a ring buffer.
swapLogger := new(log.SwapLogger)
swapLogger.Swap(outputLogger)
return &Logger{
Output: swapLogger,
// logging contexts
Info: log.With(swapLogger,
structure.ChannelKey, structure.InfoChannelName,
),
Trace: log.With(swapLogger,
structure.ChannelKey, structure.TraceChannelName,
),
}
} | go | func NewLogger(outputLogger log.Logger) *Logger {
// We will never halt the progress of a log emitter. If log output takes too
// long will start dropping log lines by using a ring buffer.
swapLogger := new(log.SwapLogger)
swapLogger.Swap(outputLogger)
return &Logger{
Output: swapLogger,
// logging contexts
Info: log.With(swapLogger,
structure.ChannelKey, structure.InfoChannelName,
),
Trace: log.With(swapLogger,
structure.ChannelKey, structure.TraceChannelName,
),
}
} | [
"func",
"NewLogger",
"(",
"outputLogger",
"log",
".",
"Logger",
")",
"*",
"Logger",
"{",
"// We will never halt the progress of a log emitter. If log output takes too",
"// long will start dropping log lines by using a ring buffer.",
"swapLogger",
":=",
"new",
"(",
"log",
".",
"SwapLogger",
")",
"\n",
"swapLogger",
".",
"Swap",
"(",
"outputLogger",
")",
"\n",
"return",
"&",
"Logger",
"{",
"Output",
":",
"swapLogger",
",",
"// logging contexts",
"Info",
":",
"log",
".",
"With",
"(",
"swapLogger",
",",
"structure",
".",
"ChannelKey",
",",
"structure",
".",
"InfoChannelName",
",",
")",
",",
"Trace",
":",
"log",
".",
"With",
"(",
"swapLogger",
",",
"structure",
".",
"ChannelKey",
",",
"structure",
".",
"TraceChannelName",
",",
")",
",",
"}",
"\n",
"}"
] | // Create an InfoTraceLogger by passing the initial outputLogger. | [
"Create",
"an",
"InfoTraceLogger",
"by",
"passing",
"the",
"initial",
"outputLogger",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/logger.go#L44-L59 | train |
hyperledger/burrow | logging/logger.go | SwapOutput | func (l *Logger) SwapOutput(infoLogger log.Logger) {
l.Output.Swap(infoLogger)
} | go | func (l *Logger) SwapOutput(infoLogger log.Logger) {
l.Output.Swap(infoLogger)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"SwapOutput",
"(",
"infoLogger",
"log",
".",
"Logger",
")",
"{",
"l",
".",
"Output",
".",
"Swap",
"(",
"infoLogger",
")",
"\n",
"}"
] | // Hot swap the underlying outputLogger with another one to re-route messages | [
"Hot",
"swap",
"the",
"underlying",
"outputLogger",
"with",
"another",
"one",
"to",
"re",
"-",
"route",
"messages"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/logger.go#L127-L129 | train |
hyperledger/burrow | logging/logger.go | InfoMsg | func (l *Logger) InfoMsg(message string, keyvals ...interface{}) error {
return Msg(l.Info, message, keyvals...)
} | go | func (l *Logger) InfoMsg(message string, keyvals ...interface{}) error {
return Msg(l.Info, message, keyvals...)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"InfoMsg",
"(",
"message",
"string",
",",
"keyvals",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Msg",
"(",
"l",
".",
"Info",
",",
"message",
",",
"keyvals",
"...",
")",
"\n",
"}"
] | // Record structured Info lo`g line with a message | [
"Record",
"structured",
"Info",
"lo",
"g",
"line",
"with",
"a",
"message"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/logger.go#L132-L134 | train |
hyperledger/burrow | logging/logger.go | TraceMsg | func (l *Logger) TraceMsg(message string, keyvals ...interface{}) error {
return Msg(l.Trace, message, keyvals...)
} | go | func (l *Logger) TraceMsg(message string, keyvals ...interface{}) error {
return Msg(l.Trace, message, keyvals...)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"TraceMsg",
"(",
"message",
"string",
",",
"keyvals",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Msg",
"(",
"l",
".",
"Trace",
",",
"message",
",",
"keyvals",
"...",
")",
"\n",
"}"
] | // Record structured Trace log line with a message | [
"Record",
"structured",
"Trace",
"log",
"line",
"with",
"a",
"message"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/logger.go#L137-L139 | train |
hyperledger/burrow | logging/logger.go | WithScope | func (l *Logger) WithScope(scopeName string) *Logger {
// InfoTraceLogger will collapse successive (ScopeKey, scopeName) pairs into a vector in the order which they appear
return l.With(structure.ScopeKey, scopeName)
} | go | func (l *Logger) WithScope(scopeName string) *Logger {
// InfoTraceLogger will collapse successive (ScopeKey, scopeName) pairs into a vector in the order which they appear
return l.With(structure.ScopeKey, scopeName)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"WithScope",
"(",
"scopeName",
"string",
")",
"*",
"Logger",
"{",
"// InfoTraceLogger will collapse successive (ScopeKey, scopeName) pairs into a vector in the order which they appear",
"return",
"l",
".",
"With",
"(",
"structure",
".",
"ScopeKey",
",",
"scopeName",
")",
"\n",
"}"
] | // Establish or extend the scope of this logger by appending scopeName to the Scope vector.
// Like With the logging scope is append only but can be used to provide parenthetical scopes by hanging on to the
// parent scope and using once the scope has been exited. The scope mechanism does is agnostic to the type of scope
// so can be used to identify certain segments of the call stack, a lexical scope, or any other nested scope. | [
"Establish",
"or",
"extend",
"the",
"scope",
"of",
"this",
"logger",
"by",
"appending",
"scopeName",
"to",
"the",
"Scope",
"vector",
".",
"Like",
"With",
"the",
"logging",
"scope",
"is",
"append",
"only",
"but",
"can",
"be",
"used",
"to",
"provide",
"parenthetical",
"scopes",
"by",
"hanging",
"on",
"to",
"the",
"parent",
"scope",
"and",
"using",
"once",
"the",
"scope",
"has",
"been",
"exited",
".",
"The",
"scope",
"mechanism",
"does",
"is",
"agnostic",
"to",
"the",
"type",
"of",
"scope",
"so",
"can",
"be",
"used",
"to",
"identify",
"certain",
"segments",
"of",
"the",
"call",
"stack",
"a",
"lexical",
"scope",
"or",
"any",
"other",
"nested",
"scope",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/logger.go#L145-L148 | train |
hyperledger/burrow | logging/logger.go | Msg | func Msg(logger log.Logger, message string, keyvals ...interface{}) error {
prepended := structure.CopyPrepend(keyvals, structure.MessageKey, message)
return logger.Log(prepended...)
} | go | func Msg(logger log.Logger, message string, keyvals ...interface{}) error {
prepended := structure.CopyPrepend(keyvals, structure.MessageKey, message)
return logger.Log(prepended...)
} | [
"func",
"Msg",
"(",
"logger",
"log",
".",
"Logger",
",",
"message",
"string",
",",
"keyvals",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"prepended",
":=",
"structure",
".",
"CopyPrepend",
"(",
"keyvals",
",",
"structure",
".",
"MessageKey",
",",
"message",
")",
"\n",
"return",
"logger",
".",
"Log",
"(",
"prepended",
"...",
")",
"\n",
"}"
] | // Record a structured log line with a message | [
"Record",
"a",
"structured",
"log",
"line",
"with",
"a",
"message"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/logger.go#L151-L154 | train |
hyperledger/burrow | crypto/sha3/sha3.go | unalignedAbsorb | func (d *digest) unalignedAbsorb(p []byte) {
var t uint64
for i := len(p) - 1; i >= 0; i-- {
t <<= 8
t |= uint64(p[i])
}
offset := (d.absorbed) % d.rate()
t <<= 8 * uint(offset%laneSize)
d.a[offset/laneSize] ^= t
d.absorbed += len(p)
} | go | func (d *digest) unalignedAbsorb(p []byte) {
var t uint64
for i := len(p) - 1; i >= 0; i-- {
t <<= 8
t |= uint64(p[i])
}
offset := (d.absorbed) % d.rate()
t <<= 8 * uint(offset%laneSize)
d.a[offset/laneSize] ^= t
d.absorbed += len(p)
} | [
"func",
"(",
"d",
"*",
"digest",
")",
"unalignedAbsorb",
"(",
"p",
"[",
"]",
"byte",
")",
"{",
"var",
"t",
"uint64",
"\n",
"for",
"i",
":=",
"len",
"(",
"p",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"t",
"<<=",
"8",
"\n",
"t",
"|=",
"uint64",
"(",
"p",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"offset",
":=",
"(",
"d",
".",
"absorbed",
")",
"%",
"d",
".",
"rate",
"(",
")",
"\n",
"t",
"<<=",
"8",
"*",
"uint",
"(",
"offset",
"%",
"laneSize",
")",
"\n",
"d",
".",
"a",
"[",
"offset",
"/",
"laneSize",
"]",
"^=",
"t",
"\n",
"d",
".",
"absorbed",
"+=",
"len",
"(",
"p",
")",
"\n",
"}"
] | // unalignedAbsorb is a helper function for Write, which absorbs data that isn't aligned with an
// 8-byte lane. This requires shifting the individual bytes into position in a uint64. | [
"unalignedAbsorb",
"is",
"a",
"helper",
"function",
"for",
"Write",
"which",
"absorbs",
"data",
"that",
"isn",
"t",
"aligned",
"with",
"an",
"8",
"-",
"byte",
"lane",
".",
"This",
"requires",
"shifting",
"the",
"individual",
"bytes",
"into",
"position",
"in",
"a",
"uint64",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/crypto/sha3/sha3.go#L89-L99 | train |
hyperledger/burrow | crypto/sha3/sha3.go | Sum | func (d *digest) Sum(in []byte) []byte {
// Make a copy of the original hash so that caller can keep writing and summing.
dup := *d
dup.finalize()
return dup.squeeze(in, dup.outputSize)
} | go | func (d *digest) Sum(in []byte) []byte {
// Make a copy of the original hash so that caller can keep writing and summing.
dup := *d
dup.finalize()
return dup.squeeze(in, dup.outputSize)
} | [
"func",
"(",
"d",
"*",
"digest",
")",
"Sum",
"(",
"in",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"// Make a copy of the original hash so that caller can keep writing and summing.",
"dup",
":=",
"*",
"d",
"\n",
"dup",
".",
"finalize",
"(",
")",
"\n",
"return",
"dup",
".",
"squeeze",
"(",
"in",
",",
"dup",
".",
"outputSize",
")",
"\n",
"}"
] | // Sum applies padding to the hash state and then squeezes out the desired nubmer of output bytes. | [
"Sum",
"applies",
"padding",
"to",
"the",
"hash",
"state",
"and",
"then",
"squeezes",
"out",
"the",
"desired",
"nubmer",
"of",
"output",
"bytes",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/crypto/sha3/sha3.go#L203-L208 | train |
hyperledger/burrow | logging/lifecycle/lifecycle.go | NewLoggerFromLoggingConfig | func NewLoggerFromLoggingConfig(loggingConfig *logconfig.LoggingConfig) (*logging.Logger, error) {
if loggingConfig == nil {
return NewStdErrLogger()
} else {
outputLogger, errCh, err := loggerFromLoggingConfig(loggingConfig)
if err != nil {
return nil, err
}
logger := logging.NewLogger(outputLogger)
if !loggingConfig.Trace {
logger.Trace = log.NewNopLogger()
}
go func() {
err := <-errCh.Out()
if err != nil {
fmt.Printf("Logging error: %v", err)
}
}()
return logger, nil
}
} | go | func NewLoggerFromLoggingConfig(loggingConfig *logconfig.LoggingConfig) (*logging.Logger, error) {
if loggingConfig == nil {
return NewStdErrLogger()
} else {
outputLogger, errCh, err := loggerFromLoggingConfig(loggingConfig)
if err != nil {
return nil, err
}
logger := logging.NewLogger(outputLogger)
if !loggingConfig.Trace {
logger.Trace = log.NewNopLogger()
}
go func() {
err := <-errCh.Out()
if err != nil {
fmt.Printf("Logging error: %v", err)
}
}()
return logger, nil
}
} | [
"func",
"NewLoggerFromLoggingConfig",
"(",
"loggingConfig",
"*",
"logconfig",
".",
"LoggingConfig",
")",
"(",
"*",
"logging",
".",
"Logger",
",",
"error",
")",
"{",
"if",
"loggingConfig",
"==",
"nil",
"{",
"return",
"NewStdErrLogger",
"(",
")",
"\n",
"}",
"else",
"{",
"outputLogger",
",",
"errCh",
",",
"err",
":=",
"loggerFromLoggingConfig",
"(",
"loggingConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"logger",
":=",
"logging",
".",
"NewLogger",
"(",
"outputLogger",
")",
"\n",
"if",
"!",
"loggingConfig",
".",
"Trace",
"{",
"logger",
".",
"Trace",
"=",
"log",
".",
"NewNopLogger",
"(",
")",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"err",
":=",
"<-",
"errCh",
".",
"Out",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"logger",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // Lifecycle provides a canonical source for burrow loggers. Components should use the functions here
// to set up their root logger and capture any other logging output.
// Obtain a logger from a LoggingConfig | [
"Lifecycle",
"provides",
"a",
"canonical",
"source",
"for",
"burrow",
"loggers",
".",
"Components",
"should",
"use",
"the",
"functions",
"here",
"to",
"set",
"up",
"their",
"root",
"logger",
"and",
"capture",
"any",
"other",
"logging",
"output",
".",
"Obtain",
"a",
"logger",
"from",
"a",
"LoggingConfig"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/lifecycle/lifecycle.go#L37-L57 | train |
hyperledger/burrow | logging/lifecycle/lifecycle.go | SwapOutputLoggersFromLoggingConfig | func SwapOutputLoggersFromLoggingConfig(logger *logging.Logger, loggingConfig *logconfig.LoggingConfig) (error, channels.Channel) {
outputLogger, errCh, err := loggerFromLoggingConfig(loggingConfig)
if err != nil {
return err, channels.NewDeadChannel()
}
logger.SwapOutput(outputLogger)
return nil, errCh
} | go | func SwapOutputLoggersFromLoggingConfig(logger *logging.Logger, loggingConfig *logconfig.LoggingConfig) (error, channels.Channel) {
outputLogger, errCh, err := loggerFromLoggingConfig(loggingConfig)
if err != nil {
return err, channels.NewDeadChannel()
}
logger.SwapOutput(outputLogger)
return nil, errCh
} | [
"func",
"SwapOutputLoggersFromLoggingConfig",
"(",
"logger",
"*",
"logging",
".",
"Logger",
",",
"loggingConfig",
"*",
"logconfig",
".",
"LoggingConfig",
")",
"(",
"error",
",",
"channels",
".",
"Channel",
")",
"{",
"outputLogger",
",",
"errCh",
",",
"err",
":=",
"loggerFromLoggingConfig",
"(",
"loggingConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
",",
"channels",
".",
"NewDeadChannel",
"(",
")",
"\n",
"}",
"\n",
"logger",
".",
"SwapOutput",
"(",
"outputLogger",
")",
"\n",
"return",
"nil",
",",
"errCh",
"\n",
"}"
] | // Hot swap logging config by replacing output loggers of passed InfoTraceLogger
// with those built from loggingConfig | [
"Hot",
"swap",
"logging",
"config",
"by",
"replacing",
"output",
"loggers",
"of",
"passed",
"InfoTraceLogger",
"with",
"those",
"built",
"from",
"loggingConfig"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/lifecycle/lifecycle.go#L61-L68 | train |
hyperledger/burrow | execution/evm/abi/abi.go | MergeAbiSpec | func MergeAbiSpec(abiSpec []*AbiSpec) *AbiSpec {
newSpec := AbiSpec{
Events: make(map[string]EventSpec),
EventsById: make(map[EventID]EventSpec),
Functions: make(map[string]FunctionSpec),
}
for _, s := range abiSpec {
for n, f := range s.Functions {
newSpec.Functions[n] = f
}
// Different Abis can have the Event name, but with a different signature
// Loop over the signatures, as these are less likely to have collisions
for _, e := range s.EventsById {
newSpec.Events[e.Name] = e
newSpec.EventsById[e.EventID] = e
}
}
return &newSpec
} | go | func MergeAbiSpec(abiSpec []*AbiSpec) *AbiSpec {
newSpec := AbiSpec{
Events: make(map[string]EventSpec),
EventsById: make(map[EventID]EventSpec),
Functions: make(map[string]FunctionSpec),
}
for _, s := range abiSpec {
for n, f := range s.Functions {
newSpec.Functions[n] = f
}
// Different Abis can have the Event name, but with a different signature
// Loop over the signatures, as these are less likely to have collisions
for _, e := range s.EventsById {
newSpec.Events[e.Name] = e
newSpec.EventsById[e.EventID] = e
}
}
return &newSpec
} | [
"func",
"MergeAbiSpec",
"(",
"abiSpec",
"[",
"]",
"*",
"AbiSpec",
")",
"*",
"AbiSpec",
"{",
"newSpec",
":=",
"AbiSpec",
"{",
"Events",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"EventSpec",
")",
",",
"EventsById",
":",
"make",
"(",
"map",
"[",
"EventID",
"]",
"EventSpec",
")",
",",
"Functions",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"FunctionSpec",
")",
",",
"}",
"\n\n",
"for",
"_",
",",
"s",
":=",
"range",
"abiSpec",
"{",
"for",
"n",
",",
"f",
":=",
"range",
"s",
".",
"Functions",
"{",
"newSpec",
".",
"Functions",
"[",
"n",
"]",
"=",
"f",
"\n",
"}",
"\n\n",
"// Different Abis can have the Event name, but with a different signature",
"// Loop over the signatures, as these are less likely to have collisions",
"for",
"_",
",",
"e",
":=",
"range",
"s",
".",
"EventsById",
"{",
"newSpec",
".",
"Events",
"[",
"e",
".",
"Name",
"]",
"=",
"e",
"\n",
"newSpec",
".",
"EventsById",
"[",
"e",
".",
"EventID",
"]",
"=",
"e",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"newSpec",
"\n",
"}"
] | // MergeAbiSpec takes multiple AbiSpecs and merges them into once structure. Note that
// the same function name or event name can occur in different abis, so there might be
// some information loss. | [
"MergeAbiSpec",
"takes",
"multiple",
"AbiSpecs",
"and",
"merges",
"them",
"into",
"once",
"structure",
".",
"Note",
"that",
"the",
"same",
"function",
"name",
"or",
"event",
"name",
"can",
"occur",
"in",
"different",
"abis",
"so",
"there",
"might",
"be",
"some",
"information",
"loss",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/evm/abi/abi.go#L937-L958 | train |
hyperledger/burrow | execution/evm/abi/abi.go | UnpackRevert | func UnpackRevert(data []byte) (message *string, err error) {
if len(data) > 0 {
var msg string
err = RevertAbi.UnpackWithID(data, &msg)
message = &msg
}
return
} | go | func UnpackRevert(data []byte) (message *string, err error) {
if len(data) > 0 {
var msg string
err = RevertAbi.UnpackWithID(data, &msg)
message = &msg
}
return
} | [
"func",
"UnpackRevert",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"message",
"*",
"string",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
">",
"0",
"{",
"var",
"msg",
"string",
"\n",
"err",
"=",
"RevertAbi",
".",
"UnpackWithID",
"(",
"data",
",",
"&",
"msg",
")",
"\n",
"message",
"=",
"&",
"msg",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // UnpackRevert decodes the revert reason if a contract called revert. If no
// reason was given, message will be nil else it will point to the string | [
"UnpackRevert",
"decodes",
"the",
"revert",
"reason",
"if",
"a",
"contract",
"called",
"revert",
".",
"If",
"no",
"reason",
"was",
"given",
"message",
"will",
"be",
"nil",
"else",
"it",
"will",
"point",
"to",
"the",
"string"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/evm/abi/abi.go#L1090-L1097 | train |
hyperledger/burrow | execution/evm/abi/abi.go | pad | func pad(input []byte, size int, left bool) []byte {
if len(input) >= size {
return input[:size]
}
padded := make([]byte, size)
if left {
copy(padded[size-len(input):], input)
} else {
copy(padded, input)
}
return padded
} | go | func pad(input []byte, size int, left bool) []byte {
if len(input) >= size {
return input[:size]
}
padded := make([]byte, size)
if left {
copy(padded[size-len(input):], input)
} else {
copy(padded, input)
}
return padded
} | [
"func",
"pad",
"(",
"input",
"[",
"]",
"byte",
",",
"size",
"int",
",",
"left",
"bool",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"input",
")",
">=",
"size",
"{",
"return",
"input",
"[",
":",
"size",
"]",
"\n",
"}",
"\n",
"padded",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n",
"if",
"left",
"{",
"copy",
"(",
"padded",
"[",
"size",
"-",
"len",
"(",
"input",
")",
":",
"]",
",",
"input",
")",
"\n",
"}",
"else",
"{",
"copy",
"(",
"padded",
",",
"input",
")",
"\n",
"}",
"\n",
"return",
"padded",
"\n",
"}"
] | // quick helper padding | [
"quick",
"helper",
"padding"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/evm/abi/abi.go#L1484-L1495 | train |
hyperledger/burrow | permission/base_permissions.go | Get | func (bp BasePermissions) Get(ty PermFlag) (bool, error) {
if ty == 0 {
return false, ErrInvalidPermission(ty)
}
if !bp.IsSet(ty) {
return false, ErrValueNotSet(ty)
}
return bp.Perms&ty == ty, nil
} | go | func (bp BasePermissions) Get(ty PermFlag) (bool, error) {
if ty == 0 {
return false, ErrInvalidPermission(ty)
}
if !bp.IsSet(ty) {
return false, ErrValueNotSet(ty)
}
return bp.Perms&ty == ty, nil
} | [
"func",
"(",
"bp",
"BasePermissions",
")",
"Get",
"(",
"ty",
"PermFlag",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"ty",
"==",
"0",
"{",
"return",
"false",
",",
"ErrInvalidPermission",
"(",
"ty",
")",
"\n",
"}",
"\n",
"if",
"!",
"bp",
".",
"IsSet",
"(",
"ty",
")",
"{",
"return",
"false",
",",
"ErrValueNotSet",
"(",
"ty",
")",
"\n",
"}",
"\n",
"return",
"bp",
".",
"Perms",
"&",
"ty",
"==",
"ty",
",",
"nil",
"\n",
"}"
] | // Gets the permission value.
// ErrValueNotSet is returned if the permission's set bits are not all on,
// and should be caught by caller so the global permission can be fetched | [
"Gets",
"the",
"permission",
"value",
".",
"ErrValueNotSet",
"is",
"returned",
"if",
"the",
"permission",
"s",
"set",
"bits",
"are",
"not",
"all",
"on",
"and",
"should",
"be",
"caught",
"by",
"caller",
"so",
"the",
"global",
"permission",
"can",
"be",
"fetched"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/base_permissions.go#L8-L16 | train |
hyperledger/burrow | permission/base_permissions.go | Set | func (bp *BasePermissions) Set(ty PermFlag, value bool) error {
if ty == 0 {
return ErrInvalidPermission(ty)
}
bp.SetBit |= ty
if value {
bp.Perms |= ty
} else {
bp.Perms &= ^ty
}
return nil
} | go | func (bp *BasePermissions) Set(ty PermFlag, value bool) error {
if ty == 0 {
return ErrInvalidPermission(ty)
}
bp.SetBit |= ty
if value {
bp.Perms |= ty
} else {
bp.Perms &= ^ty
}
return nil
} | [
"func",
"(",
"bp",
"*",
"BasePermissions",
")",
"Set",
"(",
"ty",
"PermFlag",
",",
"value",
"bool",
")",
"error",
"{",
"if",
"ty",
"==",
"0",
"{",
"return",
"ErrInvalidPermission",
"(",
"ty",
")",
"\n",
"}",
"\n",
"bp",
".",
"SetBit",
"|=",
"ty",
"\n",
"if",
"value",
"{",
"bp",
".",
"Perms",
"|=",
"ty",
"\n",
"}",
"else",
"{",
"bp",
".",
"Perms",
"&=",
"^",
"ty",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set a permission bit. Will set the permission's set bit to true. | [
"Set",
"a",
"permission",
"bit",
".",
"Will",
"set",
"the",
"permission",
"s",
"set",
"bit",
"to",
"true",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/base_permissions.go#L19-L30 | train |
hyperledger/burrow | permission/base_permissions.go | Unset | func (bp *BasePermissions) Unset(ty PermFlag) error {
if ty == 0 {
return ErrInvalidPermission(ty)
}
bp.SetBit &= ^ty
return nil
} | go | func (bp *BasePermissions) Unset(ty PermFlag) error {
if ty == 0 {
return ErrInvalidPermission(ty)
}
bp.SetBit &= ^ty
return nil
} | [
"func",
"(",
"bp",
"*",
"BasePermissions",
")",
"Unset",
"(",
"ty",
"PermFlag",
")",
"error",
"{",
"if",
"ty",
"==",
"0",
"{",
"return",
"ErrInvalidPermission",
"(",
"ty",
")",
"\n",
"}",
"\n",
"bp",
".",
"SetBit",
"&=",
"^",
"ty",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set the permission's set bits to false | [
"Set",
"the",
"permission",
"s",
"set",
"bits",
"to",
"false"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/base_permissions.go#L33-L39 | train |
hyperledger/burrow | permission/base_permissions.go | IsSet | func (bp BasePermissions) IsSet(ty PermFlag) bool {
if ty == 0 {
return false
}
return bp.SetBit&ty == ty
} | go | func (bp BasePermissions) IsSet(ty PermFlag) bool {
if ty == 0 {
return false
}
return bp.SetBit&ty == ty
} | [
"func",
"(",
"bp",
"BasePermissions",
")",
"IsSet",
"(",
"ty",
"PermFlag",
")",
"bool",
"{",
"if",
"ty",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"bp",
".",
"SetBit",
"&",
"ty",
"==",
"ty",
"\n",
"}"
] | // Check if the permission is set | [
"Check",
"if",
"the",
"permission",
"is",
"set"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/base_permissions.go#L42-L47 | train |
hyperledger/burrow | permission/base_permissions.go | Compose | func (bp BasePermissions) Compose(bpFallthrough BasePermissions) BasePermissions {
return BasePermissions{
// Combine set perm flags from bp with set perm flags in fallthrough NOT set in bp
Perms: (bp.Perms & bp.SetBit) | (bpFallthrough.Perms & (^bp.SetBit & bpFallthrough.SetBit)),
SetBit: bp.SetBit | bpFallthrough.SetBit,
}
} | go | func (bp BasePermissions) Compose(bpFallthrough BasePermissions) BasePermissions {
return BasePermissions{
// Combine set perm flags from bp with set perm flags in fallthrough NOT set in bp
Perms: (bp.Perms & bp.SetBit) | (bpFallthrough.Perms & (^bp.SetBit & bpFallthrough.SetBit)),
SetBit: bp.SetBit | bpFallthrough.SetBit,
}
} | [
"func",
"(",
"bp",
"BasePermissions",
")",
"Compose",
"(",
"bpFallthrough",
"BasePermissions",
")",
"BasePermissions",
"{",
"return",
"BasePermissions",
"{",
"// Combine set perm flags from bp with set perm flags in fallthrough NOT set in bp",
"Perms",
":",
"(",
"bp",
".",
"Perms",
"&",
"bp",
".",
"SetBit",
")",
"|",
"(",
"bpFallthrough",
".",
"Perms",
"&",
"(",
"^",
"bp",
".",
"SetBit",
"&",
"bpFallthrough",
".",
"SetBit",
")",
")",
",",
"SetBit",
":",
"bp",
".",
"SetBit",
"|",
"bpFallthrough",
".",
"SetBit",
",",
"}",
"\n",
"}"
] | // Returns a BasePermission that matches any permissions set on this BasePermission
// and falls through to any permissions set on the bpFallthrough | [
"Returns",
"a",
"BasePermission",
"that",
"matches",
"any",
"permissions",
"set",
"on",
"this",
"BasePermission",
"and",
"falls",
"through",
"to",
"any",
"permissions",
"set",
"on",
"the",
"bpFallthrough"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/base_permissions.go#L57-L63 | train |
hyperledger/burrow | core/kernel.go | NewKernel | func NewKernel(dbDir string) (*Kernel, error) {
if dbDir == "" {
return nil, fmt.Errorf("Burrow requires a database directory")
}
runID, err := simpleuuid.NewTime(time.Now()) // Create a random ID based on start time
return &Kernel{
Logger: logging.NewNoopLogger(),
RunID: runID,
Emitter: event.NewEmitter(),
processes: make(map[string]process.Process),
listeners: make(map[string]net.Listener),
shutdownNotify: make(chan struct{}),
txCodec: txs.NewAminoCodec(),
database: dbm.NewDB(BurrowDBName, dbm.GoLevelDBBackend, dbDir),
}, err
} | go | func NewKernel(dbDir string) (*Kernel, error) {
if dbDir == "" {
return nil, fmt.Errorf("Burrow requires a database directory")
}
runID, err := simpleuuid.NewTime(time.Now()) // Create a random ID based on start time
return &Kernel{
Logger: logging.NewNoopLogger(),
RunID: runID,
Emitter: event.NewEmitter(),
processes: make(map[string]process.Process),
listeners: make(map[string]net.Listener),
shutdownNotify: make(chan struct{}),
txCodec: txs.NewAminoCodec(),
database: dbm.NewDB(BurrowDBName, dbm.GoLevelDBBackend, dbDir),
}, err
} | [
"func",
"NewKernel",
"(",
"dbDir",
"string",
")",
"(",
"*",
"Kernel",
",",
"error",
")",
"{",
"if",
"dbDir",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"runID",
",",
"err",
":=",
"simpleuuid",
".",
"NewTime",
"(",
"time",
".",
"Now",
"(",
")",
")",
"// Create a random ID based on start time",
"\n",
"return",
"&",
"Kernel",
"{",
"Logger",
":",
"logging",
".",
"NewNoopLogger",
"(",
")",
",",
"RunID",
":",
"runID",
",",
"Emitter",
":",
"event",
".",
"NewEmitter",
"(",
")",
",",
"processes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"process",
".",
"Process",
")",
",",
"listeners",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"net",
".",
"Listener",
")",
",",
"shutdownNotify",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"txCodec",
":",
"txs",
".",
"NewAminoCodec",
"(",
")",
",",
"database",
":",
"dbm",
".",
"NewDB",
"(",
"BurrowDBName",
",",
"dbm",
".",
"GoLevelDBBackend",
",",
"dbDir",
")",
",",
"}",
",",
"err",
"\n",
"}"
] | // NewKernel initializes an empty kernel | [
"NewKernel",
"initializes",
"an",
"empty",
"kernel"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L85-L100 | train |
hyperledger/burrow | core/kernel.go | SetLogger | func (kern *Kernel) SetLogger(logger *logging.Logger) {
logger = logger.WithScope("NewKernel()").With(structure.TimeKey,
log.DefaultTimestampUTC, structure.RunId, kern.RunID.String())
heightValuer := log.Valuer(func() interface{} { return kern.Blockchain.LastBlockHeight() })
kern.Logger = logger.WithInfo(structure.CallerKey, log.Caller(LoggingCallerDepth)).With("height", heightValuer)
kern.Emitter.SetLogger(logger)
} | go | func (kern *Kernel) SetLogger(logger *logging.Logger) {
logger = logger.WithScope("NewKernel()").With(structure.TimeKey,
log.DefaultTimestampUTC, structure.RunId, kern.RunID.String())
heightValuer := log.Valuer(func() interface{} { return kern.Blockchain.LastBlockHeight() })
kern.Logger = logger.WithInfo(structure.CallerKey, log.Caller(LoggingCallerDepth)).With("height", heightValuer)
kern.Emitter.SetLogger(logger)
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"SetLogger",
"(",
"logger",
"*",
"logging",
".",
"Logger",
")",
"{",
"logger",
"=",
"logger",
".",
"WithScope",
"(",
"\"",
"\"",
")",
".",
"With",
"(",
"structure",
".",
"TimeKey",
",",
"log",
".",
"DefaultTimestampUTC",
",",
"structure",
".",
"RunId",
",",
"kern",
".",
"RunID",
".",
"String",
"(",
")",
")",
"\n",
"heightValuer",
":=",
"log",
".",
"Valuer",
"(",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"kern",
".",
"Blockchain",
".",
"LastBlockHeight",
"(",
")",
"}",
")",
"\n",
"kern",
".",
"Logger",
"=",
"logger",
".",
"WithInfo",
"(",
"structure",
".",
"CallerKey",
",",
"log",
".",
"Caller",
"(",
"LoggingCallerDepth",
")",
")",
".",
"With",
"(",
"\"",
"\"",
",",
"heightValuer",
")",
"\n",
"kern",
".",
"Emitter",
".",
"SetLogger",
"(",
"logger",
")",
"\n",
"}"
] | // SetLogger initializes the kernel with the provided logger | [
"SetLogger",
"initializes",
"the",
"kernel",
"with",
"the",
"provided",
"logger"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L103-L109 | train |
hyperledger/burrow | core/kernel.go | LoadState | func (kern *Kernel) LoadState(genesisDoc *genesis.GenesisDoc) (err error) {
var existing bool
existing, kern.Blockchain, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger)
if err != nil {
return fmt.Errorf("error creating or loading blockchain state: %v", err)
}
if existing {
kern.Logger.InfoMsg("Loading application state", "height", kern.Blockchain.LastBlockHeight())
kern.State, err = state.LoadState(kern.database, execution.VersionAtHeight(kern.Blockchain.LastBlockHeight()))
if err != nil {
return fmt.Errorf("could not load persisted execution state at hash 0x%X: %v",
kern.Blockchain.AppHashAfterLastBlock(), err)
}
if !bytes.Equal(kern.State.Hash(), kern.Blockchain.AppHashAfterLastBlock()) {
return fmt.Errorf("state and blockchain disagree on app hash at height %d: "+
"state gives %X, blockchain gives %X", kern.Blockchain.LastBlockHeight(),
kern.State.Hash(), kern.Blockchain.AppHashAfterLastBlock())
}
} else {
kern.Logger.InfoMsg("Creating new application state from genesis")
kern.State, err = state.MakeGenesisState(kern.database, genesisDoc)
if err != nil {
return fmt.Errorf("could not build genesis state: %v", err)
}
if err = kern.State.InitialCommit(); err != nil {
return err
}
}
kern.Logger.InfoMsg("State loading successful")
params := execution.ParamsFromGenesis(genesisDoc)
kern.checker = execution.NewBatchChecker(kern.State, params, kern.Blockchain, kern.Logger)
kern.committer = execution.NewBatchCommitter(kern.State, params, kern.Blockchain, kern.Emitter, kern.Logger, kern.exeOptions...)
return nil
} | go | func (kern *Kernel) LoadState(genesisDoc *genesis.GenesisDoc) (err error) {
var existing bool
existing, kern.Blockchain, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger)
if err != nil {
return fmt.Errorf("error creating or loading blockchain state: %v", err)
}
if existing {
kern.Logger.InfoMsg("Loading application state", "height", kern.Blockchain.LastBlockHeight())
kern.State, err = state.LoadState(kern.database, execution.VersionAtHeight(kern.Blockchain.LastBlockHeight()))
if err != nil {
return fmt.Errorf("could not load persisted execution state at hash 0x%X: %v",
kern.Blockchain.AppHashAfterLastBlock(), err)
}
if !bytes.Equal(kern.State.Hash(), kern.Blockchain.AppHashAfterLastBlock()) {
return fmt.Errorf("state and blockchain disagree on app hash at height %d: "+
"state gives %X, blockchain gives %X", kern.Blockchain.LastBlockHeight(),
kern.State.Hash(), kern.Blockchain.AppHashAfterLastBlock())
}
} else {
kern.Logger.InfoMsg("Creating new application state from genesis")
kern.State, err = state.MakeGenesisState(kern.database, genesisDoc)
if err != nil {
return fmt.Errorf("could not build genesis state: %v", err)
}
if err = kern.State.InitialCommit(); err != nil {
return err
}
}
kern.Logger.InfoMsg("State loading successful")
params := execution.ParamsFromGenesis(genesisDoc)
kern.checker = execution.NewBatchChecker(kern.State, params, kern.Blockchain, kern.Logger)
kern.committer = execution.NewBatchCommitter(kern.State, params, kern.Blockchain, kern.Emitter, kern.Logger, kern.exeOptions...)
return nil
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"LoadState",
"(",
"genesisDoc",
"*",
"genesis",
".",
"GenesisDoc",
")",
"(",
"err",
"error",
")",
"{",
"var",
"existing",
"bool",
"\n",
"existing",
",",
"kern",
".",
"Blockchain",
",",
"err",
"=",
"bcm",
".",
"LoadOrNewBlockchain",
"(",
"kern",
".",
"database",
",",
"genesisDoc",
",",
"kern",
".",
"Logger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"existing",
"{",
"kern",
".",
"Logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"kern",
".",
"Blockchain",
".",
"LastBlockHeight",
"(",
")",
")",
"\n",
"kern",
".",
"State",
",",
"err",
"=",
"state",
".",
"LoadState",
"(",
"kern",
".",
"database",
",",
"execution",
".",
"VersionAtHeight",
"(",
"kern",
".",
"Blockchain",
".",
"LastBlockHeight",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"kern",
".",
"Blockchain",
".",
"AppHashAfterLastBlock",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"kern",
".",
"State",
".",
"Hash",
"(",
")",
",",
"kern",
".",
"Blockchain",
".",
"AppHashAfterLastBlock",
"(",
")",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"kern",
".",
"Blockchain",
".",
"LastBlockHeight",
"(",
")",
",",
"kern",
".",
"State",
".",
"Hash",
"(",
")",
",",
"kern",
".",
"Blockchain",
".",
"AppHashAfterLastBlock",
"(",
")",
")",
"\n",
"}",
"\n\n",
"}",
"else",
"{",
"kern",
".",
"Logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
")",
"\n",
"kern",
".",
"State",
",",
"err",
"=",
"state",
".",
"MakeGenesisState",
"(",
"kern",
".",
"database",
",",
"genesisDoc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"kern",
".",
"State",
".",
"InitialCommit",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"kern",
".",
"Logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
")",
"\n\n",
"params",
":=",
"execution",
".",
"ParamsFromGenesis",
"(",
"genesisDoc",
")",
"\n",
"kern",
".",
"checker",
"=",
"execution",
".",
"NewBatchChecker",
"(",
"kern",
".",
"State",
",",
"params",
",",
"kern",
".",
"Blockchain",
",",
"kern",
".",
"Logger",
")",
"\n",
"kern",
".",
"committer",
"=",
"execution",
".",
"NewBatchCommitter",
"(",
"kern",
".",
"State",
",",
"params",
",",
"kern",
".",
"Blockchain",
",",
"kern",
".",
"Emitter",
",",
"kern",
".",
"Logger",
",",
"kern",
".",
"exeOptions",
"...",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // LoadState starts from scratch or previous chain | [
"LoadState",
"starts",
"from",
"scratch",
"or",
"previous",
"chain"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L112-L151 | train |
hyperledger/burrow | core/kernel.go | LoadDump | func (kern *Kernel) LoadDump(genesisDoc *genesis.GenesisDoc, restoreFile string, silent bool) (err error) {
var exists bool
if exists, kern.Blockchain, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger); err != nil {
return fmt.Errorf("error creating or loading blockchain state: %v", err)
}
if exists {
if silent {
kern.Logger.InfoMsg("State already exists, skipping...")
return nil
}
return fmt.Errorf("existing state found, please remove before restoring")
}
kern.Blockchain.SetBlockStore(bcm.NewBlockStore(blockchain.NewBlockStore(kern.database)))
if kern.State, err = state.MakeGenesisState(kern.database, genesisDoc); err != nil {
return fmt.Errorf("could not build genesis state: %v", err)
}
if len(genesisDoc.AppHash) == 0 {
return fmt.Errorf("AppHash is required when restoring chain")
}
reader, err := state.NewFileDumpReader(restoreFile)
if err != nil {
return err
}
if err = kern.State.LoadDump(reader); err != nil {
return err
}
if err = kern.State.InitialCommit(); err != nil {
return err
}
if !bytes.Equal(kern.State.Hash(), kern.Blockchain.GenesisDoc().AppHash) {
return fmt.Errorf("Restore produced a different apphash expect 0x%x got 0x%x",
kern.Blockchain.GenesisDoc().AppHash, kern.State.Hash())
}
err = kern.Blockchain.CommitWithAppHash(kern.State.Hash())
if err != nil {
return fmt.Errorf("Unable to commit %v", err)
}
kern.Logger.InfoMsg("State restore successful -> height 0",
"state_hash", kern.State.Hash())
return nil
} | go | func (kern *Kernel) LoadDump(genesisDoc *genesis.GenesisDoc, restoreFile string, silent bool) (err error) {
var exists bool
if exists, kern.Blockchain, err = bcm.LoadOrNewBlockchain(kern.database, genesisDoc, kern.Logger); err != nil {
return fmt.Errorf("error creating or loading blockchain state: %v", err)
}
if exists {
if silent {
kern.Logger.InfoMsg("State already exists, skipping...")
return nil
}
return fmt.Errorf("existing state found, please remove before restoring")
}
kern.Blockchain.SetBlockStore(bcm.NewBlockStore(blockchain.NewBlockStore(kern.database)))
if kern.State, err = state.MakeGenesisState(kern.database, genesisDoc); err != nil {
return fmt.Errorf("could not build genesis state: %v", err)
}
if len(genesisDoc.AppHash) == 0 {
return fmt.Errorf("AppHash is required when restoring chain")
}
reader, err := state.NewFileDumpReader(restoreFile)
if err != nil {
return err
}
if err = kern.State.LoadDump(reader); err != nil {
return err
}
if err = kern.State.InitialCommit(); err != nil {
return err
}
if !bytes.Equal(kern.State.Hash(), kern.Blockchain.GenesisDoc().AppHash) {
return fmt.Errorf("Restore produced a different apphash expect 0x%x got 0x%x",
kern.Blockchain.GenesisDoc().AppHash, kern.State.Hash())
}
err = kern.Blockchain.CommitWithAppHash(kern.State.Hash())
if err != nil {
return fmt.Errorf("Unable to commit %v", err)
}
kern.Logger.InfoMsg("State restore successful -> height 0",
"state_hash", kern.State.Hash())
return nil
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"LoadDump",
"(",
"genesisDoc",
"*",
"genesis",
".",
"GenesisDoc",
",",
"restoreFile",
"string",
",",
"silent",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"var",
"exists",
"bool",
"\n",
"if",
"exists",
",",
"kern",
".",
"Blockchain",
",",
"err",
"=",
"bcm",
".",
"LoadOrNewBlockchain",
"(",
"kern",
".",
"database",
",",
"genesisDoc",
",",
"kern",
".",
"Logger",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"exists",
"{",
"if",
"silent",
"{",
"kern",
".",
"Logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"kern",
".",
"Blockchain",
".",
"SetBlockStore",
"(",
"bcm",
".",
"NewBlockStore",
"(",
"blockchain",
".",
"NewBlockStore",
"(",
"kern",
".",
"database",
")",
")",
")",
"\n\n",
"if",
"kern",
".",
"State",
",",
"err",
"=",
"state",
".",
"MakeGenesisState",
"(",
"kern",
".",
"database",
",",
"genesisDoc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"genesisDoc",
".",
"AppHash",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"reader",
",",
"err",
":=",
"state",
".",
"NewFileDumpReader",
"(",
"restoreFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"kern",
".",
"State",
".",
"LoadDump",
"(",
"reader",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"kern",
".",
"State",
".",
"InitialCommit",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"kern",
".",
"State",
".",
"Hash",
"(",
")",
",",
"kern",
".",
"Blockchain",
".",
"GenesisDoc",
"(",
")",
".",
"AppHash",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"kern",
".",
"Blockchain",
".",
"GenesisDoc",
"(",
")",
".",
"AppHash",
",",
"kern",
".",
"State",
".",
"Hash",
"(",
")",
")",
"\n",
"}",
"\n",
"err",
"=",
"kern",
".",
"Blockchain",
".",
"CommitWithAppHash",
"(",
"kern",
".",
"State",
".",
"Hash",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"kern",
".",
"Logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"kern",
".",
"State",
".",
"Hash",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // LoadDump restores chain state from the given dump file | [
"LoadDump",
"restores",
"chain",
"state",
"from",
"the",
"given",
"dump",
"file"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L154-L203 | train |
hyperledger/burrow | core/kernel.go | GetNodeView | func (kern *Kernel) GetNodeView() (*tendermint.NodeView, error) {
if kern.Node == nil {
return nil, nil
}
return tendermint.NewNodeView(kern.Node, kern.txCodec, kern.RunID)
} | go | func (kern *Kernel) GetNodeView() (*tendermint.NodeView, error) {
if kern.Node == nil {
return nil, nil
}
return tendermint.NewNodeView(kern.Node, kern.txCodec, kern.RunID)
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"GetNodeView",
"(",
")",
"(",
"*",
"tendermint",
".",
"NodeView",
",",
"error",
")",
"{",
"if",
"kern",
".",
"Node",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"tendermint",
".",
"NewNodeView",
"(",
"kern",
".",
"Node",
",",
"kern",
".",
"txCodec",
",",
"kern",
".",
"RunID",
")",
"\n",
"}"
] | // GetNodeView builds and returns a wrapper of our tendermint node | [
"GetNodeView",
"builds",
"and",
"returns",
"a",
"wrapper",
"of",
"our",
"tendermint",
"node"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L206-L211 | train |
hyperledger/burrow | core/kernel.go | AddExecutionOptions | func (kern *Kernel) AddExecutionOptions(opts ...execution.ExecutionOption) {
kern.exeOptions = append(kern.exeOptions, opts...)
} | go | func (kern *Kernel) AddExecutionOptions(opts ...execution.ExecutionOption) {
kern.exeOptions = append(kern.exeOptions, opts...)
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"AddExecutionOptions",
"(",
"opts",
"...",
"execution",
".",
"ExecutionOption",
")",
"{",
"kern",
".",
"exeOptions",
"=",
"append",
"(",
"kern",
".",
"exeOptions",
",",
"opts",
"...",
")",
"\n",
"}"
] | // AddExecutionOptions extends our execution options | [
"AddExecutionOptions",
"extends",
"our",
"execution",
"options"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L214-L216 | train |
hyperledger/burrow | core/kernel.go | AddProcesses | func (kern *Kernel) AddProcesses(pl ...process.Launcher) {
kern.Launchers = append(kern.Launchers, pl...)
} | go | func (kern *Kernel) AddProcesses(pl ...process.Launcher) {
kern.Launchers = append(kern.Launchers, pl...)
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"AddProcesses",
"(",
"pl",
"...",
"process",
".",
"Launcher",
")",
"{",
"kern",
".",
"Launchers",
"=",
"append",
"(",
"kern",
".",
"Launchers",
",",
"pl",
"...",
")",
"\n",
"}"
] | // AddProcesses extends the services that we launch at boot | [
"AddProcesses",
"extends",
"the",
"services",
"that",
"we",
"launch",
"at",
"boot"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L219-L221 | train |
hyperledger/burrow | core/kernel.go | Boot | func (kern *Kernel) Boot() (err error) {
for _, launcher := range kern.Launchers {
if launcher.Enabled {
srvr, err := launcher.Launch()
if err != nil {
return fmt.Errorf("error launching %s server: %v", launcher.Name, err)
}
kern.processes[launcher.Name] = srvr
}
}
go kern.supervise()
return nil
} | go | func (kern *Kernel) Boot() (err error) {
for _, launcher := range kern.Launchers {
if launcher.Enabled {
srvr, err := launcher.Launch()
if err != nil {
return fmt.Errorf("error launching %s server: %v", launcher.Name, err)
}
kern.processes[launcher.Name] = srvr
}
}
go kern.supervise()
return nil
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"Boot",
"(",
")",
"(",
"err",
"error",
")",
"{",
"for",
"_",
",",
"launcher",
":=",
"range",
"kern",
".",
"Launchers",
"{",
"if",
"launcher",
".",
"Enabled",
"{",
"srvr",
",",
"err",
":=",
"launcher",
".",
"Launch",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"launcher",
".",
"Name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"kern",
".",
"processes",
"[",
"launcher",
".",
"Name",
"]",
"=",
"srvr",
"\n",
"}",
"\n",
"}",
"\n",
"go",
"kern",
".",
"supervise",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Boot the kernel starting Tendermint and RPC layers | [
"Boot",
"the",
"kernel",
"starting",
"Tendermint",
"and",
"RPC",
"layers"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L247-L260 | train |
hyperledger/burrow | core/kernel.go | supervise | func (kern *Kernel) supervise() {
// perform disaster restarts of the kernel; rejoining the network as if we were a new node.
shutdownCh := make(chan os.Signal, 1)
reloadCh := make(chan os.Signal, 1)
syncCh := make(chan os.Signal, 1)
signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
signal.Notify(reloadCh, syscall.SIGHUP)
signal.Notify(syncCh, syscall.SIGUSR1)
for {
select {
case <-reloadCh:
err := kern.Logger.Reload()
if err != nil {
fmt.Fprintf(os.Stderr, "%v: could not reload logger: %v", kern, err)
}
case <-syncCh:
err := kern.Logger.Sync()
if err != nil {
fmt.Fprintf(os.Stderr, "%v: could not sync logger: %v", kern, err)
}
case sig := <-shutdownCh:
kern.Logger.InfoMsg(fmt.Sprintf("Caught %v signal so shutting down", sig),
"signal", sig.String())
kern.ShutdownAndExit()
return
}
}
} | go | func (kern *Kernel) supervise() {
// perform disaster restarts of the kernel; rejoining the network as if we were a new node.
shutdownCh := make(chan os.Signal, 1)
reloadCh := make(chan os.Signal, 1)
syncCh := make(chan os.Signal, 1)
signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
signal.Notify(reloadCh, syscall.SIGHUP)
signal.Notify(syncCh, syscall.SIGUSR1)
for {
select {
case <-reloadCh:
err := kern.Logger.Reload()
if err != nil {
fmt.Fprintf(os.Stderr, "%v: could not reload logger: %v", kern, err)
}
case <-syncCh:
err := kern.Logger.Sync()
if err != nil {
fmt.Fprintf(os.Stderr, "%v: could not sync logger: %v", kern, err)
}
case sig := <-shutdownCh:
kern.Logger.InfoMsg(fmt.Sprintf("Caught %v signal so shutting down", sig),
"signal", sig.String())
kern.ShutdownAndExit()
return
}
}
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"supervise",
"(",
")",
"{",
"// perform disaster restarts of the kernel; rejoining the network as if we were a new node.",
"shutdownCh",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"reloadCh",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"syncCh",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"signal",
".",
"Notify",
"(",
"shutdownCh",
",",
"syscall",
".",
"SIGINT",
",",
"syscall",
".",
"SIGTERM",
",",
"syscall",
".",
"SIGKILL",
")",
"\n",
"signal",
".",
"Notify",
"(",
"reloadCh",
",",
"syscall",
".",
"SIGHUP",
")",
"\n",
"signal",
".",
"Notify",
"(",
"syncCh",
",",
"syscall",
".",
"SIGUSR1",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"reloadCh",
":",
"err",
":=",
"kern",
".",
"Logger",
".",
"Reload",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"kern",
",",
"err",
")",
"\n",
"}",
"\n",
"case",
"<-",
"syncCh",
":",
"err",
":=",
"kern",
".",
"Logger",
".",
"Sync",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"kern",
",",
"err",
")",
"\n",
"}",
"\n",
"case",
"sig",
":=",
"<-",
"shutdownCh",
":",
"kern",
".",
"Logger",
".",
"InfoMsg",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sig",
")",
",",
"\"",
"\"",
",",
"sig",
".",
"String",
"(",
")",
")",
"\n",
"kern",
".",
"ShutdownAndExit",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Supervise kernel once booted | [
"Supervise",
"kernel",
"once",
"booted"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L311-L338 | train |
hyperledger/burrow | core/kernel.go | Shutdown | func (kern *Kernel) Shutdown(ctx context.Context) (err error) {
kern.shutdownOnce.Do(func() {
logger := kern.Logger.WithScope("Shutdown")
logger.InfoMsg("Attempting graceful shutdown...")
logger.InfoMsg("Shutting down servers")
// Shutdown servers in reverse order to boot
for i := len(kern.Launchers) - 1; i >= 0; i-- {
name := kern.Launchers[i].Name
proc, ok := kern.processes[name]
if ok {
logger.InfoMsg("Shutting down server", "server_name", name)
sErr := proc.Shutdown(ctx)
if sErr != nil {
logger.InfoMsg("Failed to shutdown server",
"server_name", name,
structure.ErrorKey, sErr)
if err == nil {
err = sErr
}
}
}
}
logger.InfoMsg("Shutdown complete")
// Best effort
structure.Sync(kern.Logger.Info)
structure.Sync(kern.Logger.Trace)
// We don't want to wait for them, but yielding for a cooldown Let other goroutines flush
// potentially interesting final output (e.g. log messages)
time.Sleep(CooldownTime)
close(kern.shutdownNotify)
})
return
} | go | func (kern *Kernel) Shutdown(ctx context.Context) (err error) {
kern.shutdownOnce.Do(func() {
logger := kern.Logger.WithScope("Shutdown")
logger.InfoMsg("Attempting graceful shutdown...")
logger.InfoMsg("Shutting down servers")
// Shutdown servers in reverse order to boot
for i := len(kern.Launchers) - 1; i >= 0; i-- {
name := kern.Launchers[i].Name
proc, ok := kern.processes[name]
if ok {
logger.InfoMsg("Shutting down server", "server_name", name)
sErr := proc.Shutdown(ctx)
if sErr != nil {
logger.InfoMsg("Failed to shutdown server",
"server_name", name,
structure.ErrorKey, sErr)
if err == nil {
err = sErr
}
}
}
}
logger.InfoMsg("Shutdown complete")
// Best effort
structure.Sync(kern.Logger.Info)
structure.Sync(kern.Logger.Trace)
// We don't want to wait for them, but yielding for a cooldown Let other goroutines flush
// potentially interesting final output (e.g. log messages)
time.Sleep(CooldownTime)
close(kern.shutdownNotify)
})
return
} | [
"func",
"(",
"kern",
"*",
"Kernel",
")",
"Shutdown",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"kern",
".",
"shutdownOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"logger",
":=",
"kern",
".",
"Logger",
".",
"WithScope",
"(",
"\"",
"\"",
")",
"\n",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
")",
"\n",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
")",
"\n",
"// Shutdown servers in reverse order to boot",
"for",
"i",
":=",
"len",
"(",
"kern",
".",
"Launchers",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"name",
":=",
"kern",
".",
"Launchers",
"[",
"i",
"]",
".",
"Name",
"\n",
"proc",
",",
"ok",
":=",
"kern",
".",
"processes",
"[",
"name",
"]",
"\n",
"if",
"ok",
"{",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"sErr",
":=",
"proc",
".",
"Shutdown",
"(",
"ctx",
")",
"\n",
"if",
"sErr",
"!=",
"nil",
"{",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"name",
",",
"structure",
".",
"ErrorKey",
",",
"sErr",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"sErr",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
")",
"\n",
"// Best effort",
"structure",
".",
"Sync",
"(",
"kern",
".",
"Logger",
".",
"Info",
")",
"\n",
"structure",
".",
"Sync",
"(",
"kern",
".",
"Logger",
".",
"Trace",
")",
"\n",
"// We don't want to wait for them, but yielding for a cooldown Let other goroutines flush",
"// potentially interesting final output (e.g. log messages)",
"time",
".",
"Sleep",
"(",
"CooldownTime",
")",
"\n",
"close",
"(",
"kern",
".",
"shutdownNotify",
")",
"\n",
"}",
")",
"\n",
"return",
"\n",
"}"
] | // Shutdown stops the kernel allowing for a graceful shutdown of components in order | [
"Shutdown",
"stops",
"the",
"kernel",
"allowing",
"for",
"a",
"graceful",
"shutdown",
"of",
"components",
"in",
"order"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/core/kernel.go#L352-L384 | train |
hyperledger/burrow | deploy/jobs/jobs_transact.go | registerNameTx | func registerNameTx(name *def.RegisterName, do *def.DeployArgs, account string, client *def.Client, logger *logging.Logger) (*payload.NameTx, error) {
// Set Defaults
name.Source = useDefault(name.Source, account)
name.Fee = useDefault(name.Fee, do.DefaultFee)
name.Amount = useDefault(name.Amount, do.DefaultAmount)
// Formulate tx
logger.InfoMsg("NameReg Transaction",
"name", name.Name,
"data", name.Data,
"amount", name.Amount)
return client.Name(&def.NameArg{
Input: name.Source,
Sequence: name.Sequence,
Name: name.Name,
Amount: name.Amount,
Data: name.Data,
Fee: name.Fee,
}, logger)
} | go | func registerNameTx(name *def.RegisterName, do *def.DeployArgs, account string, client *def.Client, logger *logging.Logger) (*payload.NameTx, error) {
// Set Defaults
name.Source = useDefault(name.Source, account)
name.Fee = useDefault(name.Fee, do.DefaultFee)
name.Amount = useDefault(name.Amount, do.DefaultAmount)
// Formulate tx
logger.InfoMsg("NameReg Transaction",
"name", name.Name,
"data", name.Data,
"amount", name.Amount)
return client.Name(&def.NameArg{
Input: name.Source,
Sequence: name.Sequence,
Name: name.Name,
Amount: name.Amount,
Data: name.Data,
Fee: name.Fee,
}, logger)
} | [
"func",
"registerNameTx",
"(",
"name",
"*",
"def",
".",
"RegisterName",
",",
"do",
"*",
"def",
".",
"DeployArgs",
",",
"account",
"string",
",",
"client",
"*",
"def",
".",
"Client",
",",
"logger",
"*",
"logging",
".",
"Logger",
")",
"(",
"*",
"payload",
".",
"NameTx",
",",
"error",
")",
"{",
"// Set Defaults",
"name",
".",
"Source",
"=",
"useDefault",
"(",
"name",
".",
"Source",
",",
"account",
")",
"\n",
"name",
".",
"Fee",
"=",
"useDefault",
"(",
"name",
".",
"Fee",
",",
"do",
".",
"DefaultFee",
")",
"\n",
"name",
".",
"Amount",
"=",
"useDefault",
"(",
"name",
".",
"Amount",
",",
"do",
".",
"DefaultAmount",
")",
"\n\n",
"// Formulate tx",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"name",
".",
"Name",
",",
"\"",
"\"",
",",
"name",
".",
"Data",
",",
"\"",
"\"",
",",
"name",
".",
"Amount",
")",
"\n\n",
"return",
"client",
".",
"Name",
"(",
"&",
"def",
".",
"NameArg",
"{",
"Input",
":",
"name",
".",
"Source",
",",
"Sequence",
":",
"name",
".",
"Sequence",
",",
"Name",
":",
"name",
".",
"Name",
",",
"Amount",
":",
"name",
".",
"Amount",
",",
"Data",
":",
"name",
".",
"Data",
",",
"Fee",
":",
"name",
".",
"Fee",
",",
"}",
",",
"logger",
")",
"\n",
"}"
] | // Runs an individual nametx. | [
"Runs",
"an",
"individual",
"nametx",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/deploy/jobs/jobs_transact.go#L137-L157 | train |
hyperledger/burrow | vent/service/decoder.go | decodeEvent | func decodeEvent(header *exec.Header, log *exec.LogEvent, abiSpec *abi.AbiSpec) (map[string]interface{}, error) {
// to prepare decoded data and map to event item name
data := make(map[string]interface{})
var eventID abi.EventID
copy(eventID[:], log.Topics[0].Bytes())
evAbi, ok := abiSpec.EventsById[eventID]
if !ok {
return nil, fmt.Errorf("Abi spec not found for event %x", eventID)
}
// decode header to get context data for each event
data[types.EventNameLabel] = evAbi.Name
data[types.BlockHeightLabel] = fmt.Sprintf("%v", header.GetHeight())
data[types.EventTypeLabel] = header.GetEventType().String()
data[types.TxTxHashLabel] = header.TxHash.String()
// build expected interface type array to get log event values
unpackedData := abi.GetPackingTypes(evAbi.Inputs)
// unpack event data (topics & data part)
if err := abi.UnpackEvent(&evAbi, log.Topics, log.Data, unpackedData...); err != nil {
return nil, errors.Wrap(err, "Could not unpack event data")
}
// for each decoded item value, stores it in given item name
for i, input := range evAbi.Inputs {
switch v := unpackedData[i].(type) {
case *crypto.Address:
data[input.Name] = v.String()
case *big.Int:
data[input.Name] = v.String()
case *string:
data[input.Name] = *v
default:
data[input.Name] = v
}
}
return data, nil
} | go | func decodeEvent(header *exec.Header, log *exec.LogEvent, abiSpec *abi.AbiSpec) (map[string]interface{}, error) {
// to prepare decoded data and map to event item name
data := make(map[string]interface{})
var eventID abi.EventID
copy(eventID[:], log.Topics[0].Bytes())
evAbi, ok := abiSpec.EventsById[eventID]
if !ok {
return nil, fmt.Errorf("Abi spec not found for event %x", eventID)
}
// decode header to get context data for each event
data[types.EventNameLabel] = evAbi.Name
data[types.BlockHeightLabel] = fmt.Sprintf("%v", header.GetHeight())
data[types.EventTypeLabel] = header.GetEventType().String()
data[types.TxTxHashLabel] = header.TxHash.String()
// build expected interface type array to get log event values
unpackedData := abi.GetPackingTypes(evAbi.Inputs)
// unpack event data (topics & data part)
if err := abi.UnpackEvent(&evAbi, log.Topics, log.Data, unpackedData...); err != nil {
return nil, errors.Wrap(err, "Could not unpack event data")
}
// for each decoded item value, stores it in given item name
for i, input := range evAbi.Inputs {
switch v := unpackedData[i].(type) {
case *crypto.Address:
data[input.Name] = v.String()
case *big.Int:
data[input.Name] = v.String()
case *string:
data[input.Name] = *v
default:
data[input.Name] = v
}
}
return data, nil
} | [
"func",
"decodeEvent",
"(",
"header",
"*",
"exec",
".",
"Header",
",",
"log",
"*",
"exec",
".",
"LogEvent",
",",
"abiSpec",
"*",
"abi",
".",
"AbiSpec",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// to prepare decoded data and map to event item name",
"data",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"var",
"eventID",
"abi",
".",
"EventID",
"\n",
"copy",
"(",
"eventID",
"[",
":",
"]",
",",
"log",
".",
"Topics",
"[",
"0",
"]",
".",
"Bytes",
"(",
")",
")",
"\n\n",
"evAbi",
",",
"ok",
":=",
"abiSpec",
".",
"EventsById",
"[",
"eventID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"eventID",
")",
"\n",
"}",
"\n\n",
"// decode header to get context data for each event",
"data",
"[",
"types",
".",
"EventNameLabel",
"]",
"=",
"evAbi",
".",
"Name",
"\n",
"data",
"[",
"types",
".",
"BlockHeightLabel",
"]",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"header",
".",
"GetHeight",
"(",
")",
")",
"\n",
"data",
"[",
"types",
".",
"EventTypeLabel",
"]",
"=",
"header",
".",
"GetEventType",
"(",
")",
".",
"String",
"(",
")",
"\n",
"data",
"[",
"types",
".",
"TxTxHashLabel",
"]",
"=",
"header",
".",
"TxHash",
".",
"String",
"(",
")",
"\n\n",
"// build expected interface type array to get log event values",
"unpackedData",
":=",
"abi",
".",
"GetPackingTypes",
"(",
"evAbi",
".",
"Inputs",
")",
"\n\n",
"// unpack event data (topics & data part)",
"if",
"err",
":=",
"abi",
".",
"UnpackEvent",
"(",
"&",
"evAbi",
",",
"log",
".",
"Topics",
",",
"log",
".",
"Data",
",",
"unpackedData",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// for each decoded item value, stores it in given item name",
"for",
"i",
",",
"input",
":=",
"range",
"evAbi",
".",
"Inputs",
"{",
"switch",
"v",
":=",
"unpackedData",
"[",
"i",
"]",
".",
"(",
"type",
")",
"{",
"case",
"*",
"crypto",
".",
"Address",
":",
"data",
"[",
"input",
".",
"Name",
"]",
"=",
"v",
".",
"String",
"(",
")",
"\n",
"case",
"*",
"big",
".",
"Int",
":",
"data",
"[",
"input",
".",
"Name",
"]",
"=",
"v",
".",
"String",
"(",
")",
"\n",
"case",
"*",
"string",
":",
"data",
"[",
"input",
".",
"Name",
"]",
"=",
"*",
"v",
"\n",
"default",
":",
"data",
"[",
"input",
".",
"Name",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"data",
",",
"nil",
"\n",
"}"
] | // decodeEvent unpacks & decodes event data | [
"decodeEvent",
"unpacks",
"&",
"decodes",
"event",
"data"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/service/decoder.go#L15-L56 | train |
hyperledger/burrow | execution/execution.go | NewBatchChecker | func NewBatchChecker(backend ExecutorState, params Params, blockchain contexts.Blockchain, logger *logging.Logger,
options ...ExecutionOption) BatchExecutor {
return newExecutor("CheckCache", false, params, backend, blockchain, nil,
logger.WithScope("NewBatchExecutor"), options...)
} | go | func NewBatchChecker(backend ExecutorState, params Params, blockchain contexts.Blockchain, logger *logging.Logger,
options ...ExecutionOption) BatchExecutor {
return newExecutor("CheckCache", false, params, backend, blockchain, nil,
logger.WithScope("NewBatchExecutor"), options...)
} | [
"func",
"NewBatchChecker",
"(",
"backend",
"ExecutorState",
",",
"params",
"Params",
",",
"blockchain",
"contexts",
".",
"Blockchain",
",",
"logger",
"*",
"logging",
".",
"Logger",
",",
"options",
"...",
"ExecutionOption",
")",
"BatchExecutor",
"{",
"return",
"newExecutor",
"(",
"\"",
"\"",
",",
"false",
",",
"params",
",",
"backend",
",",
"blockchain",
",",
"nil",
",",
"logger",
".",
"WithScope",
"(",
"\"",
"\"",
")",
",",
"options",
"...",
")",
"\n",
"}"
] | // Wraps a cache of what is variously known as the 'check cache' and 'mempool' | [
"Wraps",
"a",
"cache",
"of",
"what",
"is",
"variously",
"known",
"as",
"the",
"check",
"cache",
"and",
"mempool"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/execution.go#L114-L119 | train |
hyperledger/burrow | execution/execution.go | Commit | func (exe *executor) Commit(header *abciTypes.Header) (stateHash []byte, err error) {
// The write lock to the executor is controlled by the caller (e.g. abci.App) so we do not acquire it here to avoid
// deadlock
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("recovered from panic in executor.Commit(): %v\n%s", r, debug.Stack())
}
}()
// Capture height
height := exe.block.Height
exe.logger.InfoMsg("Executor committing", "height", exe.block.Height)
// Form BlockExecution for this block from TxExecutions and Tendermint block header
blockExecution, err := exe.finaliseBlockExecution(header)
if err != nil {
return nil, err
}
// First commit the app state, this app hash will not get checkpointed until the next block when we are sure
// that nothing in the downstream commit process could have failed. At worst we go back one block.
hash, version, err := exe.state.Update(func(ws state.Updatable) error {
// flush the caches
err := exe.stateCache.Flush(ws, exe.state)
if err != nil {
return err
}
err = exe.nameRegCache.Flush(ws, exe.state)
if err != nil {
return err
}
err = exe.proposalRegCache.Flush(ws, exe.state)
if err != nil {
return err
}
err = exe.validatorCache.Flush(ws, exe.state)
if err != nil {
return err
}
err = ws.AddBlock(blockExecution)
if err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
expectedHeight := HeightAtVersion(version)
if expectedHeight != height {
return nil, fmt.Errorf("expected height at state tree version %d is %d but actual height is %d",
version, expectedHeight, height)
}
// Now state is fully committed publish events (this should be the last thing we do)
exe.publishBlock(blockExecution)
return hash, nil
} | go | func (exe *executor) Commit(header *abciTypes.Header) (stateHash []byte, err error) {
// The write lock to the executor is controlled by the caller (e.g. abci.App) so we do not acquire it here to avoid
// deadlock
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("recovered from panic in executor.Commit(): %v\n%s", r, debug.Stack())
}
}()
// Capture height
height := exe.block.Height
exe.logger.InfoMsg("Executor committing", "height", exe.block.Height)
// Form BlockExecution for this block from TxExecutions and Tendermint block header
blockExecution, err := exe.finaliseBlockExecution(header)
if err != nil {
return nil, err
}
// First commit the app state, this app hash will not get checkpointed until the next block when we are sure
// that nothing in the downstream commit process could have failed. At worst we go back one block.
hash, version, err := exe.state.Update(func(ws state.Updatable) error {
// flush the caches
err := exe.stateCache.Flush(ws, exe.state)
if err != nil {
return err
}
err = exe.nameRegCache.Flush(ws, exe.state)
if err != nil {
return err
}
err = exe.proposalRegCache.Flush(ws, exe.state)
if err != nil {
return err
}
err = exe.validatorCache.Flush(ws, exe.state)
if err != nil {
return err
}
err = ws.AddBlock(blockExecution)
if err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
expectedHeight := HeightAtVersion(version)
if expectedHeight != height {
return nil, fmt.Errorf("expected height at state tree version %d is %d but actual height is %d",
version, expectedHeight, height)
}
// Now state is fully committed publish events (this should be the last thing we do)
exe.publishBlock(blockExecution)
return hash, nil
} | [
"func",
"(",
"exe",
"*",
"executor",
")",
"Commit",
"(",
"header",
"*",
"abciTypes",
".",
"Header",
")",
"(",
"stateHash",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"// The write lock to the executor is controlled by the caller (e.g. abci.App) so we do not acquire it here to avoid",
"// deadlock",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"r",
",",
"debug",
".",
"Stack",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"// Capture height",
"height",
":=",
"exe",
".",
"block",
".",
"Height",
"\n",
"exe",
".",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"exe",
".",
"block",
".",
"Height",
")",
"\n",
"// Form BlockExecution for this block from TxExecutions and Tendermint block header",
"blockExecution",
",",
"err",
":=",
"exe",
".",
"finaliseBlockExecution",
"(",
"header",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// First commit the app state, this app hash will not get checkpointed until the next block when we are sure",
"// that nothing in the downstream commit process could have failed. At worst we go back one block.",
"hash",
",",
"version",
",",
"err",
":=",
"exe",
".",
"state",
".",
"Update",
"(",
"func",
"(",
"ws",
"state",
".",
"Updatable",
")",
"error",
"{",
"// flush the caches",
"err",
":=",
"exe",
".",
"stateCache",
".",
"Flush",
"(",
"ws",
",",
"exe",
".",
"state",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"exe",
".",
"nameRegCache",
".",
"Flush",
"(",
"ws",
",",
"exe",
".",
"state",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"exe",
".",
"proposalRegCache",
".",
"Flush",
"(",
"ws",
",",
"exe",
".",
"state",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"exe",
".",
"validatorCache",
".",
"Flush",
"(",
"ws",
",",
"exe",
".",
"state",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"ws",
".",
"AddBlock",
"(",
"blockExecution",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"expectedHeight",
":=",
"HeightAtVersion",
"(",
"version",
")",
"\n",
"if",
"expectedHeight",
"!=",
"height",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"version",
",",
"expectedHeight",
",",
"height",
")",
"\n",
"}",
"\n",
"// Now state is fully committed publish events (this should be the last thing we do)",
"exe",
".",
"publishBlock",
"(",
"blockExecution",
")",
"\n",
"return",
"hash",
",",
"nil",
"\n",
"}"
] | // Commit the current state - optionally pass in the tendermint ABCI header for that to be included with the BeginBlock
// StreamEvent | [
"Commit",
"the",
"current",
"state",
"-",
"optionally",
"pass",
"in",
"the",
"tendermint",
"ABCI",
"header",
"for",
"that",
"to",
"be",
"included",
"with",
"the",
"BeginBlock",
"StreamEvent"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/execution.go#L301-L354 | train |
hyperledger/burrow | execution/execution.go | updateSignatories | func (exe *executor) updateSignatories(txEnv *txs.Envelope) error {
for _, sig := range txEnv.Signatories {
// pointer dereferences are safe since txEnv.Validate() is run by txEnv.Verify() above which checks they are
// non-nil
acc, err := exe.stateCache.GetAccount(*sig.Address)
if err != nil {
return fmt.Errorf("error getting account on which to set public key: %v", *sig.Address)
}
// Important that verify has been run against signatories at this point
if sig.PublicKey.GetAddress() != acc.Address {
return fmt.Errorf("unexpected mismatch between address %v and supplied public key %v",
acc.Address, sig.PublicKey)
}
acc.PublicKey = *sig.PublicKey
exe.logger.TraceMsg("Incrementing sequence number Tx signatory/input",
"height", exe.block.Height,
"tag", "sequence",
"account", acc.Address,
"old_sequence", acc.Sequence,
"new_sequence", acc.Sequence+1)
acc.Sequence++
err = exe.stateCache.UpdateAccount(acc)
if err != nil {
return fmt.Errorf("error updating account after setting public key: %v", err)
}
}
return nil
} | go | func (exe *executor) updateSignatories(txEnv *txs.Envelope) error {
for _, sig := range txEnv.Signatories {
// pointer dereferences are safe since txEnv.Validate() is run by txEnv.Verify() above which checks they are
// non-nil
acc, err := exe.stateCache.GetAccount(*sig.Address)
if err != nil {
return fmt.Errorf("error getting account on which to set public key: %v", *sig.Address)
}
// Important that verify has been run against signatories at this point
if sig.PublicKey.GetAddress() != acc.Address {
return fmt.Errorf("unexpected mismatch between address %v and supplied public key %v",
acc.Address, sig.PublicKey)
}
acc.PublicKey = *sig.PublicKey
exe.logger.TraceMsg("Incrementing sequence number Tx signatory/input",
"height", exe.block.Height,
"tag", "sequence",
"account", acc.Address,
"old_sequence", acc.Sequence,
"new_sequence", acc.Sequence+1)
acc.Sequence++
err = exe.stateCache.UpdateAccount(acc)
if err != nil {
return fmt.Errorf("error updating account after setting public key: %v", err)
}
}
return nil
} | [
"func",
"(",
"exe",
"*",
"executor",
")",
"updateSignatories",
"(",
"txEnv",
"*",
"txs",
".",
"Envelope",
")",
"error",
"{",
"for",
"_",
",",
"sig",
":=",
"range",
"txEnv",
".",
"Signatories",
"{",
"// pointer dereferences are safe since txEnv.Validate() is run by txEnv.Verify() above which checks they are",
"// non-nil",
"acc",
",",
"err",
":=",
"exe",
".",
"stateCache",
".",
"GetAccount",
"(",
"*",
"sig",
".",
"Address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"*",
"sig",
".",
"Address",
")",
"\n",
"}",
"\n",
"// Important that verify has been run against signatories at this point",
"if",
"sig",
".",
"PublicKey",
".",
"GetAddress",
"(",
")",
"!=",
"acc",
".",
"Address",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"acc",
".",
"Address",
",",
"sig",
".",
"PublicKey",
")",
"\n",
"}",
"\n",
"acc",
".",
"PublicKey",
"=",
"*",
"sig",
".",
"PublicKey",
"\n\n",
"exe",
".",
"logger",
".",
"TraceMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"exe",
".",
"block",
".",
"Height",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"acc",
".",
"Address",
",",
"\"",
"\"",
",",
"acc",
".",
"Sequence",
",",
"\"",
"\"",
",",
"acc",
".",
"Sequence",
"+",
"1",
")",
"\n",
"acc",
".",
"Sequence",
"++",
"\n",
"err",
"=",
"exe",
".",
"stateCache",
".",
"UpdateAccount",
"(",
"acc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Capture public keys and update sequence numbers | [
"Capture",
"public",
"keys",
"and",
"update",
"sequence",
"numbers"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/execution.go#L405-L433 | train |
hyperledger/burrow | crypto/tendermint.go | ABCIPubKey | func (p PublicKey) ABCIPubKey() abci.PubKey {
return abci.PubKey{
Type: p.CurveType.ABCIType(),
Data: p.PublicKey,
}
} | go | func (p PublicKey) ABCIPubKey() abci.PubKey {
return abci.PubKey{
Type: p.CurveType.ABCIType(),
Data: p.PublicKey,
}
} | [
"func",
"(",
"p",
"PublicKey",
")",
"ABCIPubKey",
"(",
")",
"abci",
".",
"PubKey",
"{",
"return",
"abci",
".",
"PubKey",
"{",
"Type",
":",
"p",
".",
"CurveType",
".",
"ABCIType",
"(",
")",
",",
"Data",
":",
"p",
".",
"PublicKey",
",",
"}",
"\n",
"}"
] | // PublicKey extensions
// Return the ABCI PubKey. See Tendermint protobuf.go for the go-crypto conversion this is based on | [
"PublicKey",
"extensions",
"Return",
"the",
"ABCI",
"PubKey",
".",
"See",
"Tendermint",
"protobuf",
".",
"go",
"for",
"the",
"go",
"-",
"crypto",
"conversion",
"this",
"is",
"based",
"on"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/crypto/tendermint.go#L42-L47 | train |
hyperledger/burrow | vent/sqlsol/spec_loader.go | SpecLoader | func SpecLoader(specFileOrDirs []string, createBlkTxTables bool) (*Projection, error) {
var projection *Projection
var err error
if len(specFileOrDirs) == 0 {
return nil, fmt.Errorf("please provide a spec file or directory")
}
projection, err = NewProjectionFromFolder(specFileOrDirs...)
if err != nil {
return nil, fmt.Errorf("error parsing spec: %v", err)
}
if createBlkTxTables {
// add block & tx to tables definition
blkTxTables := getBlockTxTablesDefinition()
for k, v := range blkTxTables {
projection.Tables[k] = v
}
}
return projection, nil
} | go | func SpecLoader(specFileOrDirs []string, createBlkTxTables bool) (*Projection, error) {
var projection *Projection
var err error
if len(specFileOrDirs) == 0 {
return nil, fmt.Errorf("please provide a spec file or directory")
}
projection, err = NewProjectionFromFolder(specFileOrDirs...)
if err != nil {
return nil, fmt.Errorf("error parsing spec: %v", err)
}
if createBlkTxTables {
// add block & tx to tables definition
blkTxTables := getBlockTxTablesDefinition()
for k, v := range blkTxTables {
projection.Tables[k] = v
}
}
return projection, nil
} | [
"func",
"SpecLoader",
"(",
"specFileOrDirs",
"[",
"]",
"string",
",",
"createBlkTxTables",
"bool",
")",
"(",
"*",
"Projection",
",",
"error",
")",
"{",
"var",
"projection",
"*",
"Projection",
"\n",
"var",
"err",
"error",
"\n\n",
"if",
"len",
"(",
"specFileOrDirs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"projection",
",",
"err",
"=",
"NewProjectionFromFolder",
"(",
"specFileOrDirs",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"createBlkTxTables",
"{",
"// add block & tx to tables definition",
"blkTxTables",
":=",
"getBlockTxTablesDefinition",
"(",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"blkTxTables",
"{",
"projection",
".",
"Tables",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"return",
"projection",
",",
"nil",
"\n",
"}"
] | // SpecLoader loads spec files and parses them | [
"SpecLoader",
"loads",
"spec",
"files",
"and",
"parses",
"them"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqlsol/spec_loader.go#L11-L35 | train |
hyperledger/burrow | vent/sqlsol/spec_loader.go | getBlockTxTablesDefinition | func getBlockTxTablesDefinition() types.EventTables {
return types.EventTables{
types.SQLBlockTableName: &types.SQLTable{
Name: types.SQLBlockTableName,
Columns: []*types.SQLTableColumn{
{
Name: types.SQLColumnLabelHeight,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: true,
},
{
Name: types.SQLColumnLabelBlockHeader,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
},
},
types.SQLTxTableName: &types.SQLTable{
Name: types.SQLTxTableName,
Columns: []*types.SQLTableColumn{
// transaction table
{
Name: types.SQLColumnLabelHeight,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: true,
},
{
Name: types.SQLColumnLabelTxHash,
Type: types.SQLColumnTypeVarchar,
Length: txs.HashLengthHex,
Primary: true,
},
{
Name: types.SQLColumnLabelIndex,
Type: types.SQLColumnTypeNumeric,
Length: 0,
Primary: false,
},
{
Name: types.SQLColumnLabelTxType,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: false,
},
{
Name: types.SQLColumnLabelEnvelope,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelEvents,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelResult,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelReceipt,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelException,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
},
},
}
} | go | func getBlockTxTablesDefinition() types.EventTables {
return types.EventTables{
types.SQLBlockTableName: &types.SQLTable{
Name: types.SQLBlockTableName,
Columns: []*types.SQLTableColumn{
{
Name: types.SQLColumnLabelHeight,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: true,
},
{
Name: types.SQLColumnLabelBlockHeader,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
},
},
types.SQLTxTableName: &types.SQLTable{
Name: types.SQLTxTableName,
Columns: []*types.SQLTableColumn{
// transaction table
{
Name: types.SQLColumnLabelHeight,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: true,
},
{
Name: types.SQLColumnLabelTxHash,
Type: types.SQLColumnTypeVarchar,
Length: txs.HashLengthHex,
Primary: true,
},
{
Name: types.SQLColumnLabelIndex,
Type: types.SQLColumnTypeNumeric,
Length: 0,
Primary: false,
},
{
Name: types.SQLColumnLabelTxType,
Type: types.SQLColumnTypeVarchar,
Length: 100,
Primary: false,
},
{
Name: types.SQLColumnLabelEnvelope,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelEvents,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelResult,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelReceipt,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
{
Name: types.SQLColumnLabelException,
Type: types.SQLColumnTypeJSON,
Primary: false,
},
},
},
}
} | [
"func",
"getBlockTxTablesDefinition",
"(",
")",
"types",
".",
"EventTables",
"{",
"return",
"types",
".",
"EventTables",
"{",
"types",
".",
"SQLBlockTableName",
":",
"&",
"types",
".",
"SQLTable",
"{",
"Name",
":",
"types",
".",
"SQLBlockTableName",
",",
"Columns",
":",
"[",
"]",
"*",
"types",
".",
"SQLTableColumn",
"{",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelHeight",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeVarchar",
",",
"Length",
":",
"100",
",",
"Primary",
":",
"true",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelBlockHeader",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeJSON",
",",
"Primary",
":",
"false",
",",
"}",
",",
"}",
",",
"}",
",",
"types",
".",
"SQLTxTableName",
":",
"&",
"types",
".",
"SQLTable",
"{",
"Name",
":",
"types",
".",
"SQLTxTableName",
",",
"Columns",
":",
"[",
"]",
"*",
"types",
".",
"SQLTableColumn",
"{",
"// transaction table",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelHeight",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeVarchar",
",",
"Length",
":",
"100",
",",
"Primary",
":",
"true",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelTxHash",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeVarchar",
",",
"Length",
":",
"txs",
".",
"HashLengthHex",
",",
"Primary",
":",
"true",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelIndex",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeNumeric",
",",
"Length",
":",
"0",
",",
"Primary",
":",
"false",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelTxType",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeVarchar",
",",
"Length",
":",
"100",
",",
"Primary",
":",
"false",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelEnvelope",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeJSON",
",",
"Primary",
":",
"false",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelEvents",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeJSON",
",",
"Primary",
":",
"false",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelResult",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeJSON",
",",
"Primary",
":",
"false",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelReceipt",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeJSON",
",",
"Primary",
":",
"false",
",",
"}",
",",
"{",
"Name",
":",
"types",
".",
"SQLColumnLabelException",
",",
"Type",
":",
"types",
".",
"SQLColumnTypeJSON",
",",
"Primary",
":",
"false",
",",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] | // getBlockTxTablesDefinition returns block & transaction structures | [
"getBlockTxTablesDefinition",
"returns",
"block",
"&",
"transaction",
"structures"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqlsol/spec_loader.go#L38-L113 | train |
hyperledger/burrow | execution/evm/abi/core.go | DecodeFunctionReturnFromFile | func DecodeFunctionReturnFromFile(abiLocation, binPath, funcName string, resultRaw []byte, logger *logging.Logger) ([]*Variable, error) {
abiSpecBytes, err := readAbi(binPath, abiLocation, logger)
if err != nil {
return nil, err
}
logger.TraceMsg("ABI Specification (Decode)", "spec", abiSpecBytes)
// Unpack the result
return DecodeFunctionReturn(abiSpecBytes, funcName, resultRaw)
} | go | func DecodeFunctionReturnFromFile(abiLocation, binPath, funcName string, resultRaw []byte, logger *logging.Logger) ([]*Variable, error) {
abiSpecBytes, err := readAbi(binPath, abiLocation, logger)
if err != nil {
return nil, err
}
logger.TraceMsg("ABI Specification (Decode)", "spec", abiSpecBytes)
// Unpack the result
return DecodeFunctionReturn(abiSpecBytes, funcName, resultRaw)
} | [
"func",
"DecodeFunctionReturnFromFile",
"(",
"abiLocation",
",",
"binPath",
",",
"funcName",
"string",
",",
"resultRaw",
"[",
"]",
"byte",
",",
"logger",
"*",
"logging",
".",
"Logger",
")",
"(",
"[",
"]",
"*",
"Variable",
",",
"error",
")",
"{",
"abiSpecBytes",
",",
"err",
":=",
"readAbi",
"(",
"binPath",
",",
"abiLocation",
",",
"logger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"logger",
".",
"TraceMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"abiSpecBytes",
")",
"\n\n",
"// Unpack the result",
"return",
"DecodeFunctionReturn",
"(",
"abiSpecBytes",
",",
"funcName",
",",
"resultRaw",
")",
"\n",
"}"
] | // DecodeFunctionReturnFromFile ABI decodes the return value from a contract function call. | [
"DecodeFunctionReturnFromFile",
"ABI",
"decodes",
"the",
"return",
"value",
"from",
"a",
"contract",
"function",
"call",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/evm/abi/core.go#L88-L97 | train |
hyperledger/burrow | execution/evm/abi/core.go | LoadPath | func LoadPath(abiFileOrDirs ...string) (*AbiSpec, error) {
if len(abiFileOrDirs) == 0 {
return &AbiSpec{}, fmt.Errorf("no ABI file or directory provided")
}
specs := make([]*AbiSpec, 0)
for _, dir := range abiFileOrDirs {
err := filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("error returned while walking abiDir '%s': %v", dir, err)
}
ext := filepath.Ext(path)
if fi.IsDir() || !(ext == ".bin" || ext == ".abi") {
return nil
}
if err == nil {
abiSpc, err := ReadAbiSpecFile(path)
if err != nil {
return errors.Wrap(err, "Error parsing abi file "+path)
}
specs = append(specs, abiSpc)
}
return nil
})
if err != nil {
return &AbiSpec{}, err
}
}
return MergeAbiSpec(specs), nil
} | go | func LoadPath(abiFileOrDirs ...string) (*AbiSpec, error) {
if len(abiFileOrDirs) == 0 {
return &AbiSpec{}, fmt.Errorf("no ABI file or directory provided")
}
specs := make([]*AbiSpec, 0)
for _, dir := range abiFileOrDirs {
err := filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("error returned while walking abiDir '%s': %v", dir, err)
}
ext := filepath.Ext(path)
if fi.IsDir() || !(ext == ".bin" || ext == ".abi") {
return nil
}
if err == nil {
abiSpc, err := ReadAbiSpecFile(path)
if err != nil {
return errors.Wrap(err, "Error parsing abi file "+path)
}
specs = append(specs, abiSpc)
}
return nil
})
if err != nil {
return &AbiSpec{}, err
}
}
return MergeAbiSpec(specs), nil
} | [
"func",
"LoadPath",
"(",
"abiFileOrDirs",
"...",
"string",
")",
"(",
"*",
"AbiSpec",
",",
"error",
")",
"{",
"if",
"len",
"(",
"abiFileOrDirs",
")",
"==",
"0",
"{",
"return",
"&",
"AbiSpec",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"specs",
":=",
"make",
"(",
"[",
"]",
"*",
"AbiSpec",
",",
"0",
")",
"\n\n",
"for",
"_",
",",
"dir",
":=",
"range",
"abiFileOrDirs",
"{",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"dir",
",",
"func",
"(",
"path",
"string",
",",
"fi",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
",",
"err",
")",
"\n",
"}",
"\n",
"ext",
":=",
"filepath",
".",
"Ext",
"(",
"path",
")",
"\n",
"if",
"fi",
".",
"IsDir",
"(",
")",
"||",
"!",
"(",
"ext",
"==",
"\"",
"\"",
"||",
"ext",
"==",
"\"",
"\"",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"abiSpc",
",",
"err",
":=",
"ReadAbiSpecFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
"+",
"path",
")",
"\n",
"}",
"\n",
"specs",
"=",
"append",
"(",
"specs",
",",
"abiSpc",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"AbiSpec",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"MergeAbiSpec",
"(",
"specs",
")",
",",
"nil",
"\n",
"}"
] | // LoadPath loads one abi file or finds all files in a directory | [
"LoadPath",
"loads",
"one",
"abi",
"file",
"or",
"finds",
"all",
"files",
"in",
"a",
"directory"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/evm/abi/core.go#L165-L195 | train |
hyperledger/burrow | consensus/tendermint/node_view.go | MempoolTransactions | func (nv *NodeView) MempoolTransactions(maxTxs int) ([]*txs.Envelope, error) {
var transactions []*txs.Envelope
for _, txBytes := range nv.tmNode.MempoolReactor().Mempool.ReapMaxTxs(maxTxs) {
txEnv, err := nv.txDecoder.DecodeTx(txBytes)
if err != nil {
return nil, err
}
transactions = append(transactions, txEnv)
}
return transactions, nil
} | go | func (nv *NodeView) MempoolTransactions(maxTxs int) ([]*txs.Envelope, error) {
var transactions []*txs.Envelope
for _, txBytes := range nv.tmNode.MempoolReactor().Mempool.ReapMaxTxs(maxTxs) {
txEnv, err := nv.txDecoder.DecodeTx(txBytes)
if err != nil {
return nil, err
}
transactions = append(transactions, txEnv)
}
return transactions, nil
} | [
"func",
"(",
"nv",
"*",
"NodeView",
")",
"MempoolTransactions",
"(",
"maxTxs",
"int",
")",
"(",
"[",
"]",
"*",
"txs",
".",
"Envelope",
",",
"error",
")",
"{",
"var",
"transactions",
"[",
"]",
"*",
"txs",
".",
"Envelope",
"\n",
"for",
"_",
",",
"txBytes",
":=",
"range",
"nv",
".",
"tmNode",
".",
"MempoolReactor",
"(",
")",
".",
"Mempool",
".",
"ReapMaxTxs",
"(",
"maxTxs",
")",
"{",
"txEnv",
",",
"err",
":=",
"nv",
".",
"txDecoder",
".",
"DecodeTx",
"(",
"txBytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"transactions",
"=",
"append",
"(",
"transactions",
",",
"txEnv",
")",
"\n",
"}",
"\n",
"return",
"transactions",
",",
"nil",
"\n",
"}"
] | // Pass -1 to get all available transactions | [
"Pass",
"-",
"1",
"to",
"get",
"all",
"available",
"transactions"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/consensus/tendermint/node_view.go#L85-L95 | train |
hyperledger/burrow | genesis/spec/presets.go | FullAccount | func FullAccount(name string) GenesisSpec {
// Inheriting from the arbitrary figures used by monax tool for now
amount := uint64(99999999999999)
Power := uint64(9999999999)
return GenesisSpec{
Accounts: []TemplateAccount{{
Name: name,
Amounts: balance.New().Native(amount).Power(Power),
Permissions: []string{permission.AllString},
},
},
}
} | go | func FullAccount(name string) GenesisSpec {
// Inheriting from the arbitrary figures used by monax tool for now
amount := uint64(99999999999999)
Power := uint64(9999999999)
return GenesisSpec{
Accounts: []TemplateAccount{{
Name: name,
Amounts: balance.New().Native(amount).Power(Power),
Permissions: []string{permission.AllString},
},
},
}
} | [
"func",
"FullAccount",
"(",
"name",
"string",
")",
"GenesisSpec",
"{",
"// Inheriting from the arbitrary figures used by monax tool for now",
"amount",
":=",
"uint64",
"(",
"99999999999999",
")",
"\n",
"Power",
":=",
"uint64",
"(",
"9999999999",
")",
"\n",
"return",
"GenesisSpec",
"{",
"Accounts",
":",
"[",
"]",
"TemplateAccount",
"{",
"{",
"Name",
":",
"name",
",",
"Amounts",
":",
"balance",
".",
"New",
"(",
")",
".",
"Native",
"(",
"amount",
")",
".",
"Power",
"(",
"Power",
")",
",",
"Permissions",
":",
"[",
"]",
"string",
"{",
"permission",
".",
"AllString",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] | // Files here can be used as starting points for building various 'chain types' but are otherwise
// a fairly unprincipled collection of GenesisSpecs that we find useful in testing and development | [
"Files",
"here",
"can",
"be",
"used",
"as",
"starting",
"points",
"for",
"building",
"various",
"chain",
"types",
"but",
"are",
"otherwise",
"a",
"fairly",
"unprincipled",
"collection",
"of",
"GenesisSpecs",
"that",
"we",
"find",
"useful",
"in",
"testing",
"and",
"development"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/genesis/spec/presets.go#L13-L25 | train |
hyperledger/burrow | genesis/spec/presets.go | mergeAccounts | func mergeAccounts(bases, overrides []TemplateAccount) []TemplateAccount {
indexOfBase := make(map[string]int, len(bases))
for i, ta := range bases {
if ta.Name != "" {
indexOfBase[ta.Name] = i
}
}
for _, override := range overrides {
if override.Name != "" {
if i, ok := indexOfBase[override.Name]; ok {
bases[i] = mergeAccount(bases[i], override)
continue
}
}
bases = append(bases, override)
}
return bases
} | go | func mergeAccounts(bases, overrides []TemplateAccount) []TemplateAccount {
indexOfBase := make(map[string]int, len(bases))
for i, ta := range bases {
if ta.Name != "" {
indexOfBase[ta.Name] = i
}
}
for _, override := range overrides {
if override.Name != "" {
if i, ok := indexOfBase[override.Name]; ok {
bases[i] = mergeAccount(bases[i], override)
continue
}
}
bases = append(bases, override)
}
return bases
} | [
"func",
"mergeAccounts",
"(",
"bases",
",",
"overrides",
"[",
"]",
"TemplateAccount",
")",
"[",
"]",
"TemplateAccount",
"{",
"indexOfBase",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"len",
"(",
"bases",
")",
")",
"\n",
"for",
"i",
",",
"ta",
":=",
"range",
"bases",
"{",
"if",
"ta",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"indexOfBase",
"[",
"ta",
".",
"Name",
"]",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"override",
":=",
"range",
"overrides",
"{",
"if",
"override",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"if",
"i",
",",
"ok",
":=",
"indexOfBase",
"[",
"override",
".",
"Name",
"]",
";",
"ok",
"{",
"bases",
"[",
"i",
"]",
"=",
"mergeAccount",
"(",
"bases",
"[",
"i",
"]",
",",
"override",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"bases",
"=",
"append",
"(",
"bases",
",",
"override",
")",
"\n",
"}",
"\n",
"return",
"bases",
"\n",
"}"
] | // Merge accounts by adding to base list or updating previously named account | [
"Merge",
"accounts",
"by",
"adding",
"to",
"base",
"list",
"or",
"updating",
"previously",
"named",
"account"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/genesis/spec/presets.go#L117-L135 | train |
hyperledger/burrow | keys/core.go | getNameAddr | func getNameAddr(keysDir, name, addr string) (string, error) {
if name == "" && addr == "" {
return "", fmt.Errorf("at least one of name or addr must be provided")
}
// name takes precedent if both are given
var err error
if name != "" {
addr, err = coreNameGet(keysDir, name)
if err != nil {
return "", err
}
}
return strings.ToUpper(addr), nil
} | go | func getNameAddr(keysDir, name, addr string) (string, error) {
if name == "" && addr == "" {
return "", fmt.Errorf("at least one of name or addr must be provided")
}
// name takes precedent if both are given
var err error
if name != "" {
addr, err = coreNameGet(keysDir, name)
if err != nil {
return "", err
}
}
return strings.ToUpper(addr), nil
} | [
"func",
"getNameAddr",
"(",
"keysDir",
",",
"name",
",",
"addr",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"name",
"==",
"\"",
"\"",
"&&",
"addr",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// name takes precedent if both are given",
"var",
"err",
"error",
"\n",
"if",
"name",
"!=",
"\"",
"\"",
"{",
"addr",
",",
"err",
"=",
"coreNameGet",
"(",
"keysDir",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"strings",
".",
"ToUpper",
"(",
"addr",
")",
",",
"nil",
"\n",
"}"
] | // return addr from name or addr | [
"return",
"addr",
"from",
"name",
"or",
"addr"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/keys/core.go#L135-L149 | train |
hyperledger/burrow | deploy/run_deploy.go | RunPlaybooks | func RunPlaybooks(args *def.DeployArgs, playbooks []string, logger *logging.Logger) (int, error) {
// if bin and abi paths are default cli settings then use the
// stated defaults of do.Path plus bin|abi
if args.Path == "" {
var err error
args.Path, err = os.Getwd()
if err != nil {
panic(fmt.Sprintf("failed to get current directory %v", err))
}
}
// useful for debugging
logger.InfoMsg("Using chain", "Chain", args.Chain, "Signer", args.KeysService)
workQ := make(chan playbookWork, 100)
resultQ := make(chan playbookResult, 100)
for i := 1; i <= args.Jobs; i++ {
go worker(workQ, resultQ, args, logger)
}
for i, playbook := range playbooks {
workQ <- playbookWork{jobNo: i, playbook: playbook}
}
close(workQ)
// work queued, now read the results
results := make([]*playbookResult, len(playbooks))
printed := 0
failures := 0
successes := 0
for range playbooks {
jobResult := <-resultQ
results[jobResult.jobNo] = &jobResult
for results[printed] != nil {
res := results[printed]
os.Stderr.Write(res.log.Bytes())
if res.err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v", res.err)
}
res.log.Truncate(0)
if jobResult.err != nil {
failures++
} else {
successes++
}
printed++
if printed >= len(playbooks) {
break
}
}
}
close(resultQ)
if successes > 0 {
logger.InfoMsg("JOBS THAT SUCCEEEDED", "count", successes)
for i, playbook := range playbooks {
res := results[i]
if res.err != nil {
continue
}
logger.InfoMsg("Playbook result",
"jobNo", i,
"file", playbook,
"time", res.duration.String())
}
}
if failures > 0 {
logger.InfoMsg("JOBS THAT FAILED", "count", failures)
for i, playbook := range playbooks {
res := results[i]
if res.err == nil {
continue
}
logger.InfoMsg("Playbook result",
"jobNo", i,
"file", playbook,
"error", res.err,
"time", res.duration.String())
}
}
return failures, nil
} | go | func RunPlaybooks(args *def.DeployArgs, playbooks []string, logger *logging.Logger) (int, error) {
// if bin and abi paths are default cli settings then use the
// stated defaults of do.Path plus bin|abi
if args.Path == "" {
var err error
args.Path, err = os.Getwd()
if err != nil {
panic(fmt.Sprintf("failed to get current directory %v", err))
}
}
// useful for debugging
logger.InfoMsg("Using chain", "Chain", args.Chain, "Signer", args.KeysService)
workQ := make(chan playbookWork, 100)
resultQ := make(chan playbookResult, 100)
for i := 1; i <= args.Jobs; i++ {
go worker(workQ, resultQ, args, logger)
}
for i, playbook := range playbooks {
workQ <- playbookWork{jobNo: i, playbook: playbook}
}
close(workQ)
// work queued, now read the results
results := make([]*playbookResult, len(playbooks))
printed := 0
failures := 0
successes := 0
for range playbooks {
jobResult := <-resultQ
results[jobResult.jobNo] = &jobResult
for results[printed] != nil {
res := results[printed]
os.Stderr.Write(res.log.Bytes())
if res.err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v", res.err)
}
res.log.Truncate(0)
if jobResult.err != nil {
failures++
} else {
successes++
}
printed++
if printed >= len(playbooks) {
break
}
}
}
close(resultQ)
if successes > 0 {
logger.InfoMsg("JOBS THAT SUCCEEEDED", "count", successes)
for i, playbook := range playbooks {
res := results[i]
if res.err != nil {
continue
}
logger.InfoMsg("Playbook result",
"jobNo", i,
"file", playbook,
"time", res.duration.String())
}
}
if failures > 0 {
logger.InfoMsg("JOBS THAT FAILED", "count", failures)
for i, playbook := range playbooks {
res := results[i]
if res.err == nil {
continue
}
logger.InfoMsg("Playbook result",
"jobNo", i,
"file", playbook,
"error", res.err,
"time", res.duration.String())
}
}
return failures, nil
} | [
"func",
"RunPlaybooks",
"(",
"args",
"*",
"def",
".",
"DeployArgs",
",",
"playbooks",
"[",
"]",
"string",
",",
"logger",
"*",
"logging",
".",
"Logger",
")",
"(",
"int",
",",
"error",
")",
"{",
"// if bin and abi paths are default cli settings then use the",
"// stated defaults of do.Path plus bin|abi",
"if",
"args",
".",
"Path",
"==",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"args",
".",
"Path",
",",
"err",
"=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// useful for debugging",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"args",
".",
"Chain",
",",
"\"",
"\"",
",",
"args",
".",
"KeysService",
")",
"\n\n",
"workQ",
":=",
"make",
"(",
"chan",
"playbookWork",
",",
"100",
")",
"\n",
"resultQ",
":=",
"make",
"(",
"chan",
"playbookResult",
",",
"100",
")",
"\n\n",
"for",
"i",
":=",
"1",
";",
"i",
"<=",
"args",
".",
"Jobs",
";",
"i",
"++",
"{",
"go",
"worker",
"(",
"workQ",
",",
"resultQ",
",",
"args",
",",
"logger",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"playbook",
":=",
"range",
"playbooks",
"{",
"workQ",
"<-",
"playbookWork",
"{",
"jobNo",
":",
"i",
",",
"playbook",
":",
"playbook",
"}",
"\n",
"}",
"\n",
"close",
"(",
"workQ",
")",
"\n\n",
"// work queued, now read the results",
"results",
":=",
"make",
"(",
"[",
"]",
"*",
"playbookResult",
",",
"len",
"(",
"playbooks",
")",
")",
"\n",
"printed",
":=",
"0",
"\n",
"failures",
":=",
"0",
"\n",
"successes",
":=",
"0",
"\n\n",
"for",
"range",
"playbooks",
"{",
"jobResult",
":=",
"<-",
"resultQ",
"\n",
"results",
"[",
"jobResult",
".",
"jobNo",
"]",
"=",
"&",
"jobResult",
"\n",
"for",
"results",
"[",
"printed",
"]",
"!=",
"nil",
"{",
"res",
":=",
"results",
"[",
"printed",
"]",
"\n",
"os",
".",
"Stderr",
".",
"Write",
"(",
"res",
".",
"log",
".",
"Bytes",
"(",
")",
")",
"\n",
"if",
"res",
".",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"res",
".",
"err",
")",
"\n",
"}",
"\n",
"res",
".",
"log",
".",
"Truncate",
"(",
"0",
")",
"\n",
"if",
"jobResult",
".",
"err",
"!=",
"nil",
"{",
"failures",
"++",
"\n",
"}",
"else",
"{",
"successes",
"++",
"\n",
"}",
"\n",
"printed",
"++",
"\n",
"if",
"printed",
">=",
"len",
"(",
"playbooks",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"close",
"(",
"resultQ",
")",
"\n\n",
"if",
"successes",
">",
"0",
"{",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"successes",
")",
"\n",
"for",
"i",
",",
"playbook",
":=",
"range",
"playbooks",
"{",
"res",
":=",
"results",
"[",
"i",
"]",
"\n",
"if",
"res",
".",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"i",
",",
"\"",
"\"",
",",
"playbook",
",",
"\"",
"\"",
",",
"res",
".",
"duration",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"failures",
">",
"0",
"{",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"failures",
")",
"\n",
"for",
"i",
",",
"playbook",
":=",
"range",
"playbooks",
"{",
"res",
":=",
"results",
"[",
"i",
"]",
"\n",
"if",
"res",
".",
"err",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"i",
",",
"\"",
"\"",
",",
"playbook",
",",
"\"",
"\"",
",",
"res",
".",
"err",
",",
"\"",
"\"",
",",
"res",
".",
"duration",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"failures",
",",
"nil",
"\n",
"}"
] | // RunPlaybooks starts workers, and loads the playbooks in parallel in the workers, and executes them. | [
"RunPlaybooks",
"starts",
"workers",
"and",
"loads",
"the",
"playbooks",
"in",
"parallel",
"in",
"the",
"workers",
"and",
"executes",
"them",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/deploy/run_deploy.go#L82-L167 | train |
hyperledger/burrow | bcm/blockchain.go | LoadOrNewBlockchain | func LoadOrNewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc, logger *logging.Logger) (bool, *Blockchain, error) {
logger = logger.WithScope("LoadOrNewBlockchain")
logger.InfoMsg("Trying to load blockchain state from database",
"database_key", stateKey)
bc, err := loadBlockchain(db)
if err != nil {
return false, nil, fmt.Errorf("error loading blockchain state from database: %v", err)
}
if bc != nil {
dbHash := bc.genesisDoc.Hash()
argHash := genesisDoc.Hash()
if !bytes.Equal(dbHash, argHash) {
return false, nil, fmt.Errorf("GenesisDoc passed to LoadOrNewBlockchain has hash: 0x%X, which does not "+
"match the one found in database: 0x%X, database genesis:\n%v\npassed genesis:\n%v\n",
argHash, dbHash, bc.genesisDoc.JSONString(), genesisDoc.JSONString())
}
return true, bc, nil
}
logger.InfoMsg("No existing blockchain state found in database, making new blockchain")
return false, NewBlockchain(db, genesisDoc), nil
} | go | func LoadOrNewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc, logger *logging.Logger) (bool, *Blockchain, error) {
logger = logger.WithScope("LoadOrNewBlockchain")
logger.InfoMsg("Trying to load blockchain state from database",
"database_key", stateKey)
bc, err := loadBlockchain(db)
if err != nil {
return false, nil, fmt.Errorf("error loading blockchain state from database: %v", err)
}
if bc != nil {
dbHash := bc.genesisDoc.Hash()
argHash := genesisDoc.Hash()
if !bytes.Equal(dbHash, argHash) {
return false, nil, fmt.Errorf("GenesisDoc passed to LoadOrNewBlockchain has hash: 0x%X, which does not "+
"match the one found in database: 0x%X, database genesis:\n%v\npassed genesis:\n%v\n",
argHash, dbHash, bc.genesisDoc.JSONString(), genesisDoc.JSONString())
}
return true, bc, nil
}
logger.InfoMsg("No existing blockchain state found in database, making new blockchain")
return false, NewBlockchain(db, genesisDoc), nil
} | [
"func",
"LoadOrNewBlockchain",
"(",
"db",
"dbm",
".",
"DB",
",",
"genesisDoc",
"*",
"genesis",
".",
"GenesisDoc",
",",
"logger",
"*",
"logging",
".",
"Logger",
")",
"(",
"bool",
",",
"*",
"Blockchain",
",",
"error",
")",
"{",
"logger",
"=",
"logger",
".",
"WithScope",
"(",
"\"",
"\"",
")",
"\n",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"stateKey",
")",
"\n",
"bc",
",",
"err",
":=",
"loadBlockchain",
"(",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"bc",
"!=",
"nil",
"{",
"dbHash",
":=",
"bc",
".",
"genesisDoc",
".",
"Hash",
"(",
")",
"\n",
"argHash",
":=",
"genesisDoc",
".",
"Hash",
"(",
")",
"\n",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"dbHash",
",",
"argHash",
")",
"{",
"return",
"false",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\\n",
"\\n",
"\\n",
"\\n",
"\"",
",",
"argHash",
",",
"dbHash",
",",
"bc",
".",
"genesisDoc",
".",
"JSONString",
"(",
")",
",",
"genesisDoc",
".",
"JSONString",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"true",
",",
"bc",
",",
"nil",
"\n",
"}",
"\n\n",
"logger",
".",
"InfoMsg",
"(",
"\"",
"\"",
")",
"\n",
"return",
"false",
",",
"NewBlockchain",
"(",
"db",
",",
"genesisDoc",
")",
",",
"nil",
"\n",
"}"
] | // LoadOrNewBlockchain returns true if state already exists | [
"LoadOrNewBlockchain",
"returns",
"true",
"if",
"state",
"already",
"exists"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/bcm/blockchain.go#L73-L94 | train |
hyperledger/burrow | bcm/blockchain.go | NewBlockchain | func NewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc) *Blockchain {
bc := &Blockchain{
db: db,
genesisHash: genesisDoc.Hash(),
genesisDoc: *genesisDoc,
chainID: genesisDoc.ChainID(),
lastBlockTime: genesisDoc.GenesisTime,
appHashAfterLastBlock: genesisDoc.Hash(),
}
return bc
} | go | func NewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc) *Blockchain {
bc := &Blockchain{
db: db,
genesisHash: genesisDoc.Hash(),
genesisDoc: *genesisDoc,
chainID: genesisDoc.ChainID(),
lastBlockTime: genesisDoc.GenesisTime,
appHashAfterLastBlock: genesisDoc.Hash(),
}
return bc
} | [
"func",
"NewBlockchain",
"(",
"db",
"dbm",
".",
"DB",
",",
"genesisDoc",
"*",
"genesis",
".",
"GenesisDoc",
")",
"*",
"Blockchain",
"{",
"bc",
":=",
"&",
"Blockchain",
"{",
"db",
":",
"db",
",",
"genesisHash",
":",
"genesisDoc",
".",
"Hash",
"(",
")",
",",
"genesisDoc",
":",
"*",
"genesisDoc",
",",
"chainID",
":",
"genesisDoc",
".",
"ChainID",
"(",
")",
",",
"lastBlockTime",
":",
"genesisDoc",
".",
"GenesisTime",
",",
"appHashAfterLastBlock",
":",
"genesisDoc",
".",
"Hash",
"(",
")",
",",
"}",
"\n",
"return",
"bc",
"\n",
"}"
] | // NewBlockchain returns a pointer to blockchain state initialised from genesis | [
"NewBlockchain",
"returns",
"a",
"pointer",
"to",
"blockchain",
"state",
"initialised",
"from",
"genesis"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/bcm/blockchain.go#L97-L107 | train |
hyperledger/burrow | vent/types/sql_column_type.go | IsNumeric | func (ct SQLColumnType) IsNumeric() bool {
return ct == SQLColumnTypeInt || ct == SQLColumnTypeSerial || ct == SQLColumnTypeNumeric || ct == SQLColumnTypeBigInt
} | go | func (ct SQLColumnType) IsNumeric() bool {
return ct == SQLColumnTypeInt || ct == SQLColumnTypeSerial || ct == SQLColumnTypeNumeric || ct == SQLColumnTypeBigInt
} | [
"func",
"(",
"ct",
"SQLColumnType",
")",
"IsNumeric",
"(",
")",
"bool",
"{",
"return",
"ct",
"==",
"SQLColumnTypeInt",
"||",
"ct",
"==",
"SQLColumnTypeSerial",
"||",
"ct",
"==",
"SQLColumnTypeNumeric",
"||",
"ct",
"==",
"SQLColumnTypeBigInt",
"\n",
"}"
] | // IsNumeric determines if an sqlColumnType is numeric | [
"IsNumeric",
"determines",
"if",
"an",
"sqlColumnType",
"is",
"numeric"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/types/sql_column_type.go#L47-L49 | train |
hyperledger/burrow | permission/util.go | ConvertPermissionsMapAndRolesToAccountPermissions | func ConvertPermissionsMapAndRolesToAccountPermissions(permissions map[string]bool,
roles []string) (*AccountPermissions, error) {
var err error
accountPermissions := &AccountPermissions{}
accountPermissions.Base, err = convertPermissionsMapStringIntToBasePermissions(permissions)
if err != nil {
return nil, err
}
accountPermissions.Roles = roles
return accountPermissions, nil
} | go | func ConvertPermissionsMapAndRolesToAccountPermissions(permissions map[string]bool,
roles []string) (*AccountPermissions, error) {
var err error
accountPermissions := &AccountPermissions{}
accountPermissions.Base, err = convertPermissionsMapStringIntToBasePermissions(permissions)
if err != nil {
return nil, err
}
accountPermissions.Roles = roles
return accountPermissions, nil
} | [
"func",
"ConvertPermissionsMapAndRolesToAccountPermissions",
"(",
"permissions",
"map",
"[",
"string",
"]",
"bool",
",",
"roles",
"[",
"]",
"string",
")",
"(",
"*",
"AccountPermissions",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"accountPermissions",
":=",
"&",
"AccountPermissions",
"{",
"}",
"\n",
"accountPermissions",
".",
"Base",
",",
"err",
"=",
"convertPermissionsMapStringIntToBasePermissions",
"(",
"permissions",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"accountPermissions",
".",
"Roles",
"=",
"roles",
"\n",
"return",
"accountPermissions",
",",
"nil",
"\n",
"}"
] | // ConvertMapStringIntToPermissions converts a map of string-bool pairs and a slice of
// strings for the roles to an AccountPermissions type. If the value in the
// permissions map is true for a particular permission string then the permission
// will be set in the AccountsPermissions. For all unmentioned permissions the
// ZeroBasePermissions is defaulted to. | [
"ConvertMapStringIntToPermissions",
"converts",
"a",
"map",
"of",
"string",
"-",
"bool",
"pairs",
"and",
"a",
"slice",
"of",
"strings",
"for",
"the",
"roles",
"to",
"an",
"AccountPermissions",
"type",
".",
"If",
"the",
"value",
"in",
"the",
"permissions",
"map",
"is",
"true",
"for",
"a",
"particular",
"permission",
"string",
"then",
"the",
"permission",
"will",
"be",
"set",
"in",
"the",
"AccountsPermissions",
".",
"For",
"all",
"unmentioned",
"permissions",
"the",
"ZeroBasePermissions",
"is",
"defaulted",
"to",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/util.go#L26-L36 | train |
hyperledger/burrow | permission/util.go | convertPermissionsMapStringIntToBasePermissions | func convertPermissionsMapStringIntToBasePermissions(permissions map[string]bool) (BasePermissions, error) {
// initialise basePermissions as ZeroBasePermissions
basePermissions := ZeroBasePermissions
for permissionName, value := range permissions {
permissionsFlag, err := PermStringToFlag(permissionName)
if err != nil {
return basePermissions, err
}
// sets the permissions bitflag and the setbit flag for the permission.
basePermissions.Set(permissionsFlag, value)
}
return basePermissions, nil
} | go | func convertPermissionsMapStringIntToBasePermissions(permissions map[string]bool) (BasePermissions, error) {
// initialise basePermissions as ZeroBasePermissions
basePermissions := ZeroBasePermissions
for permissionName, value := range permissions {
permissionsFlag, err := PermStringToFlag(permissionName)
if err != nil {
return basePermissions, err
}
// sets the permissions bitflag and the setbit flag for the permission.
basePermissions.Set(permissionsFlag, value)
}
return basePermissions, nil
} | [
"func",
"convertPermissionsMapStringIntToBasePermissions",
"(",
"permissions",
"map",
"[",
"string",
"]",
"bool",
")",
"(",
"BasePermissions",
",",
"error",
")",
"{",
"// initialise basePermissions as ZeroBasePermissions",
"basePermissions",
":=",
"ZeroBasePermissions",
"\n\n",
"for",
"permissionName",
",",
"value",
":=",
"range",
"permissions",
"{",
"permissionsFlag",
",",
"err",
":=",
"PermStringToFlag",
"(",
"permissionName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"basePermissions",
",",
"err",
"\n",
"}",
"\n",
"// sets the permissions bitflag and the setbit flag for the permission.",
"basePermissions",
".",
"Set",
"(",
"permissionsFlag",
",",
"value",
")",
"\n",
"}",
"\n\n",
"return",
"basePermissions",
",",
"nil",
"\n",
"}"
] | // convertPermissionsMapStringIntToBasePermissions converts a map of string-bool
// pairs to BasePermissions. | [
"convertPermissionsMapStringIntToBasePermissions",
"converts",
"a",
"map",
"of",
"string",
"-",
"bool",
"pairs",
"to",
"BasePermissions",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/util.go#L40-L54 | train |
hyperledger/burrow | permission/util.go | BasePermissionsFromStringList | func BasePermissionsFromStringList(permissions []string) (BasePermissions, error) {
permFlag, err := PermFlagFromStringList(permissions)
if err != nil {
return ZeroBasePermissions, err
}
return BasePermissions{
Perms: permFlag,
SetBit: permFlag,
}, nil
} | go | func BasePermissionsFromStringList(permissions []string) (BasePermissions, error) {
permFlag, err := PermFlagFromStringList(permissions)
if err != nil {
return ZeroBasePermissions, err
}
return BasePermissions{
Perms: permFlag,
SetBit: permFlag,
}, nil
} | [
"func",
"BasePermissionsFromStringList",
"(",
"permissions",
"[",
"]",
"string",
")",
"(",
"BasePermissions",
",",
"error",
")",
"{",
"permFlag",
",",
"err",
":=",
"PermFlagFromStringList",
"(",
"permissions",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ZeroBasePermissions",
",",
"err",
"\n",
"}",
"\n",
"return",
"BasePermissions",
"{",
"Perms",
":",
"permFlag",
",",
"SetBit",
":",
"permFlag",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Builds a composite BasePermission by creating a PermFlag from permissions strings and
// setting them all | [
"Builds",
"a",
"composite",
"BasePermission",
"by",
"creating",
"a",
"PermFlag",
"from",
"permissions",
"strings",
"and",
"setting",
"them",
"all"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/util.go#L58-L67 | train |
hyperledger/burrow | permission/util.go | PermFlagFromStringList | func PermFlagFromStringList(permissions []string) (PermFlag, error) {
var permFlag PermFlag
for _, perm := range permissions {
s := strings.TrimSpace(perm)
if s == "" {
continue
}
flag, err := PermStringToFlag(s)
if err != nil {
return permFlag, err
}
permFlag |= flag
}
return permFlag, nil
} | go | func PermFlagFromStringList(permissions []string) (PermFlag, error) {
var permFlag PermFlag
for _, perm := range permissions {
s := strings.TrimSpace(perm)
if s == "" {
continue
}
flag, err := PermStringToFlag(s)
if err != nil {
return permFlag, err
}
permFlag |= flag
}
return permFlag, nil
} | [
"func",
"PermFlagFromStringList",
"(",
"permissions",
"[",
"]",
"string",
")",
"(",
"PermFlag",
",",
"error",
")",
"{",
"var",
"permFlag",
"PermFlag",
"\n",
"for",
"_",
",",
"perm",
":=",
"range",
"permissions",
"{",
"s",
":=",
"strings",
".",
"TrimSpace",
"(",
"perm",
")",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"flag",
",",
"err",
":=",
"PermStringToFlag",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"permFlag",
",",
"err",
"\n",
"}",
"\n",
"permFlag",
"|=",
"flag",
"\n",
"}",
"\n",
"return",
"permFlag",
",",
"nil",
"\n",
"}"
] | // Builds a composite PermFlag by mapping each permission string in permissions to its
// flag and composing them with binary or | [
"Builds",
"a",
"composite",
"PermFlag",
"by",
"mapping",
"each",
"permission",
"string",
"in",
"permissions",
"to",
"its",
"flag",
"and",
"composing",
"them",
"with",
"binary",
"or"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/util.go#L71-L85 | train |
hyperledger/burrow | permission/util.go | PermFlagToStringList | func PermFlagToStringList(permFlag PermFlag) []string {
permStrings := make([]string, 0, NumPermissions)
for i := uint(0); i < NumPermissions; i++ {
permFlag := permFlag & (1 << i)
if permFlag > 0 {
permStrings = append(permStrings, permFlag.String())
}
}
return permStrings
} | go | func PermFlagToStringList(permFlag PermFlag) []string {
permStrings := make([]string, 0, NumPermissions)
for i := uint(0); i < NumPermissions; i++ {
permFlag := permFlag & (1 << i)
if permFlag > 0 {
permStrings = append(permStrings, permFlag.String())
}
}
return permStrings
} | [
"func",
"PermFlagToStringList",
"(",
"permFlag",
"PermFlag",
")",
"[",
"]",
"string",
"{",
"permStrings",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"NumPermissions",
")",
"\n",
"for",
"i",
":=",
"uint",
"(",
"0",
")",
";",
"i",
"<",
"NumPermissions",
";",
"i",
"++",
"{",
"permFlag",
":=",
"permFlag",
"&",
"(",
"1",
"<<",
"i",
")",
"\n",
"if",
"permFlag",
">",
"0",
"{",
"permStrings",
"=",
"append",
"(",
"permStrings",
",",
"permFlag",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"permStrings",
"\n",
"}"
] | // Creates a list of individual permission flag strings from a possibly composite PermFlag
// by projecting out each bit and adding its permission string if it is set | [
"Creates",
"a",
"list",
"of",
"individual",
"permission",
"flag",
"strings",
"from",
"a",
"possibly",
"composite",
"PermFlag",
"by",
"projecting",
"out",
"each",
"bit",
"and",
"adding",
"its",
"permission",
"string",
"if",
"it",
"is",
"set"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/permission/util.go#L95-L104 | train |
hyperledger/burrow | rpc/service.go | NewService | func NewService(state acmstate.IterableStatsReader, nameReg names.IterableReader, blockchain bcm.BlockchainInfo,
validators validator.History, nodeView *tendermint.NodeView, logger *logging.Logger) *Service {
return &Service{
state: state,
nameReg: nameReg,
blockchain: blockchain,
validators: validators,
nodeView: nodeView,
logger: logger.With(structure.ComponentKey, "Service"),
}
} | go | func NewService(state acmstate.IterableStatsReader, nameReg names.IterableReader, blockchain bcm.BlockchainInfo,
validators validator.History, nodeView *tendermint.NodeView, logger *logging.Logger) *Service {
return &Service{
state: state,
nameReg: nameReg,
blockchain: blockchain,
validators: validators,
nodeView: nodeView,
logger: logger.With(structure.ComponentKey, "Service"),
}
} | [
"func",
"NewService",
"(",
"state",
"acmstate",
".",
"IterableStatsReader",
",",
"nameReg",
"names",
".",
"IterableReader",
",",
"blockchain",
"bcm",
".",
"BlockchainInfo",
",",
"validators",
"validator",
".",
"History",
",",
"nodeView",
"*",
"tendermint",
".",
"NodeView",
",",
"logger",
"*",
"logging",
".",
"Logger",
")",
"*",
"Service",
"{",
"return",
"&",
"Service",
"{",
"state",
":",
"state",
",",
"nameReg",
":",
"nameReg",
",",
"blockchain",
":",
"blockchain",
",",
"validators",
":",
"validators",
",",
"nodeView",
":",
"nodeView",
",",
"logger",
":",
"logger",
".",
"With",
"(",
"structure",
".",
"ComponentKey",
",",
"\"",
"\"",
")",
",",
"}",
"\n",
"}"
] | // Service provides an internal query and information service with serialisable return types on which can accomodate
// a number of transport front ends | [
"Service",
"provides",
"an",
"internal",
"query",
"and",
"information",
"service",
"with",
"serialisable",
"return",
"types",
"on",
"which",
"can",
"accomodate",
"a",
"number",
"of",
"transport",
"front",
"ends"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/rpc/service.go#L58-L69 | train |
hyperledger/burrow | rpc/service.go | Blocks | func (s *Service) Blocks(minHeight, maxHeight int64) (*ResultBlocks, error) {
if s.nodeView == nil {
return nil, fmt.Errorf("NodeView is not mounted so cannot pull Tendermint blocks")
}
latestHeight := int64(s.blockchain.LastBlockHeight())
if minHeight < 1 {
minHeight = latestHeight
}
if maxHeight == 0 || latestHeight < maxHeight {
maxHeight = latestHeight
}
if maxHeight > minHeight && maxHeight-minHeight > MaxBlockLookback {
minHeight = maxHeight - MaxBlockLookback
}
var blockMetas []*tmTypes.BlockMeta
for height := minHeight; height <= maxHeight; height++ {
blockMeta := s.nodeView.BlockStore().LoadBlockMeta(height)
blockMetas = append(blockMetas, blockMeta)
}
return &ResultBlocks{
LastHeight: uint64(latestHeight),
BlockMetas: blockMetas,
}, nil
} | go | func (s *Service) Blocks(minHeight, maxHeight int64) (*ResultBlocks, error) {
if s.nodeView == nil {
return nil, fmt.Errorf("NodeView is not mounted so cannot pull Tendermint blocks")
}
latestHeight := int64(s.blockchain.LastBlockHeight())
if minHeight < 1 {
minHeight = latestHeight
}
if maxHeight == 0 || latestHeight < maxHeight {
maxHeight = latestHeight
}
if maxHeight > minHeight && maxHeight-minHeight > MaxBlockLookback {
minHeight = maxHeight - MaxBlockLookback
}
var blockMetas []*tmTypes.BlockMeta
for height := minHeight; height <= maxHeight; height++ {
blockMeta := s.nodeView.BlockStore().LoadBlockMeta(height)
blockMetas = append(blockMetas, blockMeta)
}
return &ResultBlocks{
LastHeight: uint64(latestHeight),
BlockMetas: blockMetas,
}, nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Blocks",
"(",
"minHeight",
",",
"maxHeight",
"int64",
")",
"(",
"*",
"ResultBlocks",
",",
"error",
")",
"{",
"if",
"s",
".",
"nodeView",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"latestHeight",
":=",
"int64",
"(",
"s",
".",
"blockchain",
".",
"LastBlockHeight",
"(",
")",
")",
"\n\n",
"if",
"minHeight",
"<",
"1",
"{",
"minHeight",
"=",
"latestHeight",
"\n",
"}",
"\n",
"if",
"maxHeight",
"==",
"0",
"||",
"latestHeight",
"<",
"maxHeight",
"{",
"maxHeight",
"=",
"latestHeight",
"\n",
"}",
"\n",
"if",
"maxHeight",
">",
"minHeight",
"&&",
"maxHeight",
"-",
"minHeight",
">",
"MaxBlockLookback",
"{",
"minHeight",
"=",
"maxHeight",
"-",
"MaxBlockLookback",
"\n",
"}",
"\n\n",
"var",
"blockMetas",
"[",
"]",
"*",
"tmTypes",
".",
"BlockMeta",
"\n",
"for",
"height",
":=",
"minHeight",
";",
"height",
"<=",
"maxHeight",
";",
"height",
"++",
"{",
"blockMeta",
":=",
"s",
".",
"nodeView",
".",
"BlockStore",
"(",
")",
".",
"LoadBlockMeta",
"(",
"height",
")",
"\n",
"blockMetas",
"=",
"append",
"(",
"blockMetas",
",",
"blockMeta",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"ResultBlocks",
"{",
"LastHeight",
":",
"uint64",
"(",
"latestHeight",
")",
",",
"BlockMetas",
":",
"blockMetas",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Returns the current blockchain height and metadata for a range of blocks
// between minHeight and maxHeight. Only returns maxBlockLookback block metadata
// from the top of the range of blocks.
// Passing 0 for maxHeight sets the upper height of the range to the current
// blockchain height. | [
"Returns",
"the",
"current",
"blockchain",
"height",
"and",
"metadata",
"for",
"a",
"range",
"of",
"blocks",
"between",
"minHeight",
"and",
"maxHeight",
".",
"Only",
"returns",
"maxBlockLookback",
"block",
"metadata",
"from",
"the",
"top",
"of",
"the",
"range",
"of",
"blocks",
".",
"Passing",
"0",
"for",
"maxHeight",
"sets",
"the",
"upper",
"height",
"of",
"the",
"range",
"to",
"the",
"current",
"blockchain",
"height",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/rpc/service.go#L298-L324 | train |
hyperledger/burrow | genesis/deterministic_genesis.go | NewDeterministicGenesis | func NewDeterministicGenesis(seed int64) *deterministicGenesis {
return &deterministicGenesis{
random: rand.New(rand.NewSource(seed)),
}
} | go | func NewDeterministicGenesis(seed int64) *deterministicGenesis {
return &deterministicGenesis{
random: rand.New(rand.NewSource(seed)),
}
} | [
"func",
"NewDeterministicGenesis",
"(",
"seed",
"int64",
")",
"*",
"deterministicGenesis",
"{",
"return",
"&",
"deterministicGenesis",
"{",
"random",
":",
"rand",
".",
"New",
"(",
"rand",
".",
"NewSource",
"(",
"seed",
")",
")",
",",
"}",
"\n",
"}"
] | // Generates deterministic pseudo-random genesis state | [
"Generates",
"deterministic",
"pseudo",
"-",
"random",
"genesis",
"state"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/genesis/deterministic_genesis.go#L18-L22 | train |
hyperledger/burrow | execution/contexts/governance_context.go | Execute | func (ctx *GovernanceContext) Execute(txe *exec.TxExecution, p payload.Payload) error {
var ok bool
ctx.txe = txe
ctx.tx, ok = p.(*payload.GovTx)
if !ok {
return fmt.Errorf("payload must be NameTx, but is: %v", txe.Envelope.Tx.Payload)
}
// Nothing down with any incoming funds at this point
accounts, _, err := getInputs(ctx.StateWriter, ctx.tx.Inputs)
if err != nil {
return err
}
// ensure all inputs have root permissions
err = allHavePermission(ctx.StateWriter, permission.Root, accounts, ctx.Logger)
if err != nil {
return errors.Wrap(err, "at least one input lacks permission for GovTx")
}
for _, i := range ctx.tx.Inputs {
txe.Input(i.Address, nil)
}
for _, update := range ctx.tx.AccountUpdates {
if update.Address == nil && update.PublicKey == nil {
// We do not want to generate a key
return fmt.Errorf("could not execution GovTx since account template %v contains neither "+
"address or public key", update)
}
if update.PublicKey == nil {
update.PublicKey, err = ctx.MaybeGetPublicKey(*update.Address)
if err != nil {
return err
}
}
// Check address
if update.PublicKey != nil {
address := update.PublicKey.GetAddress()
if update.Address != nil && address != *update.Address {
return fmt.Errorf("supplied public key %v whose address %v does not match %v provided by"+
"GovTx", update.PublicKey, address, update.Address)
}
update.Address = &address
} else if update.Balances().HasPower() {
// If we are updating power we will need the key
return fmt.Errorf("GovTx must be provided with public key when updating validator power")
}
account, err := getOrMakeOutput(ctx.StateWriter, accounts, *update.Address, ctx.Logger)
if err != nil {
return err
}
governAccountEvent, err := ctx.UpdateAccount(account, update)
if err != nil {
txe.GovernAccount(governAccountEvent, errors.AsException(err))
return err
}
txe.GovernAccount(governAccountEvent, nil)
}
return nil
} | go | func (ctx *GovernanceContext) Execute(txe *exec.TxExecution, p payload.Payload) error {
var ok bool
ctx.txe = txe
ctx.tx, ok = p.(*payload.GovTx)
if !ok {
return fmt.Errorf("payload must be NameTx, but is: %v", txe.Envelope.Tx.Payload)
}
// Nothing down with any incoming funds at this point
accounts, _, err := getInputs(ctx.StateWriter, ctx.tx.Inputs)
if err != nil {
return err
}
// ensure all inputs have root permissions
err = allHavePermission(ctx.StateWriter, permission.Root, accounts, ctx.Logger)
if err != nil {
return errors.Wrap(err, "at least one input lacks permission for GovTx")
}
for _, i := range ctx.tx.Inputs {
txe.Input(i.Address, nil)
}
for _, update := range ctx.tx.AccountUpdates {
if update.Address == nil && update.PublicKey == nil {
// We do not want to generate a key
return fmt.Errorf("could not execution GovTx since account template %v contains neither "+
"address or public key", update)
}
if update.PublicKey == nil {
update.PublicKey, err = ctx.MaybeGetPublicKey(*update.Address)
if err != nil {
return err
}
}
// Check address
if update.PublicKey != nil {
address := update.PublicKey.GetAddress()
if update.Address != nil && address != *update.Address {
return fmt.Errorf("supplied public key %v whose address %v does not match %v provided by"+
"GovTx", update.PublicKey, address, update.Address)
}
update.Address = &address
} else if update.Balances().HasPower() {
// If we are updating power we will need the key
return fmt.Errorf("GovTx must be provided with public key when updating validator power")
}
account, err := getOrMakeOutput(ctx.StateWriter, accounts, *update.Address, ctx.Logger)
if err != nil {
return err
}
governAccountEvent, err := ctx.UpdateAccount(account, update)
if err != nil {
txe.GovernAccount(governAccountEvent, errors.AsException(err))
return err
}
txe.GovernAccount(governAccountEvent, nil)
}
return nil
} | [
"func",
"(",
"ctx",
"*",
"GovernanceContext",
")",
"Execute",
"(",
"txe",
"*",
"exec",
".",
"TxExecution",
",",
"p",
"payload",
".",
"Payload",
")",
"error",
"{",
"var",
"ok",
"bool",
"\n",
"ctx",
".",
"txe",
"=",
"txe",
"\n",
"ctx",
".",
"tx",
",",
"ok",
"=",
"p",
".",
"(",
"*",
"payload",
".",
"GovTx",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"txe",
".",
"Envelope",
".",
"Tx",
".",
"Payload",
")",
"\n",
"}",
"\n",
"// Nothing down with any incoming funds at this point",
"accounts",
",",
"_",
",",
"err",
":=",
"getInputs",
"(",
"ctx",
".",
"StateWriter",
",",
"ctx",
".",
"tx",
".",
"Inputs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// ensure all inputs have root permissions",
"err",
"=",
"allHavePermission",
"(",
"ctx",
".",
"StateWriter",
",",
"permission",
".",
"Root",
",",
"accounts",
",",
"ctx",
".",
"Logger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"i",
":=",
"range",
"ctx",
".",
"tx",
".",
"Inputs",
"{",
"txe",
".",
"Input",
"(",
"i",
".",
"Address",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"update",
":=",
"range",
"ctx",
".",
"tx",
".",
"AccountUpdates",
"{",
"if",
"update",
".",
"Address",
"==",
"nil",
"&&",
"update",
".",
"PublicKey",
"==",
"nil",
"{",
"// We do not want to generate a key",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"update",
")",
"\n",
"}",
"\n",
"if",
"update",
".",
"PublicKey",
"==",
"nil",
"{",
"update",
".",
"PublicKey",
",",
"err",
"=",
"ctx",
".",
"MaybeGetPublicKey",
"(",
"*",
"update",
".",
"Address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"// Check address",
"if",
"update",
".",
"PublicKey",
"!=",
"nil",
"{",
"address",
":=",
"update",
".",
"PublicKey",
".",
"GetAddress",
"(",
")",
"\n",
"if",
"update",
".",
"Address",
"!=",
"nil",
"&&",
"address",
"!=",
"*",
"update",
".",
"Address",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"update",
".",
"PublicKey",
",",
"address",
",",
"update",
".",
"Address",
")",
"\n",
"}",
"\n",
"update",
".",
"Address",
"=",
"&",
"address",
"\n",
"}",
"else",
"if",
"update",
".",
"Balances",
"(",
")",
".",
"HasPower",
"(",
")",
"{",
"// If we are updating power we will need the key",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"account",
",",
"err",
":=",
"getOrMakeOutput",
"(",
"ctx",
".",
"StateWriter",
",",
"accounts",
",",
"*",
"update",
".",
"Address",
",",
"ctx",
".",
"Logger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"governAccountEvent",
",",
"err",
":=",
"ctx",
".",
"UpdateAccount",
"(",
"account",
",",
"update",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"txe",
".",
"GovernAccount",
"(",
"governAccountEvent",
",",
"errors",
".",
"AsException",
"(",
"err",
")",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"txe",
".",
"GovernAccount",
"(",
"governAccountEvent",
",",
"nil",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // GovTx provides a set of TemplateAccounts and GovernanceContext tries to alter the chain state to match the
// specification given | [
"GovTx",
"provides",
"a",
"set",
"of",
"TemplateAccounts",
"and",
"GovernanceContext",
"tries",
"to",
"alter",
"the",
"chain",
"state",
"to",
"match",
"the",
"specification",
"given"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/contexts/governance_context.go#L29-L88 | train |
hyperledger/burrow | vent/sqldb/utils.go | findTable | func (db *SQLDB) findTable(tableName string) (bool, error) {
found := 0
safeTable := safe(tableName)
query := db.DBAdapter.FindTableQuery()
db.Log.Info("msg", "FIND TABLE", "query", query, "value", safeTable)
if err := db.DB.QueryRow(query, tableName).Scan(&found); err != nil {
db.Log.Info("msg", "Error finding table", "err", err)
return false, err
}
if found == 0 {
db.Log.Warn("msg", "Table not found", "value", safeTable)
return false, nil
}
return true, nil
} | go | func (db *SQLDB) findTable(tableName string) (bool, error) {
found := 0
safeTable := safe(tableName)
query := db.DBAdapter.FindTableQuery()
db.Log.Info("msg", "FIND TABLE", "query", query, "value", safeTable)
if err := db.DB.QueryRow(query, tableName).Scan(&found); err != nil {
db.Log.Info("msg", "Error finding table", "err", err)
return false, err
}
if found == 0 {
db.Log.Warn("msg", "Table not found", "value", safeTable)
return false, nil
}
return true, nil
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"findTable",
"(",
"tableName",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"found",
":=",
"0",
"\n",
"safeTable",
":=",
"safe",
"(",
"tableName",
")",
"\n",
"query",
":=",
"db",
".",
"DBAdapter",
".",
"FindTableQuery",
"(",
")",
"\n\n",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"query",
",",
"\"",
"\"",
",",
"safeTable",
")",
"\n",
"if",
"err",
":=",
"db",
".",
"DB",
".",
"QueryRow",
"(",
"query",
",",
"tableName",
")",
".",
"Scan",
"(",
"&",
"found",
")",
";",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"found",
"==",
"0",
"{",
"db",
".",
"Log",
".",
"Warn",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"safeTable",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // findTable checks if a table exists in the default schema | [
"findTable",
"checks",
"if",
"a",
"table",
"exists",
"in",
"the",
"default",
"schema"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L19-L37 | train |
hyperledger/burrow | vent/sqldb/utils.go | getTableDef | func (db *SQLDB) getTableDef(tableName string) (*types.SQLTable, error) {
table := &types.SQLTable{
Name: safe(tableName),
}
found, err := db.findTable(table.Name)
if err != nil {
return nil, err
}
if !found {
db.Log.Info("msg", "Error table not found", "value", table.Name)
return nil, errors.New("Error table not found " + table.Name)
}
query := db.DBAdapter.TableDefinitionQuery()
db.Log.Info("msg", "QUERY STRUCTURE", "query", query, "value", table.Name)
rows, err := db.DB.Query(query, safe(tableName))
if err != nil {
db.Log.Info("msg", "Error querying table structure", "err", err)
return nil, err
}
defer rows.Close()
var columns []*types.SQLTableColumn
for rows.Next() {
var columnName string
var columnSQLType types.SQLColumnType
var columnIsPK int
var columnLength int
if err = rows.Scan(&columnName, &columnSQLType, &columnLength, &columnIsPK); err != nil {
db.Log.Info("msg", "Error scanning table structure", "err", err)
return nil, err
}
if _, err = db.DBAdapter.TypeMapping(columnSQLType); err != nil {
return nil, err
}
columns = append(columns, &types.SQLTableColumn{
Name: columnName,
Type: columnSQLType,
Length: columnLength,
Primary: columnIsPK == 1,
})
}
if err = rows.Err(); err != nil {
db.Log.Info("msg", "Error during rows iteration", "err", err)
return nil, err
}
table.Columns = columns
return table, nil
} | go | func (db *SQLDB) getTableDef(tableName string) (*types.SQLTable, error) {
table := &types.SQLTable{
Name: safe(tableName),
}
found, err := db.findTable(table.Name)
if err != nil {
return nil, err
}
if !found {
db.Log.Info("msg", "Error table not found", "value", table.Name)
return nil, errors.New("Error table not found " + table.Name)
}
query := db.DBAdapter.TableDefinitionQuery()
db.Log.Info("msg", "QUERY STRUCTURE", "query", query, "value", table.Name)
rows, err := db.DB.Query(query, safe(tableName))
if err != nil {
db.Log.Info("msg", "Error querying table structure", "err", err)
return nil, err
}
defer rows.Close()
var columns []*types.SQLTableColumn
for rows.Next() {
var columnName string
var columnSQLType types.SQLColumnType
var columnIsPK int
var columnLength int
if err = rows.Scan(&columnName, &columnSQLType, &columnLength, &columnIsPK); err != nil {
db.Log.Info("msg", "Error scanning table structure", "err", err)
return nil, err
}
if _, err = db.DBAdapter.TypeMapping(columnSQLType); err != nil {
return nil, err
}
columns = append(columns, &types.SQLTableColumn{
Name: columnName,
Type: columnSQLType,
Length: columnLength,
Primary: columnIsPK == 1,
})
}
if err = rows.Err(); err != nil {
db.Log.Info("msg", "Error during rows iteration", "err", err)
return nil, err
}
table.Columns = columns
return table, nil
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"getTableDef",
"(",
"tableName",
"string",
")",
"(",
"*",
"types",
".",
"SQLTable",
",",
"error",
")",
"{",
"table",
":=",
"&",
"types",
".",
"SQLTable",
"{",
"Name",
":",
"safe",
"(",
"tableName",
")",
",",
"}",
"\n",
"found",
",",
"err",
":=",
"db",
".",
"findTable",
"(",
"table",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"found",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"table",
".",
"Name",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"table",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"query",
":=",
"db",
".",
"DBAdapter",
".",
"TableDefinitionQuery",
"(",
")",
"\n\n",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"query",
",",
"\"",
"\"",
",",
"table",
".",
"Name",
")",
"\n",
"rows",
",",
"err",
":=",
"db",
".",
"DB",
".",
"Query",
"(",
"query",
",",
"safe",
"(",
"tableName",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"rows",
".",
"Close",
"(",
")",
"\n\n",
"var",
"columns",
"[",
"]",
"*",
"types",
".",
"SQLTableColumn",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"columnName",
"string",
"\n",
"var",
"columnSQLType",
"types",
".",
"SQLColumnType",
"\n",
"var",
"columnIsPK",
"int",
"\n",
"var",
"columnLength",
"int",
"\n\n",
"if",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"columnName",
",",
"&",
"columnSQLType",
",",
"&",
"columnLength",
",",
"&",
"columnIsPK",
")",
";",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
"=",
"db",
".",
"DBAdapter",
".",
"TypeMapping",
"(",
"columnSQLType",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"columns",
"=",
"append",
"(",
"columns",
",",
"&",
"types",
".",
"SQLTableColumn",
"{",
"Name",
":",
"columnName",
",",
"Type",
":",
"columnSQLType",
",",
"Length",
":",
"columnLength",
",",
"Primary",
":",
"columnIsPK",
"==",
"1",
",",
"}",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"rows",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"table",
".",
"Columns",
"=",
"columns",
"\n",
"return",
"table",
",",
"nil",
"\n",
"}"
] | // getTableDef returns the structure of a given SQL table | [
"getTableDef",
"returns",
"the",
"structure",
"of",
"a",
"given",
"SQL",
"table"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L176-L232 | train |
hyperledger/burrow | vent/sqldb/utils.go | alterTable | func (db *SQLDB) alterTable(table *types.SQLTable) error {
db.Log.Info("msg", "Altering table", "value", table.Name)
// prepare log query
logQuery := db.DBAdapter.InsertLogQuery()
// current table structure
safeTable := safe(table.Name)
currentTable, err := db.getTableDef(safeTable)
if err != nil {
return err
}
sqlValues, _ := db.getJSON(nil)
// for each column in the new table structure
for order, newColumn := range table.Columns {
found := false
// check if exists in the current table structure
for _, currentColumn := range currentTable.Columns {
// if column exists
if currentColumn.Name == newColumn.Name {
found = true
break
}
}
if !found {
safeCol := safe(newColumn.Name)
query, dictionary := db.DBAdapter.AlterColumnQuery(safeTable, safeCol, newColumn.Type, newColumn.Length, order)
//alter column
db.Log.Info("msg", "ALTER TABLE", "query", safe(query))
_, err = db.DB.Exec(safe(query))
if err != nil {
if db.DBAdapter.ErrorEquals(err, types.SQLErrorTypeDuplicatedColumn) {
db.Log.Warn("msg", "Duplicate column", "value", safeCol)
} else {
db.Log.Info("msg", "Error altering table", "err", err)
return err
}
} else {
//store dictionary
db.Log.Info("msg", "STORE DICTIONARY", "query", dictionary)
_, err = db.DB.Exec(dictionary)
if err != nil {
db.Log.Info("msg", "Error storing dictionary", "err", err)
return err
}
// Marshal the table into a JSON string.
var jsonData []byte
jsonData, err = db.getJSON(newColumn)
if err != nil {
db.Log.Info("msg", "error marshaling column", "err", err, "value", fmt.Sprintf("%v", newColumn))
return err
}
//insert log
_, err = db.DB.Exec(logQuery, table.Name, "", "", nil, nil, types.ActionAlterTable, jsonData, query, sqlValues)
if err != nil {
db.Log.Info("msg", "Error inserting log", "err", err)
return err
}
}
}
}
// Ensure triggers are defined
err = db.createTableTriggers(table)
if err != nil {
db.Log.Info("msg", "error creating notification triggers", "err", err, "value", fmt.Sprintf("%v", table))
return fmt.Errorf("could not create table notification triggers: %v", err)
}
return nil
} | go | func (db *SQLDB) alterTable(table *types.SQLTable) error {
db.Log.Info("msg", "Altering table", "value", table.Name)
// prepare log query
logQuery := db.DBAdapter.InsertLogQuery()
// current table structure
safeTable := safe(table.Name)
currentTable, err := db.getTableDef(safeTable)
if err != nil {
return err
}
sqlValues, _ := db.getJSON(nil)
// for each column in the new table structure
for order, newColumn := range table.Columns {
found := false
// check if exists in the current table structure
for _, currentColumn := range currentTable.Columns {
// if column exists
if currentColumn.Name == newColumn.Name {
found = true
break
}
}
if !found {
safeCol := safe(newColumn.Name)
query, dictionary := db.DBAdapter.AlterColumnQuery(safeTable, safeCol, newColumn.Type, newColumn.Length, order)
//alter column
db.Log.Info("msg", "ALTER TABLE", "query", safe(query))
_, err = db.DB.Exec(safe(query))
if err != nil {
if db.DBAdapter.ErrorEquals(err, types.SQLErrorTypeDuplicatedColumn) {
db.Log.Warn("msg", "Duplicate column", "value", safeCol)
} else {
db.Log.Info("msg", "Error altering table", "err", err)
return err
}
} else {
//store dictionary
db.Log.Info("msg", "STORE DICTIONARY", "query", dictionary)
_, err = db.DB.Exec(dictionary)
if err != nil {
db.Log.Info("msg", "Error storing dictionary", "err", err)
return err
}
// Marshal the table into a JSON string.
var jsonData []byte
jsonData, err = db.getJSON(newColumn)
if err != nil {
db.Log.Info("msg", "error marshaling column", "err", err, "value", fmt.Sprintf("%v", newColumn))
return err
}
//insert log
_, err = db.DB.Exec(logQuery, table.Name, "", "", nil, nil, types.ActionAlterTable, jsonData, query, sqlValues)
if err != nil {
db.Log.Info("msg", "Error inserting log", "err", err)
return err
}
}
}
}
// Ensure triggers are defined
err = db.createTableTriggers(table)
if err != nil {
db.Log.Info("msg", "error creating notification triggers", "err", err, "value", fmt.Sprintf("%v", table))
return fmt.Errorf("could not create table notification triggers: %v", err)
}
return nil
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"alterTable",
"(",
"table",
"*",
"types",
".",
"SQLTable",
")",
"error",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"table",
".",
"Name",
")",
"\n\n",
"// prepare log query",
"logQuery",
":=",
"db",
".",
"DBAdapter",
".",
"InsertLogQuery",
"(",
")",
"\n\n",
"// current table structure",
"safeTable",
":=",
"safe",
"(",
"table",
".",
"Name",
")",
"\n",
"currentTable",
",",
"err",
":=",
"db",
".",
"getTableDef",
"(",
"safeTable",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sqlValues",
",",
"_",
":=",
"db",
".",
"getJSON",
"(",
"nil",
")",
"\n\n",
"// for each column in the new table structure",
"for",
"order",
",",
"newColumn",
":=",
"range",
"table",
".",
"Columns",
"{",
"found",
":=",
"false",
"\n\n",
"// check if exists in the current table structure",
"for",
"_",
",",
"currentColumn",
":=",
"range",
"currentTable",
".",
"Columns",
"{",
"// if column exists",
"if",
"currentColumn",
".",
"Name",
"==",
"newColumn",
".",
"Name",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"found",
"{",
"safeCol",
":=",
"safe",
"(",
"newColumn",
".",
"Name",
")",
"\n",
"query",
",",
"dictionary",
":=",
"db",
".",
"DBAdapter",
".",
"AlterColumnQuery",
"(",
"safeTable",
",",
"safeCol",
",",
"newColumn",
".",
"Type",
",",
"newColumn",
".",
"Length",
",",
"order",
")",
"\n\n",
"//alter column",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"safe",
"(",
"query",
")",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"DB",
".",
"Exec",
"(",
"safe",
"(",
"query",
")",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"db",
".",
"DBAdapter",
".",
"ErrorEquals",
"(",
"err",
",",
"types",
".",
"SQLErrorTypeDuplicatedColumn",
")",
"{",
"db",
".",
"Log",
".",
"Warn",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"safeCol",
")",
"\n",
"}",
"else",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"//store dictionary",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"dictionary",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"DB",
".",
"Exec",
"(",
"dictionary",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Marshal the table into a JSON string.",
"var",
"jsonData",
"[",
"]",
"byte",
"\n",
"jsonData",
",",
"err",
"=",
"db",
".",
"getJSON",
"(",
"newColumn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"newColumn",
")",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"//insert log",
"_",
",",
"err",
"=",
"db",
".",
"DB",
".",
"Exec",
"(",
"logQuery",
",",
"table",
".",
"Name",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"types",
".",
"ActionAlterTable",
",",
"jsonData",
",",
"query",
",",
"sqlValues",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Ensure triggers are defined",
"err",
"=",
"db",
".",
"createTableTriggers",
"(",
"table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"table",
")",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // alterTable alters the structure of a SQL table & add info to the dictionary | [
"alterTable",
"alters",
"the",
"structure",
"of",
"a",
"SQL",
"table",
"&",
"add",
"info",
"to",
"the",
"dictionary"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L235-L311 | train |
hyperledger/burrow | vent/sqldb/utils.go | createTable | func (db *SQLDB) createTable(table *types.SQLTable, isInitialise bool) error {
db.Log.Info("msg", "Creating Table", "value", table.Name)
// prepare log query
logQuery := db.DBAdapter.InsertLogQuery()
//get create table query
safeTable := safe(table.Name)
query, dictionary := db.DBAdapter.CreateTableQuery(safeTable, table.Columns)
if query == "" {
db.Log.Info("msg", "empty CREATE TABLE query")
return errors.New("empty CREATE TABLE query")
}
// create table
db.Log.Info("msg", "CREATE TABLE", "query", query)
_, err := db.DB.Exec(query)
if err != nil {
return err
}
//store dictionary
db.Log.Info("msg", "STORE DICTIONARY", "query", dictionary)
_, err = db.DB.Exec(dictionary)
if err != nil {
db.Log.Info("msg", "Error storing dictionary", "err", err)
return err
}
err = db.createTableTriggers(table)
if err != nil {
db.Log.Info("msg", "error creating notification triggers", "err", err, "value", fmt.Sprintf("%v", table))
return fmt.Errorf("could not create table notification triggers: %v", err)
}
//insert log (if action is not database initialization)
if !isInitialise {
// Marshal the table into a JSON string.
var jsonData []byte
jsonData, err = db.getJSON(table)
if err != nil {
db.Log.Info("msg", "error marshaling table", "err", err, "value", fmt.Sprintf("%v", table))
return err
}
sqlValues, _ := db.getJSON(nil)
//insert log
_, err = db.DB.Exec(logQuery, table.Name, "", "", nil, nil, types.ActionCreateTable, jsonData, query, sqlValues)
if err != nil {
db.Log.Info("msg", "Error inserting log", "err", err)
return err
}
}
return nil
} | go | func (db *SQLDB) createTable(table *types.SQLTable, isInitialise bool) error {
db.Log.Info("msg", "Creating Table", "value", table.Name)
// prepare log query
logQuery := db.DBAdapter.InsertLogQuery()
//get create table query
safeTable := safe(table.Name)
query, dictionary := db.DBAdapter.CreateTableQuery(safeTable, table.Columns)
if query == "" {
db.Log.Info("msg", "empty CREATE TABLE query")
return errors.New("empty CREATE TABLE query")
}
// create table
db.Log.Info("msg", "CREATE TABLE", "query", query)
_, err := db.DB.Exec(query)
if err != nil {
return err
}
//store dictionary
db.Log.Info("msg", "STORE DICTIONARY", "query", dictionary)
_, err = db.DB.Exec(dictionary)
if err != nil {
db.Log.Info("msg", "Error storing dictionary", "err", err)
return err
}
err = db.createTableTriggers(table)
if err != nil {
db.Log.Info("msg", "error creating notification triggers", "err", err, "value", fmt.Sprintf("%v", table))
return fmt.Errorf("could not create table notification triggers: %v", err)
}
//insert log (if action is not database initialization)
if !isInitialise {
// Marshal the table into a JSON string.
var jsonData []byte
jsonData, err = db.getJSON(table)
if err != nil {
db.Log.Info("msg", "error marshaling table", "err", err, "value", fmt.Sprintf("%v", table))
return err
}
sqlValues, _ := db.getJSON(nil)
//insert log
_, err = db.DB.Exec(logQuery, table.Name, "", "", nil, nil, types.ActionCreateTable, jsonData, query, sqlValues)
if err != nil {
db.Log.Info("msg", "Error inserting log", "err", err)
return err
}
}
return nil
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"createTable",
"(",
"table",
"*",
"types",
".",
"SQLTable",
",",
"isInitialise",
"bool",
")",
"error",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"table",
".",
"Name",
")",
"\n\n",
"// prepare log query",
"logQuery",
":=",
"db",
".",
"DBAdapter",
".",
"InsertLogQuery",
"(",
")",
"\n\n",
"//get create table query",
"safeTable",
":=",
"safe",
"(",
"table",
".",
"Name",
")",
"\n",
"query",
",",
"dictionary",
":=",
"db",
".",
"DBAdapter",
".",
"CreateTableQuery",
"(",
"safeTable",
",",
"table",
".",
"Columns",
")",
"\n",
"if",
"query",
"==",
"\"",
"\"",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// create table",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"query",
")",
"\n",
"_",
",",
"err",
":=",
"db",
".",
"DB",
".",
"Exec",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"//store dictionary",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"dictionary",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"DB",
".",
"Exec",
"(",
"dictionary",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"db",
".",
"createTableTriggers",
"(",
"table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"table",
")",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"//insert log (if action is not database initialization)",
"if",
"!",
"isInitialise",
"{",
"// Marshal the table into a JSON string.",
"var",
"jsonData",
"[",
"]",
"byte",
"\n",
"jsonData",
",",
"err",
"=",
"db",
".",
"getJSON",
"(",
"table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"table",
")",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"sqlValues",
",",
"_",
":=",
"db",
".",
"getJSON",
"(",
"nil",
")",
"\n\n",
"//insert log",
"_",
",",
"err",
"=",
"db",
".",
"DB",
".",
"Exec",
"(",
"logQuery",
",",
"table",
".",
"Name",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"types",
".",
"ActionCreateTable",
",",
"jsonData",
",",
"query",
",",
"sqlValues",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // createTable creates a new table | [
"createTable",
"creates",
"a",
"new",
"table"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L314-L368 | train |
hyperledger/burrow | vent/sqldb/utils.go | getSelectQuery | func (db *SQLDB) getSelectQuery(table *types.SQLTable, height uint64) (string, error) {
fields := ""
for _, tableColumn := range table.Columns {
if fields != "" {
fields += ", "
}
fields += db.DBAdapter.SecureName(tableColumn.Name)
}
if fields == "" {
return "", errors.New("error table does not contain any fields")
}
query := db.DBAdapter.SelectRowQuery(table.Name, fields, strconv.FormatUint(height, 10))
return query, nil
} | go | func (db *SQLDB) getSelectQuery(table *types.SQLTable, height uint64) (string, error) {
fields := ""
for _, tableColumn := range table.Columns {
if fields != "" {
fields += ", "
}
fields += db.DBAdapter.SecureName(tableColumn.Name)
}
if fields == "" {
return "", errors.New("error table does not contain any fields")
}
query := db.DBAdapter.SelectRowQuery(table.Name, fields, strconv.FormatUint(height, 10))
return query, nil
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"getSelectQuery",
"(",
"table",
"*",
"types",
".",
"SQLTable",
",",
"height",
"uint64",
")",
"(",
"string",
",",
"error",
")",
"{",
"fields",
":=",
"\"",
"\"",
"\n\n",
"for",
"_",
",",
"tableColumn",
":=",
"range",
"table",
".",
"Columns",
"{",
"if",
"fields",
"!=",
"\"",
"\"",
"{",
"fields",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"fields",
"+=",
"db",
".",
"DBAdapter",
".",
"SecureName",
"(",
"tableColumn",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"if",
"fields",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"query",
":=",
"db",
".",
"DBAdapter",
".",
"SelectRowQuery",
"(",
"table",
".",
"Name",
",",
"fields",
",",
"strconv",
".",
"FormatUint",
"(",
"height",
",",
"10",
")",
")",
"\n",
"return",
"query",
",",
"nil",
"\n",
"}"
] | // getSelectQuery builds a select query for a specific SQL table and a given block | [
"getSelectQuery",
"builds",
"a",
"select",
"query",
"for",
"a",
"specific",
"SQL",
"table",
"and",
"a",
"given",
"block"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L398-L415 | train |
hyperledger/burrow | vent/sqldb/utils.go | getBlockTables | func (db *SQLDB) getBlockTables(height uint64) (types.EventTables, error) {
tables := make(types.EventTables)
query := db.DBAdapter.SelectLogQuery()
db.Log.Info("msg", "QUERY LOG", "query", query, "value", height)
rows, err := db.DB.Query(query, height)
if err != nil {
db.Log.Info("msg", "Error querying log", "err", err)
return tables, err
}
defer rows.Close()
for rows.Next() {
var eventName, tableName string
var table *types.SQLTable
err = rows.Scan(&tableName, &eventName)
if err != nil {
db.Log.Info("msg", "Error scanning table structure", "err", err)
return tables, err
}
err = rows.Err()
if err != nil {
db.Log.Info("msg", "Error scanning table structure", "err", err)
return tables, err
}
table, err = db.getTableDef(tableName)
if err != nil {
return tables, err
}
tables[tableName] = table
}
return tables, nil
} | go | func (db *SQLDB) getBlockTables(height uint64) (types.EventTables, error) {
tables := make(types.EventTables)
query := db.DBAdapter.SelectLogQuery()
db.Log.Info("msg", "QUERY LOG", "query", query, "value", height)
rows, err := db.DB.Query(query, height)
if err != nil {
db.Log.Info("msg", "Error querying log", "err", err)
return tables, err
}
defer rows.Close()
for rows.Next() {
var eventName, tableName string
var table *types.SQLTable
err = rows.Scan(&tableName, &eventName)
if err != nil {
db.Log.Info("msg", "Error scanning table structure", "err", err)
return tables, err
}
err = rows.Err()
if err != nil {
db.Log.Info("msg", "Error scanning table structure", "err", err)
return tables, err
}
table, err = db.getTableDef(tableName)
if err != nil {
return tables, err
}
tables[tableName] = table
}
return tables, nil
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"getBlockTables",
"(",
"height",
"uint64",
")",
"(",
"types",
".",
"EventTables",
",",
"error",
")",
"{",
"tables",
":=",
"make",
"(",
"types",
".",
"EventTables",
")",
"\n\n",
"query",
":=",
"db",
".",
"DBAdapter",
".",
"SelectLogQuery",
"(",
")",
"\n",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"query",
",",
"\"",
"\"",
",",
"height",
")",
"\n\n",
"rows",
",",
"err",
":=",
"db",
".",
"DB",
".",
"Query",
"(",
"query",
",",
"height",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"tables",
",",
"err",
"\n",
"}",
"\n",
"defer",
"rows",
".",
"Close",
"(",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"eventName",
",",
"tableName",
"string",
"\n",
"var",
"table",
"*",
"types",
".",
"SQLTable",
"\n\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"tableName",
",",
"&",
"eventName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"tables",
",",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"rows",
".",
"Err",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Log",
".",
"Info",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"tables",
",",
"err",
"\n",
"}",
"\n\n",
"table",
",",
"err",
"=",
"db",
".",
"getTableDef",
"(",
"tableName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"tables",
",",
"err",
"\n",
"}",
"\n\n",
"tables",
"[",
"tableName",
"]",
"=",
"table",
"\n",
"}",
"\n\n",
"return",
"tables",
",",
"nil",
"\n",
"}"
] | // getBlockTables return all SQL tables that have been involved
// in a given batch transaction for a specific block | [
"getBlockTables",
"return",
"all",
"SQL",
"tables",
"that",
"have",
"been",
"involved",
"in",
"a",
"given",
"batch",
"transaction",
"for",
"a",
"specific",
"block"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L419-L457 | train |
hyperledger/burrow | vent/sqldb/utils.go | safe | func safe(parameter string) string {
replacer := strings.NewReplacer(";", "", ",", "")
return replacer.Replace(parameter)
} | go | func safe(parameter string) string {
replacer := strings.NewReplacer(";", "", ",", "")
return replacer.Replace(parameter)
} | [
"func",
"safe",
"(",
"parameter",
"string",
")",
"string",
"{",
"replacer",
":=",
"strings",
".",
"NewReplacer",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"replacer",
".",
"Replace",
"(",
"parameter",
")",
"\n",
"}"
] | // safe sanitizes a parameter | [
"safe",
"sanitizes",
"a",
"parameter"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L460-L463 | train |
hyperledger/burrow | vent/sqldb/utils.go | getJSON | func (db *SQLDB) getJSON(JSON interface{}) ([]byte, error) {
if JSON != nil {
return json.Marshal(JSON)
}
return json.Marshal("")
} | go | func (db *SQLDB) getJSON(JSON interface{}) ([]byte, error) {
if JSON != nil {
return json.Marshal(JSON)
}
return json.Marshal("")
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"getJSON",
"(",
"JSON",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"JSON",
"!=",
"nil",
"{",
"return",
"json",
".",
"Marshal",
"(",
"JSON",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | //getJSON returns marshaled json from JSON single column | [
"getJSON",
"returns",
"marshaled",
"json",
"from",
"JSON",
"single",
"column"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L466-L471 | train |
hyperledger/burrow | vent/sqldb/utils.go | getJSONFromValues | func (db *SQLDB) getJSONFromValues(values []interface{}) ([]byte, error) {
if values != nil {
return json.Marshal(values)
}
return json.Marshal("")
} | go | func (db *SQLDB) getJSONFromValues(values []interface{}) ([]byte, error) {
if values != nil {
return json.Marshal(values)
}
return json.Marshal("")
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"getJSONFromValues",
"(",
"values",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"values",
"!=",
"nil",
"{",
"return",
"json",
".",
"Marshal",
"(",
"values",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | //getJSONFromValues returns marshaled json from query values | [
"getJSONFromValues",
"returns",
"marshaled",
"json",
"from",
"query",
"values"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L474-L479 | train |
hyperledger/burrow | vent/sqldb/utils.go | getValuesFromJSON | func (db *SQLDB) getValuesFromJSON(JSON string) ([]interface{}, error) {
pointers := make([]interface{}, 0)
bytes := []byte(JSON)
err := json.Unmarshal(bytes, &pointers)
return pointers, err
} | go | func (db *SQLDB) getValuesFromJSON(JSON string) ([]interface{}, error) {
pointers := make([]interface{}, 0)
bytes := []byte(JSON)
err := json.Unmarshal(bytes, &pointers)
return pointers, err
} | [
"func",
"(",
"db",
"*",
"SQLDB",
")",
"getValuesFromJSON",
"(",
"JSON",
"string",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"pointers",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"bytes",
":=",
"[",
"]",
"byte",
"(",
"JSON",
")",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"bytes",
",",
"&",
"pointers",
")",
"\n",
"return",
"pointers",
",",
"err",
"\n",
"}"
] | //getValuesFromJSON returns query values from unmarshaled JSON column | [
"getValuesFromJSON",
"returns",
"query",
"values",
"from",
"unmarshaled",
"JSON",
"column"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/sqldb/utils.go#L482-L487 | train |
hyperledger/burrow | execution/errors/errors.go | AsException | func AsException(err error) *Exception {
if err == nil {
return nil
}
switch e := err.(type) {
case *Exception:
return e
case CodedError:
return NewException(e.ErrorCode(), e.String())
default:
return NewException(ErrorCodeGeneric, err.Error())
}
} | go | func AsException(err error) *Exception {
if err == nil {
return nil
}
switch e := err.(type) {
case *Exception:
return e
case CodedError:
return NewException(e.ErrorCode(), e.String())
default:
return NewException(ErrorCodeGeneric, err.Error())
}
} | [
"func",
"AsException",
"(",
"err",
"error",
")",
"*",
"Exception",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"switch",
"e",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Exception",
":",
"return",
"e",
"\n",
"case",
"CodedError",
":",
"return",
"NewException",
"(",
"e",
".",
"ErrorCode",
"(",
")",
",",
"e",
".",
"String",
"(",
")",
")",
"\n",
"default",
":",
"return",
"NewException",
"(",
"ErrorCodeGeneric",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Wraps any error as a Exception | [
"Wraps",
"any",
"error",
"as",
"a",
"Exception"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/execution/errors/errors.go#L171-L183 | train |
hyperledger/burrow | crypto/private_key.go | PublicKeyFromBytes | func PublicKeyFromBytes(bs []byte, curveType CurveType) (PublicKey, error) {
switch curveType {
case CurveTypeEd25519:
if len(bs) != ed25519.PublicKeySize {
return PublicKey{}, fmt.Errorf("bytes passed have length %v but ed25519 public keys have %v bytes",
len(bs), ed25519.PublicKeySize)
}
case CurveTypeSecp256k1:
if len(bs) != btcec.PubKeyBytesLenCompressed {
return PublicKey{}, fmt.Errorf("bytes passed have length %v but secp256k1 public keys have %v bytes",
len(bs), btcec.PubKeyBytesLenCompressed)
}
case CurveTypeUnset:
if len(bs) > 0 {
return PublicKey{}, fmt.Errorf("attempting to create an 'unset' PublicKey but passed non-empty key bytes: %X", bs)
}
return PublicKey{}, nil
default:
return PublicKey{}, ErrInvalidCurve(curveType)
}
return PublicKey{PublicKey: bs, CurveType: curveType}, nil
} | go | func PublicKeyFromBytes(bs []byte, curveType CurveType) (PublicKey, error) {
switch curveType {
case CurveTypeEd25519:
if len(bs) != ed25519.PublicKeySize {
return PublicKey{}, fmt.Errorf("bytes passed have length %v but ed25519 public keys have %v bytes",
len(bs), ed25519.PublicKeySize)
}
case CurveTypeSecp256k1:
if len(bs) != btcec.PubKeyBytesLenCompressed {
return PublicKey{}, fmt.Errorf("bytes passed have length %v but secp256k1 public keys have %v bytes",
len(bs), btcec.PubKeyBytesLenCompressed)
}
case CurveTypeUnset:
if len(bs) > 0 {
return PublicKey{}, fmt.Errorf("attempting to create an 'unset' PublicKey but passed non-empty key bytes: %X", bs)
}
return PublicKey{}, nil
default:
return PublicKey{}, ErrInvalidCurve(curveType)
}
return PublicKey{PublicKey: bs, CurveType: curveType}, nil
} | [
"func",
"PublicKeyFromBytes",
"(",
"bs",
"[",
"]",
"byte",
",",
"curveType",
"CurveType",
")",
"(",
"PublicKey",
",",
"error",
")",
"{",
"switch",
"curveType",
"{",
"case",
"CurveTypeEd25519",
":",
"if",
"len",
"(",
"bs",
")",
"!=",
"ed25519",
".",
"PublicKeySize",
"{",
"return",
"PublicKey",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"bs",
")",
",",
"ed25519",
".",
"PublicKeySize",
")",
"\n",
"}",
"\n",
"case",
"CurveTypeSecp256k1",
":",
"if",
"len",
"(",
"bs",
")",
"!=",
"btcec",
".",
"PubKeyBytesLenCompressed",
"{",
"return",
"PublicKey",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"bs",
")",
",",
"btcec",
".",
"PubKeyBytesLenCompressed",
")",
"\n",
"}",
"\n",
"case",
"CurveTypeUnset",
":",
"if",
"len",
"(",
"bs",
")",
">",
"0",
"{",
"return",
"PublicKey",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"bs",
")",
"\n",
"}",
"\n",
"return",
"PublicKey",
"{",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"PublicKey",
"{",
"}",
",",
"ErrInvalidCurve",
"(",
"curveType",
")",
"\n",
"}",
"\n\n",
"return",
"PublicKey",
"{",
"PublicKey",
":",
"bs",
",",
"CurveType",
":",
"curveType",
"}",
",",
"nil",
"\n",
"}"
] | // Currently this is a stub that reads the raw bytes returned by key_client and returns
// an ed25519 public key. | [
"Currently",
"this",
"is",
"a",
"stub",
"that",
"reads",
"the",
"raw",
"bytes",
"returned",
"by",
"key_client",
"and",
"returns",
"an",
"ed25519",
"public",
"key",
"."
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/crypto/private_key.go#L16-L38 | train |
hyperledger/burrow | crypto/private_key.go | Reinitialise | func (p *PrivateKey) Reinitialise() error {
initP, err := PrivateKeyFromRawBytes(p.RawBytes(), p.CurveType)
if err != nil {
return err
}
*p = initP
return nil
} | go | func (p *PrivateKey) Reinitialise() error {
initP, err := PrivateKeyFromRawBytes(p.RawBytes(), p.CurveType)
if err != nil {
return err
}
*p = initP
return nil
} | [
"func",
"(",
"p",
"*",
"PrivateKey",
")",
"Reinitialise",
"(",
")",
"error",
"{",
"initP",
",",
"err",
":=",
"PrivateKeyFromRawBytes",
"(",
"p",
".",
"RawBytes",
"(",
")",
",",
"p",
".",
"CurveType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"p",
"=",
"initP",
"\n",
"return",
"nil",
"\n",
"}"
] | // Reinitialise after serialisation | [
"Reinitialise",
"after",
"serialisation"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/crypto/private_key.go#L74-L81 | train |
hyperledger/burrow | crypto/private_key.go | EnsureEd25519PrivateKeyCorrect | func EnsureEd25519PrivateKeyCorrect(candidatePrivateKey ed25519.PrivateKey) error {
if len(candidatePrivateKey) != ed25519.PrivateKeySize {
return fmt.Errorf("ed25519 key has size %v but %v bytes passed as key", ed25519.PrivateKeySize,
len(candidatePrivateKey))
}
_, derivedPrivateKey, err := ed25519.GenerateKey(bytes.NewBuffer(candidatePrivateKey))
if err != nil {
return err
}
if !bytes.Equal(derivedPrivateKey, candidatePrivateKey) {
return fmt.Errorf("ed25519 key generated from prefix of %X should equal %X, but is %X",
candidatePrivateKey, candidatePrivateKey, derivedPrivateKey)
}
return nil
} | go | func EnsureEd25519PrivateKeyCorrect(candidatePrivateKey ed25519.PrivateKey) error {
if len(candidatePrivateKey) != ed25519.PrivateKeySize {
return fmt.Errorf("ed25519 key has size %v but %v bytes passed as key", ed25519.PrivateKeySize,
len(candidatePrivateKey))
}
_, derivedPrivateKey, err := ed25519.GenerateKey(bytes.NewBuffer(candidatePrivateKey))
if err != nil {
return err
}
if !bytes.Equal(derivedPrivateKey, candidatePrivateKey) {
return fmt.Errorf("ed25519 key generated from prefix of %X should equal %X, but is %X",
candidatePrivateKey, candidatePrivateKey, derivedPrivateKey)
}
return nil
} | [
"func",
"EnsureEd25519PrivateKeyCorrect",
"(",
"candidatePrivateKey",
"ed25519",
".",
"PrivateKey",
")",
"error",
"{",
"if",
"len",
"(",
"candidatePrivateKey",
")",
"!=",
"ed25519",
".",
"PrivateKeySize",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ed25519",
".",
"PrivateKeySize",
",",
"len",
"(",
"candidatePrivateKey",
")",
")",
"\n",
"}",
"\n",
"_",
",",
"derivedPrivateKey",
",",
"err",
":=",
"ed25519",
".",
"GenerateKey",
"(",
"bytes",
".",
"NewBuffer",
"(",
"candidatePrivateKey",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"derivedPrivateKey",
",",
"candidatePrivateKey",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"candidatePrivateKey",
",",
"candidatePrivateKey",
",",
"derivedPrivateKey",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Ensures the last 32 bytes of the ed25519 private key is the public key derived from the first 32 private bytes | [
"Ensures",
"the",
"last",
"32",
"bytes",
"of",
"the",
"ed25519",
"private",
"key",
"is",
"the",
"public",
"key",
"derived",
"from",
"the",
"first",
"32",
"private",
"bytes"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/crypto/private_key.go#L142-L156 | train |
hyperledger/burrow | storage/content_addressed_store.go | Put | func (cas *ContentAddressedStore) Put(data []byte) ([]byte, error) {
hasher := sha256.New()
_, err := hasher.Write(data)
if err != nil {
return nil, fmt.Errorf("ContentAddressedStore could not hash data: %v", err)
}
hash := hasher.Sum(nil)
cas.db.SetSync(hash, data)
return hash, nil
} | go | func (cas *ContentAddressedStore) Put(data []byte) ([]byte, error) {
hasher := sha256.New()
_, err := hasher.Write(data)
if err != nil {
return nil, fmt.Errorf("ContentAddressedStore could not hash data: %v", err)
}
hash := hasher.Sum(nil)
cas.db.SetSync(hash, data)
return hash, nil
} | [
"func",
"(",
"cas",
"*",
"ContentAddressedStore",
")",
"Put",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"hasher",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"hasher",
".",
"Write",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"hash",
":=",
"hasher",
".",
"Sum",
"(",
"nil",
")",
"\n",
"cas",
".",
"db",
".",
"SetSync",
"(",
"hash",
",",
"data",
")",
"\n",
"return",
"hash",
",",
"nil",
"\n",
"}"
] | // These function match those used in Hoard
// Put data in the database by saving data with a key that is its sha256 hash | [
"These",
"function",
"match",
"those",
"used",
"in",
"Hoard",
"Put",
"data",
"in",
"the",
"database",
"by",
"saving",
"data",
"with",
"a",
"key",
"that",
"is",
"its",
"sha256",
"hash"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/storage/content_addressed_store.go#L24-L33 | train |
hyperledger/burrow | logging/logconfig/presets/instructions.go | push | func push(stack []*logconfig.SinkConfig, sinkConfigs ...*logconfig.SinkConfig) []*logconfig.SinkConfig {
for _, sinkConfig := range sinkConfigs {
peek(stack).AddSinks(sinkConfig)
stack = append(stack, sinkConfig)
}
return stack
} | go | func push(stack []*logconfig.SinkConfig, sinkConfigs ...*logconfig.SinkConfig) []*logconfig.SinkConfig {
for _, sinkConfig := range sinkConfigs {
peek(stack).AddSinks(sinkConfig)
stack = append(stack, sinkConfig)
}
return stack
} | [
"func",
"push",
"(",
"stack",
"[",
"]",
"*",
"logconfig",
".",
"SinkConfig",
",",
"sinkConfigs",
"...",
"*",
"logconfig",
".",
"SinkConfig",
")",
"[",
"]",
"*",
"logconfig",
".",
"SinkConfig",
"{",
"for",
"_",
",",
"sinkConfig",
":=",
"range",
"sinkConfigs",
"{",
"peek",
"(",
"stack",
")",
".",
"AddSinks",
"(",
"sinkConfig",
")",
"\n",
"stack",
"=",
"append",
"(",
"stack",
",",
"sinkConfig",
")",
"\n",
"}",
"\n",
"return",
"stack",
"\n",
"}"
] | // Push a path sequence of sinks onto the stack | [
"Push",
"a",
"path",
"sequence",
"of",
"sinks",
"onto",
"the",
"stack"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/logging/logconfig/presets/instructions.go#L266-L272 | train |
hyperledger/burrow | vent/service/consumer.go | NewConsumer | func NewConsumer(cfg *config.VentConfig, log *logger.Logger, eventChannel chan types.EventData) *Consumer {
return &Consumer{
Config: cfg,
Log: log,
Closing: false,
EventsChannel: eventChannel,
}
} | go | func NewConsumer(cfg *config.VentConfig, log *logger.Logger, eventChannel chan types.EventData) *Consumer {
return &Consumer{
Config: cfg,
Log: log,
Closing: false,
EventsChannel: eventChannel,
}
} | [
"func",
"NewConsumer",
"(",
"cfg",
"*",
"config",
".",
"VentConfig",
",",
"log",
"*",
"logger",
".",
"Logger",
",",
"eventChannel",
"chan",
"types",
".",
"EventData",
")",
"*",
"Consumer",
"{",
"return",
"&",
"Consumer",
"{",
"Config",
":",
"cfg",
",",
"Log",
":",
"log",
",",
"Closing",
":",
"false",
",",
"EventsChannel",
":",
"eventChannel",
",",
"}",
"\n",
"}"
] | // NewConsumer constructs a new consumer configuration.
// The event channel will be passed a collection of rows generated from all of the events in a single block
// It will be closed by the consumer when it is finished | [
"NewConsumer",
"constructs",
"a",
"new",
"consumer",
"configuration",
".",
"The",
"event",
"channel",
"will",
"be",
"passed",
"a",
"collection",
"of",
"rows",
"generated",
"from",
"all",
"of",
"the",
"events",
"in",
"a",
"single",
"block",
"It",
"will",
"be",
"closed",
"by",
"the",
"consumer",
"when",
"it",
"is",
"finished"
] | 59993f5aad71a8e16ab6ed4e57e138e2398eae4e | https://github.com/hyperledger/burrow/blob/59993f5aad71a8e16ab6ed4e57e138e2398eae4e/vent/service/consumer.go#L47-L54 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.