-
Notifications
You must be signed in to change notification settings - Fork 28
MinimalScene
If you are interested in the barest minimum build to see bitcoin graph data, without any fancy visuals, then here is demo scene for you!
Take a look at the scene in the folder Assets/B3d/Demos/Btc/Minimal/Scenes
. Open the scene called minimal
:
The most important game object is called B3dEngineAllInOne
. This is a prefab containing all the necessary game objects for the blockchain3d engine. All we have to provide to access graph data is a miminal graph factory object. A graph factory object is any game object with a script attached that implements the C# interface IGraphFactory
. THe IGraphFactory
looks like this:
public interface IGraphFactory
{
void CreateOrUpdateNode(CdmNode nodeNew);
void CreateOrUpdateEdge(CdmEdge edgeNew);
}
The interfaces provides methods that get called when data is successfully retrieved. If data is not retrieved successfully then the methods are not called. The CdmNode
and CdmEdge
classes are the common data model, which contain all the interesting data about those graph objects.
You can see this interface implemented in the class MinimalGraphFactory
attached to the MinimalGraphFactory game object:
public class MinimalGraphFactory : MonoBehaviour, IGraphFactory
{
void IGraphFactory.CreateOrUpdateEdge(CdmEdge edgeNew)
{
// edgeNew contains all the interesting data about an edge
Debug.Log("Edge received: " + edgeNew.EdgeIdFriendly);
}
void IGraphFactory.CreateOrUpdateNode(CdmNode nodeNew)
{
// nodeNew contains all the interesting data about a node (an address or a transaction)
Debug.Log("Node received: " + nodeNew.NodeType + " " + nodeNew.NodeId);
}
void Start()
{
// Example one
// Check a bitcoin address exists, supply callbacks which will be called when result is known
Debug.Log("Checking address...");
FrontEndController.Instance.CheckAddressExists("17mjNZWa3LVXnpiewKae3VkWyDCqKwt7PV", OnCheckNodeOk, OnCheckNodeFailed);
// Similarly can use CheckTransactionExists()
// Example two
// Request bitcoin data for an address
// The methods IGraphFactory.CreateOrUpdateEdge and IGraphFactory.CreateOrUpdateNode will get called if address is good
Debug.Log("Asking for data for address...");
FrontEndController.Instance.GetAddressData("17mjNZWa3LVXnpiewKae3VkWyDCqKwt7PV", 1);
// Similarly could request data for a transaction
//Debug.Log("Asking for data for transaction...");
//FrontEndController.Instance.GetTransactionData("00c3b434effcb7a9f267ccc1f3c199694fef85491c3491ef6b29dec2fb2f8592", 1);
}
private void OnCheckNodeOk(string id)
{
Debug.Log("Node OK:" + id);
}
private void OnCheckNodeFailed(string id)
{
Debug.Log("Node failed:" + id);
}
}
The above comments explain the code that checks an address then gets data for an address. Play the scene in the editor and watch the console. You will see some messages appear something like the below, showing the requested graph data arriving:
The green messages are issued by the engine, the black messages are issued by the demo scene.