March 7, 2023Ardan Labs
From the Ardan Community
Introduction In episode 5, Miki wrote a function that counted the number of lines in a file with interfaces. The first thing his function did was to open a file with Go’s os.Open function. Miki chose this method because the variable returned by said function implements the io.Reader interface which is crucial for the next step. The remaining parts of this function consisted of a primitive type alias that satisfied the io.
Continue reading February 27, 2023Ardan Labs
From the Ardan Community
Introduction In episode 4, Miki defined an enumerated type that satisfied Go’s fmt.Stringer interface. By implementing the fmt.Stringer interface, Miki can specify how his enumerators were printed within a formatted string and in this case, he expected the values to be displayed as a predetermined text value. Miki also pointed out how using the value of the method’s receiver within the Stringer method can result in a recursive loop.
In this video, Miki will define an unusual function that returns the number of lines in a file with the io.
Continue reading February 21, 2023Ardan Labs
From the Ardan Community
Introduction In episode 3, Miki implemented a type that satisfied Go’s error interface. The odd thing about his type was it would be considered not-nil although no value was set for it. To get a better understanding of the situation, Miki gives a brief explanation of how Go determines if an error value is nil, and in this case, Miki specified the type of the variable returned to be a pointer of his custom error type which blindsided Go’s mechanism to determine a nil value.
Continue reading February 13, 2023Ardan Labs
From the Ardan Community
Introduction In episode 2, Miki examined the impact interfaces have on the performance of a Go program. To perform this experiment, Miki invoked a type’s method in two ways: with the concrete type and as an interface function to measure the difference in execution time. The conclusion of this experiment was that calling a method with the concrete type is faster than using an interface. During the experiment, Miki made use of the build flag -gcflag=’-m’ to display which variables were being allocated on the heap and where the compiler was automatically inlining function calls.
Continue reading February 8, 2023Ardan Labs
From the Ardan Community
Introduction In episode 1, Miki had two functions that performed the similar operation, but returned different types. To refactor this, Miki rewrote both functions as a generic function that allowed him to specify the type to be returned during invocation. In some cases, the compiler may not recognise a type, thus, Miki gives a few pointers on manually telling a generic function which type to use. After demonstrating how to return different types with a generic function, Miki limited the types his generic function would accept with an interface.
Continue reading January 31, 2023Ardan Labs
From the Ardan Community
Introduction Go interfaces are beneficial to Go developers because they:
Allow interfaces to separate mechanism from behavior. Increase flexibility of function parameters. Enable mocking of function parameters. With the addition of generics in Go 1.18, interfaces can be used to constrain the types of values a generic function will accept. To dive deeper into Go interfaces, we invite you to join Miki in his latest series dedicated to Go interfaces.
Continue reading January 27, 2023Ardan Labs
From the Ardan Community
Introduction In episode 19, Bill designed and implemented the data structure for an account on his blockchain. This type will have a nonce field to ensure incoming transactions are valid and performed in order. Since the database will be stored in memory and not on disk, the balances in these accounts are reconstructed with information from previous transactions and the genesis block.
In this video, Bill takes all the theories discussed in this series and applies them by launching his first blockchain node.
Continue reading January 24, 2023Ardan Labs
From the Ardan Community
Introduction In episode 18, Bill defined the Go type that will represent a transaction and implemented the methods to validate one. While developing the transaction type, Bill states that he’ll be borrowing concepts from Ethereum to ensure that he’s building a reference implementation. Bill’s transaction type has a field named nonce, similar to Ethereum, that ensures transactions are executed in order. The nonce value of the last transaction is stored in his accounting database and later compared for additional verification.
Continue reading January 24, 2023Ardan Labs
From the Ardan Community
Introduction In episode 17, Bill began to design an in-memory accounting database that will store the account balances on his blockchain. To build this database, Bill will add a memory pool on each node that stores a list of public addresses with their respective balances. The balances on these addresses are reconstructed by reading the previous transaction records found on his blockchain.
In this video, Bill will define the types of transactions his blockchain will support.
Continue reading January 19, 2023Ardan Labs
From the Ardan Community
Introduction In episode 16, Bill implemented additional means of verification for his blockchain’s transactions. The first update he made was to verify if a transaction is destined for his blockchain by reading the first byte of the signature. The next one Bill made was to recalculate the public address from a signature and compare it with the from field of the transaction to verify if the request is valid. While building this, Bill demonstrates how a user’s private key transforms into their public address.
Continue reading