solidity – Can’t access an object of another contract

So I want to deploy an instance of a Token contract and then use my Swap contract to call methods from that instance of Token. However, whenever I try to use Token a = Token(deploymentAddress), the token a does not share the deployed instance’s properties and I cannot call its functions with expected results.

import "github.com/OpenZeppelin/zeppelin-solidity/contracts/math/SafeMath.sol"; 

contract Token{
    
    uint256 private tokenPrice;
    uint256 private totalTokens = 0; // The total number of tokens in circulation   
    address private owner;
    
    mapping (address => uint256) private ownership;
    

    constructor(uint256 price) public payable{
        
        owner = msg.sender;
        tokenPrice = price;
    
    }
        
    function buyToken(uint256 amount) public payable returns(bool){
        
        //Authorisation:
        
       require (msg.value == SafeMath.mul(tokenPrice,amount) ); 

        // Buy Token:
        
       ownership(msg.sender) = SafeMath.add(ownership(msg.sender), amount);  
            
       totalTokens = SafeMath.add(totalTokens, amount); //At the end of the function to prevent re-entrancy attacks from artificially increasing the supply
       
       emit Purchase(msg.sender, amount);
       
       return true;    
    }
        
    function transfer(address recipient, uint256 amount) public payable returns(bool){
        
       // require (ownership(msg.sender) >= amount );
            
        ownership(recipient) = SafeMath.add(ownership(recipient),amount);   // Put recipient first to prevent a cancellation attack form the sender
            
        ownership(msg.sender) = SafeMath.sub(ownership(msg.sender),amount); 
        
        emit Transfer(msg.sender, recipient, amount);
        
        return true;
    }    
        
    function changePrice(uint256 price) public payable returns(bool){
            
        require (msg.sender == owner && SafeMath.mul(price,totalTokens) <= address(this).balance);
                
        tokenPrice = price;
        
        emit Price(price);
        
        return true;
                
            
        }
        
    function getBalance() external view returns(uint256){
            
        return ownership(msg.sender);
            
        }
        
        
    function sellToken(uint256 amount) public payable returns (bool){
            
        require (amount <= ownership(msg.sender));
            
        ownership(msg.sender) = SafeMath.sub(ownership(msg.sender),amount); // Put first to prevent reentrancy
            
        uint256 payout = SafeMath.mul(tokenPrice, amount);
        
        totalTokens = SafeMath.sub(totalTokens,amount); // First to prevent reentrancy
        msg.sender.transfer(payout);
        
            
        emit Sell (msg.sender, amount);    
            
        return true;    
        
            
        }
        
    
    
    // Events
    
    event Purchase(
        
        address buyer,
        uint256 amount
        
        );
        
    event Transfer(
        
        address sender,
        address receiver,
        uint256 amount
        
        );
    
    event Sell(
        
        address seller,
        uint256 amount
     );
     
     event Price(
         
         uint256 price
         );
    
    
} 

//****************

contract swap5{
    
    uint256 public balance;
    
    function retrieveBalance(address c1) public payable{
        
        Token a = Token(c1);
    
        balance = a.getBalance();
        
        
    }
    
}

After deploying an instance of Token, buying a token, then deploying swap5 and calling retrieveBalance() I return the value 0 rather than 1, which I get from calling getBalance() directly.

Any help would be greatly appreciated :).

database design – Why if a transaction unlock a data item immediately after its final access of that data item, then serializability may not be ensured

The quote below is from Silberschatz’s Database System Concepts. It says if a transaction unlock a data item immediately after its final access of that data item, serializability may not be
ensured. Can you please explain why serializability may not be ensured?

Transaction Ti may unlock a data item that it had locked at some earlier point.
Note that a transaction must hold a lock on a data item as long as it accesses that
item. Moreover, it is not necessarily desirable for a transaction to unlock a data item
immediately after its final access of that data item, since serializability may not be
ensured.

dns – Moved webhosting and cannot access website from my laptop but i can with other devices?

There are several settings on your laptop that could be preventing you from connecting to your new website.

Delete from /etc/hosts

The most obvious choice might be an entry in your /etc/hosts or (hosts.txt on Windows). You might have created an entry that pointed your laptop to the IP address of your old website for testing purposes. Remove any line that has your website domain name from the file and try again.

Use ping

Next I would open a command line and ensure that when you ping your website you get the expected IP address:

$ ping example.com
PING example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=1 ttl=59 time=19.3ms

Is the reported IP address the IP address of your old or your new website? If it is the old site, check your /etc/hosts file again. It could also be a local DNS server that you are running.

Use dig

Another command line tool I find useful is dig. It will query your DNS server (bypassing /etc/hosts). Using it you can get an idea if the problem is local or with your DNS server. It will also report the IP address of the DNS server that it uses so you can check that it is what you expect as well.

$ dig example.com
...
;; ANSWER SECTION:
example.com.        6419    IN  A   93.184.216.34
...
;; SERVER: 127.0.1.1#53(127.0.1.1)

Check:

  • Your website IP address (93.184.216.34 for example.com in this case)
  • Your DNS server (127.0.1.1 for me)
  • The TTL on your domain (6419 seconds in this case)

