-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9abe688
commit 3c7f7e1
Showing
18 changed files
with
277 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package onchain | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/massalabs/station/pkg/convert" | ||
) | ||
|
||
type DatastoreContract struct { | ||
Data []byte | ||
Args []byte | ||
Coins uint64 | ||
} | ||
|
||
// smartContractNumberKey := []bytes(0) | ||
|
||
/** | ||
* Generates a key for coin data in the datastore. | ||
* | ||
* @param offset - The offset to use when generating the key. | ||
* @returns A Uint8Array representing the key. | ||
*/ | ||
func coinsKey(offset int) []byte { | ||
byteArray := []byte{} | ||
byteArray = append(byteArray, convert.U64ToBytes(offset+1)...) | ||
byteArray = append(byteArray, []byte{1}...) | ||
return byteArray | ||
} | ||
|
||
/** | ||
* Generates a key for args data in the datastore. | ||
* | ||
* @param offset - The offset to use when generating the key. | ||
* @returns A Uint8Array representing the key. | ||
*/ | ||
func argsKey(offset int) []byte { | ||
byteArray := []byte{} | ||
byteArray = append(byteArray, convert.U64ToBytes(offset+1)...) | ||
byteArray = append(byteArray, []byte{0}...) | ||
return byteArray | ||
} | ||
|
||
/** | ||
* Generates a key for contract data in the datastore. | ||
* | ||
* @param offset - The offset to use when generating the key. | ||
* @returns A Uint8Array representing the key. | ||
*/ | ||
func contractKey(offset int) []byte { | ||
byteArray := []byte{} | ||
return append(byteArray, convert.U64ToBytes(offset+1)...) | ||
} | ||
|
||
/** | ||
* Populates the datastore with the contracts. | ||
* | ||
* @remarks | ||
* This function is to be used in conjunction with the deployer smart contract. | ||
* The deployer smart contract expects to have an execution datastore in a specific state. | ||
* This function populates the datastore according to that expectation. | ||
* | ||
* @param contracts - The contracts to populate the datastore with. | ||
* | ||
* @returns The populated datastore. | ||
*/ | ||
|
||
func populateDatastore(contracts []DatastoreContract) (map[string][]byte, error) { | ||
if len(contracts) == 0 { | ||
return nil, fmt.Errorf("contracts slice is empty with a length of: %v", len(contracts)) | ||
} | ||
|
||
datastore := make(map[string][]byte) | ||
contractNumberKey := []byte{0} | ||
|
||
// Set the number of contracts in the first key of the datastore | ||
datastore[string(convert.ToString(contractNumberKey))] = convert.U64ToBytes(len(contracts)) | ||
// TODO something is bugged here | ||
for i, contract := range contracts { | ||
datastore[convert.ToString(contractKey(i))] = contract.Data | ||
datastore[convert.ToString(argsKey(i))] = contract.Args | ||
datastore[convert.ToString(coinsKey(i))] = convert.U64ToBytes(int(contract.Coins)) | ||
} | ||
|
||
return datastore, nil | ||
} |
Oops, something went wrong.