Skip to content

Commit

Permalink
fix: solve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dnielopez committed Oct 14, 2023
2 parents 9b52d11 + 1acdc54 commit 37c5145
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 8 deletions.
22 changes: 22 additions & 0 deletions lib/anchor_types/dino_game_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:borsh_annotation/borsh_annotation.dart';
import 'package:solana/solana.dart';

part 'dino_game_info.g.dart';


@BorshSerializable()
class DinoGameArguments with _$DinoGameArguments {
factory DinoGameArguments(
{
@BU64() required BigInt score,
@BU64() required BigInt game,
@BPublicKey() required Ed25519HDPublicKey playerPubkey,
@BPublicKey() required Ed25519HDPublicKey dinoPubkey,

}) = _DinoGameArguments;

const DinoGameArguments._();

factory DinoGameArguments.fromBorsh(Uint8List data) =>
_$DinoGameArgumentsFromBorsh(data);
}
64 changes: 64 additions & 0 deletions lib/anchor_types/dino_game_info.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions lib/anchor_types/dino_score_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:borsh_annotation/borsh_annotation.dart';
import 'package:solana/solana.dart';

part 'dino_score_info.g.dart';


@BorshSerializable()
class DinoScoreArguments with _$DinoScoreArguments {
factory DinoScoreArguments(
{
@BU64() required BigInt score,
@BU32() required int gamescore,
@BPublicKey() required Ed25519HDPublicKey playerPubkey,
@BPublicKey() required Ed25519HDPublicKey dinoPubkey,
}) = _DinoScoreArguments;

const DinoScoreArguments._();

factory DinoScoreArguments.fromBorsh(Uint8List data) =>
_$DinoScoreArgumentsFromBorsh(data);
}
64 changes: 64 additions & 0 deletions lib/anchor_types/dino_score_info.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/anchor_types/score_parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ScoreArguments with _$ScoreArguments {
factory ScoreArguments(
{
@BU32() required int game,
@BU64() required BigInt score,
@BU32() required int score,
}) = _ScoreArguments;

const ScoreArguments._();
Expand Down
8 changes: 4 additions & 4 deletions lib/anchor_types/score_parameters.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 48 additions & 3 deletions lib/pages/my-dinogrow/my_dinogrow.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:solana/dto.dart';
import 'package:solana/solana.dart';

import '../../anchor_types/score_parameters.dart' as anchor_types_parameters;
import '../../anchor_types/dino_score_info.dart' as anchor_types_dino;
import '../../anchor_types/dino_game_info.dart' as anchor_types_dino_game;
import '../../ui/widgets/widgets.dart';

import 'dart:math';
import 'package:solana/solana.dart' as solana;
import 'package:solana/anchor.dart' as solana_anchor;
import 'package:solana/encoder.dart' as solana_encoder;
import 'package:solana_common/borsh/borsh.dart' as solana_borsh;
import 'package:solana_common/utils/buffer.dart' as solana_buffer;
import '../../anchor_types/nft_parameters.dart' as anchor_types;

Expand Down Expand Up @@ -52,6 +57,10 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
// text: 'Save Score',
// onPressed: saveScore,
// ),
// IntroButtonWidget(
// text: 'Get Ranking',
// onPressed: getRanking,
// ),
const SizedBox(height: 30),
Container(
color: Colors.orange[700],
Expand Down Expand Up @@ -475,7 +484,7 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {

//direccion mint del DINO
final dinoTest = solana.Ed25519HDPublicKey.fromBase58(
"2tGzpAbJVuB91dzJbUG7m45F88WqswcbznqP2KBZcurw");
"GM3EGmMCYjZs7UstuJ1fvF1Pkocn9GV34BnTGabB8Maf");

final programIdPublicKey = solana.Ed25519HDPublicKey.fromBase58(programId);

Expand All @@ -496,7 +505,7 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
arguments:
solana_encoder.ByteArray(anchor_types_parameters.ScoreArguments(
game: 1,
score: BigInt.from(100),
score: 1120,
).toBorsh().toList()),
accounts: <solana_encoder.AccountMeta>[
solana_encoder.AccountMeta.writeable(
Expand All @@ -519,4 +528,40 @@ class _MydinogrowScreenState extends State<MydinogrowScreen> {
);
print('Tx successful with hash: $signature');
}

getRanking() async {
//Get rank from blockchain
await dotenv.load(fileName: ".env");

SolanaClient? client;
client = SolanaClient(
rpcUrl: Uri.parse(dotenv.env['QUICKNODE_RPC_URL'].toString()),
websocketUrl: Uri.parse(dotenv.env['QUICKNODE_RPC_WSS'].toString()),
);

const programId = '9V9ttZw7WTYW78Dx3hi2hV7V76PxAs5ZwbCkGi7qq8FW';

// Obtener todas las cuentas del programa
final accounts = await client.rpcClient.getProgramAccounts(
programId,
encoding: Encoding.jsonParsed,
);

// Recorre las cuentas y muestra los datos
for (var account in accounts) {
final bytes = account.account.data as BinaryAccountData;

//Get Score
final decoderDataScore = anchor_types_dino.DinoScoreArguments.fromBorsh(
bytes.data as Uint8List);
print("score: ${decoderDataScore.gamescore}");

//Get Game Data
final decoderDataGame =
anchor_types_dino_game.DinoGameArguments.fromBorsh(
bytes.data as Uint8List);
print("score: ${decoderDataGame.playerPubkey}");
print("score: ${decoderDataGame.dinoPubkey}");
}
}
}

0 comments on commit 37c5145

Please sign in to comment.