DNS time to live (TTL)

If dig reports that the IP address is incorrect from your DNS server, it could be because DNS has not yet propagated. Dig will tell you how many seconds you have to wait before it refreshes.

You can test that your DNS server is returning the correct results by querying it directly. First look up the name server and then use that information to query the nameserver directly

$ dig NS example.com
...
;; ANSWER SECTION:
example.com.        2333    IN  NS  a.iana-servers.net.

$ dig @a.iana-servers.net example.com
...    
;; ANSWER SECTION:
example.com.        86400   IN  A   93.184.216.34

Add to /etc/hosts

If you can’t figure out why the IP address on the command line is your old one, you can work around by adding a line to your /etc/hosts file with the new correct IP:

93.184.216.34 example.com

Browser Plugins

If everything on the command line is correct, it could be an issue with your browser. Try using a different browser. Try starting your web browser in safe mode with all plugins disabled.

Proxy Settings

Check your web browser setting and ensure that you don’t have a proxy set. Using a proxy server (or an auto proxy configuration (PAC) file) could be causing the problem.

Cant access the site after I made a clone of Magento 2.3.5-p1 Instance using AMI on EC2

I would be really grateful if you can give me a solution to this.

  1. My main website is working fine on a custom domain "www.example.com". I made a clone of this using AMI and created a new instance on AWS.
  2. Now on the new instance(cloned) I cannot access the website I tried changing the base url to IP of the new instance and also to the localhost:8080. None of them appear to be working.
  3. I did run cache:flush and access rights to various directory (html,var,app,etc,pub,generated) non seems to be working

Please help, your input will be highly appreciated.

Regards.

Upload to Sharepoint without direct access

I want to upload to our Sharepoint site from a remote desktop server. The RDP doesn’t have a direction connection/access. Can this be done? Is there a workaround people have tried?

bitcoin core – If bitcoincore.org goes down how can I access it? What can I do to help others access it?

Wladimir van der Laan answered this on Mastodon.

if you want to help, make mirrors (can we do something like “deterministic verifiable builds for websites”?), host the files, seed the torrents

Is there a more robust way to create a mirror exist now, other than wget -mkxKE -e robots=off https://bitcoincore.org?

Yes wget seems suboptimal. The robust way is to clone the website off github (git@github.com:bitcoin-core/bitcoincore.org.git), so that you have a copy of the source code as well, then you can build it yourself. That gets all releases and verifies them against their gitian.sigs hashes

However that’s for the website—it won’t give you a copy of the historical release binaries, i’m not sure of a good way to mirror those, maybe best would be to make a script based on https://github.com/bitcoin/bitcoin/blob/master/test/get_previous_releases.py and https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/master/gitian-verify.py

This one might actually be best, it downloads SHA256SUMS.asc for an arbitrary release, verifies the signature, and downloads all the files mentioned in it: https://github.com/bitcoin/bitcoin/tree/master/contrib/verifybinaries

windows 10 – Can’t access sites like pastebin.com

I’m having issues accessing sites like Pastebin.com or The Pirate Bay from my Windows 10 system. The browser just times out. I tried different browsers (Brave, Edge, Chrome, Firefox) and also created a new user profile in Windows – same result.

Other systems in my network have no issues accessing these sites. I’m also able to access these sites from that PC, when I boot Linux on the system.

This shows, that there’s no filtering being done on the router or at the ISP level – else, other systems should also not be able to reach those sites.

Any ideas what I might look for?

[Hostpoco.com]*OpenVZ VPS Hosting + Root / SSH Access + Free Setup + 99 % Uptime,$14.

Hostpoco.com is a  perfect hosting company to get simple, fast, and secure hosting services, that allow you to take your business to the next level.

We offer a wide range of web hosting services from shared hosting, reseller hosting, OpenVZ VPS & Dedicated Servers. We’re committed to providing the highest level of customer support across all of our offerings.

All our VPS hosting service includes control panel installation and setup, full root access, dedicated IP, free RDNS, and free re-installations. Just Sign up and be online within Hour with our instant & free setup!

We offer a 30-day money-back guarantee if you are not 100% satisfied with our service.

VPS Plans

Startup:$14.99 /Monthly

★ 1024 MB Memory
★ 30 GB Raid 10 Storage
★ 2 TB Monthly Traffic
★ 1 IPv4 included
★ Free Setup

Pro:$24.99 /Monthly

★ 2048 MB Memory
★ 60 GB Raid 10 Storage
★ 3 TB Monthly Traffic
★ 1 IPv4 included
★ Free Setup

Premium:$44.99 /Monthly

★ 4096 MB Memory
★ 120 GB Raid 10 Storage
★ 4 TB Monthly Traffic
★ 1 IPv4 included
★ Free Setup

Elite:$84.99 /Monthly

★ 8192 MB Memory
★ 180 GB Raid 10 Storage
★ 8 TB Monthly Traffic
★ 1 IPv4 included
★ Free Setup

BUY NOW:
https://hostpoco.com/cheap-us-vps-hosting.php

