16
16
using Phantasma . Domain ;
17
17
using Phantasma . Core . Utils ;
18
18
using Phantasma . Core . Performance ;
19
- using Phantasma . Contracts ;
20
- using Phantasma . Contracts . Native ;
21
19
22
20
namespace Phantasma . Blockchain
23
21
{
@@ -64,7 +62,7 @@ public IContract[] GetContracts(StorageContext storage)
64
62
{
65
63
var contractList = new StorageList ( GetContractListKey ( ) , storage ) ;
66
64
var addresses = contractList . All < Address > ( ) ;
67
- return addresses . Select ( x => Nexus . GetContractByAddress ( Nexus . RootStorage , x ) ) . ToArray ( ) ;
65
+ return addresses . Select ( x => Nexus . GetContractByAddress ( x ) ) . ToArray ( ) ;
68
66
}
69
67
70
68
public override string ToString ( )
@@ -424,14 +422,13 @@ internal ExecutionContext GetContractContext(StorageContext storage, SmartContra
424
422
throw new ChainException ( $ "contract { contract . Name } not deployed on { Name } chain") ;
425
423
}
426
424
427
- // TODO this needs to suport non-native contexts too..
428
- var context = new NativeExecutionContext ( contract ) ;
425
+ var context = contract . CreateContext ( ) ;
429
426
return context ;
430
427
}
431
428
432
429
public VMObject InvokeContract ( StorageContext storage , string contractName , string methodName , Timestamp time , params object [ ] args )
433
430
{
434
- var contract = Nexus . GetContractByName ( storage , contractName ) ;
431
+ var contract = Nexus . GetContractByName ( contractName ) ;
435
432
Throw . IfNull ( contract , nameof ( contract ) ) ;
436
433
437
434
var script = ScriptUtils . BeginScript ( ) . CallContract ( contractName , methodName , args ) . EndScript ( ) ;
@@ -574,7 +571,7 @@ public bool IsContractDeployed(StorageContext storage, Address contractAddress)
574
571
return storage . Has ( key ) ;
575
572
}
576
573
577
- private bool DeployContractScript ( StorageContext storage , Address contractAddress , byte [ ] script )
574
+ public bool DeployContractScript ( StorageContext storage , Address contractAddress , byte [ ] script )
578
575
{
579
576
var key = GetContractDeploymentKey ( contractAddress ) ;
580
577
if ( storage . Has ( key ) )
@@ -590,23 +587,22 @@ private bool DeployContractScript(StorageContext storage, Address contractAddres
590
587
return true ;
591
588
}
592
589
593
- public bool DeployNativeContract ( StorageContext storage , Address contractAddress )
590
+ public SmartContract GetContractByName ( StorageContext storage , string name )
594
591
{
595
- var contract = Nexus . GetContractByAddress ( storage , contractAddress ) ;
596
- if ( contract == null )
592
+ if ( Nexus . IsNativeContract ( name ) )
597
593
{
598
- return false ;
594
+ return Nexus . GetContractByName ( name ) ;
599
595
}
600
596
601
- DeployContractScript ( storage , contractAddress , new byte [ ] { ( byte ) Opcode . RET } ) ;
602
- return true ;
603
- }
597
+ var address = SmartContract . GetAddressForName ( name ) ;
598
+ var key = GetContractDeploymentKey ( address ) ;
599
+ if ( ! storage . Has ( key ) )
600
+ {
601
+ return null ;
602
+ }
604
603
605
- public bool DeployContract ( StorageContext storage , byte [ ] script )
606
- {
607
- var contractAddress = Address . FromHash ( script ) ;
608
- DeployContractScript ( storage , contractAddress , script ) ;
609
- return true ;
604
+ var script = storage . Get ( key ) ;
605
+ return new CustomContract ( name , script ) ;
610
606
}
611
607
#endregion
612
608
0 commit comments