4irelabs-blackchain-smart-contract
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -17,3 +17,18 @@ /// <reference types="bn.js" /> | ||
hireCharacter(name: string, clas: Clas): Promise<Character | BCResult>; | ||
scoutDungeon(difficulty: Difficulty, level: Number): Promise<Character | BCResult>; | ||
scoutDungeon(difficulty: Difficulty, character: PublicKey): Promise<Dungeon | BCResult>; | ||
lockCharacter(character: PublicKey): Promise<BCResult>; | ||
lockWeapon(weapon: PublicKey): Promise<BCResult>; | ||
lockArmor(armor: PublicKey): Promise<BCResult>; | ||
lockShield(shield: PublicKey): Promise<BCResult>; | ||
lockDungeon(dungeon: PublicKey): Promise<BCResult>; | ||
unlockCharacter(character: PublicKey): Promise<BCResult>; | ||
unlockWeapon(weapon: PublicKey): Promise<BCResult>; | ||
unlockArmor(armor: PublicKey): Promise<BCResult>; | ||
unlockShield(shield: PublicKey): Promise<BCResult>; | ||
unlockDungeon(dungeon: PublicKey): Promise<BCResult>; | ||
transferCharacter(character: PublicKey, receiver: PublicKey): Promise<BCResult>; | ||
transferWeapon(weapon: PublicKey, receiver: PublicKey): Promise<BCResult>; | ||
transferArmor(armor: PublicKey, receiver: PublicKey): Promise<BCResult>; | ||
transferShield(shield: PublicKey, receiver: PublicKey): Promise<BCResult>; | ||
transferDungeon(dungeon: PublicKey, receiver: PublicKey): Promise<BCResult>; | ||
getPlayerAccountPublicKey(address?: PublicKey): Promise<PublicKey>; | ||
@@ -20,0 +35,0 @@ getPlayerAccount(address?: PublicKey): Promise<PlayerAccount | null>; |
@@ -35,2 +35,3 @@ "use strict"; | ||
exports.BC = void 0; | ||
const types_1 = require("./types"); | ||
const Anchor = __importStar(require("@project-serum/anchor")); | ||
@@ -77,3 +78,2 @@ const blackchain_program_1 = require("../idl/blackchain_program"); | ||
}); | ||
console.log(this.program.programId.toString()); | ||
const associated_account = yield (0, utils_1.getGoldAssociatedPublicKey)(this.provider.wallet.publicKey, this.programId); | ||
@@ -146,6 +146,12 @@ const [goldMint, bump] = yield (0, utils_1.getGoldMintPublicKey)(this.programId); | ||
const weapon = web3_js_1.Keypair.generate(); | ||
const armor = web3_js_1.Keypair.generate(); | ||
const characterIndex = (yield this.program.account.playerAccount.fetch(playerPubkey)).characters.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
const weaponIndex = (yield this.program.account.playerAccount.fetch(playerPubkey)).weapons.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
const armorIndex = (yield this.program.account.playerAccount.fetch(playerPubkey)).armors.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
const chest_armor = web3_js_1.Keypair.generate(); | ||
const head_armor = web3_js_1.Keypair.generate(); | ||
const boots_armor = web3_js_1.Keypair.generate(); | ||
const playerAccount = yield this.program.account.playerAccount.fetch(playerPubkey); | ||
const characterIndex = playerAccount.characters.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
const weaponIndex = playerAccount.weapons.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
const freeIndexes = playerAccount.armors | ||
.map((key, index) => [key, index]) | ||
.filter((key) => key[0].toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
console.log(freeIndexes[0][1], freeIndexes[1][1], freeIndexes[2][1]); | ||
const nameToBytes = new Uint8Array(20); | ||
@@ -155,15 +161,52 @@ nameToBytes.set(name.split("").map((ch) => ch.charCodeAt(0))); | ||
try { | ||
yield this.program.rpc.hireCharacter(new anchor_1.BN(characterIndex), new anchor_1.BN(weaponIndex), new anchor_1.BN(armorIndex), clas, nameToBytes, pdaBump, { | ||
accounts: { | ||
characterAccount: character.publicKey, | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID, | ||
systemProgram: web3_js_1.SystemProgram.programId, | ||
program: feePdaAccount, | ||
weaponAccount: weapon.publicKey, | ||
chestAccount: armor.publicKey, | ||
}, | ||
signers: [character, weapon, armor], | ||
}); | ||
if ((0, types_1.enumEq)(clas, types_1.ClassEnum.Templar)) { | ||
const shield = web3_js_1.Keypair.generate(); | ||
const shieldIndex = playerAccount.weapons.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
yield this.program.rpc.hireCharacter(new anchor_1.BN(characterIndex), new anchor_1.BN(weaponIndex), new anchor_1.BN(shieldIndex), [ | ||
new anchor_1.BN(freeIndexes[0][1]), | ||
new anchor_1.BN(freeIndexes[1][1]), | ||
new anchor_1.BN(freeIndexes[2][1]), | ||
], clas, nameToBytes, { | ||
accounts: { | ||
characterAccount: character.publicKey, | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
systemProgram: web3_js_1.SystemProgram.programId, | ||
program: feePdaAccount, | ||
weaponAccount: weapon.publicKey, | ||
chestAccount: chest_armor.publicKey, | ||
bootsAccount: boots_armor.publicKey, | ||
headAccount: head_armor.publicKey, | ||
shieldAccount: shield.publicKey, | ||
}, | ||
signers: [ | ||
character, | ||
weapon, | ||
chest_armor, | ||
head_armor, | ||
boots_armor, | ||
shield, | ||
], | ||
}); | ||
} | ||
else { | ||
yield this.program.rpc.hireCharacterWithoutShield(new anchor_1.BN(characterIndex), new anchor_1.BN(weaponIndex), [ | ||
new anchor_1.BN(freeIndexes[0][1]), | ||
new anchor_1.BN(freeIndexes[1][1]), | ||
new anchor_1.BN(freeIndexes[2][1]), | ||
], clas, nameToBytes, { | ||
accounts: { | ||
characterAccount: character.publicKey, | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
systemProgram: web3_js_1.SystemProgram.programId, | ||
program: feePdaAccount, | ||
weaponAccount: weapon.publicKey, | ||
chestAccount: chest_armor.publicKey, | ||
bootsAccount: boots_armor.publicKey, | ||
headAccount: head_armor.publicKey, | ||
}, | ||
signers: [character, weapon, chest_armor, head_armor, boots_armor], | ||
}); | ||
} | ||
} | ||
@@ -184,3 +227,3 @@ catch (e) { | ||
} | ||
scoutDungeon(difficulty, level) { | ||
scoutDungeon(difficulty, character) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -194,10 +237,10 @@ if (!this.isMut) | ||
try { | ||
yield this.program.rpc.scoutDungeon(new anchor_1.BN(dungeonIndex), difficulty, level, { | ||
yield this.program.rpc.scoutDungeon(new anchor_1.BN(dungeonIndex), difficulty, { | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID, | ||
systemProgram: web3_js_1.SystemProgram.programId, | ||
program: feePdaAccount, | ||
dungeonAccount: dungeon.publicKey, | ||
characterAccount: character, | ||
}, | ||
@@ -221,27 +264,427 @@ signers: [dungeon], | ||
} | ||
// async hireCharacterRandom(index: Anchor.BN): Promise<void> { | ||
// if (!this.isMut) throw new Error("No wallet"); | ||
// const playerPubkey = await this.getPlayerAccountPublicKey( | ||
// this.provider.wallet.publicKey, | ||
// this.programId | ||
// ); | ||
// const character = Keypair.generate(); | ||
// await this.program.rpc.hireCharacterRandom( | ||
// index, | ||
// new BN( | ||
// Math.floor( | ||
// Math.random() * (Date.now() / 1000 - 1643454547 + 1) + 1643454547 | ||
// ) | ||
// ), | ||
// { | ||
// accounts: { | ||
// characterAccount: character.publicKey, | ||
// playerAccount: playerPubkey, | ||
// user: this.provider.wallet.publicKey, | ||
// systemProgram: SystemProgram.programId, | ||
// }, | ||
// signers: [character], | ||
// } | ||
// ); | ||
// } | ||
lockCharacter(character) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.lockCharacter({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
characterAccount: character, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
lockWeapon(weapon) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.lockWeapon({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
weaponAccount: weapon, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
lockArmor(armor) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.lockArmor({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
armorAccount: armor, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
lockShield(shield) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.lockShield({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
shieldAccount: shield, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
lockDungeon(dungeon) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.lockDungeon({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
dungeonAccount: dungeon, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
unlockCharacter(character) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.unlockCharacter({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
characterAccount: character, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
unlockWeapon(weapon) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.unlockWeapon({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
weaponAccount: weapon, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
unlockArmor(armor) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.unlockArmor({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
armorAccount: armor, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
unlockShield(shield) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.unlockShield({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
shieldAccount: shield, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
unlockDungeon(dungeon) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
try { | ||
yield this.program.rpc.unlockDungeon({ | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
dungeonAccount: dungeon, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
transferCharacter(character, receiver) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
const receiverPlayerPubkey = yield this.getPlayerAccountPublicKey(receiver); | ||
const characterIndex = (yield this.program.account.playerAccount.fetch(playerPubkey)).characters.findIndex((key) => key.toString() == character.toString()); | ||
const freeIndex = (yield this.program.account.playerAccount.fetch(receiverPlayerPubkey)).characters.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
try { | ||
yield this.program.rpc.transferCharacter(new anchor_1.BN(characterIndex), new anchor_1.BN(freeIndex), { | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
characterAccount: character, | ||
receiver: receiverPlayerPubkey, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
transferWeapon(weapon, receiver) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
const receiverPlayerPubkey = yield this.getPlayerAccountPublicKey(receiver); | ||
const weaponIndex = (yield this.program.account.playerAccount.fetch(playerPubkey)).weapons.findIndex((key) => key.toString() == weapon.toString()); | ||
const freeIndex = (yield this.program.account.playerAccount.fetch(receiverPlayerPubkey)).weapons.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
try { | ||
yield this.program.rpc.transferWeapon(new anchor_1.BN(weaponIndex), new anchor_1.BN(freeIndex), { | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
weaponAccount: weapon, | ||
receiver: receiverPlayerPubkey, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
transferArmor(armor, receiver) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
const receiverPlayerPubkey = yield this.getPlayerAccountPublicKey(receiver); | ||
const armorIndex = (yield this.program.account.playerAccount.fetch(playerPubkey)).armors.findIndex((key) => key.toString() == armor.toString()); | ||
const freeIndex = (yield this.program.account.playerAccount.fetch(receiverPlayerPubkey)).armors.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
try { | ||
yield this.program.rpc.transferArmor(new anchor_1.BN(armorIndex), new anchor_1.BN(freeIndex), { | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
armorAccount: armor, | ||
receiver: receiverPlayerPubkey, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
transferShield(shield, receiver) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
const receiverPlayerPubkey = yield this.getPlayerAccountPublicKey(receiver); | ||
const shieldIndex = (yield this.program.account.playerAccount.fetch(playerPubkey)).shields.findIndex((key) => key.toString() == shield.toString()); | ||
const freeIndex = (yield this.program.account.playerAccount.fetch(receiverPlayerPubkey)).shields.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
try { | ||
yield this.program.rpc.transferShield(new anchor_1.BN(shieldIndex), new anchor_1.BN(freeIndex), { | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
shieldAccount: shield, | ||
receiver: receiverPlayerPubkey, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
transferDungeon(dungeon, receiver) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const playerPubkey = yield this.getPlayerAccountPublicKey(this.provider.wallet.publicKey); | ||
const receiverPlayerPubkey = yield this.getPlayerAccountPublicKey(receiver); | ||
const dungeonIndex = (yield this.program.account.playerAccount.fetch(playerPubkey)).dungeons.findIndex((key) => key.toString() == dungeon.toString()); | ||
const freeIndex = (yield this.program.account.playerAccount.fetch(receiverPlayerPubkey)).dungeons.findIndex((key) => key.toString() == constants_1.DEFAULT_PUBLIC_KEY); | ||
try { | ||
yield this.program.rpc.transferDungeon(new anchor_1.BN(dungeonIndex), new anchor_1.BN(freeIndex), { | ||
accounts: { | ||
playerAccount: playerPubkey, | ||
user: this.provider.wallet.publicKey, | ||
dungeonAccount: dungeon, | ||
receiver: receiverPlayerPubkey, | ||
}, | ||
signers: [], | ||
}); | ||
return { status: true, error: null }; | ||
} | ||
catch (e) { | ||
const error = e; | ||
let BCerror; | ||
if (constants_1.ErrorsRegex.NotEnoughRooms.test(error.message)) | ||
BCerror = 1 /* NotEnoughRooms */; | ||
else if (constants_1.ErrorsRegex.NotEnoughTokens.test(error.message)) | ||
BCerror = 2 /* NotEnoughTokens */; | ||
else | ||
BCerror = 0 /* AccountNotExist */; | ||
return { status: false, error: BCerror }; | ||
} | ||
}); | ||
} | ||
getPlayerAccountPublicKey(address = this.provider.wallet.publicKey) { | ||
@@ -248,0 +691,0 @@ return __awaiter(this, void 0, void 0, function* () { |
export declare const DEFAULT_PUBLIC_KEY = "11111111111111111111111111111111"; | ||
export declare const PLAYER_ACCOUNT_SPACE = 19257; | ||
export declare const PLAYER_ACCOUNT_SPACE = 22457; | ||
export declare const Cluster: { | ||
@@ -4,0 +4,0 @@ localnet: string; |
@@ -6,3 +6,3 @@ "use strict"; | ||
exports.DEFAULT_PUBLIC_KEY = "11111111111111111111111111111111"; | ||
exports.PLAYER_ACCOUNT_SPACE = 19257; | ||
exports.PLAYER_ACCOUNT_SPACE = 22457; | ||
exports.Cluster = { | ||
@@ -9,0 +9,0 @@ localnet: "http://127.0.0.1:8899", |
@@ -7,5 +7,6 @@ /// <reference types="bn.js" /> | ||
export declare type PlayerAccount = TypeDef<BlackchainProgram["accounts"]["3"], Anchor.IdlTypes<BlackchainProgram>>; | ||
export declare type Weapon = TypeDef<BlackchainProgram["accounts"]["5"], Anchor.IdlTypes<BlackchainProgram>>; | ||
export declare type Weapon = TypeDef<BlackchainProgram["accounts"]["6"], Anchor.IdlTypes<BlackchainProgram>>; | ||
export declare type Armor = TypeDef<BlackchainProgram["accounts"]["0"], Anchor.IdlTypes<BlackchainProgram>>; | ||
export declare type Dungeon = TypeDef<BlackchainProgram["accounts"]["2"], Anchor.IdlTypes<BlackchainProgram>>; | ||
export declare type Shield = TypeDef<BlackchainProgram["accounts"]["4"], Anchor.IdlTypes<BlackchainProgram>>; | ||
export declare function enumEq<T>(fst: T, snd: T): boolean; | ||
@@ -193,2 +194,8 @@ export declare const RankEnum: { | ||
export declare const WeaponTypeEnum: { | ||
BluntedSword: { | ||
bluntedSword: {}; | ||
}; | ||
BluntedKnife: { | ||
bluntedKnife: {}; | ||
}; | ||
ShortSword: { | ||
@@ -305,2 +312,5 @@ shortSword: {}; | ||
}; | ||
CrackedStaff: { | ||
crackedStaff: {}; | ||
}; | ||
WoodStaff: { | ||
@@ -366,2 +376,11 @@ woodStaff: {}; | ||
export declare const ArmorTypeEnum: { | ||
DirtySandals: { | ||
dirtySandals: {}; | ||
}; | ||
DirtyCap: { | ||
dirtyCap: {}; | ||
}; | ||
DirtyCloak: { | ||
dirtyCloak: {}; | ||
}; | ||
ApprenticesRobe: { | ||
@@ -454,2 +473,11 @@ apprenticesRobe: {}; | ||
}; | ||
DirtyBoots: { | ||
dirtyBoots: {}; | ||
}; | ||
DirtyHat: { | ||
dirtyHat: {}; | ||
}; | ||
DirtyJacket: { | ||
dirtyJacket: {}; | ||
}; | ||
OldJacket: { | ||
@@ -551,2 +579,11 @@ oldJacket: {}; | ||
}; | ||
DirtySabatons: { | ||
dirtySabatons: {}; | ||
}; | ||
DirtyHelmet: { | ||
dirtyHelmet: {}; | ||
}; | ||
DirtyPlatemail: { | ||
dirtyPlatemail: {}; | ||
}; | ||
WornBreastplate: { | ||
@@ -729,32 +766,95 @@ wornBreastplate: {}; | ||
export declare type MainStat = typeof MainStatEnum[keyof typeof MainStatEnum]; | ||
export declare type a = TypeDef<{ | ||
name: "WeaponsType"; | ||
type: { | ||
kind: "enum"; | ||
variants: [ | ||
{ | ||
name: "H1"; | ||
fields: [ | ||
{ | ||
name: "value"; | ||
type: { | ||
defined: "MainStat"; | ||
}; | ||
} | ||
]; | ||
}, | ||
{ | ||
name: "H2"; | ||
fields: [ | ||
{ | ||
name: "value"; | ||
type: { | ||
defined: "MainStat"; | ||
}; | ||
} | ||
]; | ||
} | ||
]; | ||
export declare const ShieldsEnum: { | ||
CrackedShield: { | ||
crackedShield: {}; | ||
}; | ||
}, Anchor.IdlTypes<BlackchainProgram>>; | ||
WoodShield: { | ||
woodShield: {}; | ||
}; | ||
IronShield: { | ||
ironShield: {}; | ||
}; | ||
ShieldOfForgottenFaith: { | ||
shieldOfForgottenFaith: {}; | ||
}; | ||
CursedShield: { | ||
cursedShield: {}; | ||
}; | ||
OrichalcumShield: { | ||
orichalcumShield: {}; | ||
}; | ||
SunOfTheNorth: { | ||
sunOfTheNorth: {}; | ||
}; | ||
FaithfulProtector: { | ||
faithfulProtector: {}; | ||
}; | ||
Adamantinum: { | ||
adamantinum: {}; | ||
}; | ||
ShieldOfTheRedMists: { | ||
shieldOfTheRedMists: {}; | ||
}; | ||
TheRuler: { | ||
theRuler: {}; | ||
}; | ||
}; | ||
export declare type Shields = typeof ShieldsEnum[keyof typeof ShieldsEnum]; | ||
export declare const EnemyRaceEnum: { | ||
Undead: { | ||
Undead: {}; | ||
}; | ||
Demon: { | ||
Demon: {}; | ||
}; | ||
Humanoid: { | ||
Humanoid: {}; | ||
}; | ||
UndeadVampire: { | ||
UndeadVampire: {}; | ||
}; | ||
}; | ||
export declare type EnemyRace = typeof EnemyRaceEnum[keyof typeof EnemyRaceEnum]; | ||
export declare const EnemyTypeEnum: { | ||
UndeadWarrior: { | ||
undeadWarrior: {}; | ||
}; | ||
Ghoul: { | ||
ghoul: {}; | ||
}; | ||
Imp: { | ||
imp: {}; | ||
}; | ||
Harpy: { | ||
harpy: {}; | ||
}; | ||
Witch: { | ||
witch: {}; | ||
}; | ||
Vampire: { | ||
vampire: {}; | ||
}; | ||
Abomination: { | ||
abomination: {}; | ||
}; | ||
HarpyQueen: { | ||
harpyQueen: {}; | ||
}; | ||
AncientVampire: { | ||
ancientVampire: {}; | ||
}; | ||
UndeadGeneral: { | ||
undeadGeneral: {}; | ||
}; | ||
Lich: { | ||
lich: {}; | ||
}; | ||
GraveyardDemon: { | ||
graveyardDemon: {}; | ||
}; | ||
Werewolf: { | ||
werewolf: {}; | ||
}; | ||
}; | ||
export declare type EnemyType = typeof EnemyTypeEnum[keyof typeof EnemyTypeEnum]; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MainStatEnum = exports.WeaponsWearingTypeEnum = exports.WorldEnum = exports.TrapTypeEnum = exports.DamageTypeEnum = exports.TurnWayEnum = exports.ArmorWearingTypeEnum = exports.StatusEnum = exports.ArmorTypeEnum = exports.WeaponTypeEnum = exports.BonusTypeEnum = exports.StatEnum = exports.DifficultyEnum = exports.ClassEnum = exports.RankEnum = exports.enumEq = void 0; | ||
exports.EnemyTypeEnum = exports.EnemyRaceEnum = exports.ShieldsEnum = exports.MainStatEnum = exports.WeaponsWearingTypeEnum = exports.WorldEnum = exports.TrapTypeEnum = exports.DamageTypeEnum = exports.TurnWayEnum = exports.ArmorWearingTypeEnum = exports.StatusEnum = exports.ArmorTypeEnum = exports.WeaponTypeEnum = exports.BonusTypeEnum = exports.StatEnum = exports.DifficultyEnum = exports.ClassEnum = exports.RankEnum = exports.enumEq = void 0; | ||
function enumEq(fst, snd) { | ||
@@ -78,2 +78,4 @@ return JSON.stringify(fst) === JSON.stringify(snd); | ||
// | ||
BluntedSword: { bluntedSword: {} }, | ||
BluntedKnife: { bluntedKnife: {} }, | ||
ShortSword: { shortSword: {} }, | ||
@@ -119,2 +121,3 @@ Longsword: { longsword: {} }, | ||
// | ||
CrackedStaff: { crackedStaff: {} }, | ||
WoodStaff: { woodStaff: {} }, | ||
@@ -141,2 +144,5 @@ ApprenticesStaff: { apprenticesStaff: {} }, | ||
exports.ArmorTypeEnum = { | ||
DirtySandals: { dirtySandals: {} }, | ||
DirtyCap: { dirtyCap: {} }, | ||
DirtyCloak: { dirtyCloak: {} }, | ||
ApprenticesRobe: { apprenticesRobe: {} }, | ||
@@ -171,2 +177,6 @@ OldMantle: { oldMantle: {} }, | ||
BootsOf5Elements: { bootsOf5Elements: {} }, | ||
//medium | ||
DirtyBoots: { dirtyBoots: {} }, | ||
DirtyHat: { dirtyHat: {} }, | ||
DirtyJacket: { dirtyJacket: {} }, | ||
OldJacket: { oldJacket: {} }, | ||
@@ -204,2 +214,6 @@ ShabbyVest: { shabbyVest: {} }, | ||
DuskHelmet: { duskHelmet: {} }, | ||
//heavy | ||
DirtySabatons: { dirtySabatons: {} }, | ||
DirtyHelmet: { dirtyHelmet: {} }, | ||
DirtyPlatemail: { dirtyPlatemail: {} }, | ||
WornBreastplate: { wornBreastplate: {} }, | ||
@@ -283,2 +297,35 @@ RustyChainMail: { rustyChainMail: {} }, | ||
}; | ||
//let b = WeaponsWearingTypeEnum.H1(MainStatEnum.Agi) as a; | ||
exports.ShieldsEnum = { | ||
CrackedShield: { crackedShield: {} }, | ||
WoodShield: { woodShield: {} }, | ||
IronShield: { ironShield: {} }, | ||
ShieldOfForgottenFaith: { shieldOfForgottenFaith: {} }, | ||
CursedShield: { cursedShield: {} }, | ||
OrichalcumShield: { orichalcumShield: {} }, | ||
SunOfTheNorth: { sunOfTheNorth: {} }, | ||
FaithfulProtector: { faithfulProtector: {} }, | ||
Adamantinum: { adamantinum: {} }, | ||
ShieldOfTheRedMists: { shieldOfTheRedMists: {} }, | ||
TheRuler: { theRuler: {} }, | ||
}; | ||
exports.EnemyRaceEnum = { | ||
Undead: { Undead: {} }, | ||
Demon: { Demon: {} }, | ||
Humanoid: { Humanoid: {} }, | ||
UndeadVampire: { UndeadVampire: {} }, | ||
}; | ||
exports.EnemyTypeEnum = { | ||
UndeadWarrior: { undeadWarrior: {} }, | ||
Ghoul: { ghoul: {} }, | ||
Imp: { imp: {} }, | ||
Harpy: { harpy: {} }, | ||
Witch: { witch: {} }, | ||
Vampire: { vampire: {} }, | ||
Abomination: { abomination: {} }, | ||
HarpyQueen: { harpyQueen: {} }, | ||
AncientVampire: { ancientVampire: {} }, | ||
UndeadGeneral: { undeadGeneral: {} }, | ||
Lich: { lich: {} }, | ||
GraveyardDemon: { graveyardDemon: {} }, | ||
Werewolf: { werewolf: {} }, | ||
}; |
{ | ||
"name": "4irelabs-blackchain-smart-contract", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "Integration with Solana API", | ||
@@ -5,0 +5,0 @@ "author": "", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
274941
8711