For more Hosting plan details, please visit: www.hostpoco.com

In case you have any questions, you can contact our sales department by initiating a chat or by dropping an email to [email protected]

php – Syntax error or access violation: 1066 Not unique table/alias com relacionamento polimórficos no Laravel

Estou quebrando a cabeça a semanas e não consigo resolver este problema.

Estou usando este pacote https://github.com/rappasoft/laravel-livewire-tables para utilizar Datables no Laravel com Livewire.

Tenho os models com os seguintes relacionamentos:

User.php

public function getAdminAttribute()
    {
        return $this->admins->first();
    }

    public function admins()
    {
        return $this->morphedByMany(Admin::class, 'userable');
    }

    public function getCoachAttribute() //permite pegar o $user->coach direto (encapsulamento)
    {
        return $this->coaches->first();
    }

    public function coaches()
    {
        return $this->morphedByMany(Coach::class, 'userable');
    }

    public function getAthleteAttribute()
    {
        return $this->athletes->first();
    }

    public function athletes()
    {
        return $this->morphedByMany(Athlete::class, 'userable');
    }

Athlete.php

public function coach()
    {
        return $this->belongsTo(Coach::class);
    }

    public function getUserAttribute()
    {
        return $this->users->first();
    }

    public function users()
    {
        return $this->morphToMany(User::class, 'userable');
    }

Coach.php

public function athletes()
    {
        return $this->hasMany(Athlete::class);
    }

    public function getUserAttribute()
    {
        return $this->users->first();
    }

    public function users()
    {
        return $this->morphToMany(User::class, 'userable');
    }

E a tabela pivo:

public function up()
    {
        Schema::create('userables', function (Blueprint $table) {
            $table->integer('user_id');
            $table->morphs('userable'); //nullableMorphs
        });
    }

No tabela component do Livewire do pacote:

public function query() : Builder
    {
        return Athlete::with(('coach.users:id,name', 'users:id,name'))->where('company_id', $this->companyId);
    }

    public function columns() : array
    {
        return (
            Column::make('Avatar', 'avatar')
                ->format(function(Athlete $model) {
                    return $this->html('<img class="rounded-circle m-0 avatar-sm-table" src="'. asset("images/users/{$model->user->id}/{$model->user->avatar}") .'" alt="avatar">');
                })
                ->excludeFromExport(),
            Column::make('Nome', 'users.name')
                ->searchable()
                ->sortable(/* aqui é o problema */)
                ->format(function(Athlete $model) {
                    return $this->html($model->user->name);
                }),
            Column::make('Treinador', 'coach.users.name')
                ->searchable()
                //->sortable()
                ->format(function(Athlete $model) {
                    return $this->html($model->coach->user->name);
                }),
                Column::make('Ações', 'actions')
                ->format(function(Athlete $model) {
                    return $this->html(
                        '<a href="'. route('athletes.profile', ('uuid' => $model->uuid)) .'" class="btn btn-outline-info btn-icon m-0 m-0" data-toggle="tooltip" data-trigger="hover" data-original-title="Ver atleta" title="Ver atleta" target="_blank">
                            <i class="nav-icon fas fa-eye font-weight-bold"></i>
                        </a>
                        <a href="#" wire:click.prevent="showConfirmation('. $model->uuid .')" class="btn btn-outline-danger btn-icon m-0 m-0 alert-confirm" data-toggle="tooltip" data-trigger="hover" data-original-title="Desvincular atleta da empresa" title="Desvincular atleta da empresa">
                            <i class="nav-icon fas fa-user-times font-weight-bold"></i>
                        </a>'
                    );
                })
                ->excludeFromExport(),
        );
    }

O erro retornado é esse:

IlluminateDatabaseQueryException
SQLSTATE(42000): Syntax error or access violation: 1066 Not unique table/alias: 'users' (SQL: select count(*) as aggregate from `athletes` left join `userables` on `userables`.`userable_id` = `athletes`.`id` left join `users` on `userables`.`user_id` = `users`.`id` left join `users` on `userables`.`user_id` = `users`.`id` where `company_id` = 1)

Deveria ter como criar um Alias?, mas acontece que o pacote faz isso automaticamente (estes joins) e não entendi como contornar.
Já tentei inúmeras coisas e não da certo,

Inclusive no trecho comentado ali aqui é o problema, no git do pacote, eles dizem para quando precisar contornar algo diferente no sortable(), para fazer ali dentro usando o Builder. No caso eu tentei fazer isso:

Column::make('Nome', 'users.name')
                ->searchable()
                ->sortable(function ($builder, $direction) {
                    return $builder->join('userables', 'athletes.id', '=', 'userables.userable_id')
                                ->join('users', 'users.id', '=', 'userables.user_id')
                                ->where('userables.userable_type', '=', Athlete::class)
                                ->orderBy('users.name', $direction);
                } )
                ->format(function(Athlete $model) {
                    return $this->html($model->user->name);
                })

Assim não acontece nenhum erro, mas não ordena corretamente pelos nomes.

Alguém consegue me ajudar nisso?