Exemple #1
0
func NetworkEmmit(e *tree_event.Event, path *tree_graph.Path) (err tree_lib.TreeError) {
	var (
		sdata []byte
		p     *big.Int
	)
	err.From = tree_lib.FROM_NETWORK_EMIT

	// Calling get value, because maybe some one will calculate this path before calling this functions
	// If path is not calculated yet, it will be automatically calculated in GetValue function
	p, err = path.GetValue()
	if !err.IsNull() {
		return
	}

	// If we emitting from API then we need to multiply path with connected node
	// For sending data through him
	if strings.Contains(node_info.CurrentNodeInfo.Name, tree_api.API_NAME_PREFIX) {
		p.Mul(p, node_info.ChildsNodeValue[path.From])
	}

	// If from not set, setting it before network sending
	if len(e.From) == 0 {
		e.From = node_info.CurrentNodeInfo.Name
	}

	sdata, err.Err = ffjson.Marshal(e)
	if !err.IsNull() {
		return
	}

	SendToPath(sdata, p)
	return
}